metajack / libstrophe

The libstrophe repository has moved to https://github.com/strophe/libstrophe
http://strophe.im/libstrophe
Other
135 stars 49 forks source link

Fixed sock_read bug when returning 0 values on Windows. #39

Closed luiscuriel closed 11 years ago

luiscuriel commented 11 years ago

On windows, sock_read returns 0 when an error reading occurs.

metajack commented 11 years ago

Everything I can find in the windows documentation says that -1 should be returned on error. Can you find any documentation on this returning zero instead?

It definitely seems weird that there would be ready data but recv() would return 0.

luiscuriel commented 11 years ago

Hi Jack,

from the code:

int sock_read(const sock_t sock, void * const buff, const size_t len) { return recv(sock, buff, len, 0); }

Recv on msdn:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx

It says:

If the connection has been gracefully closed, the return value is zero.

So the problem is that it was not being detected when the connection was closed by the server, for example restarting our xmpp server (ejabberd), and the libstrophe client remained connected all the time.

Let me know if you need more info.

Best Regards, Luis.