| 3664 | |
| 3665 | #[pymethod] |
| 3666 | fn pending(&self) -> PyResult<usize> { |
| 3667 | // Returns the number of already decrypted bytes available for read |
| 3668 | // This is critical for asyncore's readable() method which checks socket.pending() > 0 |
| 3669 | let mut conn_guard = self.connection.lock(); |
| 3670 | let conn = match conn_guard.as_mut() { |
| 3671 | Some(c) => c, |
| 3672 | None => return Ok(0), // No connection established yet |
| 3673 | }; |
| 3674 | |
| 3675 | // Use rustls Reader's fill_buf() to check buffered plaintext |
| 3676 | // fill_buf() returns a reference to buffered data without consuming it |
| 3677 | // This matches OpenSSL's SSL_pending() behavior |
| 3678 | let mut reader = conn.reader(); |
| 3679 | match reader.fill_buf() { |
| 3680 | Ok(buf) => Ok(buf.len()), |
| 3681 | Err(_) => { |
| 3682 | // WouldBlock or other errors mean no data available |
| 3683 | // Return 0 like OpenSSL does when buffer is empty |
| 3684 | Ok(0) |
| 3685 | } |
| 3686 | } |
| 3687 | } |
| 3688 | |
| 3689 | #[pymethod] |
| 3690 | fn write(&self, data: ArgBytesLike, vm: &VirtualMachine) -> PyResult<usize> { |