def test_create_socket(self): # testing various options # regular socket sock = create_socket('0.0.0.0') try: _, port = sock.getsockname() self.assertNotEqual(port, 0) finally: sock.close() # fd-based socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('0.0.0.0', 0)) _, port = sock.getsockname() sock2 = create_socket('fd://%d' % sock.fileno()) try: _, port2 = sock2.getsockname() self.assertEqual(port2, port) finally: sock2.close() sock.close() # unix socket fd, path = tempfile.mkstemp() os.close(fd) sock = create_socket('unix://%s' % path) try: self.assertEqual('//' + path, sock.getsockname()) finally: sock.close() os.remove(path)
def __init__(self, listener, application=None, backlog=None): eventlet.monkey_patch() host, port = listener self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.application = application
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None, socket_type=None, address_family=None, graceful_timeout=None, disable_monkeypatch=False, **ssl_args): if address_family: self.address_family = address_family if socket_type: self.socket_type = socket_type if handler_class: self.handler_class = handler_class host, port = listener self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname() if graceful_timeout is not None: self.stop_timeout = graceful_timeout gevent_signal(signal.SIGTERM, self.stop) super(Server, self).__init__(self.socket, application, None, spawn, log, self.handler_class, environ, **ssl_args)
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET, graceful_timeout=None, **ssl_args): host, port = listener self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname() if graceful_timeout is not None: self.stop_timeout = graceful_timeout gevent_signal(signal.SIGTERM, self.stop) super(Server, self).__init__(self.socket, application, None, spawn, log, handler_class, environ, **ssl_args)
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET, **ssl_args): monkey.noisy = False monkey.patch_all() self.address_family = address_family self.socket_type = socket_type host, port = listener self.handler_class = CustomWebSocketHandler self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname() super(Server, self).__init__(self.socket, application, None, spawn, log, handler_class, environ, **ssl_args) gevent.signal(signal.SIGHUP, partial(self.stop, timeout=10000))
def __init__(self, *args, **kwargs): address_family = kwargs.pop('address_family', socket.AF_INET) socket_type = kwargs.pop('socket_type', socket.SOCK_STREAM) backlog = kwargs.pop('backlog', 2048) listener = args[0] if isinstance(listener, tuple): host, port = listener _socket = create_socket(host, port, address_family, socket_type, backlog=backlog) _socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) args = [_socket] + list(args[1:]) else: # it's already a socket.. host, port = listener.getsockname() # socketio makes the assumption that listener is a host/port # tuple, which is a false assumption, it can be a socket. # it uses listener in its constructor to set the policy server # # Let's set it ourselves here afterwards. old_policy_server = kwargs.pop('policy_server', True) kwargs['policy_server'] = False super(Server, self).__init__(*args, **kwargs) if old_policy_server: policylistener = kwargs.pop('policy_listener', (host, 10843)) self.policy_server = FlashPolicyServer(policylistener)
def __init__(self, listener, application=None, backlog=None, socket_type=None, address_family=None, **kw): host, port = listener self.app = application self.sock = create_socket(host, port, address_family, socket_type, backlog=backlog) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET, **ssl_args): self.address_family = address_family self.socket_type = socket_type monkey.noisy = False monkey.patch_all() host, port = listener self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname() log = None super(Server, self).__init__(self.socket, application, None, spawn, log, handler_class, environ, **ssl_args)
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET, **ssl_args): host, port = listener self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname() super(Server, self).__init__(self.socket, application, None, spawn, log, handler_class, environ, **ssl_args)
def __init__(self, server_address, app, bind_and_activate=True, backlog=2048): BaseServer.__init__(self, server_address, self.handler_class) self.set_app(app) host, port = self.server_address = server_address self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.byfd = host.startswith('fd://') if bind_and_activate: self.server_bind() self.server_activate()
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None, **ssl_args): monkey.noisy = False monkey.patch_all() host, port = listener self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname() log = None super(Server, self).__init__(self.socket, application, None, spawn, log, handler_class, environ, **ssl_args)
def __init__(self, listener, application=None, backlog=2048, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET, disable_monkeypatch=False): self.address_family = address_family self.socket_type = socket_type if not disable_monkeypatch: eventlet.monkey_patch() host, port = listener self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.application = application
def __init__(self, listener, application=None, backlog=None, socket_type=None, address_family=None): host, port = listener self.app = application self.sock = create_socket(host, port, address_family, socket_type, backlog=backlog) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
def __init__(self, server_address, app, bind_and_activate=True, backlog=2048, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET): self.address_family = address_family self.socket_type = socket_type BaseServer.__init__(self, server_address, self.handler_class) self.set_app(app) host, port = self.server_address = server_address self.socket = create_socket(host, port, family=self.address_family, type=self.socket_type, backlog=backlog) self.byfd = host.startswith('fd://') if bind_and_activate: self.server_bind() self.server_activate()
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET, **ssl_args): monkey.noisy = False monkey.patch_all() self.address_family = address_family self.socket_type = socket_type host, port = listener self.handler_class = CustomWebSocketHandler self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname() super(Server, self).__init__(self.socket, application, None, spawn, log, handler_class, environ, **ssl_args) gevent.signal(signal.SIGHUP, partial(self.stop, timeout = 10000))
def __init__(self, listener, application=None, backlog=2048, socket_type=socket.SOCK_STREAM, spawn='default', handler_class=None, environ=None, log='default', address_family=socket.AF_INET, **config): self.address_family = address_family self.socket_type = socket_type host, port = listener self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.application = application self.sockets = {} if 'namespace' in config: self.resource = config.pop('namespace', 'socket.io') else: self.resource = config.pop('resource', 'socket.io') self.transports = config.pop('transports', None) self.policy_server = None WSGIServer.__init__(self, self.socket, application, None, spawn, log, self.handler_class, environ, **config)
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None, environ=None, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET, graceful_timeout=None, **ssl_args): self.address_family = address_family self.socket_type = socket_type host, port = listener self.handler_class = WebSocketHandler self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname() if graceful_timeout is not None: self.stop_timeout = graceful_timeout gevent_signal(signal.SIGTERM, self.stop) super(Server, self).__init__(self.socket, application, None, spawn, log, handler_class, environ, **ssl_args)
def __init__( self, listener, application=None, backlog=2048, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET ): """ Create socket. """ host, port = listener self.application = application self.address_family = address_family self.socket_type = socket_type self.socket = create_socket( host, port, self.address_family, self.socket_type, backlog=backlog ) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname()
def __init__(self, listener, application=None, backlog=2048, socket_type=socket.SOCK_STREAM, address_family=socket.AF_INET): """ Create socket. """ host, port = listener self.application = application self.address_family = address_family self.socket_type = socket_type self.socket = create_socket(host, port, self.address_family, self.socket_type, backlog=backlog) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server_address = self.socket.getsockname()