Server Help

Non-Subspace Related Coding - TCP help

Mr Ekted - Fri Mar 17, 2006 3:15 am
Post subject: TCP help
I'm playing around with some non-SS stuff. It's been so long since I did anything with TCP. I create a socket, make it non-blocking, and connect...

socket()
ioctlsocket()
connect()

At this point connect returns WSAEWOULDBLOCK. Fine. Now I seem to remember being able to ONLY use send()/recv() from this point on, as long as I am careful with the return values. However, I find that if I perform a test to a non-listening server, that I simply get WSAENOTCONN forever. I can't find any documentation that clarifies if this error state is pre-connection, post-connection, or both. I would expect recv() to eventually cause a WSAETIMEDOUT or WSAECONNRESET error, but I never see it, even when the other end aborts the connection.

Any thoughts?
Bak - Fri Mar 17, 2006 5:45 am
Post subject:
i'd use select with a 0 second timeout and check the return value of send or recv for disconnect as usual
Mr Ekted - Fri Mar 17, 2006 1:56 pm
Post subject:
According to documentation on select()...

read check tells: Connection has been closed/reset/terminated

write check tells: If processing a connect call (nonblocking), connection has succeeded

exception check tells: If processing a connect call (nonblocking), connection attempt failed

But, for example, if the connection has failed, why wouldn't send() or recv() give me that same information? Why should I have to make 3 other checks to see the state of the connection?
Cyan~Fire - Fri Mar 17, 2006 10:05 pm
Post subject:
I think WSAENOTCONN is both pre- and post-connection. Since it's a connection-oriented protocol, then it makes perfect sense to me to have send() or recv() just produce WSAENOTCONN. Obviously connect() failed (as expected), so you'll have to check its return value before trying any other operations.
Mr Ekted - Fri Mar 17, 2006 11:04 pm
Post subject:
I set the socket non-blocking. connect() always fails with WSAEWOULDBLOCK. It sucks that I am forced to use the completely gay function select(), when recv() and send() should be perfectly able to return the socket state.
Mine GO BOOM - Sat Mar 18, 2006 1:22 am
Post subject:
I might be missing something, but couldn't you set the socket to non-blocking after you connect?
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group