Valhalla Legends Forums Archive | General Programming | select(), sockets, and writefds...

AuthorMessageTime
iago
I was wondering if it's ever possible for sockets to block writing.  When implement select(), waiting to send packets is really annoying, since I don't normally wait on writefds, I have to adds it to a queue, set a flag, wake up the select() call, and tell it to wait for writing.  Is this necessary for sockets? Or is that only designed for other select() uses?

Thanks
January 6, 2006, 6:21 PM
Skywing
Yes, sockets will block on send() if the underlying send buffer is filled and the socket is operating in blocking mode.  As far as I know, there is no standard way to make sockets block on send and not recv.

If you are targetting Win32, I strongly recommend that you use overlapped I/O instead of conventional, BSD-compatible socket APIs.
January 6, 2006, 6:54 PM
iago
I'm targetting Linux, actually, so I'm using the BSD interface. 

Thanks for the response, though, I'll find a way to implement it properly!
January 6, 2006, 7:02 PM
Skywing
[quote author=iago link=topic=13810.msg140832#msg140832 date=1136574170]
I'm targetting Linux, actually, so I'm using the BSD interface. 

Thanks for the response, though, I'll find a way to implement it properly!

[/quote]

I would recommend just building a queue of send requests and then transferring as much of them as you can at once with an iovec send when writing is reenabled on the socket.
January 6, 2006, 7:09 PM

Search