buglwIP - A Lightweight TCP/IP stack - Bugs: bug #51505, select and sock->rcvevent

 
 

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

bug #51505: select and sock->rcvevent

Submitter:  Oleg Tyshev <olegreen>
Submitted:  Wed 19 Jul 2017 10:18:01 AM UTC
   
 
Category:  sockets/netconn Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  Invalid
Privacy:  Public Assigned to:  jcunningham
Open/Closed:  Closed Planned Release:  None
lwIP version:  git head

Wed 19 Jul 2017 05:25:17 PM UTC, comment #2: 

No, I don't have running pure lwip stack.
I have tried to review socket layer.

You are right, the code will work without any error.
At first I thought that error can happen wenn chain of pbuf will be inserted into recv mbox,
but with lastdata variable this case processed correctly too.

Joel, please, close this issue.

Oleg Tyshev <olegreen>
Wed 19 Jul 2017 02:08:48 PM UTC, comment #1: 

Did you find an issue through testing or was this looking at the code?

The rcvevent is not a byte counter but instead is incremented/decremented for each pbuf stored in the netconn's recvmbox.

> lwip_selscan() code has patch trying to fix this behaviour -
> it is checked not only rcvevent, but lastdata too:
> ((lastdata != NULL) || (sock->rcvevent > 0))


lastdata is used to track a pbuf that was received from the netconn layer but not fully consumed by the caller of recv().  So if the last pbuf from recvmbox is only partially read, rcvevent will be at 0, but lastdata will be non-NULL and select should return the socket as readable.

> recv() to receive 100 bytes called:
> 100 bytes received
> sock->rcvevent is 99,


I think this part is incorrect.  Each 1-byte pbuf will be received by the socket layer from the netconn recvmbox via netconn_recv_data().  When that happens, API_EVENT(conn, NETCONN_EVT_RCVMINUS, len); is called for each 1 byte pbuf


Joel Cunningham <jcunningham>
Group Member
Wed 19 Jul 2017 10:18:01 AM UTC, original submission:  

select and sock->rcvevent

With receive of each data portion will be

recv_tcp() callback function called.
  API_EVENT(conn, NETCONN_EVT_RCVPLUS, len);

API_EVENT(conn, NETCONN_EVT_RCVPLUS, len) is expanded to event_callback()
  and hier will be following code executed:
    sock->rcvevent++;

It doesn't matter how many data is received:
   NETCONN_EVT_RCVPLUS  -> sock->rcvevent++
   NETCONN_EVT_RCVMINUS -> sock->rcvevent--


The comment in lwip_selscan "/* ... then examine it: */"
say that code should be reworked

lwip_selscan() code has patch trying to fix this behaviour -
it is checked not only rcvevent, but lastdata too:
((lastdata != NULL) || (sock->rcvevent > 0))


Error scenario:
  100 times 1-byte packet recieved:
    sock->rcvevent is 100,

  recv() to receive 100 bytes called:
     100 bytes received
     sock->rcvevent is 99,

  select after that returns 99 times readset active, but socket has no data and recv() returns EWOULDBLOCK
  It is not correct.
  After recv() sock->rcvevent should be 0

Oleg Tyshev <olegreen>

 

(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 jcunningham (Posted a comment)
  • -email is unavailable- added by olegreen (Submitted the item)
  •  

    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
    2017-07-19 jcunningham StatusNone Invalid
        Assigned toNone jcunningham
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code