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


Python socket.MSG_DONTWAIT属性代码示例

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


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

示例1: test_flags

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def test_flags(self):
        """
        The C{flags} argument to L{send1msg} is passed on to the underlying
        C{sendmsg} call, to affect it in whatever way is defined by those
        flags.
        """
        # Just exercise one flag with simple, well-known behavior. MSG_DONTWAIT
        # makes the send a non-blocking call, even if the socket is in blocking
        # mode.  See also test_flags in RecvmsgTests
        for i in range(1024):
            try:
                send1msg(self.input.fileno(), "x" * 1024, MSG_DONTWAIT)
            except error as e:
                self.assertEqual(e.args[0], errno.EAGAIN)
                break
        else:
            self.fail(
                "Failed to fill up the send buffer, "
                "or maybe send1msg blocked for a while") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_sendmsg.py

示例2: sendto

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def sendto(self, msg, address):
        if (self.sock.getsockname(), address) not in self.isolations:
            self.lg.debug("{} - [{}] --> {}".format(self.sock.getsockname(), msg, address))
            try:
                return self.sock.sendto(msg, socket.MSG_DONTWAIT, address)
            except ConnectionRefusedError:
                self.lg.warning(
                    "simulator_stuff.sendto: the message {} has not been \
                     delivered because the destination {} left the team".format(
                        msg, address))
            except KeyboardInterrupt:
                self.lg.warning("simulator_stuff.sendto: send_packet {} to {}".format(msg, address))
                raise
            except FileNotFoundError:
                self.lg.error("simulator_stuff.sendto: {}".format(address))
                raise
            except BlockingIOError:
                raise
        else:
            self.lg.warning("{} not sent from {} to {} (isolated)".format(msg, self.sock.getsockname(), address)) 
开发者ID:P2PSP,项目名称:simulator,代码行数:22,代码来源:simulator_stuff.py

示例3: test_flags

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def test_flags(self):
        """
        The C{flags} argument to L{send1msg} is passed on to the underlying
        C{sendmsg} call, to affect it in whatever way is defined by those
        flags.
        """
        # Just exercise one flag with simple, well-known behavior. MSG_DONTWAIT
        # makes the send a non-blocking call, even if the socket is in blocking
        # mode.  See also test_flags in RecvmsgTests
        for i in range(8 * 1024):
            try:
                send1msg(self.input.fileno(), "x" * 1024, MSG_DONTWAIT)
            except error as e:
                self.assertEqual(e.args[0], errno.EAGAIN)
                break
        else:
            self.fail(
                "Failed to fill up the send buffer, "
                "or maybe send1msg blocked for a while") 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:21,代码来源:test_sendmsg.py

示例4: _read

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def _read(self):
        #read until the server is stopped or the client disconnects
        while self._client_connected:
            #read data from Bluetooth socket
            try:
                data = self._client_sock.recv(1024, socket.MSG_DONTWAIT)
            except IOError as e:
                self._handle_bt_error(e)
                data = b""
            if data:
                if self._data_received_callback:
                    if self._encoding:
                        data = data.decode(self._encoding)
                    self.data_received_callback(data)
            if self._conn_thread.stopping.wait(BLUETOOTH_TIMEOUT):
                break

        #close the client socket
        self._client_sock.close()
        self._client_sock = None
        self._client_info = None
        self._client_connected = False 
开发者ID:martinohanlon,项目名称:BlueDot,代码行数:24,代码来源:btcomm.py

示例5: read_ha_proxy_stats

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def read_ha_proxy_stats(haproxy_stats_socket):
    conn = socket(AF_UNIX, SOCK_STREAM)
    try:
        conn.connect(haproxy_stats_socket)
        conn.sendall(b'show stat\r\n')
        data = conn.recv(BUFFER_SIZE)
        while len(data) % BUFFER_SIZE == 0:
            try:
                data += conn.recv(BUFFER_SIZE, MSG_DONTWAIT)
            except socket.error:
                break
        return data
    finally:
        conn.close() 
开发者ID:innogames,项目名称:igcollect,代码行数:16,代码来源:haproxy.py

示例6: sendto

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def sendto(self, msg, address):

        self.lg.debug(f"{self.sock.getsockname()} - [{msg}] --> {address}")
        try:
            return self.sock.sendto(msg, socket.MSG_DONTWAIT, address)
        except ConnectionRefusedError:
            self.lg.error("sendto: connection refused from {address}")
        except KeyboardInterrupt:
            self.lg.warning("sendto: keyboard interrupt")
            raise
        except FileNotFoundError:
            self.lg.error("sendto: file not found")
            raise
        except BlockingIOError:
            raise 
开发者ID:P2PSP,项目名称:simulator,代码行数:17,代码来源:socket_wrapper.py

示例7: _send

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def _send(self, sock, data):
        sock.sendall(data, socket.MSG_DONTWAIT) 
开发者ID:what-studio,项目名称:profiling,代码行数:4,代码来源:select.py

示例8: _testSendmsgTimeout

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def _testSendmsgTimeout(self):
        try:
            self.cli_sock.settimeout(0.03)
            with self.assertRaises(socket.timeout):
                while True:
                    self.sendmsgToServer([b"a"*512])
        finally:
            self.misc_event.set()

    # XXX: would be nice to have more tests for sendmsg flags argument.

    # Linux supports MSG_DONTWAIT when sending, but in general, it
    # only works when receiving.  Could add other platforms if they
    # support it too. 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_socket.py

示例9: testSendmsgDontWait

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def testSendmsgDontWait(self):
        # Check that MSG_DONTWAIT in flags causes non-blocking behaviour.
        self.assertEqual(self.serv_sock.recv(512), b"a"*512)
        self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_socket.py

示例10: _testSendmsgDontWait

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def _testSendmsgDontWait(self):
        try:
            with self.assertRaises(OSError) as cm:
                while True:
                    self.sendmsgToServer([b"a"*512], [], socket.MSG_DONTWAIT)
            self.assertIn(cm.exception.errno,
                          (errno.EAGAIN, errno.EWOULDBLOCK))
        finally:
            self.misc_event.set() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_socket.py

示例11: process

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def process(self):
    """Without blocking, read available packets and invoke their callbacks."""
    data = self.socket.recv(BUFFER_SIZE, socket.MSG_DONTWAIT)
    buf = ctypes.create_string_buffer(data)
    nfq.nfq_handle_packet(self.handle, buf, len(data)) 
开发者ID:google,项目名称:packet-queue,代码行数:7,代码来源:libnetfilter_queue.py

示例12: try_recv

# 需要导入模块: import socket [as 别名]
# 或者: from socket import MSG_DONTWAIT [as 别名]
def try_recv(self):
        """Return None immediately if nothing is waiting"""
        try:
            lenstr = self.sock.recv(4, socket.MSG_DONTWAIT)
        except socket.error:
            return None
        if len(lenstr) < 4:
            raise EOFError("Socket closed")
        length = struct.unpack("<I", lenstr)[0]
        return self._get_next_obj(length) 
开发者ID:SiLab-Bonn,项目名称:basil,代码行数:12,代码来源:Protocol.py


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