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


Python socket.SO_RCVBUF屬性代碼示例

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


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

示例1: update

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def update(self, key, ip, port):
        """Update the running config for the udp socket server

        :param key: The hmac key used to verify the UDP packets. String
        :param ip: The ip address the UDP server will read from
        :param port: The port the UDP server will read from
        :return: None
        """
        self.key = key
        for addrinfo in socket.getaddrinfo(ip, port, 0, socket.SOCK_DGRAM):
            ai_family = addrinfo[0]
            self.sockaddr = addrinfo[4]
            if self.sock is not None:
                self.sock.close()
            self.sock = socket.socket(ai_family, socket.SOCK_DGRAM)
            self.sock.settimeout(1)
            self.sock.bind(self.sockaddr)
            if cfg.CONF.health_manager.sock_rlimit > 0:
                rlimit = cfg.CONF.health_manager.sock_rlimit
                LOG.info("setting sock rlimit to %s", rlimit)
                self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF,
                                     rlimit)
            break  # just used the first addr getaddrinfo finds
        if self.sock is None:
            raise exceptions.NetworkConfig("unable to find suitable socket") 
開發者ID:openstack,項目名稱:octavia,代碼行數:27,代碼來源:heartbeat_udp.py

示例2: _testCongestion

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def _testCongestion(self):
        # test the behavior in case of congestion
        self.data = b'fill'
        self.cli.setblocking(False)
        try:
            # try to lower the receiver's socket buffer size
            self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 16384)
        except OSError:
            pass
        with self.assertRaises(OSError) as cm:
            try:
                # fill the receiver's socket buffer
                while True:
                    self.cli.sendto(self.data, 0, (HOST, self.port))
            finally:
                # signal the receiver we're done
                self.evt.set()
        # sendto() should have failed with ENOBUFS
        self.assertEqual(cm.exception.errno, errno.ENOBUFS)
        # and we should have received a congestion notification through poll
        r, w, x = select.select([self.serv], [], [], 3.0)
        self.assertIn(self.serv, r) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,代碼來源:test_socket.py

示例3: connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def connect(self, host, port):
        self.__state = CONNECTION_STATE.DISCONNECTED
        self.__fileno = None
        self.__socket = socket.socket(_getAddrType(host), socket.SOCK_STREAM)
        self.__socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, self.__sendBufferSize)
        self.__socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.__recvBufferSize)
        self.__socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self.__socket.setblocking(0)
        self.__readBuffer = bytes()
        self.__writeBuffer = bytes()
        self.__lastReadTime = monotonicTime()

        try:
            self.__socket.connect((host, port))
        except socket.error as e:
            if e.errno not in (socket.errno.EINPROGRESS, socket.errno.EWOULDBLOCK):
                return False
        self.__fileno = self.__socket.fileno()
        self.__state = CONNECTION_STATE.CONNECTING
        self.__poller.subscribe(self.__fileno,
                                 self.__processConnection,
                                 POLL_EVENT_TYPE.READ | POLL_EVENT_TYPE.WRITE | POLL_EVENT_TYPE.ERROR)
        return True 
開發者ID:bakwc,項目名稱:PySyncObj,代碼行數:25,代碼來源:tcp_connection.py

示例4: __onNewConnection

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def __onNewConnection(self, descr, event):
        if event & POLL_EVENT_TYPE.READ:
            try:
                sock, addr = self.__socket.accept()
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, self.__sendBufferSize)
                sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.__recvBufferSize)
                sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
                sock.setblocking(0)
                conn = TcpConnection(poller=self.__poller,
                                     socket=sock,
                                     timeout=self.__connectionTimeout,
                                     sendBufferSize=self.__sendBufferSize,
                                     recvBufferSize=self.__recvBufferSize)
                self.__onNewConnectionCallback(conn)
            except socket.error as e:
                if e.errno not in (socket.errno.EAGAIN, socket.errno.EWOULDBLOCK):
                    self.unbind()
                    return

        if event & POLL_EVENT_TYPE.ERROR:
            self.unbind()
            return 
開發者ID:bakwc,項目名稱:PySyncObj,代碼行數:24,代碼來源:tcp_server.py

示例5: __open_socket

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def __open_socket(self):
        # We need the numpy
        if self.np is None:
            try:
                import numpy as np
                self.np = np
            except ImportError:
                self.logger.error('The numpy librairy is not installed')
                self.np = None
                return
        self.udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
        self.udp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1048576)
        self.udp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.logger.debug(self.udp_sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))
        self.udp_sock.bind((self.addr, self.statsd_port))
        self.logger.info("TS UDP port open", self.statsd_port)
        self.logger.debug("UDP RCVBUF", self.udp_sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)) 
開發者ID:naparuba,項目名稱:opsbro,代碼行數:19,代碼來源:module.py

示例6: _testTCPServerOption

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def _testTCPServerOption(self, level, option, values):
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self._testSetAndGetOption(sock, level, option, values)
            # now bind and listen on the socket i.e. cause the implementation socket to be created
            sock.bind( (HOST, PORT) )
            sock.listen(50)
            msg = "Option value '(%s,%s)'='%s' did not propagate to implementation socket" % (level, option, values[-1])
            if is_solaris and option == socket.SO_RCVBUF:
                # NOTE: see similar bsd/solaris workaround above
                self.assert_(sock.getsockopt(level, option) >= values[-1], msg)
            else:
                self.failUnlessEqual(sock.getsockopt(level, option), values[-1], msg)
            self._testSetAndGetOption(sock, level, option, values)
        finally:
            sock.close() 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:18,代碼來源:test_socket.py

示例7: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def __init__(self, client_ip=CLIENT_ADDRESS, uPort=PORT_COMMAND,
                 max_packet_size=MAX_PACKETSIZE):
        """Internet Protocol socket with presets for Motive Command Socket.

        Args:
            client_ip (int): an int

        """
        super(NatCommSocket, self).__init__(client_ip, uPort, max_packet_size)
        # Set Instance Attributes
        self.server_ip = client_ip  # Currently set to same value as client_ip.  May change when computer changes.

        # Connect Socket
        self._sock.bind((client_ip, 0))
        self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        self._sock.setblocking(0)
        self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, OPT_VAL)  # Not originally in this function. Check why. 
開發者ID:ratcave,項目名稱:natnetclient,代碼行數:19,代碼來源:natnet.py

示例8: modify_buff_size

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def modify_buff_size():
    sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
    
    # Get the size of the socket's send buffer
    bufsize = sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
    print ("Buffer size [Before]:%d" %bufsize)
    
    sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
    sock.setsockopt(
            socket.SOL_SOCKET,
            socket.SO_SNDBUF,
            SEND_BUF_SIZE)
    sock.setsockopt(
            socket.SOL_SOCKET,
            socket.SO_RCVBUF,
            RECV_BUF_SIZE)
    bufsize = sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
    print ("Buffer size [After]:%d" %bufsize) 
開發者ID:PacktPublishing,項目名稱:Python-Network-Programming-Cookbook-Second-Edition,代碼行數:20,代碼來源:1_8_modify_buff_size.py

示例9: receiver

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def receiver(service='mihome'):
    from plugins import gateway

    assert service in MULTICAST, 'No such service'
    store = get_store()
    address, port = MULTICAST.get(service)
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.bind(("0.0.0.0", port))
 
    mreq = struct.pack("=4sl", socket.inet_aton(address), socket.INADDR_ANY)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 32)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 1)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, SOCKET_BUFSIZE)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
    sock.settimeout(20)  # 2x of heartbeat period

    current = {}

    while True:
        try:
            data, _ = sock.recvfrom(SOCKET_BUFSIZE)  # buffer size is 1024 bytes
        except socket.timeout:
            continue
        print(datetime.now().isoformat(), data)
        if service == 'mihome':
            message = json.loads(data.decode())
            data = json.loads(message['data'])
            if message.get('model') in ('sensor_ht', 'weather.v1') and not sensor_ht.process(conn, cursor, current, message, data):
                continue
            elif message.get('model') == 'magnet':
                magnet.process(store, message, data)
            elif message.get('model') == 'gateway':
                gateway.process(store, message, data)
            current = {}
        elif service == 'yeelight':
            yeelight.process(data.decode()) 
開發者ID:aluminiumgeek,項目名稱:goodbye-mihome,代碼行數:38,代碼來源:mihome.py

示例10: serve

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def serve (self):
		# The best a 10 Mb interface can do is 14,880 frames per second
		# each frame being only 84 bytes
		# On 127.0.0.1, my Mac can receive around 10/12k frames ..
		# So it would seems the MAC loopback is bad for high perf networking ...
		try:
			sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
			current = sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)  # value of 196724 on my mac
			new = current
			while True:
				try:
					new += current
					sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, new)
				except socket.error:
					log('ipfix changed SO_RCVBUF from %d to %d' % (current,new-current))
					sys.stdout.flush()
					break

			sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
			sock.bind((self.host,self.port))
			self.running = True
		except:
			err('could not start ipfix server')
			raise

		if self.use_thread:
			try:
				while self.running:
					data, addr = sock.recvfrom(8192)
					data = self.queue.put(data)
			except Exception,e:
				self.running = False
				raise e 
開發者ID:Exa-Networks,項目名稱:exaddos,代碼行數:35,代碼來源:flow.py

示例11: connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def connect(self):
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        sock.settimeout(DEFAULT_SOCKET_TIMEOUT)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, BUFF_SIZE)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, BUFF_SIZE)

        try:
            sock.connect(str(self.server_address))
        except socket.error:
            sock.close()
            raise Exception(
                "Could not connect to {addr}".format(addr=self.server_address)
            )

        self.sock = sock 
開發者ID:hrehfeld,項目名稱:python-keepassxc-browser,代碼行數:17,代碼來源:protocol.py

示例12: __init__

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0):
        self.type = type
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)
        _flush_fd(self.ins)
        if iface:
            self.ins.bind((iface, type))
        if not nofilter:
            if conf.except_filter:
                if filter:
                    filter = "(%s) and not (%s)" % (filter, conf.except_filter)
                else:
                    filter = "not (%s)" % conf.except_filter
            if filter is not None:
                attach_filter(self.ins, filter)
        self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2**30)
        self.outs = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        self.outs.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 2**30)
        if promisc is None:
            promisc = conf.promisc
        self.promisc = promisc
        if self.promisc:
            if iface is None:
                self.iff = get_if_list()
            else:
                if iface.__class__ is list:
                    self.iff = iface
                else:
                    self.iff = [iface]
            for i in self.iff:
                set_promisc(self.ins, i) 
開發者ID:medbenali,項目名稱:CyberScan,代碼行數:33,代碼來源:linux.py

示例13: set_bufsizes

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def set_bufsizes(sock, recv_buf, send_buf):
    try_setsockopt(sock, socket.SOL_SOCKET, socket.SO_RCVBUF, recv_buf)
    try_setsockopt(sock, socket.SOL_SOCKET, socket.SO_SNDBUF, send_buf) 
開發者ID:alexbers,項目名稱:mtprotoproxy,代碼行數:5,代碼來源:mtprotoproxy.py

示例14: open

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def open(self):
        """
        Open the the Endpoint.

        :return: True is the Endpoint was successfully opened, False otherwise.
        """
        # If the endpoint is already running, then there is no need to try and open it again

        if self._running:
            return True

        loop = asyncio.get_event_loop()

        for _ in range(10000):
            try:
                # It is recommended that this endpoint is opened at port = 0,
                # such that the OS handles the port assignment
                self._transport = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                self._transport.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 870400)
                self._transport.bind((self._ip, self._port))
                self._transport.setblocking(False)
                self._port = self._transport.getsockname()[1]

                self._transport, _ = await loop.create_datagram_endpoint(lambda: self,
                                                                         sock=self._transport)

                self._logger.debug("Listening at %d", self._port)
                break
            except (OSError, ValueError):
                self._logger.debug("Listening failed at %d", self._port)
                self._port += 1
                continue

        self._running = True
        return True 
開發者ID:Tribler,項目名稱:py-ipv8,代碼行數:37,代碼來源:endpoint.py

示例15: _create_remote_socket

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_RCVBUF [as 別名]
def _create_remote_socket(self, ip, port):
        if self._remote_udp:
            addrs_v6 = socket.getaddrinfo("::", 0, 0, socket.SOCK_DGRAM, socket.SOL_UDP)
            addrs = socket.getaddrinfo("0.0.0.0", 0, 0, socket.SOCK_DGRAM, socket.SOL_UDP)
        else:
            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

        if self._remote_udp:
            af, socktype, proto, canonname, sa = addrs_v6[0]
            remote_sock_v6 = socket.socket(af, socktype, proto)
            self._remote_sock_v6 = remote_sock_v6
            self._fd_to_handlers[remote_sock_v6.fileno()] = self
            remote_sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024 * 32)
            remote_sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024 * 32)
            remote_sock_v6.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024 * 32)
            remote_sock_v6.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024 * 32)

        remote_sock.setblocking(False)
        if self._remote_udp:
            remote_sock_v6.setblocking(False)
        else:
            remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
        return remote_sock 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:35,代碼來源:tcprelay.py


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