TCP read improvements

properly handle lines split across two reads
drop connections when I/O errors occur
reduce number of calls to select(2)