コード例 #1
0
    def handle_close_msg(self, channel: Channel, session: FBDPSession,
                         msg: FBDPMessage) -> None:
        """Process CLOSE message received from client.

        Calls `on_pipe_closed` and then discards the session.

        Arguments:
            channel: Channel that received the message.
            session: Session instance.
            msg:     Received message.
        """
        try:
            self.on_pipe_closed(channel, session, msg)
        except:
            # We don't want to handle this via `handle_exception` and we're closing
            # the pipe anyway
            pass
        finally:
            channel.discard_session(session)
コード例 #2
0
    def send_close(self,
                   channel: Channel,
                   session: FBDPSession,
                   error_code: ErrorCode,
                   exc: Exception = None) -> None:
        """Sends `CLOSE` message, calls `on_pipe_closed` and then discards the session.

        Arguments:
            channel: Channel associate with data pipe.
            session: Session associated with transmission.
            error_code: Error code.
            exc: Exception that caused the error.
        """
        msg = self.create_message_for(MsgType.CLOSE, error_code)
        if exc:
            msg.note_exception(exc)
        try:
            channel.send(msg, session)
            self.on_pipe_closed(channel, session, msg, exc)
        finally:
            channel.discard_session(session)