def __init__(self, family_or_realsock=socket.AF_INET, *args, **kwargs): should_set_nonblocking = kwargs.pop('set_nonblocking', True) if isinstance(family_or_realsock, six.integer_types): fd = _original_socket(family_or_realsock, *args, **kwargs) else: fd = family_or_realsock # import timeout from other socket, if it was there try: self._timeout = fd.gettimeout() or socket.getdefaulttimeout() except AttributeError: self._timeout = socket.getdefaulttimeout() if should_set_nonblocking: set_nonblocking(fd) self.fd = fd # when client calls setblocking(0) or settimeout(0) the socket must # act non-blocking self.act_non_blocking = False # Copy some attributes from underlying real socket. # This is the easiest way that i found to fix # https://bitbucket.org/eventlet/eventlet/issue/136 # Only `getsockopt` is required to fix that issue, others # are just premature optimization to save __getattr__ call. self.bind = fd.bind self.close = fd.close self.fileno = fd.fileno self.getsockname = fd.getsockname self.getsockopt = fd.getsockopt self.listen = fd.listen self.setsockopt = fd.setsockopt self.shutdown = fd.shutdown
def __init__(self, family_or_realsock=socket.AF_INET, *args, **kwargs): should_set_nonblocking = kwargs.pop('set_nonblocking', True) if isinstance(family_or_realsock, (int, long)): fd = _original_socket(family_or_realsock, *args, **kwargs) else: fd = family_or_realsock # import timeout from other socket, if it was there try: self._timeout = fd.gettimeout() or socket.getdefaulttimeout() except AttributeError: self._timeout = socket.getdefaulttimeout() if should_set_nonblocking: set_nonblocking(fd) self.fd = fd # when client calls setblocking(0) or settimeout(0) the socket must # act non-blocking self.act_non_blocking = False # Copy some attributes from underlying real socket. # This is the easiest way that i found to fix # https://bitbucket.org/eventlet/eventlet/issue/136 # Only `getsockopt` is required to fix that issue, others # are just premature optimization to save __getattr__ call. self.bind = fd.bind self.close = fd.close self.fileno = fd.fileno self.getsockname = fd.getsockname self.getsockopt = fd.getsockopt self.listen = fd.listen self.setsockopt = fd.setsockopt self.shutdown = fd.shutdown
def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, _sock=None, _hub=None): """ Initialize the UV socket :param family_or_realsock: a socket descriptor or a socket family """ self.uv_fd = None self.uv_handle = None self.uv_hub = None self.uv_recv_string = '' # buffer for receiving data... if isinstance(family, (int, long)): self.uv_fd = _original_socket(family, type, proto, _sock) elif isinstance(family, GreenSocket): _sock = family self.uv_fd = _sock.uv_fd if hasattr(_sock, 'uv_hub') and _sock.uv_hub: _hub = _sock.uv_hub else: _sock = family self.uv_fd = _sock if not self.uv_hub: if _hub: self.uv_hub = _hub else: self.uv_hub = weakref.proxy(get_hub()) ## check if the socket type is supported by pyUV and we can create a pyUV socket... if not self.uv_handle: if self.type == socket.SOCK_STREAM: self.uv_handle = pyuv.TCP(self.uv_hub.uv_loop) self.uv_handle.open(self.fileno()) elif self.type == socket.SOCK_DGRAM: self.uv_handle = pyuv.UDP(self.uv_hub.uv_loop) self.uv_handle.open(self.fileno()) # import timeout from other socket, if it was there try: self._timeout = self.uv_fd.gettimeout( ) or socket.getdefaulttimeout() except AttributeError: self._timeout = socket.getdefaulttimeout() assert self.uv_fd, 'the socket descriptor must be not null' set_nonblocking(self.uv_fd) # when client calls setblocking(0) or settimeout(0) the socket must act non-blocking self.act_non_blocking = False
def __init__ (self, family = socket.AF_INET, type = socket.SOCK_STREAM, proto = 0, _sock = None, _hub = None): """ Initialize the UV socket :param family_or_realsock: a socket descriptor or a socket family """ self.uv_fd = None self.uv_handle = None self.uv_hub = None self.uv_recv_string = '' # buffer for receiving data... if isinstance(family, (int, long)): self.uv_fd = _original_socket(family, type, proto, _sock) elif isinstance(family, GreenSocket): _sock = family self.uv_fd = _sock.uv_fd if hasattr(_sock, 'uv_hub') and _sock.uv_hub: _hub = _sock.uv_hub else: _sock = family self.uv_fd = _sock if not self.uv_hub: if _hub: self.uv_hub = _hub else: self.uv_hub = weakref.proxy(get_hub()) ## check if the socket type is supported by pyUV and we can create a pyUV socket... if not self.uv_handle: if self.type == socket.SOCK_STREAM: self.uv_handle = pyuv.TCP(self.uv_hub.uv_loop) self.uv_handle.open(self.fileno()) elif self.type == socket.SOCK_DGRAM: self.uv_handle = pyuv.UDP(self.uv_hub.uv_loop) self.uv_handle.open(self.fileno()) # import timeout from other socket, if it was there try: self._timeout = self.uv_fd.gettimeout() or socket.getdefaulttimeout() except AttributeError: self._timeout = socket.getdefaulttimeout() assert self.uv_fd, 'the socket descriptor must be not null' set_nonblocking(self.uv_fd) # when client calls setblocking(0) or settimeout(0) the socket must act non-blocking self.act_non_blocking = False
def __init__(self, family_or_realsock=socket.AF_INET, *args, **kwargs): if isinstance(family_or_realsock, (int, long)): fd = _original_socket(family_or_realsock, *args, **kwargs) else: fd = family_or_realsock assert not args, args assert not kwargs, kwargs # import timeout from other socket, if it was there try: self._timeout = fd.gettimeout() or socket.getdefaulttimeout() except AttributeError: self._timeout = socket.getdefaulttimeout() set_nonblocking(fd) self.fd = fd # when client calls setblocking(0) or settimeout(0) the socket must # act non-blocking self.act_non_blocking = False
def __init__(self, family_or_realsock=socket.AF_INET, *args, **kwargs): if isinstance(family_or_realsock, int): fd = _original_socket(family_or_realsock, *args, **kwargs) else: fd = family_or_realsock assert not args, args assert not kwargs, kwargs set_nonblocking(fd) self.fd = fd self._fileno = fd.fileno() self.sendcount = 0 self.recvcount = 0 self.recvbuffer = b'' self.closed = False self.timeout = socket.getdefaulttimeout() # when client calls setblocking(0) or settimeout(0) the socket must # act non-blocking self.act_non_blocking = False
def __init__(self, family_or_realsock=socket.AF_INET, *args, **kwargs): if isinstance(family_or_realsock, (int, long)): fd = _original_socket(family_or_realsock, *args, **kwargs) else: fd = family_or_realsock assert not args, args assert not kwargs, kwargs set_nonblocking(fd) self.fd = fd self._fileno = fd.fileno() self.sendcount = 0 self.recvcount = 0 self.recvbuffer = '' self.closed = False self.timeout = socket.getdefaulttimeout() # when client calls setblocking(0) or settimeout(0) the socket must # act non-blocking self.act_non_blocking = False