コード例 #1
0
ファイル: session.py プロジェクト: majek/sockjs-tornado
    def set_handler(self, handler, start_heartbeat=True):
        """Set active handler for the session

        `handler`
            Associate active Tornado handler with the session
        """
        # Check if session already has associated handler
        if self.handler is not None:
            handler.send_pack(proto.disconnect(2010, "Another connection still open"))
            return False

        if self.state == OPEN:
            # If IP address doesn't match - refuse connection
            if handler.request.remote_ip != self.remote_ip:
                logging.error('Attempted to attach to session %s (%s) from different IP (%s)' % (
                              self.session_id,
                              self.remote_ip,
                              self.handler.request.remote_ip
                              ))

                handler.send_pack(proto.disconnect(2010, "Attempted to connect to session from different IP"))
                return False
        elif self.state == CLOSED:
            handler.send_pack(proto.disconnect(3000, "Go away!"))
            return False

        # Associate handler and promote session
        self.handler = handler
        self.promote()

        if start_heartbeat:
            self.start_heartbeat()

        return True
コード例 #2
0
ファイル: session.py プロジェクト: Icarus-xx/sockjs-tornado
    def close(self, code=3000, message='Go away!'):
        """Close session or endpoint connection.
        """
        if self.state != CLOSED:
            # Notify handler
            if self.handler is not None:
                self.handler.send_pack(proto.disconnect(code, message))

        super(Session, self).close(code, message)
コード例 #3
0
ファイル: session.py プロジェクト: yoster0520/sockjs-tornado
    def set_handler(self, handler, start_heartbeat=True):
        """Set active handler for the session

        `handler`
            Associate active Tornado handler with the session
        `start_heartbeat`
            Should session start heartbeat immediately
        """
        # Check if session already has associated handler
        if self.handler is not None:
            handler.send_pack(
                proto.disconnect(2010, "Another connection still open"))
            return False

        if self._verify_ip and self.conn_info is not None:
            # If IP address doesn't match - refuse connection
            if handler.request.remote_ip != self.conn_info.ip:
                LOG.error(
                    'Attempted to attach to session %s (%s) from different IP (%s)'
                    % (self.session_id, self.conn_info.ip,
                       handler.request.remote_ip))

                handler.send_pack(
                    proto.disconnect(
                        2010,
                        "Attempted to connect to session from different IP"))
                return False

        if (self.state == CLOSING
                or self.state == CLOSED) and not self.send_queue:
            handler.send_pack(proto.disconnect(*self.get_close_reason()))
            return False

        # Associate handler and promote session
        super(Session, self).set_handler(handler)

        self.promote()

        if start_heartbeat:
            self.start_heartbeat()

        return True
コード例 #4
0
ファイル: session.py プロジェクト: majek/sockjs-tornado
    def close(self):
        """Close session or endpoint connection.
        """
        try:
            self.conn.on_close()
        finally:
            self.state = CLOSED

        if self.handler is not None:
            self.handler.send_pack(proto.disconnect(3000, 'Go away!'))
            self.handler.session_closed()
コード例 #5
0
ファイル: session.py プロジェクト: shergin/sockjs-tornado
    def close(self):
        """Close session or endpoint connection.
        """
        try:
            self.conn.on_close()
        finally:
            self.state = CLOSED

        if self.handler is not None:
            self.handler.send_pack(proto.disconnect(3000, 'Go away!'))
            self.handler.session_closed()
コード例 #6
0
ファイル: session.py プロジェクト: cablehead/sockjs-tornado
    def set_handler(self, handler, start_heartbeat=True):
        """Set active handler for the session

        `handler`
            Associate active Tornado handler with the session
        `start_heartbeat`
            Should session start heartbeat immediately
        """
        # Check if session already has associated handler
        if self.handler is not None:
            handler.send_pack(proto.disconnect(2010, "Another connection still open"))
            return False

        if self._verify_ip and self.conn_info is not None:
            # If IP address doesn't match - refuse connection
            if handler.request.remote_ip != self.conn_info.ip:
                logging.error('Attempted to attach to session %s (%s) from different IP (%s)' % (
                              self.session_id,
                              self.conn_info.ip,
                              handler.request.remote_ip
                              ))

                handler.send_pack(proto.disconnect(2010, "Attempted to connect to session from different IP"))
                return False

        if self.state == CLOSING or self.state == CLOSED:
            handler.send_pack(proto.disconnect(*self.get_close_reason()))
            return False

        # Associate handler and promote session
        super(Session, self).set_handler(handler)

        self.promote()

        if start_heartbeat:
            self.start_heartbeat()

        return True
コード例 #7
0
    def close(self, code=3000, message='Go away!'):
        """Close session.

        `code`
            Closing code
        `message`
            Closing message
        """
        if self.state != CLOSED:
            # Notify handler
            if self.handler is not None:
                self.handler.send_pack(proto.disconnect(code, message))

        super(Session, self).close(code, message)
コード例 #8
0
ファイル: session.py プロジェクト: nevo-a8/sockjs-tornado
    def close(self, code=3000, message="Go away!"):
        """Close session.

        `code`
            Closing code
        `message`
            Closing message
        """
        if self.state != CLOSED:
            # Notify handler
            if self.handler is not None:
                self.handler.send_pack(proto.disconnect(code, message))

        super(Session, self).close(code, message)
コード例 #9
0
ファイル: session.py プロジェクト: shergin/sockjs-tornado
    def set_handler(self, handler, start_heartbeat=True):
        """Set active handler for the session

        `handler`
            Associate active Tornado handler with the session
        """
        # Check if session already has associated handler
        if self.handler is not None:
            handler.send_pack(
                proto.disconnect(2010, "Another connection still open"))
            return False

        if self.state == OPEN:
            # If IP address doesn't match - refuse connection
            if handler.request.remote_ip != self.remote_ip:
                logging.error(
                    'Attempted to attach to session %s (%s) from different IP (%s)'
                    % (self.session_id, self.remote_ip,
                       self.handler.request.remote_ip))

                handler.send_pack(
                    proto.disconnect(
                        2010,
                        "Attempted to connect to session from different IP"))
                return False
        elif self.state == CLOSED:
            handler.send_pack(proto.disconnect(3000, "Go away!"))
            return False

        # Associate handler and promote session
        self.handler = handler
        self.promote()

        if start_heartbeat:
            self.start_heartbeat()

        return True