Some Hub documentation, made wrap_socket_with_coroutine_socket happen only once.
This commit is contained in:
@@ -34,6 +34,9 @@ from eventlet import greenlib
|
|||||||
from eventlet.timer import Timer
|
from eventlet.timer import Timer
|
||||||
|
|
||||||
class BaseHub(object):
|
class BaseHub(object):
|
||||||
|
""" Base hub class for easing the implementation of subclasses that are
|
||||||
|
specific to a particular underlying event architecture. """
|
||||||
|
|
||||||
SYSTEM_EXCEPTIONS = (KeyboardInterrupt, SystemExit)
|
SYSTEM_EXCEPTIONS = (KeyboardInterrupt, SystemExit)
|
||||||
|
|
||||||
def __init__(self, clock=time.time):
|
def __init__(self, clock=time.time):
|
||||||
@@ -58,6 +61,20 @@ class BaseHub(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def add_descriptor(self, fileno, read=None, write=None, exc=None):
|
def add_descriptor(self, fileno, read=None, write=None, exc=None):
|
||||||
|
""" Signals an intent to read/write from a particular file descriptor.
|
||||||
|
|
||||||
|
The fileno argument is the file number of the file of interest. The other
|
||||||
|
arguments are either callbacks or None. If there is a callback for read
|
||||||
|
or write, the hub sets things up so that when the file descriptor is
|
||||||
|
ready to be read or written, the callback is called.
|
||||||
|
|
||||||
|
The exc callback is called when the socket represented by the file
|
||||||
|
descriptor is closed. The intent is that the the exc callbacks should
|
||||||
|
only be present when either a read or write callback is also present,
|
||||||
|
so the exc callback happens instead of the respective read or write
|
||||||
|
callback.
|
||||||
|
"""
|
||||||
|
|
||||||
self.readers[fileno] = read or self.readers.get(fileno)
|
self.readers[fileno] = read or self.readers.get(fileno)
|
||||||
self.writers[fileno] = write or self.writers.get(fileno)
|
self.writers[fileno] = write or self.writers.get(fileno)
|
||||||
self.excs[fileno] = exc or self.excs.get(fileno)
|
self.excs[fileno] = exc or self.excs.get(fileno)
|
||||||
|
@@ -90,8 +90,12 @@ def wrap_ssl(sock, certificate=None, private_key=None):
|
|||||||
connection.set_connect_state()
|
connection.set_connect_state()
|
||||||
return greenio.GreenSocket(connection)
|
return greenio.GreenSocket(connection)
|
||||||
|
|
||||||
|
socket_already_wrapped = False
|
||||||
def wrap_socket_with_coroutine_socket():
|
def wrap_socket_with_coroutine_socket():
|
||||||
|
global socket_already_wrapped
|
||||||
|
if socket_already_wrapped:
|
||||||
|
return
|
||||||
|
|
||||||
def new_socket(*args, **kw):
|
def new_socket(*args, **kw):
|
||||||
from eventlet import greenio
|
from eventlet import greenio
|
||||||
s = __original_socket__(*args, **kw)
|
s = __original_socket__(*args, **kw)
|
||||||
@@ -100,6 +104,8 @@ def wrap_socket_with_coroutine_socket():
|
|||||||
socket.socket = new_socket
|
socket.socket = new_socket
|
||||||
|
|
||||||
socket.ssl = wrap_ssl
|
socket.ssl = wrap_ssl
|
||||||
|
|
||||||
|
socket_already_wrapped = True
|
||||||
|
|
||||||
|
|
||||||
def socket_bind_and_listen(descriptor, addr=('', 0), backlog=50):
|
def socket_bind_and_listen(descriptor, addr=('', 0), backlog=50):
|
||||||
|
Reference in New Issue
Block a user