def __init__(self, *args, **kwargs): guv.hubs.get_hub() super().__init__(*args, **kwargs) self.connected_event = TEvent() self._write_queue = Queue() self._callbacks = {} self._push_watchers = defaultdict(set) sockerr = None addresses = socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM) for (af, socktype, proto, canonname, sockaddr) in addresses: try: self._socket = socket.socket(af, socktype, proto) if self.ssl_options: self._socket = ssl.wrap_socket(self._socket, **self.ssl_options) self._socket.settimeout(1.0) self._socket.connect(sockaddr) sockerr = None break except socket.error as err: sockerr = err if sockerr: msg = 'Tried connecting to {}. Last error: {}'.format([a[4] for a in addresses], sockerr.strerror) raise socket.error(sockerr.errno, msg) if self.sockopts: for args in self.sockopts: self._socket.setsockopt(*args) self._read_watcher = guv.spawn(self.handle_read) self._write_watcher = guv.spawn(self.handle_write) self._send_options_message() log.debug('Create Cassandra GuvConnection ({})'.format(id(self)))
def test_socket_init(self): sock = socket_patched.socket() assert isinstance(sock, green_socket)