Hi Christopher,
Thanks everyone for the help. It seems that if I do a receive I get
a return value of '0' but when I do a rdline I get a '-1'
This is a quote from the Information Center for the recv() API:
For sockets that use a connection-oriented transport service (for
example, sockets with a type of SOCK_STREAM), a returned value of zero
indicates one of the following:
* The partner program has issued a close() for the socket.
* The partner program has issued a shutdown() to disable
writing to the socket.
* The connection is broken and the error was returned on a
previously issued socket function.
* A shutdown() to disable reading was previously done on
the socket.
You have the code for rdline. Here's the part in question:
** read 1 byte:
c eval rc = recv(peSock: %addr(ch): 1: 0)
c if rc < 1
c if wwLen > 0
c leave
c else
c return -1
c endif
c endif
Think about it. If the recv() API returns a bunch of data (a "record"),
and then the remote side disconnects it's socket, what will happen?
The code will read all of the data from the remote side, adding each one
to the buffer. When the remote site disconnects, recv() will return -1.
The code, above, will have wwLen>0 (since it already added data to the
buffer) so it'll LEAVE, ultimately returning the length of data you
received.
When you call it again, since the error was returned on a previous call
to recv(), recv() will return 0. This will cause rdline() to return -1
-- which, in my opinion, is what it SHOULD do, since -1 indicates an
error -- and since there was a previous error, this seems correct to me...
If recv() is returning 0 when the remote side HASN'T disconnected or
disabled writing (assuming that you haven't called shutdown() to disable
reading) then I'd say that it's a bug in i5/OS. But, more likely, the
other side has finished sending data to you and has disconnected.
As an Amazon Associate we earn from qualifying purchases.