Пример #1
0
    def connection_lost(self, exc):
        logger.debug('Connection %s lost!', self)

        if self.inactivity_timer:
            self.inactivity_timer.cancel()

        if self.on_connection_lost:
            self.on_connection_lost(self)

        closed_connection = ConnectionClosed()
        for request in self.requests.values():
            request.set_exception(closed_connection)
        self.free_channels.destroy(closed_connection)
Пример #2
0
 async def send_notification(self, request):
     response = NotificationResult(request.notification_id,
                                   APNS_RESPONSE_CODE.BAD_REQUEST)
     response.description = "connection error"
     logger.debug('Notification %s: waiting for connection',
                  request.notification_id)
     try:
         connection = await self.acquire()
     except ConnectionError:
         logger.warning('Could not send notification %s: ConnectionError',
                        request.notification_id)
         return response
     logger.debug('Notification %s: connection %s acquired',
                  request.notification_id, connection)
     response.description = "internal error"
     try:
         response = await connection.send_notification(request)
         return response
     except NoAvailableStreamIDError:
         connection.close()
     except ConnectionClosed:
         logger.warning('Could not send notification %s: ConnectionClosed',
                        request.notification_id)
     except FlowControlError:
         logger.debug('Got FlowControlError for notification %s',
                      request.notification_id)
     except:
         logger.debug('internal error for %s', request.notification_id)
     return response
Пример #3
0
 async def send_notification(self, request):
     attempt = 0
     while True:
         attempt += 1
         if attempt > self.MAX_ATTEMPTS:
             logger.warning('Trying to send notification %s: attempt #%s',
                            request.notification_id, attempt)
         logger.debug('Notification %s: waiting for connection',
                      request.notification_id)
         try:
             connection = await self.acquire()
         except ConnectionError:
             logger.warning(
                 'Could not send notification %s: '
                 'ConnectionError', request.notification_id)
             await asyncio.sleep(1)
             continue
         logger.debug('Notification %s: connection %s acquired',
                      request.notification_id, connection)
         try:
             response = await connection.send_notification(request)
             return response
         except NoAvailableStreamIDError:
             connection.close()
         except ConnectionClosed:
             logger.warning(
                 'Could not send notification %s: '
                 'ConnectionClosed', request.notification_id)
         except FlowControlError:
             logger.debug('Got FlowControlError for notification %s',
                          request.notification_id)
             await asyncio.sleep(1)
Пример #4
0
    async def send_notification(self, request):
        failed_attempts = 0
        while True:
            logger.debug('Notification %s: waiting for connection',
                         request.notification_id)
            try:
                connection = await self.acquire()
            except ConnectionError:
                failed_attempts += 1
                logger.warning('Could not send notification %s: '
                               'ConnectionError', request.notification_id)

                if self.max_connection_attempts \
                        and failed_attempts > self.max_connection_attempts:
                    logger.error('Failed to connect after %d attempts.',
                                 failed_attempts)
                    raise

                await asyncio.sleep(1)
                continue
            logger.debug('Notification %s: connection %s acquired',
                         request.notification_id, connection)
            try:
                response = await connection.send_notification(request)
                return response
            except NoAvailableStreamIDError:
                connection.close()
            except ConnectionClosed:
                logger.warning('Could not send notification %s: '
                               'ConnectionClosed', request.notification_id)
            except FlowControlError:
                logger.debug('Got FlowControlError for notification %s',
                             request.notification_id)
                await asyncio.sleep(1)
Пример #5
0
 async def send_notification(self, request):
     attempts = 0
     while attempts < self.max_connection_attempts:
         attempts += 1
         logger.debug(
             "Notification %s: waiting for connection",
             request.notification_id,
         )
         try:
             connection = await self.acquire()
         except ConnectionError:
             logger.warning(
                 "Could not send notification %s: "
                 "ConnectionError",
                 request.notification_id,
             )
             await asyncio.sleep(1)
             continue
         logger.debug(
             "Notification %s: connection %s acquired",
             request.notification_id,
             connection,
         )
         try:
             response = await connection.send_notification(request)
             return response
         except NoAvailableStreamIDError:
             connection.close()
         except ConnectionClosed:
             logger.warning(
                 "Could not send notification %s: "
                 "ConnectionClosed",
                 request.notification_id,
             )
         except FlowControlError:
             logger.debug(
                 "Got FlowControlError for notification %s",
                 request.notification_id,
             )
             await asyncio.sleep(1)
     logger.error("Failed to send after %d attempts.", attempts)
     raise MaxAttemptsExceeded
Пример #6
0
 def on_remote_settings_changed(self, changed_settings):
     for setting in changed_settings.values():
         logger.debug('Remote setting changed: %s', setting)
         if setting.setting == SettingCodes.MAX_CONCURRENT_STREAMS:
             self.free_channels.bound = setting.new_value
Пример #7
0
 def discard_connection(self, connection):
     logger.debug('Connection %s discarded', connection)
     self.connections.remove(connection)
     logger.info('Connection released (total: %d)', len(self.connections))
Пример #8
0
 def close(self):
     if self.inactivity_timer:
         self.inactivity_timer.cancel()
     logger.debug('Closing connection %s', self)
     self.transport._ssl_protocol._transport.close()
Пример #9
0
 def close(self):
     if self.inactivity_timer:
         self.inactivity_timer.cancel()
     logger.debug("Closing connection %s", self)
     self.transport.close()