Allow reading if there is data left in the buffer event socket is closed

Also fixed the bug when writing to a closed socket.