def test_reuse_same_address_port(self): # NOTE: This test should ensure that same address port can be used by two # sockets. This to prevent accidental changes to socket options. In Windows # SO_REUSEADDR flag allows two sockets to bind to same address:port combination. # Windows should always use SO_EXCLUSIVEADDRUSE try: sock1 = create_server(self.HOST1, self.PORT1) with pytest.raises(Exception): create_server(self.HOST1, self.PORT1) assert sock1.getsockname() == (self.HOST1, self.PORT1) finally: close_socket(sock1)
def test_reuse_same_port(self): try: sock1, sock2 = None, None sock1 = create_server(self.HOST1, self.PORT1) sock2 = create_server(self.HOST2, self.PORT1) assert sock1.getsockname() == (self.HOST1, self.PORT1) assert sock2.getsockname() == (self.HOST2, self.PORT1) except Exception: pytest.fail() finally: if sock1 is not None: close_socket(sock1) if sock2 is not None: close_socket(sock2)
def close(self): """Stop all loops and release all resources.""" if self._closed: raise DaemonClosedError('already closed') self._closed = True if self._adapter is not None: normal, abnormal = self._adapter._wait_options() if (normal and not self.exitcode) or (abnormal and self.exitcode): self.wait_on_exit() if self._pydevd is not None: close_socket(self._pydevd) if self._client is not None: self._release_connection()
def connect(addr, wait=None, closeonly=False): sock = create_client() try: sock.settimeout(1) sock.connect(addr) debug('>connected') if wait is not None: debug('>waiting') time.sleep(wait) finally: debug('>closing') if closeonly: sock.close() else: close_socket(sock)
def _stop(self): with self._lock: if self._stopped: return self._stopped = True server = self._server self._server = None with ignore_errors(): self._finish_session() self._sessionlock = None # TODO: Call self._clear_sessionlock? # TODO: Close the server socket *before* finish the session? if server is not None: with ignore_errors(): close_socket(server) # TODO: Close self._sock *before* finishing the session? if self._sock is not None: with ignore_errors(): close_socket(self._sock)
def _release_connection(self): if self._adapter is not None: # TODO: This is not correct in the "attach" case. self._adapter.handle_pydevd_stopped(self.exitcode) self._adapter.close() close_socket(self._client)
def close(sock): """Shutdown and close the socket.""" _ptvsd.close_socket(sock)
def _release_connection(self): if self._adapter is not None: self._adapter.handle_stopped(self.exitcode) self._adapter.close() close_socket(self._client)