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


Python socket.SHUT_RD属性代码示例

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


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

示例1: ip_latency_test

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def ip_latency_test(ip, port=443):
    tag = 'IP_Latency_TEST'
    print_with_tag(tag, ['Prepare IP latency test for ip', ip, 'Port', str(port)])
    s_test = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s_test.settimeout(10)
    s_start = time.time()
    try:
        s_test.connect((ip, port))
        s_test.shutdown(socket.SHUT_RD)
    except Exception as e:
        print_with_tag(tag, ['Error:', e])
        return None
    s_stop = time.time()
    s_runtime = '%.2f' % (1000 * (s_stop - s_start))
    print_with_tag(tag, [ip, 'Latency:', s_runtime])
    return float(s_runtime) 
开发者ID:SuzukiHonoka,项目名称:Starx_Pixiv_Collector,代码行数:18,代码来源:start.py

示例2: _rd_shutdown

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [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

示例3: _close_socket_on_stop

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def _close_socket_on_stop(self, sock: socket.socket) -> None:
        # This function runs in the background waiting for the `stop` Event to
        # be set at which point it closes the socket, causing the server to
        # shutdown.  This allows the server threads to be cleanly closed on
        # demand.
        self.wait_stopped()

        try:
            sock.shutdown(socket.SHUT_RD)
        except OSError as e:
            # on mac OS this can result in the following error:
            # OSError: [Errno 57] Socket is not connected
            if e.errno != errno.ENOTCONN:
                raise

        sock.close() 
开发者ID:ethereum,项目名称:trinity,代码行数:18,代码来源:socket.py

示例4: tcp

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def tcp(host, port=80, count=1, timeout=1):
    result = []
    for _ in range(count):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(timeout)
        start_time = time.time()
        try:
            s.connect((host, port))
            s.shutdown(socket.SHUT_RD)
            stop_time = time.time()
            result.append(round(1000 * (stop_time - start_time), 2))
        except socket.timeout:
            result.append(-1)
        except OSError as e:
            print("OS Error:", e)
            result.append(-1)
        finally:
            s.close()
    return result 
开发者ID:Berkeley-Reject,项目名称:network-lib,代码行数:21,代码来源:ping.py

示例5: shutdown

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def shutdown(self, how=socket.SHUT_RDWR):
        """
        Send a shutdown signal for one or both of reading and writing. Valid
        arguments are ``socket.SHUT_RDWR``, ``socket.SHUT_RD``, and
        ``socket.SHUT_WR``.

        Shutdown differs from closing in that it explicitly changes the state of
        the socket resource to closed, whereas closing will only decrement the
        number of peers on this end of the socket, since sockets can be a
        resource shared by multiple peers on a single OS. When the number of
        peers reaches zero, the socket is closed, but not deallocated, so you
        still need to call close. (except that this is python and close is
        automatically called on the deletion of the socket)

        http://stackoverflow.com/questions/409783/socket-shutdown-vs-socket-close
        """
        return self.sock.shutdown(how) 
开发者ID:rhelmot,项目名称:nclib,代码行数:19,代码来源:netcat.py

示例6: _shutdown_connection

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def _shutdown_connection(connection):
    if not connection.rfile.closed:
      connection.socket.shutdown(socket.SHUT_RD) 
开发者ID:elsigh,项目名称:browserscope,代码行数:5,代码来源:wsgi_server.py

示例7: test_shutdown_connection

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def test_shutdown_connection(self):

    class DummyObect(object):
      pass

    connection = DummyObect()
    connection.rfile = DummyObect()
    connection.rfile.closed = False
    connection.socket = self.mox.CreateMockAnything()
    connection.socket.shutdown(socket.SHUT_RD)

    self.mox.ReplayAll()
    self.thread_pool._shutdown_connection(connection)
    self.mox.VerifyAll() 
开发者ID:elsigh,项目名称:browserscope,代码行数:16,代码来源:wsgi_server_test.py

示例8: _get_database_tcp_latency

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def _get_database_tcp_latency(self, timeout: float = 5):
        db_config = database.get_config()
        host, port = self._get_db_host_and_port(db_config["DatabaseHost"])
        # New Socket and Time out
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(timeout)

        # Start a timer
        s_start = timer()

        # Try to Connect
        try:
            sock.connect((host, int(port)))
            sock.shutdown(socket.SHUT_RD)
            sock.close()

        # If something bad happens, the latency is None
        except socket.timeout:
            return None
        except OSError:
            return None

        # Stop Timer
        s_stop = timer()
        s_runtime = "%.2f" % (1000 * (s_stop - s_start))

        return s_runtime 
开发者ID:mendix,项目名称:cf-mendix-buildpack,代码行数:29,代码来源:metrics.py

示例9: stop

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def stop(self, timeout=5):
        # OmniMarkupPreviewer: Force shutdown without waiting too much
        while self._get_qsize() > 0:
            conn = self.get()
            if conn is not _SHUTDOWNREQUEST:
                conn.close()
        # Must shut down threads here so the code that calls
        # this method can know when all threads are stopped.
        for worker in self._threads:
            self._queue.put(_SHUTDOWNREQUEST)

        # Don't join currentThread (when stop is called inside a request).
        current = threading.currentThread()
        if timeout and timeout >= 0:
            endtime = time.time() + timeout
        while self._threads:
            worker = self._threads.pop()
            if worker is not current and worker.isAlive():
                try:
                    if timeout is None or timeout < 0:
                        worker.join()
                    else:
                        remaining_time = endtime - time.time()
                        if remaining_time > 0:
                            worker.join(remaining_time)
                        if worker.isAlive():
                            # We exhausted the timeout.
                            # Forcibly shut down the socket.
                            c = worker.conn
                            if c and not c.rfile.closed:
                                try:
                                    c.socket.shutdown(socket.SHUT_RD)
                                except TypeError:
                                    # pyOpenSSL sockets don't take an arg
                                    c.socket.shutdown()
                            worker.join()
                except (AssertionError,
                        # Ignore repeated Ctrl-C.
                        # See https://bitbucket.org/cherrypy/cherrypy/issue/691.
                        KeyboardInterrupt):
                    pass 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:43,代码来源:wsgiserver3.py

示例10: stop

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def stop(self, timeout=5):
        # Must shut down threads here so the code that calls
        # this method can know when all threads are stopped.
        for worker in self._threads:
            self._queue.put(_SHUTDOWNREQUEST)
        
        # Don't join currentThread (when stop is called inside a request).
        current = threading.currentThread()
        if timeout and timeout >= 0:
            endtime = time.time() + timeout
        while self._threads:
            worker = self._threads.pop()
            if worker is not current and worker.isAlive():
                try:
                    if timeout is None or timeout < 0:
                        worker.join()
                    else:
                        remaining_time = endtime - time.time()
                        if remaining_time > 0:
                            worker.join(remaining_time)
                        if worker.isAlive():
                            # We exhausted the timeout.
                            # Forcibly shut down the socket.
                            c = worker.conn
                            if c and not c.rfile.closed:
                                try:
                                    c.socket.shutdown(socket.SHUT_RD)
                                except TypeError:
                                    # pyOpenSSL sockets don't take an arg
                                    c.socket.shutdown()
                            worker.join()
                except (AssertionError,
                        # Ignore repeated Ctrl-C.
                        # See http://www.cherrypy.org/ticket/691.
                        KeyboardInterrupt), exc1:
                    pass 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:38,代码来源:__init__.py

示例11: test_005_event

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def test_005_event(self):
        self.writer.write(b'mgmt.event+arg dom0 name dom0\0payload')
        self.writer.write_eof()
        with self.assertNotRaises(asyncio.TimeoutError):
            response = self.loop.run_until_complete(
                asyncio.wait_for(self.reader.readuntil(b'\0\0'), 1))
        self.assertEqual(response, b"1\0subject\0event\0payload\0payload\0\0")
        # this will trigger connection_lost, but only when next event is sent
        self.sock_client.shutdown(socket.SHUT_RD)
        # check if event-producing method is interrupted
        with self.assertNotRaises(asyncio.TimeoutError):
            self.loop.run_until_complete(
                asyncio.wait_for(self.protocol.mgmt.task, 1)) 
开发者ID:QubesOS,项目名称:qubes-core-admin,代码行数:15,代码来源:api.py

示例12: close_socket_for_read

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def close_socket_for_read(self):
        """Close the server-client socket for reads incoming from client.

        We do not completly close the socket right now to allow late reads
        in the client side. But this socket will soon be closed.
        """
        if self._sock is not None:
            self.outmsg("Closing socket for reads")
            try:
                self._sock.shutdown(socket.SHUT_RD)
            except Exception:
                # already closed
                pass
        self._sock_accept_reads = False 
开发者ID:regilero,项目名称:HTTPWookiee,代码行数:16,代码来源:worker.py

示例13: stop

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def stop(self, timeout=5):
        # Must shut down threads here so the code that calls
        # this method can know when all threads are stopped.
        for worker in self._threads:
            self._queue.put(_SHUTDOWNREQUEST)

        # Don't join currentThread (when stop is called inside a request).
        current = threading.currentThread()
        if timeout and timeout >= 0:
            endtime = time.time() + timeout
        while self._threads:
            worker = self._threads.pop()
            if worker is not current and worker.isAlive():
                try:
                    if timeout is None or timeout < 0:
                        worker.join()
                    else:
                        remaining_time = endtime - time.time()
                        if remaining_time > 0:
                            worker.join(remaining_time)
                        if worker.isAlive():
                            # We exhausted the timeout.
                            # Forcibly shut down the socket.
                            c = worker.conn
                            if c and not c.rfile.closed:
                                try:
                                    c.socket.shutdown(socket.SHUT_RD)
                                except TypeError:
                                    # pyOpenSSL sockets don't take an arg
                                    c.socket.shutdown()
                            worker.join()
                except (AssertionError,
                        # Ignore repeated Ctrl-C.
                        # See
                        # https://github.com/cherrypy/cherrypy/issues/691.
                        KeyboardInterrupt):
                    pass 
开发者ID:Naayouu,项目名称:Hatkey,代码行数:39,代码来源:wsgiserver3.py

示例14: server

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def server(self):
        print "[+] Redirect with script injection initialized."
        self.dnsspoof.start(None, "Inject")

        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        server_address = (self.host, self.port)
        print '[+] Injection URL - http://{}:{}'.format(self.host, self.port)
        server.bind(server_address)
        server.listen(1)

        for i in range(0, 2):
            if i >= 1:
                domain = self.dnsspoof.getdomain()
                domain = domain[:-1]
                print "[+] Target was requesting: {}".format(domain)
                self.dnsspoof.stop()

                try:
                    connection, client_address = server.accept()
                    redirect = self.response + """<body> <meta http-equiv="refresh" content="0; URL='http://{}"/> </body>""".format(
                        domain)
                    connection.send("%s" % redirect)
                    print "[+] Script Injected on: ", client_address
                    connection.shutdown(socket.SHUT_WR | socket.SHUT_RD)
                    connection.close()
                except KeyboardInterrupt:
                    server.close()

            try:
                connection, client_address = server.accept()
                connection.send("%s" % self.response)
                connection.shutdown(socket.SHUT_WR | socket.SHUT_RD)
                connection.close()
            except KeyboardInterrupt:
                server.close() 
开发者ID:m4n3dw0lf,项目名称:pythem,代码行数:38,代码来源:redirect.py

示例15: cancel

# 需要导入模块: import socket [as 别名]
# 或者: from socket import SHUT_RD [as 别名]
def cancel(self):
        """Cancel this context; gevent might complain about this with an
        exception later on."""
        try:
            self.sock.shutdown(socket.SHUT_RD)
        except socket.error:
            pass 
开发者ID:Ryuchen,项目名称:Panda-Sandbox,代码行数:9,代码来源:ResultManager.py


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