Page 2 of 2

Re: Puzzled by ReceiveNetworkData().

Posted: Wed Feb 24, 2010 8:05 pm
by idle
You may be looking for a #WSAECONNABORTED

If the connection gets dropped during a send or recieve this error will be reported as a -1 on the send or receive and you have to look up the last error, for windows a call to WSAGetLastError_() and in linux you just look at errno (if there's a way in PB way to read the current processes errno in linux) the error constants are more of less the same for compatibility with Berkley sockets.

Creating a thread per connection and using semaphores is the a reasonable compromise, even if you're transferring small amounts of data, the cost of a signal is minimal compared to spawning a thread per receive, though that may be appropriate if you're only dealing with large transfers.

Re: Puzzled by ReceiveNetworkData().

Posted: Wed Feb 24, 2010 8:17 pm
by srod
A good idea using semaphores. Yes, better than my signalling through a connection variable - though admittedly that works fine for my needs. Yes that would avoid the need for a delay as well.

Thanks for the tip Idle. :)

Re: Puzzled by ReceiveNetworkData().

Posted: Wed Feb 24, 2010 8:36 pm
by idle
There's no issues doing that for receive though there are possibly some issues with a send thread as you have to get your data in to the thread and I'm not sure if you could run into any issues there or not.

Re: Puzzled by ReceiveNetworkData().

Posted: Thu Feb 25, 2010 11:21 am
by srod
I am not using individual send/receive threads etc. The server simply spawns a new thread for each individual connection and then sends 'messages' to each thread as appropriate.