当前位置: 首页>>代码示例>>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;未经允许,请勿转载。