Moved IOInterrupt to socket module

This commit is contained in:
nocturn9x 2021-04-29 15:58:46 +02:00
parent f55826d534
commit ec721fafd8
2 changed files with 8 additions and 8 deletions

View File

@ -18,7 +18,6 @@ limitations under the License.
# Import libraries and internal resources # Import libraries and internal resources
import types import types
import socket
from itertools import chain from itertools import chain
from timeit import default_timer from timeit import default_timer
from giambio.context import TaskManager from giambio.context import TaskManager
@ -34,8 +33,6 @@ from giambio.exceptions import (InternalError,
TooSlowError 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 # TODO: Right now this value is pretty much arbitrary, we need some testing to choose a sensible default
IO_SKIP_LIMIT = 5 IO_SKIP_LIMIT = 5

View File

@ -20,6 +20,9 @@ from giambio.run import get_event_loop
from giambio.exceptions import ResourceClosed from giambio.exceptions import ResourceClosed
from giambio.traps import want_write, want_read from giambio.traps import want_write, want_read
# TODO: Take into account SSLWantReadError and SSLWantWriteError
IOInterrupt = (BlockingIOError, InterruptedError)
class AsyncSocket: class AsyncSocket:
""" """
@ -43,7 +46,7 @@ class AsyncSocket:
await want_read(self.sock) await want_read(self.sock)
try: try:
return self.sock.recv(max_size) return self.sock.recv(max_size)
except BlockingIOError: except IOInterrupt:
await want_read(self.sock) await want_read(self.sock)
return self.sock.recv(max_size) return self.sock.recv(max_size)
@ -57,7 +60,7 @@ class AsyncSocket:
await want_read(self.sock) await want_read(self.sock)
try: try:
to_wrap = self.sock.accept() to_wrap = self.sock.accept()
except BlockingIOError: except IOInterrupt:
# Some platforms (namely OSX systems) act weird and handle # Some platforms (namely OSX systems) act weird and handle
# the errno 35 signal (EAGAIN) for sockets in a weird manner, # the errno 35 signal (EAGAIN) for sockets in a weird manner,
# and this seems to fix the issue. Not sure about why since we # and this seems to fix the issue. Not sure about why since we
@ -77,7 +80,7 @@ class AsyncSocket:
await want_write(self.sock) await want_write(self.sock)
try: try:
sent_no = self.sock.send(data) sent_no = self.sock.send(data)
except BlockingIOError: except IOInterrupt:
await want_write(self.sock) await want_write(self.sock)
sent_no = self.sock.send(data) sent_no = self.sock.send(data)
data = data[sent_no:] data = data[sent_no:]
@ -92,7 +95,7 @@ class AsyncSocket:
await want_write(self.sock) await want_write(self.sock)
try: try:
self.sock.close() self.sock.close()
except BlockingIOError: except IOInterrupt:
await want_write(self.sock) await want_write(self.sock)
self.sock.close() self.sock.close()
self.loop.selector.unregister(self.sock) self.loop.selector.unregister(self.sock)
@ -109,7 +112,7 @@ class AsyncSocket:
await want_write(self.sock) await want_write(self.sock)
try: try:
self.sock.connect(addr) self.sock.connect(addr)
except BlockingIOError: except IOInterrupt:
await want_write(self.sock) await want_write(self.sock)
self.sock.connect(addr) self.sock.connect(addr)