Mercurial > cosocket
comparison channels.py @ 87:43d37495e9d4
Added timeout functionality.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 01 May 2009 16:46:31 -0700 |
parents | b0f802c4fafc |
children | 57681224a62a |
comparison
equal
deleted
inserted
replaced
86:408738c3cd5d | 87:43d37495e9d4 |
---|---|
14 for receiver in receivers: | 14 for receiver in receivers: |
15 receiver.continue_from_yield(self.message) | 15 receiver.continue_from_yield(self.message) |
16 dispatcher.continue_from_yield() | 16 dispatcher.continue_from_yield() |
17 | 17 |
18 class _until_message_received(object): | 18 class _until_message_received(object): |
19 def __init__(self, channel_name): | 19 def __init__(self, channel_name, timeout = cosocket.DEFAULT_TIMEOUT): |
20 self.channel_name = channel_name | 20 self.channel_name = channel_name |
21 self._timeout = timeout | |
21 self._fd = None | 22 self._fd = None |
22 | 23 |
23 def execute(self, dispatcher): | 24 def execute(self, dispatcher): |
24 if self.channel_name not in _channels: | 25 if self.channel_name not in _channels: |
25 _channels[self.channel_name] = {} | 26 _channels[self.channel_name] = {} |
26 self._fd = dispatcher.socket.fileno() | 27 self._fd = dispatcher.socket.fileno() |
27 _channels[self.channel_name][self._fd] = dispatcher | 28 _channels[self.channel_name][self._fd] = dispatcher |
29 dispatcher.set_timeout(self._timeout) | |
28 | 30 |
29 def finalize(self): | 31 def finalize(self): |
30 if (self.channel_name in _channels and | 32 if (self.channel_name in _channels and |
31 self._fd in _channels[self.channel_name]): | 33 self._fd in _channels[self.channel_name]): |
32 del _channels[self.channel_name][self._fd] | 34 del _channels[self.channel_name][self._fd] |