Fixed bugs 760475, 953599, and 1519.
This commit is contained in:
parent
3b1e6b2f83
commit
ff5f42088b
|
@ -59,7 +59,7 @@ class async_chat (asyncore.dispatcher):
|
||||||
ac_in_buffer_size = 4096
|
ac_in_buffer_size = 4096
|
||||||
ac_out_buffer_size = 4096
|
ac_out_buffer_size = 4096
|
||||||
|
|
||||||
def __init__ (self, conn=None):
|
def __init__ (self, sock=None, map=None):
|
||||||
# for string terminator matching
|
# for string terminator matching
|
||||||
self.ac_in_buffer = ''
|
self.ac_in_buffer = ''
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class async_chat (asyncore.dispatcher):
|
||||||
# we toss the use of the "simple producer" and replace it with
|
# we toss the use of the "simple producer" and replace it with
|
||||||
# a pure deque, which the original fifo was a wrapping of
|
# a pure deque, which the original fifo was a wrapping of
|
||||||
self.producer_fifo = deque()
|
self.producer_fifo = deque()
|
||||||
asyncore.dispatcher.__init__ (self, conn)
|
asyncore.dispatcher.__init__ (self, sock, map)
|
||||||
|
|
||||||
def collect_incoming_data(self, data):
|
def collect_incoming_data(self, data):
|
||||||
raise NotImplementedError("must be implemented in subclass")
|
raise NotImplementedError("must be implemented in subclass")
|
||||||
|
|
|
@ -99,8 +99,10 @@ def readwrite(obj, flags):
|
||||||
obj.handle_read_event()
|
obj.handle_read_event()
|
||||||
if flags & select.POLLOUT:
|
if flags & select.POLLOUT:
|
||||||
obj.handle_write_event()
|
obj.handle_write_event()
|
||||||
if flags & (select.POLLERR | select.POLLHUP | select.POLLNVAL):
|
if flags & (select.POLLERR | select.POLLNVAL):
|
||||||
obj.handle_expt_event()
|
obj.handle_expt_event()
|
||||||
|
if flags & select.POLLHUP:
|
||||||
|
obj.handle_close_event()
|
||||||
except (ExitNow, KeyboardInterrupt, SystemExit):
|
except (ExitNow, KeyboardInterrupt, SystemExit):
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
@ -467,7 +469,7 @@ class dispatcher:
|
||||||
),
|
),
|
||||||
'error'
|
'error'
|
||||||
)
|
)
|
||||||
self.close()
|
self.handle_close()
|
||||||
|
|
||||||
def handle_expt(self):
|
def handle_expt(self):
|
||||||
self.log_info('unhandled exception', 'warning')
|
self.log_info('unhandled exception', 'warning')
|
||||||
|
|
|
@ -38,6 +38,7 @@ class exitingdummy:
|
||||||
raise asyncore.ExitNow()
|
raise asyncore.ExitNow()
|
||||||
|
|
||||||
handle_write_event = handle_read_event
|
handle_write_event = handle_read_event
|
||||||
|
handle_close_event = handle_read_event
|
||||||
handle_expt_event = handle_read_event
|
handle_expt_event = handle_read_event
|
||||||
|
|
||||||
class crashingdummy:
|
class crashingdummy:
|
||||||
|
@ -48,6 +49,7 @@ class crashingdummy:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
|
|
||||||
handle_write_event = handle_read_event
|
handle_write_event = handle_read_event
|
||||||
|
handle_close_event = handle_read_event
|
||||||
handle_expt_event = handle_read_event
|
handle_expt_event = handle_read_event
|
||||||
|
|
||||||
def handle_error(self):
|
def handle_error(self):
|
||||||
|
@ -117,6 +119,7 @@ class HelperFunctionTests(unittest.TestCase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.read = False
|
self.read = False
|
||||||
self.write = False
|
self.write = False
|
||||||
|
self.closed = False
|
||||||
self.expt = False
|
self.expt = False
|
||||||
|
|
||||||
def handle_read_event(self):
|
def handle_read_event(self):
|
||||||
|
@ -125,6 +128,9 @@ class HelperFunctionTests(unittest.TestCase):
|
||||||
def handle_write_event(self):
|
def handle_write_event(self):
|
||||||
self.write = True
|
self.write = True
|
||||||
|
|
||||||
|
def handle_close_event(self):
|
||||||
|
self.closed = True
|
||||||
|
|
||||||
def handle_expt_event(self):
|
def handle_expt_event(self):
|
||||||
self.expt = True
|
self.expt = True
|
||||||
|
|
||||||
|
@ -167,9 +173,9 @@ class HelperFunctionTests(unittest.TestCase):
|
||||||
|
|
||||||
for flag in (select.POLLERR, select.POLLHUP, select.POLLNVAL):
|
for flag in (select.POLLERR, select.POLLHUP, select.POLLNVAL):
|
||||||
tobj = testobj()
|
tobj = testobj()
|
||||||
self.assertEqual(tobj.expt, False)
|
self.assertEqual((tobj.expt, tobj.closed)[flag == select.POLLHUP], False)
|
||||||
asyncore.readwrite(tobj, flag)
|
asyncore.readwrite(tobj, flag)
|
||||||
self.assertEqual(tobj.expt, True)
|
self.assertEqual((tobj.expt, tobj.closed)[flag == select.POLLHUP], True)
|
||||||
|
|
||||||
# check that ExitNow exceptions in the object handler method
|
# check that ExitNow exceptions in the object handler method
|
||||||
# bubbles all the way up through asyncore readwrite calls
|
# bubbles all the way up through asyncore readwrite calls
|
||||||
|
|
Loading…
Reference in New Issue