Browse Source

fix asyncmgr.py

dev
breakwa11 10 years ago
parent
commit
6e5744829c
  1. 35
      asyncmgr.py

35
asyncmgr.py

@ -55,8 +55,7 @@ class ServerMgr(object):
socket.SOL_UDP) socket.SOL_UDP)
self._sock.bind((Config.MANAGE_BIND_IP, Config.MANAGE_PORT)) self._sock.bind((Config.MANAGE_BIND_IP, Config.MANAGE_PORT))
self._sock.setblocking(False) self._sock.setblocking(False)
loop.add(self._sock, eventloop.POLL_IN) loop.add(self._sock, eventloop.POLL_IN, self)
loop.add_handler(self.handle_events)
def _handle_data(self, sock): def _handle_data(self, sock):
data, addr = sock.recvfrom(128) data, addr = sock.recvfrom(128)
@ -70,25 +69,25 @@ class ServerMgr(object):
elif args[3] == '1': elif args[3] == '1':
server_pool.ServerPool.get_instance().new_server(args[1], args[2]) server_pool.ServerPool.get_instance().new_server(args[1], args[2])
def handle_events(self, events): def handle_events(self, sock, event):
for sock, fd, event in events: if sock != self._sock:
if sock != self._sock: return
continue if event & eventloop.POLL_ERR:
if event & eventloop.POLL_ERR: logging.error('mgr socket err')
logging.error('mgr socket err') self._loop.remove(self._sock)
self._loop.remove(self._sock) self._sock.close()
self._sock.close() # TODO when dns server is IPv6
# TODO when dns server is IPv6 self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.SOL_UDP)
socket.SOL_UDP) self._sock.setblocking(False)
self._sock.setblocking(False) self._loop.add(self._sock, eventloop.POLL_IN, self)
self._loop.add(self._sock, eventloop.POLL_IN) else:
else: self._handle_data(sock)
self._handle_data(sock)
break
def close(self): def close(self):
if self._sock: if self._sock:
if self._loop:
self._loop.remove(self._sock)
self._sock.close() self._sock.close()
self._sock = None self._sock = None

Loading…
Cancel
Save