Removed Event from __init__ and added some comments to greenio.
This commit is contained in:
@@ -8,7 +8,6 @@ sleep = greenthread.sleep
|
|||||||
|
|
||||||
spawn = greenthread.spawn
|
spawn = greenthread.spawn
|
||||||
spawn_n = greenthread.spawn_n
|
spawn_n = greenthread.spawn_n
|
||||||
Event = greenthread.Event
|
|
||||||
call_after_global = greenthread.call_after_global
|
call_after_global = greenthread.call_after_global
|
||||||
call_after_local = greenthread.call_after_local
|
call_after_local = greenthread.call_after_local
|
||||||
TimeoutError = greenthread.TimeoutError
|
TimeoutError = greenthread.TimeoutError
|
||||||
|
@@ -21,6 +21,10 @@ CONNECT_ERR = set((errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK))
|
|||||||
CONNECT_SUCCESS = set((0, errno.EISCONN))
|
CONNECT_SUCCESS = set((0, errno.EISCONN))
|
||||||
|
|
||||||
def socket_connect(descriptor, address):
|
def socket_connect(descriptor, address):
|
||||||
|
"""
|
||||||
|
Attempts to connect to the address, returns the descriptor if it succeeds,
|
||||||
|
returns None if it needs to trampoline, and raises any exceptions.
|
||||||
|
"""
|
||||||
err = descriptor.connect_ex(address)
|
err = descriptor.connect_ex(address)
|
||||||
if err in CONNECT_ERR:
|
if err in CONNECT_ERR:
|
||||||
return None
|
return None
|
||||||
@@ -30,6 +34,11 @@ def socket_connect(descriptor, address):
|
|||||||
|
|
||||||
|
|
||||||
def socket_accept(descriptor):
|
def socket_accept(descriptor):
|
||||||
|
"""
|
||||||
|
Attempts to accept() on the descriptor, returns a client,address tuple
|
||||||
|
if it succeeds; returns None if it needs to trampoline, and raises
|
||||||
|
any exceptions.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return descriptor.accept()
|
return descriptor.accept()
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
@@ -50,6 +59,11 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
def set_nonblocking(fd):
|
def set_nonblocking(fd):
|
||||||
|
"""
|
||||||
|
Sets the descriptor to be nonblocking. Works on many file-like
|
||||||
|
objects as well as sockets. Only sockets can be nonblocking on
|
||||||
|
Windows, however.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
setblocking = fd.setblocking
|
setblocking = fd.setblocking
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -70,6 +84,10 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
class GreenSocket(object):
|
class GreenSocket(object):
|
||||||
|
"""
|
||||||
|
Green version of socket.socket class, that is intended to be 100%
|
||||||
|
API-compatible.
|
||||||
|
"""
|
||||||
timeout = None
|
timeout = None
|
||||||
def __init__(self, family_or_realsock=socket.AF_INET, *args, **kwargs):
|
def __init__(self, family_or_realsock=socket.AF_INET, *args, **kwargs):
|
||||||
if isinstance(family_or_realsock, (int, long)):
|
if isinstance(family_or_realsock, (int, long)):
|
||||||
@@ -310,6 +328,8 @@ class GreenSocket(object):
|
|||||||
|
|
||||||
|
|
||||||
class GreenPipe(object):
|
class GreenPipe(object):
|
||||||
|
""" GreenPipe is a cooperatively-yielding wrapper around OS pipes.
|
||||||
|
"""
|
||||||
newlines = '\r\n'
|
newlines = '\r\n'
|
||||||
def __init__(self, fd):
|
def __init__(self, fd):
|
||||||
set_nonblocking(fd)
|
set_nonblocking(fd)
|
||||||
|
Reference in New Issue
Block a user