lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #55875] select() malfunction with C++ compiler


From: Jian Jiao
Subject: [lwip-devel] [bug #55875] select() malfunction with C++ compiler
Date: Sun, 10 Mar 2019 01:28:34 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0

URL:
  <https://savannah.nongnu.org/bugs/?55875>

                 Summary: select() malfunction with C++ compiler
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: jj8431
            Submitted on: Sun 10 Mar 2019 06:28:33 AM UTC
                Category: sockets/netconn
                Severity: 3 - Normal
              Item Group: Faulty Behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: 2.0.3

    _______________________________________________________

Details:

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.





    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?55875>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]