From 5bf06031ac57ca35856979cef933e02b429d595e Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Fri, 20 Mar 2020 15:42:44 +0000 Subject: [PATCH] Added connect() method to giambio.core.AsyncSocket class --- giambio/core.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/giambio/core.py b/giambio/core.py index 86d1332..3b84842 100644 --- a/giambio/core.py +++ b/giambio/core.py @@ -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__()