當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。