High performance IO on non-blocking sockets

Troels Walsted Hansen troels at fast.no
Fri Mar 14 15:22:01 CET 2003

"Richie Hindle" <richie at entrian.com> wrote in message
news:lgm37vsi6631fimchqdivsg5vh713cifaj at 4ax.com...
> From http://www.python.org/doc/current/lib/socket-objects.html :
> 7.2.1 Socket Objects
> sendall( string[, flags])

I should have mentioned that in my original post... sendall() doesn't work
for non-blocking sockets. :(

The good news is that Kjetil Jacobsen came up with the perfect solution for

  send_buffer = buffer(self.data, self.offset)
  sent = self.socket.send(send_buffer)
  self.buffer_offset += sent

No copying, and all writes are as big as the socket buffer can hold. Cost of
allocating a buffer object should be very minor in the grand scheme of

> Nothing springs to mind for the recv case (but the problems are lesser in
> that case).

2*total_recv_size memory consumption is 1*total_recv_size too many. :)

Working on this one...

Troels Walsted Hansen

More information about the Python-list mailing list