Beispiel #1
0
    def connect(self, address, use_proxy=True, callback=None):

        if not (self.family == socket.AF_INET
                and self.type == socket.SOCK_STREAM):
            use_proxy = False

        if use_proxy:
            proxyinfo = self.GetProxyInfo()
        else:
            proxyinfo = {}

        log.info('asyncsocket.connect%r', address)
        if isinstance(self, ProxySocket):
            log.info('\t\twas already a proxy socket')
            old_error, callback.error = callback.error, lambda: (
                self.handle_close(), old_error())
            async_chat.connect(self, address)
        else:
            if not self._proxy_setup and proxyinfo:
                log.info('\t\tneed to setup proxies')
                sck = self.socket
                self.del_channel()
                psck = ProxySocket(proxyinfo, sck, self.set_socket)
                self.__proxysocket = psck

                import common
                if common.pref('socket.retry_noproxy',
                               type=bool,
                               default=sys.DEV):

                    def retry_noproxy(*a):
                        log.info("Retry no proxy: %r", self)
                        self.__proxysocket = None
                        self.make_socket(proxy=False,
                                         family=self.family,
                                         type=self.type)
                        AsyncSocket.connect(self,
                                            address,
                                            use_proxy=False,
                                            callback=callback)

                    psck.connect(address,
                                 success=callback.success,
                                 error=retry_noproxy)
                else:
                    psck.connect(address, callback=callback)
            elif self._proxy_setup:
                log.info('\t\tproxy was already setup, calling handle_connect')
                self.handle_connect_event()
            elif not proxyinfo:
                log.info('\t\tno proxy neecessary')
                self._proxy_setup = True
                AsyncoreThread.call_later(
                    lambda: async_chat.connect(self, address),
                    callback=callback,
                    verbose=False)
            else:
                log.info('\t\terrr you didnt finish')
                pass
Beispiel #2
0
    def connect(self):
        if self._request_q is None:
            self._request_q = []

        if self.conn is None:
            self.conn = self._make_connection()
            self.bind_events()

        AsyncoreThread.call_later(self._do_connect)
Beispiel #3
0
    def connect(self):
        if self._request_q is None:
            self._request_q = []

        if self.conn is None:
            self.conn = self._make_connection()
            self.bind_events()

        AsyncoreThread.call_later(self._do_connect)
Beispiel #4
0
    def close(self):
        def _doit():
            log.info('closing socket %r', self)
            psck = self.__proxysocket
            if psck is not None:
                log.info('Closing proxy socket: %r', psck)
                psck.close()
            self.__proxysocket = None
            async_chat.close(self)

        AsyncoreThread.call_later(_doit)
Beispiel #5
0
    def close(self):
        def _doit():
            log.info('closing socket %r', self)
            psck = self.__proxysocket
            if psck is not None:
                log.info('Closing proxy socket: %r', psck)
                psck.close()
            self.__proxysocket = None
            async_chat.close(self)

        AsyncoreThread.call_later(_doit)
Beispiel #6
0
    def connect(self, address, use_proxy = True, callback = None):

        if not (self.family == socket.AF_INET and self.type == socket.SOCK_STREAM):
            use_proxy = False

        if use_proxy:
            proxyinfo = self.GetProxyInfo()
        else:
            proxyinfo = {}

        log.info('asyncsocket.connect%r', address)
        if isinstance(self, ProxySocket):
            log.info('\t\twas already a proxy socket')
            old_error, callback.error = callback.error, lambda : (self.handle_close(), old_error())
            async_chat.connect(self, address)
        else:
            if not self._proxy_setup and proxyinfo:
                log.info('\t\tneed to setup proxies')
                sck = self.socket
                self.del_channel()
                psck = ProxySocket(proxyinfo, sck, self.set_socket)
                self.__proxysocket = psck

                import common
                if common.pref('socket.retry_noproxy', type = bool, default = sys.DEV):
                    def retry_noproxy(*a):
                        log.info("Retry no proxy: %r", self)
                        self.__proxysocket = None
                        self.make_socket(proxy = False, family = self.family, type = self.type)
                        AsyncSocket.connect(self, address, use_proxy = False, callback = callback)

                    psck.connect(address, success = callback.success, error = retry_noproxy)
                else:
                    psck.connect(address, callback = callback)
            elif self._proxy_setup:
                log.info('\t\tproxy was already setup, calling handle_connect')
                self.handle_connect_event()
            elif not proxyinfo:
                log.info('\t\tno proxy neecessary')
                self._proxy_setup = True
                AsyncoreThread.call_later(lambda: async_chat.connect(self, address), callback = callback, verbose = False)
            else:
                log.info('\t\terrr you didnt finish')
                pass
Beispiel #7
0
 def close_when_done(self):
     AsyncoreThread.call_later(lambda: async_chat.close_when_done(self))
Beispiel #8
0
 def close_when_done(self):
     AsyncoreThread.call_later(lambda: async_chat.close_when_done(self))