buglwIP - A Lightweight TCP/IP stack - Bugs: bug #55875, select() malfunction with C++...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #55875: select() malfunction with C++ compiler

Submitter:  Jian Jiao <jj8431>
Submitted:  Sun 10 Mar 2019 06:28:33 AM UTC
   
 
Category:  sockets/netconn Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Closed Planned Release:  None
lwIP version:  2.0.3

Mon 11 Mar 2019 07:00:05 PM UTC, comment #1: 

Sorry, this is not a bug in lwIP. If it doesn't work when compiling with your C++ compiler, you're probably doing something wrong.

I'd suspect you're mixing up includes and when compiling with the C++ compiler, the fd_set type probably looks different how what lwIP defines it...

Simon Goldschmidt <goldsimon>
Group administrator
Sun 10 Mar 2019 06:28:33 AM UTC, original submission:  

I'm using esp-open-rtos which has Lwip 2.03

Trying to use c++ compiler but fund very strange behaviour of select() .

part of the original c++ code is : (where mysock is a private member of the IPStack class)
int IPStack::ip_read (unsigned char* buffer, int len, int timeout_ms)
{
struct timeval tv;
fd_set fdset;
int rc = 0;
int rcvd = 0;
FD_ZERO(&fdset);
FD_SET(mysock, &fdset);
tv.tv_sec = timeout_ms/1000;
tv.tv_usec = (timeout_ms % 1000)*1000;
rc = select(mysock+1, &fdset, 0, 0, &tv);

I found the select and not return when there's data received, and if the select() is used for sending , you can not send either because select() doesn't return. It only returns when the timeout is reached.

It works if I put the same code in a c file and call the function from c++

c code:
int esp_read(int mysock, unsigned char* buffer, int len, int timeout_ms)
{
struct timeval tv;
fd_set fdset;
int rc = 0;
int rcvd = 0;
FD_ZERO(&fdset);
FD_SET(mysock, &fdset);
tv.tv_sec = timeout_ms/1000;
tv.tv_usec = (timeout_ms % 1000)*1000;
rc = select(mysock+1, &fdset, 0, 0, &tv);
if ((rc>0) && (FD_ISSET(mysock, &fdset)))
{
rcvd = recv(mysock, buffer, len, 0);
}
else
{
return -1;
}
return rcvd;
}

c++ code:
int IPStack::ip_read (unsigned char* buffer, int len, int timeout_ms)
{
int rc = esp_read(mysock, buffer, len, timeout_ms);
return rc;
}

In this way the select() can return if there is data received. But there's another problem, that when the select() returns from timeout, the return code is not '0', it returns '-1', but if you check the 'errno', the errno is 0.

I don't know if this is a bug in Lwip or something else, I'd just report it and hope it can be fixed.

Jian Jiao <jj8431>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by jj8431 (Submitted the item)
  • -email is unavailable- added by jj8431
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-11 goldsimon StatusNone Invalid
        Open/ClosedOpen Closed
    2019-03-10 jj8431 Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code