This software is owned by The university of California, Irvine,
and is not distributed under
any version of the GPL. GPL is a fine series of licenses, but the owners of the software need it to be distributed under these terms.
bufsock.py is a python module that makes it a little bit easier to work
with sockets, and may also make your I/O faster if you're reading and/or
writing lots of tiny packets.
Also, you may find that it makes your
network applications more reliable, as the network is allowed to split
apart your packets into multiple smaller packets, or aggregate two or
more packets into one larger packet, if it decides it needs to do so for
reliability or performance. So you might do a s.recv expecting to get
one line of input, but the network decided to batch together two remote
s.send's into one s.recv, for example. But the network
usually, but not always, will batch up your packets the way
you'd expect - so this can be a difficult problem to track down.
read(length) brings in a specific number of bytes.
readto(char) reads up thru the next occurence of char
readtomax(char,length) reads up thru the next occurence of char, or
length bytes, whichever is less
set_chunk_len(length) says "do reads and writes in increments of length".
The chunk length defaults to 4096. You should make this larger on
networks that employ jumbo frames to squeeze out more performance!
send(buf) writes the bytes in buf.
flush() is just like stdio's (the C library's) flush function.
Call it when you want an output buffer flushed (written immediately).
shutdown(v) just like for a regular socket, except it flushes
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
bs = bufsock.bufsock(sock)
version = bs.readto('\n')
Or alternatively, you might examine the entire application from
which this code was clipped: fallback-reboot. The
"fallback-reboot-client" portion of fallback-reboot utilizes
bufsock to make its job easier.