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