> There should be no problems with opening a socket (udp or tcp) from a
> 3rd party plugin. The only thing to worry about is blocking for too long
> when reading from the socket (and potentially writing). Make sure the
> socket is non-blocking and do a zero time select() to poll the socket
> for data to read.

Once you've set your socket up to non-blocking mode, like Alfred said, be
REAL careful about reading and writing data.

For normal blocking socket operations, you can write a huge block of data
and the OS will suspend your process until it has completely written all of
the data.  For non-blocking socket operations, you MUST check the return
values of the write function to see how much data was written.  It might be
less than the size that you passed into the write function.  This is your
indication that the OS can't shove any more data into the pipe right now and
you should try sending the rest of the data again in a little while (perhaps
during the next frame?).  The point is that you can't just assume that all
of the data will be written to the socket when you tell it to.

The same goes for reading.  You might request 1000 bytes, but you might only
get back 200.  You'll need to read again later to complete that read
operation.

This all mostly applies to TCP.  UDP is nastier in that the OS won't buffer
any data for you.  If you don't read it all in one pass, it's gone forever.
I'm not sure what the result would be if you tried to write 1400 bytes to a
UDP packet and the OS was only able to write part of it.  It probably won't
be a problem if you stick to small packets (less than the MTU size of 1400
bytes or so), but it could become a large problem if your packet size is
fairly big.

Jeffrey "botman" Broome

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to