Fix a race in socket code

Merged Witold Krecicki requested to merge 874-fix-race-in-socket-code into master

Fix a race in socket code when internal_{accept, send, receive} is called from event loop on an socket and, in the meantime, someone has closed this socket.

Closes #874 (closed)

Merge request reports