當前位置: 首頁>>代碼示例>>Python>>正文


Python socket.SocketType方法代碼示例

本文整理匯總了Python中socket.SocketType方法的典型用法代碼示例。如果您正苦於以下問題:Python socket.SocketType方法的具體用法?Python socket.SocketType怎麽用?Python socket.SocketType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在socket的用法示例。


在下文中一共展示了socket.SocketType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _make_socket

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def _make_socket(iface_name: str, can_fd: bool) -> socket.SocketType:
    s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
    try:
        s.bind((iface_name,))
        s.setsockopt(socket.SOL_SOCKET, _SO_TIMESTAMP, 1)  # timestamping
        if can_fd:
            s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FD_FRAMES, 1)

        s.setblocking(False)

        if 0 != s.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR):
            raise OSError('Could not configure the socket: getsockopt(SOL_SOCKET, SO_ERROR) != 0')
    except BaseException:
        with contextlib.suppress(Exception):
            s.close()
        raise

    return s 
開發者ID:UAVCAN,項目名稱:pyuavcan,代碼行數:20,代碼來源:_socketcan.py

示例2: test_init_handles_ipv6_addr

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_init_handles_ipv6_addr(self):
        addr = (
            sentinel.host,
            sentinel.port,
            sentinel.flowinfo,
            sentinel.scopeid,
        )
        protocol = Mock(spec=network.LineProtocol)
        protocol_kwargs = {}
        sock = Mock(spec=socket.SocketType)

        network.Connection.__init__(
            self.mock, protocol, protocol_kwargs, sock, addr, sentinel.timeout
        )
        assert sentinel.host == self.mock.host
        assert sentinel.port == self.mock.port 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:18,代碼來源:test_connection.py

示例3: select_recv

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def select_recv(conn, buff_size, timeout=None):
    """add timeout for socket.recv()
    :type conn: socket.SocketType
    :type buff_size: int
    :type timeout: float
    :rtype: Union[bytes, None]
    """
    rlist, _, _ = select.select([conn], [], [], timeout)
    if not rlist:
        # timeout
        raise RuntimeError("recv timeout")

    buff = conn.recv(buff_size)
    if not buff:
        raise RuntimeError("received zero bytes, socket was closed")

    return buff 
開發者ID:mxdg,項目名稱:passbytcp,代碼行數:19,代碼來源:common_func.py

示例4: _rd_shutdown

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def _rd_shutdown(self, conn, once=False):
        """action when connection should be read-shutdown
        :type conn: socket.SocketType
        """
        if conn in self.conn_rd:
            self.conn_rd.remove(conn)

        try:
            conn.shutdown(socket.SHUT_RD)
        except:
            pass

        if not once and conn in self.map:  # use the `once` param to avoid infinite loop
            # if a socket is rd_shutdowned, then it's
            #   pair should be wr_shutdown.
            self._wr_shutdown(self.map[conn], True)

        if self.map.get(conn) not in self.conn_rd:
            # if both two connection pair was rd-shutdowned,
            #   this pair sockets are regarded to be completed
            #   so we gonna close them
            self._terminate(conn) 
開發者ID:mxdg,項目名稱:passbytcp,代碼行數:24,代碼來源:common_func.py

示例5: add_conn_pair

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def add_conn_pair(self, conn1, conn2, callback=None):
        """
        transfer anything between two sockets

        :type conn1: socket.SocketType
        :type conn2: socket.SocketType
        :param callback: callback in connection finish
        :type callback: Callable
        """
        # mark as readable
        self.conn_rd.add(conn1)
        self.conn_rd.add(conn2)

        # record sockets pairs
        self.map[conn1] = conn2
        self.map[conn2] = conn1

        # record callback
        if callback is not None:
            self.callbacks[conn1] = callback 
開發者ID:mxdg,項目名稱:passbytcp,代碼行數:22,代碼來源:common_func.py

示例6: test_init_ensure_nonblocking_io

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_init_ensure_nonblocking_io(self):
        sock = Mock(spec=socket.SocketType)

        network.Connection.__init__(
            self.mock,
            Mock(),
            {},
            sock,
            (sentinel.host, sentinel.port),
            sentinel.timeout,
        )
        sock.setblocking.assert_called_once_with(False) 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:14,代碼來源:test_connection.py

示例7: test_init_stores_values_in_attributes

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_init_stores_values_in_attributes(self):
        addr = (sentinel.host, sentinel.port)
        protocol = Mock(spec=network.LineProtocol)
        protocol_kwargs = {}
        sock = Mock(spec=socket.SocketType)

        network.Connection.__init__(
            self.mock, protocol, protocol_kwargs, sock, addr, sentinel.timeout
        )
        assert sock == self.mock._sock
        assert protocol == self.mock.protocol
        assert protocol_kwargs == self.mock.protocol_kwargs
        assert sentinel.timeout == self.mock.timeout
        assert sentinel.host == self.mock.host
        assert sentinel.port == self.mock.port 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:17,代碼來源:test_connection.py

示例8: test_stop_disables_recv_send_and_timeout

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_stop_disables_recv_send_and_timeout(self):
        self.mock.stopping = False
        self.mock.actor_ref = Mock()
        self.mock._sock = Mock(spec=socket.SocketType)

        network.Connection.stop(self.mock, sentinel.reason)
        self.mock.disable_timeout.assert_called_once_with()
        self.mock.disable_recv.assert_called_once_with()
        self.mock.disable_send.assert_called_once_with() 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:11,代碼來源:test_connection.py

示例9: test_stop_closes_socket

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_stop_closes_socket(self):
        self.mock.stopping = False
        self.mock.actor_ref = Mock()
        self.mock._sock = Mock(spec=socket.SocketType)

        network.Connection.stop(self.mock, sentinel.reason)
        self.mock._sock.close.assert_called_once_with() 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:9,代碼來源:test_connection.py

示例10: test_stop_stops_actor

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_stop_stops_actor(self):
        self.mock.stopping = False
        self.mock.actor_ref = Mock()
        self.mock._sock = Mock(spec=socket.SocketType)

        network.Connection.stop(self.mock, sentinel.reason)
        self.mock.actor_ref.stop.assert_called_once_with(block=False) 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:9,代碼來源:test_connection.py

示例11: test_stop_handles_actor_already_being_stopped

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_stop_handles_actor_already_being_stopped(self):
        self.mock.stopping = False
        self.mock.actor_ref = Mock()
        self.mock.actor_ref.stop.side_effect = pykka.ActorDeadError()
        self.mock._sock = Mock(spec=socket.SocketType)

        network.Connection.stop(self.mock, sentinel.reason)
        self.mock.actor_ref.stop.assert_called_once_with(block=False) 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:10,代碼來源:test_connection.py

示例12: test_stop_sets_stopping_to_true

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_stop_sets_stopping_to_true(self):
        self.mock.stopping = False
        self.mock.actor_ref = Mock()
        self.mock._sock = Mock(spec=socket.SocketType)

        network.Connection.stop(self.mock, sentinel.reason)
        assert self.mock.stopping is True 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:9,代碼來源:test_connection.py

示例13: test_stop_does_not_proceed_when_already_stopping

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_stop_does_not_proceed_when_already_stopping(self):
        self.mock.stopping = True
        self.mock.actor_ref = Mock()
        self.mock._sock = Mock(spec=socket.SocketType)

        network.Connection.stop(self.mock, sentinel.reason)
        assert 0 == self.mock.actor_ref.stop.call_count
        assert 0 == self.mock._sock.close.call_count 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:10,代碼來源:test_connection.py

示例14: test_stop_logs_reason

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_stop_logs_reason(self):
        self.mock.stopping = False
        self.mock.actor_ref = Mock()
        self.mock._sock = Mock(spec=socket.SocketType)

        network.Connection.stop(self.mock, sentinel.reason)
        network.logger.log.assert_called_once_with(
            logging.DEBUG, sentinel.reason
        ) 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:11,代碼來源:test_connection.py

示例15: test_stop_logs_that_it_is_calling_itself

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SocketType [as 別名]
def test_stop_logs_that_it_is_calling_itself(self):
        self.mock.stopping = True
        self.mock.actor_ref = Mock()
        self.mock._sock = Mock(spec=socket.SocketType)

        network.Connection.stop(self.mock, sentinel.reason)
        network.logger.log(any_int, any_unicode) 
開發者ID:mopidy,項目名稱:mopidy-mpd,代碼行數:9,代碼來源:test_connection.py


注:本文中的socket.SocketType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。