我们从Python开源项目中,提取了以下39个代码示例,用于说明如何使用errno.ESHUTDOWN。
def _recv(self, which, maxsize): conn, maxsize = self.get_conn_maxsize(which, maxsize) if conn is None: return None try: x = msvcrt.get_osfhandle(conn.fileno()) (read, nAvail, nMessage) = PeekNamedPipe(x, 0) if maxsize < nAvail: nAvail = maxsize if nAvail > 0: (errCode, read) = ReadFile(x, nAvail, None) except ValueError: return self._close(which) except (subprocess.pywintypes.error, Exception): if geterror()[0] in (109, errno.ESHUTDOWN): return self._close(which) raise if self.universal_newlines: # Translate newlines. For Python 3.x assume read is text. # If bytes then another solution is needed. read = read.replace("\r\n", "\n").replace("\r", "\n") return read
def test_recv(self, tco): pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122')) assert tco.enqueue(pdu) is True assert tco.recv() == pdu threading.Timer(0.01, tco.close).start() with pytest.raises(nfc.llcp.Error) as excinfo: tco.recv() assert excinfo.value.errno == errno.EPIPE with pytest.raises(nfc.llcp.Error) as excinfo: tco.recv() assert excinfo.value.errno == errno.ESHUTDOWN # ============================================================================= # Logical Data Link # =============================================================================
def test_recvfrom(self, tco): pdu = nfc.llcp.pdu.Symmetry() assert tco.enqueue(pdu) is False pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, (tco.recv_miu+1) * b'1') assert tco.enqueue(pdu) is False pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122')) assert tco.enqueue(pdu) is True assert tco.recvfrom() == (pdu.data, pdu.ssap) threading.Timer(0.01, tco.close).start() with pytest.raises(nfc.llcp.Error) as excinfo: tco.recvfrom() assert excinfo.value.errno == errno.EPIPE with pytest.raises(nfc.llcp.Error) as excinfo: tco.recvfrom() assert excinfo.value.errno == errno.ESHUTDOWN # ============================================================================= # Data Link Connection # =============================================================================
def _recv(self, which, maxsize): conn, maxsize = self.get_conn_maxsize(which, maxsize) if conn is None: return None try: x = msvcrt.get_osfhandle(conn.fileno()) (read, nAvail, nMessage) = PeekNamedPipe(x, 0) if maxsize < nAvail: nAvail = maxsize if nAvail > 0: (errCode, read) = ReadFile(x, nAvail, None) except (ValueError, NameError): return self._close(which) except (subprocess.pywintypes.error, Exception), why: if why[0] in (109, errno.ESHUTDOWN): return self._close(which) raise if self.universal_newlines: read = self._translate_newlines(read) return read
def _recv(self, which, maxsize): conn, maxsize = self.get_conn_maxsize(which, maxsize) if conn is None: return None try: x = msvcrt.get_osfhandle(conn.fileno()) (read, nAvail, nMessage) = PeekNamedPipe(x, 0) if maxsize < nAvail: nAvail = maxsize if nAvail > 0: (errCode, read) = ReadFile(x, nAvail, None) except ValueError: return self._close(which) except (subprocess.pywintypes.error, Exception), why: if why[0] in (109, errno.ESHUTDOWN): return self._close(which) raise #if self.universal_newlines: # read = self._translate_newlines(read) return read
def run(self): method = self.__method echo_buf = self.echo_buf run_lock = self.__run_lock while True: run_lock.acquire() check = self.check print(self.name, 'start') while True: try: method(echo_buf) except IOError as exc: if exc.errno == errno.ESHUTDOWN: break if exc.errno not in (errno.EINTR, errno.EAGAIN): raise if check(): self.ep_file.halt() print(self.name, 'exit') run_lock.acquire(False)
def _recv(self, which, maxsize): conn, maxsize = self.get_conn_maxsize(which, maxsize) if conn is None: return None try: x = msvcrt.get_osfhandle(conn.fileno()) (read, nAvail, nMessage) = PeekNamedPipe(x, 0) if maxsize < nAvail: nAvail = maxsize if nAvail > 0: (errCode, read) = ReadFile(x, nAvail, None) except ValueError: return self._close(which) except (subprocess.pywintypes.error, Exception) as why: if why[0] in (109, errno.ESHUTDOWN): return self._close(which) raise if self.universal_newlines: read = self._translate_newlines(read) return read
def send(self, input): if not self.stdin: return None try: x = msvcrt.get_osfhandle(self.stdin.fileno()) (errCode, written) = WriteFile(x, input) except ValueError: return self._close('stdin') except (subprocess.pywintypes.error, Exception): if geterror()[0] in (109, errno.ESHUTDOWN): return self._close('stdin') raise return written
def wait_for(test, timeout=1.0, raise_on_error=True, rate=100, timeout_msg="timeout expired", body=None): """ Waits until some condition evaluates to true. @param test: zero param function to be evaluated @param timeout: max amount of time to wait. negative/inf for indefinitely @param raise_on_error: raise or just return False @param rate: the rate at which to check @param timout_msg: message to supply to the timeout exception @param body: optional function to execute while waiting """ end_time = rospy.get_time() + timeout rate = rospy.Rate(rate) notimeout = (timeout < 0.0) or timeout == float("inf") while not test(): if rospy.is_shutdown(): if raise_on_error: raise OSError(errno.ESHUTDOWN, "ROS Shutdown") return False elif (not notimeout) and (rospy.get_time() >= end_time): if raise_on_error: raise OSError(errno.ETIMEDOUT, timeout_msg) return False if callable(body): body() rate.sleep() return True
def test_sockopt(self, tco): assert tco.getsockopt(nfc.llcp.SO_RCVBUF) == 1 tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) assert tco.getsockopt(nfc.llcp.SO_RCVBUF) == 2 tco.close() with pytest.raises(nfc.llcp.Error) as excinfo: tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) assert excinfo.value.errno == errno.ESHUTDOWN with pytest.raises(nfc.llcp.Error) as excinfo: tco.getsockopt(nfc.llcp.SO_RCVBUF) assert excinfo.value.errno == errno.ESHUTDOWN
def setsockopt(self, option, value): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) super(RawAccessPoint, self).setsockopt(option, value)
def poll(self, event, timeout): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) if event not in ("recv", "send"): raise err.Error(errno.EINVAL) return super(RawAccessPoint, self).poll(event, timeout) is not None
def send(self, send_pdu, flags): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) log.debug("{0} send {1}".format(str(self), send_pdu)) super(RawAccessPoint, self).send(send_pdu, flags) return self.state.ESTABLISHED is True
def recv(self): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) try: return super(RawAccessPoint, self).recv() except IndexError: raise err.Error(errno.EPIPE)
def setsockopt(self, option, value): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) super(LogicalDataLink, self).setsockopt(option, value)
def getsockopt(self, option): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) return super(LogicalDataLink, self).getsockopt(option)
def poll(self, event, timeout): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) if event not in ("recv", "send"): raise err.Error(errno.EINVAL) return super(LogicalDataLink, self).poll(event, timeout) is not None
def sendto(self, message, dest, flags): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) if self.peer and dest != self.peer: raise err.Error(errno.EDESTADDRREQ) if len(message) > self.send_miu: raise err.Error(errno.EMSGSIZE) send_pdu = pdu.UnnumberedInformation(dest, self.addr, data=message) super(LogicalDataLink, self).send(send_pdu, flags) return self.state.ESTABLISHED is True
def recvfrom(self): if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) try: rcvd_pdu = super(LogicalDataLink, self).recv() except IndexError: raise err.Error(errno.EPIPE) return (rcvd_pdu.data, rcvd_pdu.ssap) if rcvd_pdu else (None, None)
def listen(self, backlog): with self.lock: if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) if not self.state.CLOSED: self.err("listen() but socket state is {0}".format(self.state)) raise err.Error(errno.ENOTSUP) self.state.LISTEN = True self.recv_buf = backlog
def accept(self): with self.lock: if self.state.SHUTDOWN: raise err.Error(errno.ESHUTDOWN) if not self.state.LISTEN: self.err("accept() but socket state is {0}".format(self.state)) raise err.Error(errno.EINVAL) self.recv_buf += 1 try: rcvd_pdu = super(DataLinkConnection, self).recv() except IndexError: raise err.Error(errno.EPIPE) self.recv_buf -= 1 if rcvd_pdu.name == "CONNECT": dlc = DataLinkConnection(self.recv_miu, self.recv_win) dlc.addr = self.addr dlc.peer = rcvd_pdu.ssap dlc.send_miu = rcvd_pdu.miu dlc.send_win = rcvd_pdu.rw send_pdu = pdu.ConnectionComplete(dlc.peer, dlc.addr) send_pdu.miu, send_pdu.rw = dlc.recv_miu, dlc.recv_win log.debug("accepting CONNECT from SAP %d" % dlc.peer) dlc.state.ESTABLISHED = True self.send_queue.append(send_pdu) return dlc else: # pragma: no cover raise RuntimeError("CONNECT expected, not " + rcvd_pdu.name)
def send(self, input): if not self.stdin: return None try: x = msvcrt.get_osfhandle(self.stdin.fileno()) (errCode, written) = WriteFile(x, input) except ValueError: return self._close('stdin') except (subprocess.pywintypes.error, Exception), why: if why[0] in (109, errno.ESHUTDOWN): return self._close('stdin') raise return written
def test_shutdown_closed(self): """ If the underlying socket is closed, :py:obj:`Connection.shutdown` propagates the write error from the low level write call. """ server, client = self._loopback() server.sock_shutdown(2) exc = self.assertRaises(SysCallError, server.shutdown) if platform == "win32": self.assertEqual(exc.args[0], ESHUTDOWN) else: self.assertEqual(exc.args[0], EPIPE)
def test_closed(self): """ If the underlying socket is closed, :py:obj:`Connection.sendall` propagates the write error from the low level write call. """ server, client = self._loopback() server.sock_shutdown(2) exc = self.assertRaises(SysCallError, server.sendall, b"hello, world") if platform == "win32": self.assertEqual(exc.args[0], ESHUTDOWN) else: self.assertEqual(exc.args[0], EPIPE)
def send(self) -> int: """Send outgoing data """ with self._write_lock: while len(self.outbuffer) > 0: try: sent = self.sock.send(self.outbuffer) self.outbuffer = self.outbuffer[sent:] except socket.error as error: if error.args[0] == errno.EAGAIN: time.sleep(0.1) elif error.args[0] in ( errno.ECONNRESET, errno.ENOTCONN, errno.ESHUTDOWN, errno.ECONNABORTED, errno.EPIPE ): self.close() return 0 elif os.name == 'posix': # Windows doesn't seems to have EBADFD if sys.platform == 'darwin': # OS X uses EBADF as EBADFD. why? no idea asks Tim if error.args[0] == errno.EBADF: self.close() return 0 else: if error.args[0] == errno.EBADFD: self.close() return 0 raise else: raise
def _onReceived(self, block, res, res2): if res != -errno.ESHUTDOWN: # XXX: is it good to resubmit on any other error ? self._aio_context.submit([block]) if res < 0: trace('aio read completion error:', -res) else: trace('aio read completion received', res, 'bytes') self._writer(block.buffer_list[0][:res])
def send(self, input): if not self.stdin: return None try: x = msvcrt.get_osfhandle(self.stdin.fileno()) (errCode, written) = WriteFile(x, input) except ValueError: print("close stdin") return self._close('stdin') except (subprocess.pywintypes.error, Exception) as why: if why[0] in (109, errno.ESHUTDOWN): print("close stdin") return self._close('stdin') raise return written