Ejemplo n.º 1
0
def main():
    try:
        cfg = LocalConfigManager.get_config()

        logging_init(cfg)
        daemon = MiserableDaemon(cfg['daemon'], cfg['pid-file'], cfg['user'])
        daemon.execute()
        INFO('starting local at %s:%d' %
             (cfg['local_address'].ipaddr, cfg['local_address'].port))

        loop = MainLoop()

        dns_resolver = DNSResolver(loop)
        tcp_proxy = TCPProxy(dns_resolver, loop)
        udp_proxy = UDPProxy(dns_resolver, loop)

        def sigint_handler(signum, _):
            DEBUG('received SIGINT, doing graceful shutting down..')
            tcp_proxy.close()
            udp_proxy.close()
            loop.stop()

        signal.signal(signal.SIGINT, sigint_handler)

        loop.run()
    except OSError as e:
        ERROR(e)
    except Exception as e:
        import traceback
        traceback.print_exc()
Ejemplo n.º 2
0
def main():
    try:
        cfg = LocalConfigManager.get_config()

        logging_init(cfg)
        daemon = MiserableDaemon(cfg['daemon'], cfg['pid-file'], cfg['user'])
        daemon.execute()
        INFO('starting local at %s:%d' %
             (cfg['local_address'].ipaddr, cfg['local_address'].port))

        loop = MainLoop()

        dns_resolver = DNSResolver(loop)
        tcp_proxy = TCPProxy(dns_resolver, loop)
        udp_proxy = UDPProxy(dns_resolver, loop)

        def sigint_handler(signum, _):
            DEBUG('received SIGINT, doing graceful shutting down..')
            tcp_proxy.close()
            udp_proxy.close()
            loop.stop()
        signal.signal(signal.SIGINT, sigint_handler)

        loop.run()
    except OSError as e:
        ERROR(e)
    except Exception as e:
        import traceback
        traceback.print_exc()
Ejemplo n.º 3
0
 def test_main_loop(self):
     self.loop = MainLoop()
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
     s.bind(('127.0.0.1', 27132))
     s.setblocking(False)
     self.loop.register(s, MainLoop.EVENT_READ, self._accept)
     self.loop.add_timeout(self._timeout, 1000)
     self.loop.run()
Ejemplo n.º 4
0
 def test_main_loop(self):
     self.loop = MainLoop()
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
     s.bind(('127.0.0.1', 27132))
     s.setblocking(False)
     self.loop.register(s, MainLoop.EVENT_READ, self._accept)
     self.loop.add_timeout(self._timeout, 1000)
     self.loop.run()
Ejemplo n.º 5
0
class MainLoopTestCase(unittest.TestCase):
    def test_main_loop(self):
        self.loop = MainLoop()
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
        s.bind(('127.0.0.1', 27132))
        s.setblocking(False)
        self.loop.register(s, MainLoop.EVENT_READ, self._accept)
        self.loop.add_timeout(self._timeout, 1000)
        self.loop.run()

    def _timeout(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
        s.connect(('127.0.0.1', 27132))

    def _accept(self, fileobj, events):
        self.loop.stop()
        self.assertEqual(events, MainLoop.EVENT_READ)
Ejemplo n.º 6
0
class MainLoopTestCase(unittest.TestCase):

    def test_main_loop(self):
        self.loop = MainLoop()
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
        s.bind(('127.0.0.1', 27132))
        s.setblocking(False)
        self.loop.register(s, MainLoop.EVENT_READ, self._accept)
        self.loop.add_timeout(self._timeout, 1000)
        self.loop.run()

    def _timeout(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
        s.connect(('127.0.0.1', 27132))

    def _accept(self, fileobj, events):
        self.loop.stop()
        self.assertEqual(events, MainLoop.EVENT_READ)