(self, sock, fd, event)
| 107 | port)) |
| 108 | |
| 109 | def handle_event(self, sock, fd, event): |
| 110 | if sock == self._control_socket and event == eventloop.POLL_IN: |
| 111 | data, self._control_client_addr = sock.recvfrom(BUF_SIZE) |
| 112 | parsed = self._parse_command(data) |
| 113 | if parsed: |
| 114 | command, config = parsed |
| 115 | a_config = self._config.copy() |
| 116 | if config: |
| 117 | # let the command override the configuration file |
| 118 | a_config.update(config) |
| 119 | if 'server_port' not in a_config: |
| 120 | logging.error('can not find server_port in config') |
| 121 | else: |
| 122 | if command == 'add': |
| 123 | self.add_port(a_config) |
| 124 | self._send_control_data(b'ok') |
| 125 | elif command == 'remove': |
| 126 | self.remove_port(a_config) |
| 127 | self._send_control_data(b'ok') |
| 128 | elif command == 'ping': |
| 129 | self._send_control_data(b'pong') |
| 130 | else: |
| 131 | logging.error('unknown command %s', command) |
| 132 | |
| 133 | def _parse_command(self, data): |
| 134 | # commands: |
no test coverage detected