This commit is contained in:
Ryan Williams
2009-08-02 23:12:44 -07:00
parent 903a5000b0
commit b46075bb80
3 changed files with 9 additions and 22 deletions

View File

@@ -53,17 +53,17 @@ class BaseHub(object):
'exit': [],
}
def add_reader(self, fileno, reader):
def add_reader(self, fileno, read_cb):
""" Signals an intent to read from a particular file descriptor.
The *fileno* argument is the file number of the file of interest.
The *reader* argument is the greenlet which will be switched to when the file
The *read_cb* argument is the callback which will be called when the file
is ready for reading.
"""
self.readers[fileno] = reader
self.readers[fileno] = read_cb
def add_writer(self, fileno, writer):
def add_writer(self, fileno, write_cb):
""" Signals an intent to write to a particular file descriptor.
The *fileno* argument is the file number of the file of interest.
@@ -71,7 +71,8 @@ class BaseHub(object):
The *write_cb* argument is the callback which will be called when the file
is ready for writing.
"""
self.writers[fileno] = writer
self.writers[fileno] = write_cb
def closed(self, fileno):
""" Clean up any references so that we don't try and

View File

@@ -64,6 +64,9 @@ class Hub(object):
self.signal_exc_info = None
self.signal(2, lambda signalnum, frame: self.greenlet.parent.throw(KeyboardInterrupt))
self.events_to_add = []
def closed(self, fd):
pass
def switch(self):
cur = api.getcurrent()

View File

@@ -104,42 +104,25 @@ class TestGreenIo(TestCase):
listener = api.tcp_listener(('127.0.0.1', 0))
def send_large(sock):
print "about to send large"
# needs to send enough data that trampoline() is called
sock.sendall('*' * 100000)
print "sent large"
def server():
(client, addr) = listener.accept()
print "accepted"
# start reading, then, while reading, start writing.
# the reader should not hang forever
api.spawn(send_large, client)
print "spawned send_large"
api.sleep(0) # allow send_large to execute up to the trampoline
print "slept"
result = client.recv(1000)
print "received"
assert result == 'hello world', result
server_evt = coros.execute(server)
print "spawned server"
client = api.connect_tcp(('127.0.0.1', listener.getsockname()[1]))
api.spawn(client.makefile().read)
print "spawned read"
api.sleep(0)
print "slept 2"
client.send('hello world')
print "sent hello world"
# close() hangs
client.close()
print "closed"
# this tests "full duplex" bug which is still not fixed
server_evt.wait()
print "waited"
def test_server(sock, func, *args):