mirror of https://github.com/nocturn9x/giambio.git
Fixed the giambio.socket.AsyncSocket.connect() method
This commit is contained in:
parent
6e49e5112d
commit
14c21b56de
|
@ -6,10 +6,10 @@ import socket
|
||||||
from .exceptions import AlreadyJoinedError, CancelledError
|
from .exceptions import AlreadyJoinedError, CancelledError
|
||||||
from timeit import default_timer
|
from timeit import default_timer
|
||||||
from time import sleep as wait
|
from time import sleep as wait
|
||||||
from .socket import AsyncSocket
|
from .socket import AsyncSocket, WantRead, WantWrite
|
||||||
from .traps import join, sleep, want_read, want_write, cancel
|
from .traps import join, sleep, want_read, want_write, cancel
|
||||||
from .abstractions import Task, Result
|
from .abstractions import Task, Result
|
||||||
|
from socket import SOL_SOCKET, SO_ERROR
|
||||||
|
|
||||||
class EventLoop:
|
class EventLoop:
|
||||||
|
|
||||||
|
@ -157,9 +157,11 @@ class EventLoop:
|
||||||
|
|
||||||
|
|
||||||
async def connect_sock(self, sock: socket.socket, addr: tuple):
|
async def connect_sock(self, sock: socket.socket, addr: tuple):
|
||||||
try:
|
try: # "Borrowed" from curio
|
||||||
sock.connect(addr)
|
result = sock.connect(addr)
|
||||||
except BlockingIOError:
|
return result
|
||||||
|
except WantWrite:
|
||||||
await want_write(sock)
|
await want_write(sock)
|
||||||
|
err = sock.getsockopt(SOL_SOCKET, SO_ERROR)
|
||||||
|
if err != 0:
|
||||||
|
raise OSError(err, f'Connect call failed {addr}')
|
||||||
|
|
|
@ -6,6 +6,13 @@ Basic abstraction layer for giambio asynchronous sockets
|
||||||
|
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
|
try:
|
||||||
|
from ssl import SSLWantReadError, SSLWantWriteError
|
||||||
|
WantRead = (BlockingIOError, InterruptedError, SSLWantReadError)
|
||||||
|
WantWrite = (BlockingIOError, InterruptedError, SSLWantWriteError)
|
||||||
|
except ImportError:
|
||||||
|
WantRead = (BlockingIOError, InterruptedError)
|
||||||
|
WantWrite = (BlockingIOError, InterruptedError)
|
||||||
|
|
||||||
|
|
||||||
class AsyncSocket(object):
|
class AsyncSocket(object):
|
||||||
|
|
Loading…
Reference in New Issue