Author |
Message |
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: 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? _________________ 4,691 irradiated haggis! |
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:25 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: 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 |
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: 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? |
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: 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. |
|
Back to top |
|
|
Mine GO BOOM Hunch Hunch What What
Age:40 Gender: Joined: Aug 01 2002 Posts: 3614 Location: Las Vegas Offline
|
Posted: 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? |
|
Back to top |
|
|
|