本文整理匯總了Python中errno.WSAEWOULDBLOCK屬性的典型用法代碼示例。如果您正苦於以下問題:Python errno.WSAEWOULDBLOCK屬性的具體用法?Python errno.WSAEWOULDBLOCK怎麽用?Python errno.WSAEWOULDBLOCK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類errno
的用法示例。
在下文中一共展示了errno.WSAEWOULDBLOCK屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: doRead
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def doRead(self):
"""Calls self.protocol.dataReceived with all available data.
This reads up to self.bufferSize bytes of data from its socket, then
calls self.dataReceived(data) to process it. If the connection is not
lost through an error in the physical recv(), this function will return
the result of the dataReceived call.
"""
try:
data = self.socket.recv(self.bufferSize)
except socket.error as se:
if se.args[0] == EWOULDBLOCK:
return
else:
return main.CONNECTION_LOST
return self._dataReceived(data)
示例2: writeSomeData
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def writeSomeData(self, data):
"""
Write as much as possible of the given data to this TCP connection.
This sends up to C{self.SEND_LIMIT} bytes from C{data}. If the
connection is lost, an exception is returned. Otherwise, the number
of bytes successfully written is returned.
"""
# Limit length of buffer to try to send, because some OSes are too
# stupid to do so themselves (ahem windows)
limitedData = lazyByteSlice(data, 0, self.SEND_LIMIT)
try:
return untilConcludes(self.socket.send, limitedData)
except socket.error as se:
if se.args[0] in (EWOULDBLOCK, ENOBUFS):
return 0
else:
return main.CONNECTION_LOST
示例3: __init__
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def __init__ (self):
self.sock = None # socket object
self.send_buf = [] # send buffer
self.recv_buf = [] # recv buffer
self.pend_buf = '' # send pending
self.state = NET_STATE_CLOSED
self.errd = [ errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK ]
self.conn = ( errno.EISCONN, 10057, 10053 )
self.errc = 0
self.ipv6 = False
self.eintr = ()
if 'EINTR' in errno.__dict__:
self.eintr = (errno.__dict__['EINTR'],)
if 'WSAEWOULDBLOCK' in errno.__dict__:
self.errd.append(errno.WSAEWOULDBLOCK)
self.errd = tuple(self.errd)
self.timeout = 0
self.timecon = 0
示例4: doRead
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def doRead(self):
"""
Called when my socket is ready for reading.
"""
read = 0
while read < self.maxThroughput:
try:
data, addr = self.socket.recvfrom(self.maxPacketSize)
except socket.error, se:
no = se.args[0]
if no in (EAGAIN, EINTR, EWOULDBLOCK):
return
if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET):
if self._connectedAddr:
self.protocol.connectionRefused()
else:
raise
else:
read += len(data)
try:
self.protocol.datagramReceived(data, addr)
except:
log.err()
示例5: writeSomeData
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def writeSomeData(self, data):
"""
Write as much as possible of the given data to this TCP connection.
This sends up to C{self.SEND_LIMIT} bytes from C{data}. If the
connection is lost, an exception is returned. Otherwise, the number
of bytes successfully written is returned.
"""
try:
# Limit length of buffer to try to send, because some OSes are too
# stupid to do so themselves (ahem windows)
return self.socket.send(buffer(data, 0, self.SEND_LIMIT))
except socket.error, se:
if se.args[0] == EINTR:
return self.writeSomeData(data)
elif se.args[0] in (EWOULDBLOCK, ENOBUFS):
return 0
else:
return main.CONNECTION_LOST
示例6: doRead
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def doRead(self):
"""Called when my socket is ready for reading."""
read = 0
while read < self.maxThroughput:
try:
data, addr = self.socket.recvfrom(self.maxPacketSize)
except socket.error, se:
no = se.args[0]
if no in (EAGAIN, EINTR, EWOULDBLOCK):
return
if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET):
if self._connectedAddr:
self.protocol.connectionRefused()
else:
raise
else:
read += len(data)
try:
self.protocol.datagramReceived(data, addr)
except:
log.err()
示例7: writeSomeData
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def writeSomeData(self, data):
"""Connection.writeSomeData(data) -> #of bytes written | CONNECTION_LOST
This writes as much data as possible to the socket and returns either
the number of bytes read (which is positive) or a connection error code
(which is negative)
"""
try:
# Limit length of buffer to try to send, because some OSes are too
# stupid to do so themselves (ahem windows)
return self.socket.send(buffer(data, 0, self.SEND_LIMIT))
except socket.error, se:
if se.args[0] == EINTR:
return self.writeSomeData(data)
elif se.args[0] in (EWOULDBLOCK, ENOBUFS):
return 0
else:
return main.CONNECTION_LOST
示例8: wakeUp
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def wakeUp(self):
"""Send a byte to my connection.
"""
try:
util.untilConcludes(self.w.send, b'x')
except socket.error as e:
if e.args[0] != errno.WSAEWOULDBLOCK:
raise
示例9: test_stopOnlyCloses
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def test_stopOnlyCloses(self):
"""
When the L{IListeningPort} returned by
L{IReactorSocket.adoptStreamPort} is stopped using
C{stopListening}, the underlying socket is closed but not
shutdown. This allows another process which still has a
reference to it to continue accepting connections over it.
"""
reactor = self.buildReactor()
portSocket = socket.socket()
self.addCleanup(portSocket.close)
portSocket.bind(("127.0.0.1", 0))
portSocket.listen(1)
portSocket.setblocking(False)
# The file descriptor is duplicated by adoptStreamPort
port = reactor.adoptStreamPort(
portSocket.fileno(), portSocket.family, ServerFactory())
d = port.stopListening()
def stopped(ignored):
# Should still be possible to accept a connection on
# portSocket. If it was shutdown, the exception would be
# EINVAL instead.
exc = self.assertRaises(socket.error, portSocket.accept)
if platform.isWindows() and _PY3:
self.assertEqual(exc.args[0], errno.WSAEWOULDBLOCK)
else:
self.assertEqual(exc.args[0], errno.EAGAIN)
d.addCallback(stopped)
d.addErrback(err, "Failed to accept on original port.")
needsRunningReactor(
reactor,
lambda: d.addCallback(lambda ignored: reactor.stop()))
reactor.run()
示例10: test_readImmediateError
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def test_readImmediateError(self):
"""
If the socket is unconnected, socket reads with an immediate
connection refusal are ignored, and reading stops. The protocol's
C{connectionRefused} method is not called.
"""
# Add a fake error to the list of those that count as connection
# refused:
udp._sockErrReadRefuse.append(-6000)
self.addCleanup(udp._sockErrReadRefuse.remove, -6000)
protocol = KeepReads()
# Fail if connectionRefused is called:
protocol.connectionRefused = lambda: 1/0
port = udp.Port(None, protocol)
# Try an immediate "connection refused"
port.socket = StringUDPSocket([b"a", socket.error(-6000), b"b",
socket.error(EWOULDBLOCK)])
port.doRead()
# Read stops on error:
self.assertEqual(protocol.reads, [b"a"])
# Read again:
port.doRead()
self.assertEqual(protocol.reads, [b"a", b"b"])
示例11: test_connectedReadImmediateError
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def test_connectedReadImmediateError(self):
"""
If the socket connected, socket reads with an immediate
connection refusal are ignored, and reading stops. The protocol's
C{connectionRefused} method is called.
"""
# Add a fake error to the list of those that count as connection
# refused:
udp._sockErrReadRefuse.append(-6000)
self.addCleanup(udp._sockErrReadRefuse.remove, -6000)
protocol = KeepReads()
refused = []
protocol.connectionRefused = lambda: refused.append(True)
port = udp.Port(None, protocol)
port.socket = StringUDPSocket([b"a", socket.error(-6000), b"b",
socket.error(EWOULDBLOCK)])
port.connect("127.0.0.1", 9999)
# Read stops on error:
port.doRead()
self.assertEqual(protocol.reads, [b"a"])
self.assertEqual(refused, [True])
# Read again:
port.doRead()
self.assertEqual(protocol.reads, [b"a", b"b"])
self.assertEqual(refused, [True])
示例12: test_mlistener_nonblocking
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def test_mlistener_nonblocking(self):
sock = MultipleSocketsListener([('127.0.0.1', 0), ('::1', 0)])
sock.setblocking(False)
try:
sock.accept()
except socket.error as err:
if os.name == 'nt':
code = errno.WSAEWOULDBLOCK
else:
code = errno.EAGAIN
self.assertEqual(err.errno, code)
else:
self.fail('exception not raised')
示例13: read
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def read(self, num):
try:
return self.sr.recv(num)
except socket.error as exc:
# emulate os.read exception
if exc.errno == errno.WSAEWOULDBLOCK:
new_exc = OSError()
new_exc.errno = errno.EAGAIN
raise new_exc
else:
raise
示例14: _sendCloseAlert
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def _sendCloseAlert(self):
# Okay, *THIS* is a bit complicated.
# Basically, the issue is, OpenSSL seems to not actually return
# errors from SSL_shutdown. Therefore, the only way to
# determine if the close notification has been sent is by
# SSL_shutdown returning "done". However, it will not claim it's
# done until it's both sent *and* received a shutdown notification.
# I don't actually want to wait for a received shutdown
# notification, though, so, I have to set RECEIVED_SHUTDOWN
# before calling shutdown. Then, it'll return True once it's
# *SENT* the shutdown.
# However, RECEIVED_SHUTDOWN can't be left set, because then
# reads will fail, breaking half close.
# Also, since shutdown doesn't report errors, an empty write call is
# done first, to try to detect if the connection has gone away.
# (*NOT* an SSL_write call, because that fails once you've called
# shutdown)
try:
os.write(self.socket.fileno(), '')
except OSError, se:
if se.args[0] in (EINTR, EWOULDBLOCK, ENOBUFS):
return 0
# Write error, socket gone
return main.CONNECTION_LOST
示例15: doRead
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import WSAEWOULDBLOCK [as 別名]
def doRead(self):
"""Calls self.protocol.dataReceived with all available data.
This reads up to self.bufferSize bytes of data from its socket, then
calls self.dataReceived(data) to process it. If the connection is not
lost through an error in the physical recv(), this function will return
the result of the dataReceived call.
"""
try:
data = self.socket.recv(self.bufferSize)
except socket.error, se:
if se.args[0] == EWOULDBLOCK:
return
else:
return main.CONNECTION_LOST