def accept(self): """Accepts a new connection from a remote client, and returns a tuple containing that new connection wrapped with a server-side SSL channel, and the address of the remote client.""" # RDW grr duplication of code from greenio if self.act_non_blocking: newsock, addr = socket.accept(self) else: while True: try: newsock, addr = socket.accept(self) set_nonblocking(newsock) break except orig_socket.error as e: if get_errno(e) not in greenio.SOCKET_BLOCKING: raise trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out')) new_ssl = type(self)( newsock, keyfile=self.keyfile, certfile=self.certfile, server_side=True, cert_reqs=self.cert_reqs, ssl_version=self.ssl_version, ca_certs=self.ca_certs, do_handshake_on_connect=False, suppress_ragged_eofs=self.suppress_ragged_eofs) return (new_ssl, addr)
def accept(self): """Accepts a new connection from a remote client, and returns a tuple containing that new connection wrapped with a server-side SSL channel, and the address of the remote client.""" # RDW grr duplication of code from greenio if self.act_non_blocking: newsock, addr = socket.accept(self) else: while True: try: newsock, addr = socket.accept(self) set_nonblocking(newsock) break except orig_socket.error as e: if get_errno(e) != errno.EWOULDBLOCK: raise trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out')) new_ssl = type(self)( newsock, keyfile=self.keyfile, certfile=self.certfile, server_side=True, cert_reqs=self.cert_reqs, ssl_version=self.ssl_version, ca_certs=self.ca_certs, do_handshake_on_connect=self.do_handshake_on_connect, suppress_ragged_eofs=self.suppress_ragged_eofs) return (new_ssl, addr)
def __init__(self, f, mode='r', bufsize=-1): if not isinstance(f, (basestring, int, file)): raise TypeError( 'f(ile) should be int, str, unicode or file, not %r' % f) if isinstance(f, basestring): f = open(f, mode, 0) if isinstance(f, int): fileno = f self._name = "<fd:%d>" % fileno else: fileno = os.dup(f.fileno()) self._name = f.name if f.mode != mode: raise ValueError( 'file.mode %r does not match mode parameter %r' % (f.mode, mode)) self._name = f.name f.close() greenio._fileobject.__init__(self, _SocketDuckForFdTimeout(fileno), mode, bufsize) greenio.set_nonblocking(self) self.softspace = 0
def test_set_nonblocking(): sock = _orig_sock.socket(socket.AF_INET, socket.SOCK_DGRAM) fileno = sock.fileno() orig_flags = fcntl.fcntl(fileno, fcntl.F_GETFL) assert orig_flags & os.O_NONBLOCK == 0 greenio.set_nonblocking(sock) new_flags = fcntl.fcntl(fileno, fcntl.F_GETFL) assert new_flags == (orig_flags | os.O_NONBLOCK)
def test_set_nonblocking(): sock = _orig_sock.socket(socket.AF_INET, socket.SOCK_DGRAM) fileno = sock.fileno() orig_flags = fcntl.fcntl(fileno, fcntl.F_GETFL) assert orig_flags & os.O_NONBLOCK == 0 greenio.set_nonblocking(sock) new_flags = fcntl.fcntl(fileno, fcntl.F_GETFL) # on SPARC, O_NDELAY is set as well, and it might be a superset # of O_NONBLOCK assert (new_flags == (orig_flags | os.O_NONBLOCK) or new_flags == (orig_flags | os.O_NONBLOCK | os.O_NDELAY))
def __init__(self, *args, **kwds): # Forward the call to base-class constructor subprocess_orig.Popen.__init__(self, *args, **kwds) # Now wrap the pipes, if any. This logic is loosely borrowed from # eventlet.processes.Process.run() method. for attr in "stdin", "stdout", "stderr": pipe = getattr(self, attr) if pipe is not None: greenio.set_nonblocking(pipe) wrapped_pipe = greenio.GreenPipe(pipe) # The default 'newlines' attribute is '\r\n', which aren't # sent over pipes. wrapped_pipe.newlines = '\n' setattr(self, attr, wrapped_pipe)
def accept(self): """Accepts a new connection from a remote client, and returns a tuple containing that new connection wrapped with a server-side SSL channel, and the address of the remote client.""" # RDW grr duplication of code from greenio if self.act_non_blocking: newsock, addr = socket.accept(self) else: while True: try: newsock, addr = socket.accept(self) set_nonblocking(newsock) break except orig_socket.error, e: if get_errno(e) != errno.EWOULDBLOCK: raise trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc("timed out"))
def accept(self): """Accepts a new connection from a remote client, and returns a tuple containing that new connection wrapped with a server-side SSL channel, and the address of the remote client.""" # RDW grr duplication of code from greenio if self.act_non_blocking: newsock, addr = socket.accept(self) else: while True: try: newsock, addr = socket.accept(self) set_nonblocking(newsock) break except orig_socket.error, e: if get_errno(e) != errno.EWOULDBLOCK: raise trampoline(self, read=True, timeout=self.gettimeout(), timeout_exc=timeout_exc('timed out'))
def run(self): self.dead = False self.started = False self.popen4 = None ## We use popen4 so that read() will read from either stdout or stderr self.popen4 = popen2.Popen4([self.command] + self.args) self.event = _add_child_pobj(self.popen4) child_stdout_stderr = self.popen4.fromchild child_stdin = self.popen4.tochild greenio.set_nonblocking(child_stdout_stderr) greenio.set_nonblocking(child_stdin) self.child_stdout_stderr = greenio.GreenPipe(child_stdout_stderr) self.child_stdout_stderr.newlines = '\n' # the default is \r\n, which aren't sent over pipes self.child_stdin = greenio.GreenPipe(child_stdin) self.child_stdin.newlines = '\n' self.sendall = self.child_stdin.write self.send = self.child_stdin.write self.recv = self.child_stdout_stderr.read self.readline = self.child_stdout_stderr.readline
def __init__(self, f, mode='r', bufsize=-1): if not isinstance(f, (basestring, int, file)): raise TypeError('f(ile) should be int, str, unicode or file, not %r' % f) if isinstance(f, basestring): f = open(f, mode, 0) if isinstance(f, int): fileno = f self._name = "<fd:%d>" % fileno else: fileno = os.dup(f.fileno()) self._name = f.name if f.mode != mode: raise ValueError('file.mode %r does not match mode parameter %r' % (f.mode, mode)) self._name = f.name f.close() greenio._fileobject.__init__(self, _SocketDuckForFdTimeout(fileno), mode, bufsize) greenio.set_nonblocking(self) self.softspace = 0