Connector.py
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Handles the acc_ready event. Accept as long as possible on subject.
For each successfull accept assign protocol and emit a new_con event
holding the new connection.
Author: Georg Hopp <ghopp@spamtitan.com>
"""
from Connection import Connection
from ConnectEntryPoint import ConnectEntryPoint
from Event.EventHandler import EventHandler
from Transport import Transport
class Connector(EventHandler):
def __init__(self):
super(Connector, self).__init__()
self._event_methods = {
ConnectEntryPoint.eventId('acc_ready') : self._accept
}
def _accept(self, event):
try:
protocol = event.subject.getProtocol()
if event.subject.accept():
con = event.subject.pop()
while con:
new_con = Connection(con, protocol)
self.issueEvent(new_con, 'new_con')
con = event.subject.pop()
except Transport.Error as error:
self.issueEvent(event.subject, 'close')
return True
# vim: set ft=python et ts=8 sw=4 sts=4: