Skip to content Skip to sidebar Skip to footer

Scatter/gather Socket Write In Python

In POSIX C we can use writev to write multiple arrays at once to a file descriptor. This is useful when you have to concatenate multiple buffers in order to form a single message t

Solution 1:

There is in the upcoming Python 3.3, now in alpha testing. See socket.sendmsg.

Solution 2:

  1. Python supports os.writev() as well as sendmsg(). These functions are atomic, so are equivalent of calling write() and send() respectively with concatenated buffer.

  2. There is TCP_CORK. You may say kernel not to send partial frames until un-corked.

Using either technique, you may have control over partial TCP frames.

Post a Comment for "Scatter/gather Socket Write In Python"