Esempio n. 1
0
    def _process(self):
        rlist, rdict = get_select_list(
            'get_rlist', self.backend, self.tunnels.iterkeys(),
            (frontend
             for frontend, (conn_id, tunnel) in self.frontends.iteritems()
             if tunnel.available))
        wlist, wdict = get_select_list('get_wlist', self.tunnels.iterkeys(),
                                       self.frontends.iterkeys())
        try:
            rlist, wlist, _ = select.select(rlist, wlist, [])
        except select.error as e:
            if e[0] == errno.EINTR:
                return
            raise

        for fileno in rlist:
            conn = rdict[fileno]
            if conn is self.backend:
                self._process_backend()
            elif conn in self.tunnels:
                self._process_tunnel(conn)
            elif conn in self.frontends:
                self._process_frontend(conn)
        written_conns = ObjectSet()
        for fileno in wlist:
            conn = wdict[fileno]
            if conn in written_conns:
                continue
            written_conns.add(conn)
            if conn in self.tunnels:
                self._process_tunnel_sending(conn)
            else:
                conn.send()
Esempio n. 2
0
    def _process(self):
        rlist, rdict = get_select_list('get_rlist',
                self.backend, self.tunnels.iterkeys(),
                (frontend for frontend, (conn_id, tunnel)
                    in self.frontends.iteritems()
                    if tunnel.available))
        wlist, wdict = get_select_list('get_wlist',
                self.tunnels.iterkeys(), self.frontends.iterkeys())
        try:
            rlist, wlist, _ = select.select(rlist, wlist, [])
        except select.error as e:
            if e[0] == errno.EINTR:
                return
            raise

        for fileno in rlist:
            conn = rdict[fileno]
            if conn is self.backend:
                self._process_backend()
            elif conn in self.tunnels:
                self._process_tunnel(conn)
            elif conn in self.frontends:
                self._process_frontend(conn)
        written_conns = ObjectSet()
        for fileno in wlist:
            conn = wdict[fileno]
            if conn in written_conns:
                continue
            written_conns.add(conn)
            if conn in self.tunnels:
                self._process_tunnel_sending(conn)
            else:
                conn.send()
Esempio n. 3
0
    def _process(self):
        rlist, rdict = get_select_list('get_rlist', 
                self.tunnel, self.local_conn,
                self.conns.itervalues() if self.tunnel.available else [])
        wlist, wdict = get_select_list('get_wlist',
                self.tunnel, self.conns.itervalues())
        try:
            rlist, wlist, _ = select.select(rlist, wlist, [])
        except select.error as e:
            if e[0] == errno.EINTR:
                return
            raise

        for fileno in rlist:
            conn = rdict[fileno]
            if conn is self.tunnel:
                self._process_tunnel()
            elif conn is self.local_conn:
                self._process_listening()
            elif conn.conn_id in self.conns:
                self._process_connection(conn)
        written_conns = ObjectSet()
        for fileno in wlist:
            conn = wdict[fileno]
            if conn in written_conns:
                continue
            written_conns.add(conn)
            self._process_sending(conn)
Esempio n. 4
0
    def _process(self):
        rlist, rdict = get_select_list(
            'get_rlist', self.tunnel, self.local_conn,
            self.conns.itervalues() if self.tunnel.available else [])
        wlist, wdict = get_select_list('get_wlist', self.tunnel,
                                       self.conns.itervalues())
        try:
            rlist, wlist, _ = select.select(rlist, wlist, [])
        except select.error as e:
            if e[0] == errno.EINTR:
                return
            raise

        for fileno in rlist:
            conn = rdict[fileno]
            if conn is self.tunnel:
                self._process_tunnel()
            elif conn is self.local_conn:
                self._process_listening()
            elif conn.conn_id in self.conns:
                self._process_connection(conn)
        written_conns = ObjectSet()
        for fileno in wlist:
            conn = wdict[fileno]
            if conn in written_conns:
                continue
            written_conns.add(conn)
            self._process_sending(conn)
Esempio n. 5
0
 def run(self):
     self.running = True
     while self.running:
         try:
             self._process()
         except Exception as e:
             exc_type, _, exc_tb = sys.exc_info()
             exc_type = exc_type.__name__
             exc_tb = traceback.extract_tb(exc_tb)
             msg = "unknown exception occurred: {0}, {1}; {2}"\
                     .format(exc_type, str(e), repr(exc_tb))
             error(msg, 'tunnel', None)
     # close connections
     self.backend.close()
     for tunnel in self.tunnels.keys():
         self._close_tunnel(tunnel)
     while True:
         wlist, wdict = get_select_list('get_wlist',
                                        self.tunnels.iterkeys())
         if not wlist:
             break
         _, wlist, _ = select.select([], wlist, [])
         for fileno in wlist:
             conn = wdict[fileno]
             if conn in self.tunnels:
                 self._process_tunnel_sending(conn)
Esempio n. 6
0
 def run(self):
     self.running = True
     while self.running:
         try:
             self._process()
         except Exception as e:
             exc_type, _, exc_tb = sys.exc_info()
             exc_type = exc_type.__name__
             exc_tb = traceback.extract_tb(exc_tb)
             msg = "unknown exception occurred: {0}, {1}; {2}"\
                     .format(exc_type, str(e), repr(exc_tb))
             error(msg, 'tunnel', None)
     # close connections
     self.backend.close()
     for tunnel in self.tunnels.keys():
         self._close_tunnel(tunnel)
     while True:
         wlist, wdict = get_select_list(
                 'get_wlist', self.tunnels.iterkeys())
         if not wlist:
             break
         _, wlist, _ = select.select([], wlist, [])
         for fileno in wlist:
             conn = wdict[fileno]
             if conn in self.tunnels:
                 self._process_tunnel_sending(conn)