check the fucking buffer BEFORE trying to read to avoid spurious closed
socket errors.