This is the function that has the message loop.
(self)
| 572 | pass |
| 573 | |
| 574 | def run(self): |
| 575 | """This is the function that has the message loop.""" |
| 576 | |
| 577 | try: |
| 578 | while self.isConnected() or not self.msg_queue.empty(): |
| 579 | try: |
| 580 | try: |
| 581 | text = self.msg_queue.get(block=True, timeout=0.2) |
| 582 | if len(text) > MAX_MSG_LEN: |
| 583 | self.wrapper.error( |
| 584 | NO_VALID_ID, |
| 585 | currentTimeMillis(), |
| 586 | BAD_LENGTH.code(), |
| 587 | f"{BAD_LENGTH.msg()}:{len(text)}:{text}", |
| 588 | ) |
| 589 | break |
| 590 | except queue.Empty: |
| 591 | logger.debug("queue.get: empty") |
| 592 | self.msgLoopTmo() |
| 593 | else: |
| 594 | |
| 595 | if self.serverVersion() >= MIN_SERVER_VER_PROTOBUF: |
| 596 | sMsgId = text[:4] |
| 597 | msgId = int.from_bytes(sMsgId, 'big') |
| 598 | text = text[4:] |
| 599 | else: |
| 600 | sMsgId = text[:text.index(b"\0")] |
| 601 | text = text[text.index(b"\0") + len(b"\0"):] |
| 602 | msgId = int(sMsgId) |
| 603 | |
| 604 | if msgId > PROTOBUF_MSG_ID: |
| 605 | msgId -= PROTOBUF_MSG_ID |
| 606 | logger.debug("msgId: %d, protobuf: %s", msgId, text) |
| 607 | self.decoder.processProtoBuf(text, msgId) |
| 608 | else: |
| 609 | fields = comm.read_fields(text) |
| 610 | logger.debug("msgId: %d, fields: %s", msgId, fields) |
| 611 | self.decoder.interpret(fields, msgId) |
| 612 | |
| 613 | self.msgLoopRec() |
| 614 | except (KeyboardInterrupt, SystemExit): |
| 615 | logger.info("detected KeyboardInterrupt, SystemExit") |
| 616 | self.keyboardInterrupt() |
| 617 | self.keyboardInterruptHard() |
| 618 | except BadMessage: |
| 619 | logger.info("BadMessage") |
| 620 | |
| 621 | logger.debug( |
| 622 | "conn:%d queue.sz:%d", self.isConnected(), self.msg_queue.qsize() |
| 623 | ) |
| 624 | finally: |
| 625 | self.disconnect() |
| 626 | |
| 627 | def reqCurrentTime(self): |
| 628 | """Asks the current system time on the server side.""" |
nothing calls this directly
no test coverage detected