sock.setblocking(0)
return sock.send(data)
except socket.error as e:
- if e.errno == errno.EAGAIN or e.errno == errno.EWOULDBLOCK:
+ if e.errno in [ errno.EAGAIN,
+ errno.EWOULDBLOCK,
+ errno.EINTR ]:
return 0
else:
raise e
try:
amount_sent = self.__send_data(sock, msg)
except socket.error as sockerr:
- # in the case the other side seems gone, kill the socket
- # and drop the send action
- if sockerr.errno == errno.EPIPE:
- print("[b10-msgq] SIGPIPE on send, dropping message " +
- "and closing connection")
+ # in the case the other side seems gone, or unable to handle
+ # life, kill the socket and drop the send action
+ if sockerr.errno in [ errno.EPIPE,
+ errno.ECONNRESET,
+ errno.ENOBUFS
+ ]:
+ print("[b10-msgq] " + errno.errorcode[sockerr.errno] +
+ " on send, dropping message and closing connection")
self.kill_socket(fileno, sock)
return
else:
try:
amount_sent = self.__send_data(sock, msg)
except socket.error as sockerr:
- # in the case the other side seems gone, kill the socket
- # and drop the send action
- if sockerr.errno == errno.EPIPE:
- print("[b10-msgq] SIGPIPE on send, dropping message " +
- "and closing connection")
+ # in the case the other side seems gone, or unable to handle
+ # life, kill the socket and drop the send action
+ if sockerr.errno in [ errno.EPIPE,
+ errno.ECONNRESET,
+ errno.ENOBUFS
+ ]:
+ print("[b10-msgq] " + errno.errorcode[sockerr.errno] +
+ " on send, dropping message and closing connection")
self.kill_socket(fileno, sock)
return
else:
write.close()
read.close()
- def test_send_raise_eagain(self):
+ def test_send_raise_recoverable(self):
"""
- Test whether msgq survices an EAGAIN socket error when sending.
- Two tests are done: one where EAGAIN is raised on the 3rd octet,
+ Test whether msgq survices a recoverable socket errors when sending.
+ Two tests are done: one where the error is raised on the 3rd octet,
and one on the 23rd.
"""
sockerr = socket.error
- sockerr.errno = errno.EAGAIN
- self.do_send_with_send_error(3, sockerr)
- self.do_send_with_send_error(23, sockerr)
+ for err in [ errno.EAGAIN, errno.EWOULDBLOCK, errno.EINTR ]:
+ sockerr.errno = err
+ self.do_send_with_send_error(3, sockerr)
+ self.do_send_with_send_error(23, sockerr)
- def test_send_raise_ewouldblock(self):
+ def test_send_raise_nonrecoverable(self):
"""
- Test whether msgq survices an EWOULDBLOCK socket error when sending.
- Two tests are done: one where EWOULDBLOCK is raised on the 3rd octet,
+ Test whether msgq survives socket errors that are nonrecoverable
+ (for said socket that is, i.e. EPIPE etc).
+ Two tests are done: one where the error is raised on the 3rd octet,
and one on the 23rd.
"""
sockerr = socket.error
- sockerr.errno = errno.EWOULDBLOCK
- self.do_send_with_send_error(3, sockerr)
- self.do_send_with_send_error(23, sockerr)
+ for err in [ errno.EPIPE, errno.ENOBUFS, errno.ECONNRESET ]:
+ sockerr.errno = err
+ self.do_send_with_send_error(3, sockerr, False)
+ self.do_send_with_send_error(23, sockerr, False)
- def test_send_raise_pipe(self):
- """
- Test whether msgq survices an EPIPE socket error when sending.
- Two tests are done: one where EPIPE is raised on the 3rd octet,
- and one on the 23rd.
- """
- sockerr = socket.error
- sockerr.errno = errno.EPIPE
- self.do_send_with_send_error(3, sockerr, False)
- self.do_send_with_send_error(23, sockerr, False)
-
- def test_send_raise_exception(self):
+ def otest_send_raise_crash(self):
"""
Test whether msgq does NOT survive on a general exception.
Note, perhaps it should; but we'd have to first discuss and decide