According to the docs (http://www.cplusplus.com/reference/iostream/istream/readsome/) readsome would also set state flag eofbit, but apparently I'm misinterpreting it. Anyway, using read() and then gcount() to get the number of bytes does work.