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)
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)
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
def discard_connection(self, connection): logger.debug('Connection %s discarded', connection) self.connections.remove(connection) logger.info('Connection released (total: %d)', len(self.connections))
def close(self): if self.inactivity_timer: self.inactivity_timer.cancel() logger.debug('Closing connection %s', self) self.transport._ssl_protocol._transport.close()