Unexpected behaviour on socket
Daniel Murphy
yebbliesnospam at gmail.com
Tue Feb 9 23:19:22 PST 2010
Gythzel Wrote:
> (relating code at http://dpaste.com/156595/ on D2)
>
> This is a very trimmed version of something I'm experimenting with, so the design of the code is not the issue. The problem is what happens on the "accepter" function.
>
> After the Socket.select returns 1 (meaning, 1 socket has its state changed) I do a .receive on the only socket inside the set and that function returns 0 (meaning connection closed). However, I'm still able to send through that socket and the socketset keeps saying the socket is ready, although everytime I do a .recieve on it, 0 bytes are read. I used PuTTY to test this program (to open a connection) and even though I didn't close the connection the program keeps saying it was remotely closed (.receive==0). Also, isAlive() of this socket returns true.
>
> Am I doing something wrong?
>
> This program is similar to listener.d on the samples dir of the compiler, however, that sample works without a problem (after sorting D2 stuff on that file, see http://d.puremagic.com/issues/show_bug.cgi?id=2000).
The buffer you are passing to receive is 0 bytes long. The std.socket.Socket.receive function is a wrapper over the normal socket function, and includes a test for an empty buffer.
Daniel
More information about the Digitalmars-d-learn
mailing list