当前位置: 首页>>代码示例>>Python>>正文


Python socket.SOL_TCP属性代码示例

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


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

示例1: _create_remote_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [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: _get_addrinfo_list

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def _get_addrinfo_list(hostname, port, is_secure, proxy):
    phost, pport, pauth = get_proxy_info(
        hostname, is_secure, proxy.host, proxy.port, proxy.auth, proxy.no_proxy)
    try:
        if not phost:
            addrinfo_list = socket.getaddrinfo(
                hostname, port, 0, 0, socket.SOL_TCP)
            return addrinfo_list, False, None
        else:
            pport = pport and pport or 80
            # when running on windows 10, the getaddrinfo used above
            # returns a socktype 0. This generates an error exception:
            #_on_error: exception Socket type must be stream or datagram, not 0
            # Force the socket type to SOCK_STREAM
            addrinfo_list = socket.getaddrinfo(phost, pport, 0, socket.SOCK_STREAM, socket.SOL_TCP)
            return addrinfo_list, True, pauth
    except socket.gaierror as e:
        raise WebSocketAddressException(e) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:_http.py

示例3: open_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def open_socket(self):
        if self.useInetSocket:
            this_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
        else:
            this_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

        if this_socket:
            try:
                if self.useInetSocket:
                    this_socket.connect((self.socketHost, self.socketPort))
                else:
                    this_socket.connect(self.socket_name)
            except:
                this_socket.close()

        return this_socket 
开发者ID:thorrak,项目名称:fermentrack,代码行数:18,代码来源:models.py

示例4: test_tcp_no_delay

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [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

示例5: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def __init__(self, inSock, nodelay = True, littleEndian = True):
        self.prefix_ = "" if littleEndian else ">"
        self.sock_ = inSock
        self.sock_.setblocking(0)
        if nodelay:
            self.sock_.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0)				
        self.readTime = .001
        self.gotSize_ = False
        self.msgSize_ = 0
        self.buf_ = ""
        self.gotSize_ = False		

        self.incoming = collections.deque()
        self.outgoing = collections.deque()
    
    # element access functions 
开发者ID:ufora,项目名称:ufora,代码行数:18,代码来源:SocketWrapper.py

示例6: _create_remote_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [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:shadowsocksr-backup,项目名称:shadowsocksr,代码行数:19,代码来源:udprelay.py

示例7: test_connect_tcp_keepalive_options

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def test_connect_tcp_keepalive_options(event_loop):
    conn = Connection(
        loop=event_loop,
        socket_keepalive=True,
        socket_keepalive_options={
            socket.TCP_KEEPIDLE: 1,
            socket.TCP_KEEPINTVL: 1,
            socket.TCP_KEEPCNT: 3,
        },
    )
    await conn._connect()
    sock = conn._writer.transport.get_extra_info('socket')
    assert sock.getsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE) == 1
    for k, v in (
        (socket.TCP_KEEPIDLE, 1),
        (socket.TCP_KEEPINTVL, 1),
        (socket.TCP_KEEPCNT, 3),
    ):
        assert sock.getsockopt(socket.SOL_TCP, k) == v
    conn.disconnect() 
开发者ID:NoneGG,项目名称:aredis,代码行数:22,代码来源:test_connection.py

示例8: _gethostbyaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def _gethostbyaddr(ip):
    try:
        dns.ipv6.inet_aton(ip)
        sockaddr = (ip, 80, 0, 0)
        family = socket.AF_INET6
    except Exception:
        sockaddr = (ip, 80)
        family = socket.AF_INET
    (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
    aliases = []
    addresses = []
    tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP,
                          socket.AI_CANONNAME)
    canonical = tuples[0][3]
    for item in tuples:
        addresses.append(item[4][0])
    # XXX we just ignore aliases
    return (canonical, aliases, addresses) 
开发者ID:elgatito,项目名称:script.elementum.burst,代码行数:20,代码来源:resolver.py

示例9: _socket_bind_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def _socket_bind_addr(self, sock, af):
        bind_addr = ''
        if self._bind and af == socket.AF_INET:
            bind_addr = self._bind
        elif self._bindv6 and af == socket.AF_INET6:
            bind_addr = self._bindv6
        else:
            bind_addr = self._accept_address[0]

        bind_addr = bind_addr.replace("::ffff:", "")
        if bind_addr in self._ignore_bind_list:
            bind_addr = None
        if bind_addr:
            local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP)
            if local_addrs[0][0] == af:
                logging.debug("bind %s" % (bind_addr,))
                try:
                    sock.bind((bind_addr, 0))
                except Exception as e:
                    logging.warn("bind %s fail" % (bind_addr,)) 
开发者ID:hao35954514,项目名称:shadowsocksR-b,代码行数:22,代码来源:tcprelay.py

示例10: _socket_bind_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def _socket_bind_addr(self, sock, af, is_relay):
        bind_addr = ''
        if self._bind and af == socket.AF_INET:
            bind_addr = self._bind
        elif self._bindv6 and af == socket.AF_INET6:
            bind_addr = self._bindv6

        bind_addr = bind_addr.replace("::ffff:", "")
        if bind_addr in self._ignore_bind_list:
            bind_addr = None

        if is_relay:
            bind_addr = None

        if bind_addr:
            local_addrs = socket.getaddrinfo(
                bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP)
            if local_addrs[0][0] == af:
                logging.debug("bind %s" % (bind_addr,))
                sock.bind((bind_addr, 0)) 
开发者ID:PaperDashboard,项目名称:shadowsocks,代码行数:22,代码来源:udprelay.py

示例11: _socket_bind_addr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def _socket_bind_addr(self, sock, af):
        bind_addr = ''
        if self._bind and af == socket.AF_INET:
            bind_addr = self._bind
        elif self._bindv6 and af == socket.AF_INET6:
            bind_addr = self._bindv6
        else:
            bind_addr = self._accept_address[0]

        bind_addr = bind_addr.replace("::ffff:", "")
        if bind_addr in self._ignore_bind_list:
            bind_addr = None

        if self._is_relay:
            bind_addr = None

        if bind_addr:
            local_addrs = socket.getaddrinfo(
                bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP)
            if local_addrs[0][0] == af:
                logging.debug("bind %s" % (bind_addr,))
                sock.bind((bind_addr, 0)) 
开发者ID:PaperDashboard,项目名称:shadowsocks,代码行数:24,代码来源:tcprelay.py

示例12: _gethostbyaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def _gethostbyaddr(ip):
    try:
        addr = dns.ipv6.inet_aton(ip)
        sockaddr = (ip, 80, 0, 0)
        family = socket.AF_INET6
    except:
        sockaddr = (ip, 80)
        family = socket.AF_INET
    (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
    aliases = []
    addresses = []
    tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP,
                          socket.AI_CANONNAME)
    canonical = tuples[0][3]
    for item in tuples:
        addresses.append(item[4][0])
    # XXX we just ignore aliases
    return (canonical, aliases, addresses) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:20,代码来源:resolver.py

示例13: init

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def init(self, channels):
        global main_socket
        if not main_socket:
            main_socket = socket.socket()
            main_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

            # Disable Nagle's algorithm
            main_socket.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
            main_socket.bind(('', 2666))
            main_socket.listen(1)

        self.channels = list(channels.values())


        threading.Thread(target=self.socket_thread).start()


    # Add header and send to clients 
开发者ID:strfry,项目名称:OpenNFB,代码行数:20,代码来源:server.py

示例14: server_bind

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [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

示例15: get_ip_address

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_TCP [as 别名]
def get_ip_address(hostname: str, workaround127: bool = False, version: int = None) \
        -> Union[ipaddress.IPv4Address, ipaddress.IPv6Address]:
    """
    Returns the IP address for the given host. If you enable the workaround,
    it will use a little hack if the ip address is found to be the loopback address.
    The hack tries to discover an externally visible ip address instead (this only works for ipv4 addresses).
    Set ipVersion=6 to return ipv6 addresses, 4 to return ipv4, 0 to let OS choose the best one or None to use config.PREFER_IP_VERSION.
    """
    if not workaround127:
        with contextlib.suppress(ValueError):
            addr = ipaddress.ip_address(hostname)
            return addr

    def getaddr(ip_version):
        if ip_version == 6:
            family = socket.AF_INET6
        elif ip_version == 4:
            family = socket.AF_INET
        elif ip_version == 0:
            family = socket.AF_UNSPEC
        else:
            raise ValueError("unknown value for argument ipVersion.")
        ip = socket.getaddrinfo(hostname or socket.gethostname(), 80, family, socket.SOCK_STREAM, socket.SOL_TCP)[0][4][0]
        if workaround127 and (ip.startswith("127.") or ip == "0.0.0.0"):
            return get_interface("4.2.2.2").ip
        return ipaddress.ip_address(ip)

    try:
        if hostname and ':' in hostname and version is None:
            version = 0
        return getaddr(config.PREFER_IP_VERSION) if version is None else getaddr(version)
    except socket.gaierror:
        if version == 6 or (version is None and config.PREFER_IP_VERSION == 6):
            raise socket.error("unable to determine IPV6 address")
        return getaddr(0) 
开发者ID:irmen,项目名称:Pyro5,代码行数:37,代码来源:socketutil.py


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