Added connect() method to giambio.core.AsyncSocket class

This commit is contained in:
nocturn9x 2020-03-20 15:42:44 +00:00
parent 87fd7af36b
commit 5bf06031ac
1 changed files with 10 additions and 0 deletions

View File

@ -146,6 +146,10 @@ class EventLoop:
def want_cancel(self, task):
task.coroutine.throw(CancelledError)
async def connect_sock(self, sock: socket.socket, addr: tuple):
await want_write(sock)
return sock.connect(addr)
class AsyncSocket(object):
"""Abstraction layer for asynchronous sockets"""
@ -176,6 +180,12 @@ class AsyncSocket(object):
await self.loop.close_sock(self.sock)
async def connect(self, addr: tuple):
"""Connects the socket to an endpoint"""
await self.loop.connect_sock(self.sock, addr)
def __enter__(self):
return self.sock.__enter__()