mirror of https://github.com/nocturn9x/giambio.git
Moved IOInterrupt to socket module
This commit is contained in:
parent
f55826d534
commit
ec721fafd8
|
@ -18,7 +18,6 @@ limitations under the License.
|
|||
|
||||
# Import libraries and internal resources
|
||||
import types
|
||||
import socket
|
||||
from itertools import chain
|
||||
from timeit import default_timer
|
||||
from giambio.context import TaskManager
|
||||
|
@ -34,8 +33,6 @@ from giambio.exceptions import (InternalError,
|
|||
TooSlowError
|
||||
)
|
||||
|
||||
# TODO: Take into account SSLWantReadError and SSLWantWriteError
|
||||
IOInterrupt = (BlockingIOError, InterruptedError)
|
||||
# TODO: Right now this value is pretty much arbitrary, we need some testing to choose a sensible default
|
||||
IO_SKIP_LIMIT = 5
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ from giambio.run import get_event_loop
|
|||
from giambio.exceptions import ResourceClosed
|
||||
from giambio.traps import want_write, want_read
|
||||
|
||||
# TODO: Take into account SSLWantReadError and SSLWantWriteError
|
||||
IOInterrupt = (BlockingIOError, InterruptedError)
|
||||
|
||||
|
||||
class AsyncSocket:
|
||||
"""
|
||||
|
@ -43,7 +46,7 @@ class AsyncSocket:
|
|||
await want_read(self.sock)
|
||||
try:
|
||||
return self.sock.recv(max_size)
|
||||
except BlockingIOError:
|
||||
except IOInterrupt:
|
||||
await want_read(self.sock)
|
||||
return self.sock.recv(max_size)
|
||||
|
||||
|
@ -57,7 +60,7 @@ class AsyncSocket:
|
|||
await want_read(self.sock)
|
||||
try:
|
||||
to_wrap = self.sock.accept()
|
||||
except BlockingIOError:
|
||||
except IOInterrupt:
|
||||
# Some platforms (namely OSX systems) act weird and handle
|
||||
# the errno 35 signal (EAGAIN) for sockets in a weird manner,
|
||||
# and this seems to fix the issue. Not sure about why since we
|
||||
|
@ -77,7 +80,7 @@ class AsyncSocket:
|
|||
await want_write(self.sock)
|
||||
try:
|
||||
sent_no = self.sock.send(data)
|
||||
except BlockingIOError:
|
||||
except IOInterrupt:
|
||||
await want_write(self.sock)
|
||||
sent_no = self.sock.send(data)
|
||||
data = data[sent_no:]
|
||||
|
@ -92,7 +95,7 @@ class AsyncSocket:
|
|||
await want_write(self.sock)
|
||||
try:
|
||||
self.sock.close()
|
||||
except BlockingIOError:
|
||||
except IOInterrupt:
|
||||
await want_write(self.sock)
|
||||
self.sock.close()
|
||||
self.loop.selector.unregister(self.sock)
|
||||
|
@ -109,7 +112,7 @@ class AsyncSocket:
|
|||
await want_write(self.sock)
|
||||
try:
|
||||
self.sock.connect(addr)
|
||||
except BlockingIOError:
|
||||
except IOInterrupt:
|
||||
await want_write(self.sock)
|
||||
self.sock.connect(addr)
|
||||
|
||||
|
|
Loading…
Reference in New Issue