== A common socket programming mistake: not handling short IO With normal file IO, when you do do '_read(fd, buf, len)_' you'll almost always get back _len_ bytes unless you hit EOF or a disk IO error. This breeds a certain sloppyness when filling buffers; an awful lot of code effectively ignores the return value of _read()_ except to check it for errors. This can and will bite you on the rear when writing socket code, because networks only give you so much data at once. Short reads are *routine* for socket IO; you can't assume that you can get all of what you want in a single read. The mistake is especially pernicious because the mistaken code almost always works. Usually the lines or transactions you're reading from the network are small; usually you test on a fast local network. Speaking from personal experience, it's easy to forget this and then not notice. (Today's case was some of my code that assumed it could read all of a HTTP _POST_ body in one _read()_.) Whether or not a normal (blocking) _write()_ has similar issues is probably system dependent. Linux seems to only return from a socket _write()_ once all data has been pushed out, but I don't know what other systems do in practice. (According to the [[Single Unix Specification http://www.opengroup.org/onlinepubs/009695399/]] page for _[[write() http://www.opengroup.org/onlinepubs/009695399/functions/write.html]]_, in theory you can count on this behavior on any SuS compliant system.)