Fix error in buffer.c where a closed socket would result in infinite looping.