× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.