Make networking more thread safe.
Reading and writing to a socket should be done only in one thread. If an error
occurs during these two operations an exception is thrown and the socket should
be closed after catching the exception. The socket deletes itself after closing
on a safe place so there is only one safe and single point of deletion. If an
error occurs during polling then a signal is emitted and the socket should be
cosed after receiving that signal. Any pending and undelivered signals are
disabled so that there should be no errors caused by writing to such socket.