Skip to main content
gamedev.net
🔒 Locked

Winsock2

Started by Zoot Oct 18, 2003 at 4:01 PM 1 replies 1k views
Original Post
Zoot
Zoot
Hi I wana increase the send buffer, for a non-blocking socket. Since it fails if i send a lot of data. It works if I add some "sleeps". It works fine in blocked mode. I use this code to make my socket non-blocked:
bool true_value = true;
setsockopt(m_sockSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &true_value, sizeof (true_value));
ioctlsocket(m_sockSocket, FIONBIO, (unsigned long *)&true_value);
 
[edited by - zoot on October 18, 2003 5:05:52 PM]
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
Zoot
Zoot
I get this error: WSAEWOULDBLOCK
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
jermz
jermz
You are seeing the normal behaviour of non-blocking sockets. Although its possible to modify the send/receive buffer size via setsockopt() and SO_SNDBUF/SO_RCVBUF, that will only delay the onset of your problems. You need to use non-blocking sockets correctly.

When you send some data via TCP, you are asking the networking system to transport that data reliably and ensure the receiver gets an exact copy. This takes time; time to send and more if you need to resend or problems occur. If you are in blocking mode, your threads execution will halt until that data is successfully transfered. If you are in non-blocking mode, you tell the network system to transfer the data when it gets the chance but give you back immediate control for your thread. It takes time to send that data and if you are continually pushing more data, the waiting buffer will fill up. This is what gives you your WSAEWOULDBLOCK error.

With non-blocking sockets, you will need to allow some time for the transfer data and between your requests to send more data. You will be able to execute other things though during that time such as logic, ai, etc, and this can be a big benefit of non-blocking over blocking. You will need to tune your data amount so you can reasonably expect to one transfer to be finished before you send more. Otherwise a backlog will continually build up and cause havoc with your timings. You also need to handle the WOULDBLOCK error by doing your own buffering of the send data.

If you are trying to transfer a large amount of data as fast as possible, blocking is usually faster than non-blocking sockets.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.