Beispiel #1
0
 async def _wait_for_cam_frame(self, cam: int) -> MethodFrame:
     future = self._loop.create_future()
     self._cam_waiters[cam].append(future)
     log_debug = logger.isEnabledFor(logging.DEBUG)
     if log_debug:
         logger.debug('Waiting for %s', pretty_format_cam(cam))
     method_frame = await future
     if log_debug:
         logger.debug('Received %s (same key as for %s)', pretty_format_cam(method_frame.cam), pretty_format_cam(cam))
     return method_frame
Beispiel #2
0
 def __str__(self):
     if self.class_id != 0 and self.method_id != 0:
         cam_text = ' because of method {}'.format(
             pretty_format_cam(cam_long_uint(self.class_id,
                                             self.method_id)))
     else:
         cam_text = ''
     return 'Server closed connection with code {}{}: {}'.format(
         self.reply_code, cam_text, self.reply_text)
Beispiel #3
0
 def _dispatch_frame(self, frame):
     logger.debug('Received frame: %s', frame)
     self._last_receive_timestamp = time.monotonic()
     if self.closing:
         if frame.frame_type != FRAME_TYPE_METHOD:
             logger.debug('Closing so ignoring frame of type %s', frame.frame_type)
             return
         elif frame.cam not in (CONNECTION_CLOSE_CAM, CONNECTION_CLOSE_OK_CAM):
             logger.debug('Closing so ignoring method %s frame', pretty_format_cam(frame.cam))
             return
     try:
         frame_type = frame.frame_type
         if frame_type == FRAME_TYPE_HEARTBEAT:
             if self._heartbeat_interval is None or self._heartbeat_interval == 0:
                 logger.warning('Server sent heartbeat frame though heartbeats are turned off')
                 raise UnexpectedFrame(frame)
         elif frame.channel_id > 0:
             channel_id = frame.channel_id
             try:
                 channel = self._channels[channel_id]
             except KeyError as exc:
                 logger.warning('Got frame for channel id %s, but it is not open', channel_id)
                 raise UnexpectedFrame(frame) from exc
             else:
                 channel.dispatch_frame(frame)
         elif frame_type == FRAME_TYPE_METHOD:
             cam = frame.cam
             if cam == CONNECTION_CLOSE_CAM:
                 self._on_connection_close(frame)
             elif cam in self._cam_waiters:
                 try:
                     future = self._cam_waiters[cam].popleft()
                 except IndexError:
                     raise UnexpectedFrame(frame)
                 if not future.done():
                     future.set_result(frame)
             else:
                 raise UnexpectedFrame(frame)
         else:
             raise UnexpectedFrame(frame)
     except UnexpectedFrame:
         # TODO: send a 503 or whatnot connection.close to server? Need to wait for connection.close-ok then?
         raise
Beispiel #4
0
 def __str__(self):
     return 'Method {} frame channel {}, parameters: {}'.format(
         pretty_format_cam(self.cam), self.channel_id, self.parameters)