Python socket.TCP_NODELAY属性代码示例

本文整理汇总了Python中socket.TCP_NODELAY属性的典型用法代码示例。如果您正苦于以下问题:Python socket.TCP_NODELAY属性的具体用法?Python socket.TCP_NODELAY怎么用?Python socket.TCP_NODELAY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在模块socket的用法示例。

在下文中一共展示了socket.TCP_NODELAY属性的21个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _create_remote_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def _create_remote_socket(self, ip, port):
        addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM,
                                   socket.SOL_TCP)
        if len(addrs) == 0:
            raise Exception("getaddrinfo failed for %s:%d" % (ip, port))
        af, socktype, proto, canonname, sa = addrs[0]
        if self._forbidden_iplist:
            if common.to_str(sa[0]) in self._forbidden_iplist:
                raise Exception('IP %s is in forbidden list, reject' %
                                common.to_str(sa[0]))
        remote_sock = socket.socket(af, socktype, proto)
        self._remote_sock = remote_sock
        self._fd_to_handlers[remote_sock.fileno()] = self
        remote_sock.setblocking(False)
        remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
        return remote_sock 
开发者ID:ntfreedom,项目名称:neverendshadowsocks,代码行数:18,代码来源:tcprelay.py


示例2: bind

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def bind(self, family, type, proto=0):
        """Create (or recreate) the actual socket object."""
        self.socket = socket.socket(family, type, proto)
        prevent_socket_inheritance(self.socket)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if self.nodelay and not isinstance(self.bind_addr, str):
            self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        if self.ssl_adapter is not None:
            self.socket = self.ssl_adapter.bind(self.socket)
        # If listening on the IPV6 any address ('::' = IN6ADDR_ANY),
        # activate dual-stack. See https://bitbucket.org/cherrypy/cherrypy/issue/871.
        if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6
            and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')):
            try:
                self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
            except (AttributeError, socket.error):
                # Apparently, the socket option is not available in
                # this machine's TCP stack
                pass
        self.socket.bind(self.bind_addr) 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:25,代码来源:wsgiserver3.py


示例3: _socks_connection

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def _socks_connection(host, port, timeout, socks_config):
    """Create a SOCKS connection based on the supplied configuration."""
    try:
        socks_type = dict(
            socks4=socks.PROXY_TYPE_SOCKS4,
            socks5=socks.PROXY_TYPE_SOCKS5,
            socks5h=socks.PROXY_TYPE_SOCKS5
        )[socks_config.scheme]
    except KeyError:
        raise TypeError('Invalid SOCKS scheme: {}'.format(socks_config.scheme))
    socks_host, socks_port = socks_config.hostport.split(':')
    return socks.create_connection(
        (host, port),
        timeout,
        None,
        socks_type,
        socks_host,
        int(socks_port),
        socks_config.scheme == 'socks5h',
        socks_config.username,
        socks_config.password,
        ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
    ) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:27,代码来源:proxy2.py


示例4: test_connect_uses_socks5_proxy

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def test_connect_uses_socks5_proxy(self, mock_socks):
        conf = namedtuple('ProxyConf', 'scheme username password hostport')
        self.config = {
            'http': conf(*_parse_proxy('socks5://socks_user:socks_pass@socks_host:3128')),
            'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }
        mock_socks.PROXY_TYPE_SOCKS5 = socks.PROXY_TYPE_SOCKS5
        conn = ProxyAwareHTTPConnection(self.config, 'example.com')
        conn.connect()
        mock_socks.create_connection.assert_called_once_with(
            ('example.com', 80),
            socket._GLOBAL_DEFAULT_TIMEOUT,
            None,
            socks.PROXY_TYPE_SOCKS5,
            'socks_host',
            3128,
            False,
            'socks_user',
            'socks_pass',
            ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
        ) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:25,代码来源:test_proxy2.py


示例5: test_connect_uses_remote_dns

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def test_connect_uses_remote_dns(self, mock_socks):
        conf = namedtuple('ProxyConf', 'scheme username password hostport')
        self.config = {
            'http': conf(*_parse_proxy('socks5h://socks_user:socks_pass@socks_host:3128')),
            'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }
        mock_socks.PROXY_TYPE_SOCKS5 = socks.PROXY_TYPE_SOCKS5
        conn = ProxyAwareHTTPConnection(self.config, 'example.com')
        conn.connect()
        mock_socks.create_connection.assert_called_once_with(
            ('example.com', 80),
            socket._GLOBAL_DEFAULT_TIMEOUT,
            None,
            socks.PROXY_TYPE_SOCKS5,
            'socks_host',
            3128,
            True,
            'socks_user',
            'socks_pass',
            ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
        ) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:25,代码来源:test_proxy2.py


示例6: test_connect_uses_socks4_proxy

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def test_connect_uses_socks4_proxy(self, mock_socks):
        conf = namedtuple('ProxyConf', 'scheme username password hostport')
        self.config = {
            'http': conf(*_parse_proxy('socks4://socks_user:socks_pass@socks_host:3128')),
            'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }
        mock_socks.PROXY_TYPE_SOCKS4 = socks.PROXY_TYPE_SOCKS4
        conn = ProxyAwareHTTPConnection(self.config, 'example.com')
        conn.connect()
        mock_socks.create_connection.assert_called_once_with(
            ('example.com', 80),
            socket._GLOBAL_DEFAULT_TIMEOUT,
            None,
            socks.PROXY_TYPE_SOCKS4,
            'socks_host',
            3128,
            False,
            'socks_user',
            'socks_pass',
            ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
        ) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:25,代码来源:test_proxy2.py


示例7: bind

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def bind(self, family, type, proto=0):
        """Create (or recreate) the actual socket object."""
        self.socket = socket.socket(family, type, proto)
        prevent_socket_inheritance(self.socket)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if self.nodelay and not isinstance(self.bind_addr, str):
            self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        if self.ssl_adapter is not None:
            self.socket = self.ssl_adapter.bind(self.socket)
        # If listening on the IPV6 any address ('::' = IN6ADDR_ANY),
        # activate dual-stack. See http://www.cherrypy.org/ticket/871.
        if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6
            and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')):
            try:
                self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
            except (AttributeError, socket.error):
                # Apparently, the socket option is not available in
                # this machine's TCP stack
                pass
        self.socket.bind(self.bind_addr) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:25,代码来源:__init__.py


示例8: tearDown

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def tearDown(self):
        os.remove(TESTFN)
        # set back options to their original value
        self.server.server.max_cons = 0
        self.server.server.max_cons_per_ip = 0
        self.server.handler.banner = "pyftpdlib ready."
        self.server.handler.max_login_attempts = 3
        self.server.handler.auth_failed_timeout = 5
        self.server.handler.masquerade_address = None
        self.server.handler.masquerade_address_map = {}
        self.server.handler.permit_privileged_ports = False
        self.server.handler.passive_ports = None
        self.server.handler.use_gmt_times = True
        self.server.handler.tcp_no_delay = hasattr(socket, 'TCP_NODELAY')
        self.server.stop()
        self.client.close() 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:18,代码来源:test_functional.py


示例9: test_tcp_no_delay

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def test_tcp_no_delay(self):
        def get_handler_socket():
            # return the server's handler socket object
            ioloop = IOLoop.instance()
            for fd in ioloop.socket_map:
                instance = ioloop.socket_map[fd]
                if isinstance(instance, FTPHandler):
                    break
            return instance.socket
        s = get_handler_socket()
        self.assertTrue(s.getsockopt(socket.SOL_TCP, socket.TCP_NODELAY))
        self.client.quit()
        self.server.handler.tcp_no_delay = False
        self.client.connect(self.server.host, self.server.port)
        self.client.sendcmd('noop')
        s = get_handler_socket()
        self.assertFalse(s.getsockopt(socket.SOL_TCP, socket.TCP_NODELAY)) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:20,代码来源:test_functional.py


示例10: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def __init__(self, reactor):
        """Initialize.
        """
        self.reactor = reactor
        # Following select_trigger (from asyncore)'s example;
        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        server.bind(('127.0.0.1', 0))
        server.listen(1)
        client.connect(server.getsockname())
        reader, clientaddr = server.accept()
        client.setblocking(0)
        reader.setblocking(0)
        self.r = reader
        self.w = client
        self.fileno = self.r.fileno 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:posixbase.py


示例11: init_wifi

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def init_wifi(self, reinit=False):
        '''
        Needed for wifi adapters with short connection timeout
        '''
        if self.portType != 1:
            return
        import socket
        if reinit:
            self.hdr.close()
        self.hdr = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.hdr.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        try:
            self.hdr.connect((self.ipaddr, self.tcpprt))
            self.hdr.setblocking(True)
            self.connectionStatus = True
        except:
            options.elm_failed = True 
开发者ID:cedricp,项目名称:ddt4all,代码行数:21,代码来源:elm.py


示例12: init

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def init(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self.socket.connect((self.ms_ip, self.ms_tcp_port))
        self.socket_1 = socket.socket()
        self.recv_handle_live = True
        self.recv_thread = threading.Thread(target=self.recv_handler)
        self.recv_thread.daemon = True
        self.session = Session()
        self.session.conf = {}
        self.session.locks = {}
        self.last_send = 0 
开发者ID:rnbguy,项目名称:pysphere,代码行数:15,代码来源:misphere.py


示例13: setup

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def setup(self):
        self.connection = self.request
        if self.timeout is not None:
            self.connection.settimeout(self.timeout)
        if self.disable_nagle_algorithm:
            self.connection.setsockopt(socket.IPPROTO_TCP,
                                       socket.TCP_NODELAY, True)
        self.rfile = self.connection.makefile('rb', self.rbufsize)
        self.wfile = self.connection.makefile('wb', self.wbufsize) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:11,代码来源:socketserver.py


示例14: set_nodelay

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def set_nodelay(self, value):
        if (self.socket is not None and
                self.socket.family in (socket.AF_INET, socket.AF_INET6)):
            try:
                self.socket.setsockopt(socket.IPPROTO_TCP,
                                       socket.TCP_NODELAY, 1 if value else 0)
            except socket.error as e:
                # Sometimes setsockopt will fail if the socket is closed
                # at the wrong time.  This can happen with HTTPServer
                # resetting the value to false between requests.
                if e.errno != errno.EINVAL and not self._is_connreset(e):
                    raise 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:14,代码来源:iostream.py


示例15: server_bind

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def server_bind(self):
        sock = self.socket
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, True)
        self.RequestHandlerClass.bufsize = sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
        SocketServer.TCPServer.server_bind(self) 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:8,代码来源:rangefetch_server.py


示例16: set_nodelay

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def set_nodelay(sock: socket.socket) -> None:
    """sets the TCP_NODELAY option on the socket (to disable Nagle's algorithm), if possible."""
    with contextlib.suppress(Exception):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) 
开发者ID:irmen,项目名称:Pyro5,代码行数:6,代码来源:socketutil.py


示例17: set_options

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def set_options(self, sock, bound=False):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        return super(TCPSocket, self).set_options(sock, bound=bound) 
开发者ID:jpush,项目名称:jbox,代码行数:5,代码来源:sock.py


示例18: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def __init__(self, server, fd_to_handlers, loop, local_sock, config,
                 dns_resolver, is_local):
        self._server = server
        self._fd_to_handlers = fd_to_handlers
        self._loop = loop
        self._local_sock = local_sock
        self._remote_sock = None
        self._config = config
        self._dns_resolver = dns_resolver
        # TCP Relay works as either sslocal or ssserver
        # if is_local, this is sslocal
        self._is_local = is_local
        self._stage = STAGE_INIT
        self._encryptor = encrypt.Encryptor(config['password'],
                                            config['method'])
        self._fastopen_connected = False
        self._data_to_write_to_local = []
        self._data_to_write_to_remote = []
        self._upstream_status = WAIT_STATUS_READING
        self._downstream_status = WAIT_STATUS_INIT
        self._client_address = local_sock.getpeername()[:2]
        self._remote_address = None
        if 'forbidden_ip' in config:
            self._forbidden_iplist = config['forbidden_ip']
        else:
            self._forbidden_iplist = None
        if is_local:
            self._chosen_server = self._get_a_server()
        fd_to_handlers[local_sock.fileno()] = self
        local_sock.setblocking(False)
        local_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
        loop.add(local_sock, eventloop.POLL_IN | eventloop.POLL_ERR,
                 self._server)
        self.last_activity = 0
        self._update_activity() 
开发者ID:ntfreedom,项目名称:neverendshadowsocks,代码行数:38,代码来源:tcprelay.py


示例19: accept_new_connection

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def accept_new_connection(self, sock):
		try:
			client_sock, addr = sock.accept()
		except (ssl.SSLError, socket.error, OSError):
			return
		client_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
		client = Client(server=self, socket=client_sock)
		self.add_client(client) 
开发者ID:NVDARemote,项目名称:NVDARemote,代码行数:10,代码来源:server.py


示例20: create_outbound_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def create_outbound_socket(self, address):
		address = socket.getaddrinfo(*address)[0]
		server_sock = socket.socket(*address[:3])
		if self.timeout:
			server_sock.settimeout(self.timeout)
		server_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
		server_sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 60000, 2000))
		server_sock = ssl.wrap_socket(server_sock)
		return server_sock 
开发者ID:NVDARemote,项目名称:NVDARemote,代码行数:11,代码来源:transport.py


示例21: send_request

# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_NODELAY [as 别名]
def send_request(self, req_inter):
        try:
            if self.logger:
                self.logger.debug("SendRequest %s" % req_inter)
            self.conn.request(req_inter.method, req_inter.uri, req_inter.data, req_inter.header)
            self.conn.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
            try:
                http_resp = self.conn.getresponse()
            except BadStatusLine:
                #open another connection when keep-alive timeout
                #httplib will not handle keep-alive timeout, so we must handle it ourself
                self.conn.close()
                self.conn.request(req_inter.method, req_inter.uri, req_inter.data, req_inter.header)
                self.conn.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
                http_resp = self.conn.getresponse()
            try:
                headers = http_resp.headers
            except:
                headers = dict(http_resp.getheaders())
            resp_inter = ResponseInternal(status = http_resp.status, header = headers, data = http_resp.read())
            self.request_size = self.conn.request_length
            self.response_size = len(resp_inter.data)
            if not self.is_keep_alive():
                self.conn.close()
            if self.logger:
                self.logger.debug("GetResponse %s" % resp_inter)
            return resp_inter
        except Exception as e:
            self.conn.close()
            raise MNSClientNetworkException("NetWorkException", str(e), req_inter.get_req_id()) #raise netException 
开发者ID:gikoluo,项目名称:aliyun-mns,代码行数:33,代码来源:mns_http.py



注:本文中的socket.TCP_NODELAY属性示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。