本文整理汇总了Python中socket.TCP_NODELAY属性的典型用法代码示例。如果您正苦于以下问题:Python socket.TCP_NODELAY属性的具体用法?Python socket.TCP_NODELAY怎么用?Python socket.TCP_NODELAY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.TCP_NODELAY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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),)
)
示例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),)
)
示例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),)
)
示例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),)
)
示例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)
示例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()
示例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))
示例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
示例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
示例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
示例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)
示例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
示例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)