buglwIP - A Lightweight TCP/IP stack - Bugs: bug #28853, recv() returns 0 on receive...

 
 

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

bug #28853: recv() returns 0 on receive time-out / any netconn_recv() error

Submitted by:  Stephane Lesage <slesage>
Submitted on:  Tue 09 Feb 2010 06:15:52 PM UTC  
 
Category: sockets/netconnSeverity: 3 - Normal
Item Group: Faulty BehaviourStatus: Fixed
Privacy: PublicAssigned to: Simon Goldschmidt <goldsimon>
Open/Closed: ClosedPlanned Release: None
lwIP version: CVS Head

Tue 09 Feb 2010 08:18:39 PM UTC, comment #3:

> actually my patch is wrong because it returns -1 on close.


I just noticed that, too when writing a test for it. Seems I have been too fast checking in the fix ;-)

> on receive time-out, netconn_recv() returns ERR_TIMEOUT (which is a fatal error !)


It's not (any more? I think I changed that some time ago...). I've fixed err_to_errno_table to convert ERR_TIMEOUT to EWOULDBLOCK. Thanks for finding that, too!

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Tue 09 Feb 2010 06:48:29 PM UTC, comment #2:

Re,

actually my patch is wrong because it returns -1 on close.
this is better:

diff -u -r1.147 sockets.c
--- sockets.c 8 Feb 2010 17:25:57 -0000 1.147
+++ sockets.c 9 Feb 2010 18:42:15 -0000
@@ -544,7 +544,7 @@
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL, error is \"%s\"!\n",
s, lwip_strerr(err)));
sock_set_errno(sock, err_to_errno(err));
- return 0;
+ return (err == ERR_CLSD) ? 0 : -1;
}
LWIP_ASSERT("buf != NULL", buf != NULL);
sock->lastdata = buf;

BTW, on receive time-out, netconn_recv() returns ERR_TIMEOUT (which is a fatal error !) and translates as ETIMEDOUT in socket domain, which is wrong:

"If a receive operation has blocked for this much time without receiving additional data, it shall return with a partial count or errno set to [EAGAIN] or [EWOULDBLOCK] if no data is received."

http://www.opengroup.org/onlinepubs/000095399/functions/setsockopt.html

Stephane Lesage <slesage>
Tue 09 Feb 2010 06:48:04 PM UTC, comment #1:

Fixed, thanks for reporting. It's been in there quite long but has been hidden by the fact that netconn_recv didn't return an error on timeout.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Tue 09 Feb 2010 06:15:52 PM UTC, original submission:

Hi,

read() and recv() should return error=-1 on receive time-out with socket error EWOULDBLOCK.

actually the bug also returns 0 on any netconn_recv() error.

diff -u -r1.147 sockets.c
--- sockets.c 8 Feb 2010 17:25:57 -0000 1.147
+++ sockets.c 9 Feb 2010 18:10:10 -0000
@@ -544,7 +544,7 @@
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL, error is \"%s\"!\n",
s, lwip_strerr(err)));
sock_set_errno(sock, err_to_errno(err));
- return 0;
+ return -1;
}
LWIP_ASSERT("buf != NULL", buf != NULL);
sock->lastdata = buf;

Stephane Lesage <slesage>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 09 Feb 2010 06:48:04 PM UTCgoldsimonItem GroupNone=>Faulty Behaviour
      StatusNone=>Fixed
      Assigned toNone=>goldsimon
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1