Close the connection gracefully with GOAWAY. Args: error_code: HTTP/2 error code (default: NO_ERROR) last_stream_id: Last processed stream ID (default: highest)
(self, error_code=0x0, last_stream_id=None)
| 608 | self._send_pending_data() |
| 609 | |
| 610 | def close(self, error_code=0x0, last_stream_id=None): |
| 611 | """Close the connection gracefully with GOAWAY. |
| 612 | |
| 613 | Args: |
| 614 | error_code: HTTP/2 error code (default: NO_ERROR) |
| 615 | last_stream_id: Last processed stream ID (default: highest) |
| 616 | """ |
| 617 | if self._closed: |
| 618 | return |
| 619 | |
| 620 | self._closed = True |
| 621 | |
| 622 | if last_stream_id is None: |
| 623 | # Use highest stream ID we've seen |
| 624 | last_stream_id = max(self.streams.keys()) if self.streams else 0 |
| 625 | |
| 626 | try: |
| 627 | self.h2_conn.close_connection(error_code=error_code) |
| 628 | self._send_pending_data() |
| 629 | except Exception: |
| 630 | pass # Best effort |
| 631 | |
| 632 | def _send_pending_data(self): |
| 633 | """Send any pending data from h2 to the socket.""" |