Python socket.fromfd方法代码示例

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

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

示例1: _fromListeningDescriptor

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def _fromListeningDescriptor(cls, reactor, fd, addressFamily, factory):
        """
        Create a new L{Port} based on an existing listening I{SOCK_STREAM}
        socket.
        Arguments are the same as to L{Port.__init__}, except where noted.
        @param fd: An integer file descriptor associated with a listening
            socket.  The socket must be in non-blocking mode.  Any additional
            attributes desired, such as I{FD_CLOEXEC}, must also be set already.
        @param addressFamily: The address family (sometimes called I{domain}) of
            the existing socket.  For example, L{socket.AF_INET}.
        @return: A new instance of C{cls} wrapping the socket given by C{fd}.
        """
        port = socket.fromfd(fd, addressFamily, cls.socketType)
        interface = port.getsockname()[0]
        self = cls(None, factory, None, interface, reactor)
        self._preexistingSocket = port
        return self 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:tcp.py


示例2: recvfd

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def recvfd(socketfd):
    """
    Receive a file descriptor from a L{sendmsg} message on the given C{AF_UNIX}
    socket.
    @param socketfd: An C{AF_UNIX} socket, attached to another process waiting
        to send sockets via the ancillary data mechanism in L{send1msg}.
    @param fd: C{int}
    @return: a 2-tuple of (new file descriptor, description).
    @rtype: 2-tuple of (C{int}, C{bytes})
    """
    ourSocket = socket.fromfd(socketfd, socket.AF_UNIX, socket.SOCK_STREAM)
    data, ancillary, flags = recvmsg(ourSocket)
    [(cmsgLevel, cmsgType, packedFD)] = ancillary
    # cmsgLevel and cmsgType really need to be SOL_SOCKET / SCM_RIGHTS, but
    # since those are the *only* standard values, there's not much point in
    # checking.
    [unpackedFD] = unpack("i", packedFD)
    return (unpackedFD, data) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:pullpipe.py


示例3: killSocket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def killSocket(self):
        if not self.currentResponse:
            return
        try:
            socket.fromfd(self.currentResponse.raw.fileno(), socket.AF_INET, socket.SOCK_STREAM).shutdown(socket.SHUT_RDWR)
            return
        except AttributeError:
            pass
        except Exception as e:
            util.ERROR(err=e)
        try:
            self.currentResponse.raw._fp.fp._sock.shutdown(socket.SHUT_RDWR)
        except AttributeError:
            pass
        except Exception as e:
            util.ERROR(err=e) 
开发者ID:plexinc,项目名称:plex-for-kodi,代码行数:20,代码来源:http.py


示例4: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def __init__(self,
                 socketFd,
                 sharedStateAddress):
        self.socketFd = socketFd
        self.callbackSchedulerFactory = CallbackScheduler.createSimpleCallbackSchedulerFactory()
        self.scheduler = self.callbackSchedulerFactory.createScheduler(
            "BackendGatewayRequestHandler",
            1
            )
        sharedStateHost, sharedStatePort = sharedStateAddress.split(':')
        sharedStateViewFactory = ViewFactory.ViewFactory.TcpViewFactory(
            self.callbackSchedulerFactory.createScheduler('SharedState', 1),
            sharedStateHost,
            int(sharedStatePort)
            )
        self.subscribableHandler = ConnectionHandler.ConnectionHandler(
            self.scheduler,
            sharedStateViewFactory,
            lambda: TcpChannelFactory.TcpStringChannelFactory(self.scheduler)
            )
        self.sock = socket.fromfd(socketFd, socket.AF_INET, socket.SOCK_STREAM) 
开发者ID:ufora,项目名称:ufora,代码行数:26,代码来源:handleBackendGatewayConnection.py


示例5: get_high_socket_fd

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def get_high_socket_fd(self):
        if WIN32:
            # The child process will not have any socket handles, so
            # calling socket.fromfd() should produce WSAENOTSOCK even
            # if there is a handle of the same number.
            return socket.socket().detach()
        else:
            # We want to produce a socket with an fd high enough that a
            # freshly created child process will not have any fds as high.
            fd = socket.socket().detach()
            to_close = []
            while fd < 50:
                to_close.append(fd)
                fd = os.dup(fd)
            for x in to_close:
                os.close(x)
            return fd 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:_test_multiprocessing.py


示例6: _fromListeningDescriptor

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def _fromListeningDescriptor(cls, reactor, fd, addressFamily, factory):
        """
        Create a new L{Port} based on an existing listening I{SOCK_STREAM}
        socket.
        Arguments are the same as to L{Port.__init__}, except where noted.
        @param fd: An integer file descriptor associated with a listening
            socket.  The socket must be in non-blocking mode.  Any additional
            attributes desired, such as I{FD_CLOEXEC}, must also be set already.
        @param addressFamily: The address family (sometimes called I{domain}) of
            the existing socket.  For example, L{socket.AF_INET}.
        @return: A new instance of C{cls} wrapping the socket given by C{fd}.
        """
        port = socket.fromfd(fd, addressFamily, cls.socketType)
        interface = _getsockname(port)[0]
        self = cls(None, factory, None, interface, reactor)
        self._preexistingSocket = port
        return self 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:tcp.py


示例7: _fromListeningDescriptor

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def _fromListeningDescriptor(cls, reactor, fd, factory):
        """
        Create a new L{Port} based on an existing listening I{SOCK_STREAM}
        socket.
        Arguments are the same as to L{Port.__init__}, except where noted.
        @param fd: An integer file descriptor associated with a listening
            socket.  The socket must be in non-blocking mode.  Any additional
            attributes desired, such as I{FD_CLOEXEC}, must also be set already.
        @return: A new instance of C{cls} wrapping the socket given by C{fd}.
        """
        port = socket.fromfd(fd, cls.addressFamily, cls.socketType)
        self = cls(port.getsockname(), factory, reactor=reactor)
        self._preexistingSocket = port
        return self 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:unix.py


示例8: is_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def is_socket(fd):
    """ Determine if the file descriptor is a socket.
        Return ``False`` if querying the socket type of `fd` raises an
        error; otherwise return ``True``.
        """
    result = False
    file_socket = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW)
    try:
        socket_type = file_socket.getsockopt(
            socket.SOL_SOCKET, socket.SO_TYPE)
    except socket.error, exc:
        exc_errno = exc.args[0]
        if exc_errno == errno.ENOTSOCK:
            # Socket operation on non-socket
            pass
        else:
            # Some other socket error
            result = True 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:daemon.py


示例9: _is_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def _is_socket(cls, stream):
        """Check if the given stream is a socket."""
        try:
            fd = stream.fileno()
        except ValueError:
            # If it has no file descriptor, it's not a socket
            return False
        sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW)
        try:
            # This will raise a socket.error if it's not a socket
            sock.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
        except socket.error as ex:
            if ex.args[0] != errno.ENOTSOCK:
                # It must be a socket
                return True
        else:
            # If an exception wasn't raised, it's a socket
            return True 
开发者ID:jnrbsn,项目名称:daemonocle,代码行数:21,代码来源:core.py


示例10: _get_systemd_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def _get_systemd_socket(self, address):
        fds = sd.listen_fds()
        if not fds:
            return address
        elif len(fds) > 1:
            raise ValueError('Too many listening sockets', fds)
        if isinstance(address, tuple):
            port = address[1]
            # systemd uses IPv6
            if not sd.is_socket_inet(fds[0], family=socket.AF_INET6,
                                     type=socket.SOCK_STREAM,
                                     listening=True, port=port):
                raise ValueError(
                    "FD {} is not TCP IPv6 socket on port {}".format(
                        fds[0], port
                    )
                )
            logger.info('Using systemd socket activation on port %i', port)
            sock = socket.fromfd(fds[0], socket.AF_INET6, socket.SOCK_STREAM)
        else:
            if not sd.is_socket_unix(fds[0], socket.SOCK_STREAM,
                                     listening=True, path=address):
                raise ValueError(
                    "FD {} is not Unix stream socket on path {}".format(
                        fds[0], address
                    )
                )
            logger.info('Using systemd socket activation on path %s', address)
            sock = socket.fromfd(fds[0], socket.AF_UNIX, socket.SOCK_STREAM)
        if sys.version_info[0] < 3:
            # Python 2.7's socket.fromfd() returns _socket.socket
            sock = socket.socket(_sock=sock)
        return sock 
开发者ID:latchset,项目名称:custodia,代码行数:37,代码来源:server.py


示例11: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def __init__(self, host, port, app, handler=None,
                 passthrough_errors=False, ssl_context=None, fd=None):
        if handler is None:
            handler = WSGIRequestHandler
        self.address_family = select_ip_version(host, port)
        if fd is not None:
            real_sock = socket.fromfd(fd, self.address_family,
                                      socket.SOCK_STREAM)
            port = 0
        HTTPServer.__init__(self, (host, int(port)), handler)
        self.app = app
        self.passthrough_errors = passthrough_errors
        self.shutdown_signal = False
        self.host = host
        self.port = port
        # Patch in the original socket.
        if fd is not None:
            self.socket.close()
            self.socket = real_sock
            self.server_address = self.socket.getsockname()
        if ssl_context is not None:
            if isinstance(ssl_context, tuple):
                ssl_context = load_ssl_context(*ssl_context)
            if ssl_context == 'adhoc':
                ssl_context = generate_adhoc_ssl_context()
            # If we are on Python 2 the return value from socket.fromfd
            # is an internal socket object but what we need for ssl wrap
            # is the wrapper around it :(
            sock = self.socket
            if PY2 and not isinstance(sock, socket.socket):
                sock = socket.socket(sock.family, sock.type, sock.proto, sock)
            self.socket = ssl_context.wrap_socket(sock, server_side=True)
            self.ssl_context = ssl_context
        else:
            self.ssl_context = None 
开发者ID:jpush,项目名称:jbox,代码行数:41,代码来源:serving.py


示例12: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def __init__(self, address, conf, log, fd=None):
        self.log = log
        self.conf = conf
        self.cfg_addr = address
        if fd is None:
            sock = socket.socket(self.FAMILY, socket.SOCK_STREAM)
        else:
            sock = socket.fromfd(fd, self.FAMILY, socket.SOCK_STREAM)
        self.sock = self.set_options(sock, bound=(fd is not None)) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:sock.py


示例13: is_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def is_socket (fd):
		try:
			s = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW)
		except ValueError,e:
			# The file descriptor is closed
			return False 
开发者ID:Exa-Networks,项目名称:exaddos,代码行数:8,代码来源:application.py


示例14: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def __init__(self, host, port, app, handler=None,
                 passthrough_errors=False, ssl_context=None, fd=None):
        if handler is None:
            handler = WSGIRequestHandler
        self.address_family = select_ip_version(host, port)
        if fd is not None:
            real_sock = socket.fromfd(fd, self.address_family,
                                      socket.SOCK_STREAM)
            port = 0
        HTTPServer.__init__(self, get_sockaddr(host, int(port),
                                               self.address_family), handler)
        self.app = app
        self.passthrough_errors = passthrough_errors
        self.shutdown_signal = False
        self.host = host
        self.port = self.socket.getsockname()[1]
        # Patch in the original socket.
        if fd is not None:
            self.socket.close()
            self.socket = real_sock
            self.server_address = self.socket.getsockname()
        if ssl_context is not None:
            if isinstance(ssl_context, tuple):
                ssl_context = load_ssl_context(*ssl_context)
            if ssl_context == 'adhoc':
                ssl_context = generate_adhoc_ssl_context()
            # If we are on Python 2 the return value from socket.fromfd
            # is an internal socket object but what we need for ssl wrap
            # is the wrapper around it :(
            sock = self.socket
            if PY2 and not isinstance(sock, socket.socket):
                sock = socket.socket(sock.family, sock.type, sock.proto, sock)
            self.socket = ssl_context.wrap_socket(sock, server_side=True)
            self.ssl_context = ssl_context
        else:
            self.ssl_context = None 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:42,代码来源:serving.py


示例15: testFromFd

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def testFromFd(self):
        # Testing fromfd()
        fd = self.cli_conn.fileno()
        sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
        self.addCleanup(sock.close)
        msg = sock.recv(1024)
        self.assertEqual(msg, MSG) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_socket.py


示例16: fromfd

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def fromfd(fd, family, type_, proto=0):
    s = socket.fromfd(fd, family, type_, proto)
    if s.__class__ is not socket.socket:
        s = socket.socket(_sock=s)
    return s 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:reduction.py


示例17: rebuild_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def rebuild_socket(reduced_handle, family, type_, proto):
    fd = rebuild_handle(reduced_handle)
    _sock = fromfd(fd, family, type_, proto)
    close(fd)
    return _sock 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:reduction.py


示例18: is_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def is_socket(fd):
    """Determine if the file descriptor is a socket."""
    file_socket = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW)
    try:
        file_socket.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
    except socket.error as ex:
        return ex.args[0] != errno.ENOTSOCK
    else:
        return True 
开发者ID:edgedb,项目名称:edgedb,代码行数:12,代码来源:lib.py


示例19: testFromFd

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def testFromFd(self):
        # Testing fromfd()
        if not hasattr(socket, "fromfd"):
            return # On Windows, this doesn't exist
        fd = self.cli_conn.fileno()
        sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
        self.addCleanup(sock.close)
        msg = sock.recv(1024)
        self.assertEqual(msg, MSG) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:11,代码来源:test_socket.py


示例20: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def __init__(self, host, port, app, handler=None,
                 passthrough_errors=False, ssl_context=None, fd=None):
        if handler is None:
            handler = WSGIRequestHandler
        self.address_family = select_ip_version(host, port)
        if fd is not None:
            real_sock = socket.fromfd(fd, self.address_family,
                                      socket.SOCK_STREAM)
            port = 0
        HTTPServer.__init__(self, (host, int(port)), handler)
        self.app = app
        self.passthrough_errors = passthrough_errors
        self.shutdown_signal = False
        self.host = host
        self.port = self.socket.getsockname()[1]
        # Patch in the original socket.
        if fd is not None:
            self.socket.close()
            self.socket = real_sock
            self.server_address = self.socket.getsockname()
        if ssl_context is not None:
            if isinstance(ssl_context, tuple):
                ssl_context = load_ssl_context(*ssl_context)
            if ssl_context == 'adhoc':
                ssl_context = generate_adhoc_ssl_context()
            # If we are on Python 2 the return value from socket.fromfd
            # is an internal socket object but what we need for ssl wrap
            # is the wrapper around it :(
            sock = self.socket
            if PY2 and not isinstance(sock, socket.socket):
                sock = socket.socket(sock.family, sock.type, sock.proto, sock)
            self.socket = ssl_context.wrap_socket(sock, server_side=True)
            self.ssl_context = ssl_context
        else:
            self.ssl_context = None 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:41,代码来源:serving.py


示例21: _start_worker

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def _start_worker(self):
        env = dict(os.environ)
        env["ABUSEHELPER_SUBPROCESS"] = ""
        # Find out the full package & module name. Don't refer to the
        # variable __loader__ directly to keep flake8 (version 2.5.0)
        # linter happy.
        fullname = globals()["__loader__"].fullname
        own_conn, other_conn = native_socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
        try:
            process = subprocess.Popen(
                [sys.executable, "-m", fullname],
                preexec_fn=os.setpgrp,
                stdin=other_conn.fileno(),
                close_fds=True,
                env=env
            )
            try:
                conn = socket.fromfd(own_conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM)
            except:
                process.terminate()
                process.wait()
                raise
        finally:
            own_conn.close()
            other_conn.close()
        return process, conn 
开发者ID:abusesa,项目名称:abusehelper,代码行数:31,代码来源:roomgraph.py


示例22: _fromListeningDescriptor

# 需要导入模块: import socket [as 别名]
# 或者: from socket import fromfd [as 别名]
def _fromListeningDescriptor(cls, reactor, fd, addressFamily, protocol,
                                 maxPacketSize):
        """
        Create a new L{Port} based on an existing listening
        I{SOCK_DGRAM} socket.
        @param reactor: A reactor which will notify this L{Port} when
            its socket is ready for reading or writing. Defaults to
            L{None}, ie the default global reactor.
        @type reactor: L{interfaces.IReactorFDSet}
        @param fd: An integer file descriptor associated with a listening
            socket.  The socket must be in non-blocking mode.  Any additional
            attributes desired, such as I{FD_CLOEXEC}, must also be set already.
        @type fd: L{int}
        @param addressFamily: The address family (sometimes called I{domain}) of
            the existing socket.  For example, L{socket.AF_INET}.
        @param addressFamily: L{int}
        @param protocol: A C{DatagramProtocol} instance which will be
            connected to the C{port}.
        @type proto: L{twisted.internet.protocol.DatagramProtocol}
        @param maxPacketSize: The maximum packet size to accept.
        @type maxPacketSize: L{int}
        @return: A new instance of C{cls} wrapping the socket given by C{fd}.
        @rtype: L{Port}
        """
        port = socket.fromfd(fd, addressFamily, cls.socketType)
        interface = port.getsockname()[0]
        self = cls(None, protocol, interface=interface, reactor=reactor,
                   maxPacketSize=maxPacketSize)
        self._preexistingSocket = port
        return self 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:38,代码来源:udp.py



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