Bug 365 - TcpSocketImpl::Recv returns 0 without setting m_errno
TcpSocketImpl::Recv returns 0 without setting m_errno
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: internet
pre-release
All All
: P1 normal
Assigned To: Rajib Bhattacharjea
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-09-23 16:51 EDT by Mathieu Lacage
Modified: 2008-12-11 23:47 EST (History)
4 users (show)

See Also:


Attachments
untested fix (502 bytes, patch)
2008-11-06 16:57 EST, Rajib Bhattacharjea
Details | Diff
tested fix (1.34 KB, patch)
2008-12-11 14:23 EST, Rajib Bhattacharjea
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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