Bug 365

Summary: TcpSocketImpl::Recv returns 0 without setting m_errno
Product: ns-3 Reporter: Mathieu Lacage <mathieu.lacage>
Component: internetAssignee: Rajib Bhattacharjea <raj.b>
Status: RESOLVED FIXED    
Severity: normal CC: craigdo, gjcarneiro, ns-bugs, raj.b
Priority: P1    
Version: pre-release   
Hardware: All   
OS: All   
Attachments: untested fix
tested fix

Description Mathieu Lacage 2008-09-23 16:51:19 EDT
it should return 0 _and_ set errno to ERROR_AGAIN
Comment 1 Mathieu Lacage 2008-09-23 16:53:24 EDT
same for NscTcpSocketImpl::Recv
Comment 2 Mathieu Lacage 2008-09-23 17:01:54 EDT
as florian pointed out, that whole API is problematic for EOF. 0 is a valid return value which does not indicate error so, we can't use it to indicate error.

options:
  - add ERROR_EOF
  - return -1 
  - change the Ptr<Packet> return value to int

all are pretty ugly :/
Comment 3 Mathieu Lacage 2008-09-23 17:16:33 EDT
another option to represent EOF would be to return a zero-sized packet. That is not less ugly than the other options.
Comment 4 Gustavo J. A. M. Carneiro 2008-09-24 07:19:41 EDT
How about returning a NULL "pointer" (Ptr<Packet> ()) on error?

Ptr<Packet> p = socket->Recv ();
if (!p)
{
  // check socket->GetErrno ();
}
Comment 5 Mathieu Lacage 2008-09-24 11:43:12 EDT
(In reply to comment #4)
> How about returning a NULL "pointer" (Ptr<Packet> ()) on error?
> 
> Ptr<Packet> p = socket->Recv ();
> if (!p)
> {
>   // check socket->GetErrno ();
> }


yes, we already do this. The question is: how do you handle EOF ?

Comment 6 Rajib Bhattacharjea 2008-11-06 16:48:36 EST
As an update, the last thing we agreed on during the last IRC chat was:
 - Recv returns the pointer 0 if the connection is still open, but there is no data to read
 - Recv returns a pointer to an empty Packet if there is no data to read and the connection has closed (the EOF case)
Comment 7 Rajib Bhattacharjea 2008-11-06 16:57:10 EST
Created attachment 291 [details]
untested fix
Comment 8 Rajib Bhattacharjea 2008-12-11 14:23:49 EST
Created attachment 333 [details]
tested fix
Comment 9 Rajib Bhattacharjea 2008-12-11 23:47:19 EST
changeset
4014:b6349d9c007e