Discard incoming data. This coroutine replaces :meth:`parse`: - after receiving a close frame, during a normal closure (1.4); - after sending a close frame, during an abnormal closure (7.1.7).
(self)
| 639 | raise AssertionError("parse() shouldn't step after error") |
| 640 | |
| 641 | def discard(self) -> Generator[None]: |
| 642 | """ |
| 643 | Discard incoming data. |
| 644 | |
| 645 | This coroutine replaces :meth:`parse`: |
| 646 | |
| 647 | - after receiving a close frame, during a normal closure (1.4); |
| 648 | - after sending a close frame, during an abnormal closure (7.1.7). |
| 649 | |
| 650 | """ |
| 651 | # After the opening handshake completes, the server closes the TCP |
| 652 | # connection in the same circumstances where discard() replaces parse(). |
| 653 | # The client closes it when it receives EOF from the server or times |
| 654 | # out. (The latter case cannot be handled in this Sans-I/O layer.) |
| 655 | assert (self.side is SERVER or self.state is CONNECTING) == (self.eof_sent) |
| 656 | while not (yield from self.reader.at_eof()): |
| 657 | self.reader.discard() |
| 658 | if self.debug: |
| 659 | self.logger.debug("< EOF") |
| 660 | # A server closes the TCP connection immediately, while a client |
| 661 | # waits for the server to close the TCP connection. |
| 662 | if self.side is CLIENT and self.state is not CONNECTING: |
| 663 | self.send_eof() |
| 664 | self.state = CLOSED |
| 665 | # If discard() completes normally, execution ends here. |
| 666 | yield |
| 667 | # Once the reader reaches EOF, its feed_data/eof() methods raise an |
| 668 | # error, so our receive_data/eof() methods don't step the generator. |
| 669 | raise AssertionError("discard() shouldn't step after EOF") |
| 670 | |
| 671 | def recv_frame(self, frame: Frame) -> None: |
| 672 | """ |