◐ Shell
reader mode source ↗
Skip to content
Merged
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
96 changes: 76 additions & 20 deletions crates/stdlib/src/ssl/compat.rs
Original file line number Diff line number Diff line change
@@ -1421,6 +1421,50 @@ pub(super) fn ssl_read(
return Err(SslError::Eof);
}
}
return Err(SslError::WantRead);
}

@@ -1432,20 +1476,9 @@ pub(super) fn ssl_read(
// Continue loop to try reading plaintext
}
Err(SslError::Io(ref io_err)) if io_err.to_string().contains("message buffer full") => {
// Buffer is full - we need to consume plaintext before reading more
// Try to read plaintext now
match try_read_plaintext(conn, buf)? {
Some(n) if n > 0 => {
// Have plaintext - return it
// Python will call read() again if it needs more data
return Ok(n);
}
_ => {
// No plaintext available yet - this is unusual
// Return WantRead to let Python retry
return Err(SslError::WantRead);
}
}
}
Err(e) => {
// Other errors - check for buffered plaintext before propagating
Expand Down @@ -1524,7 +1557,7 @@ fn ssl_read_tls_records(
}

// Feed all received data to read_tls - loop to consume all data
// read_tls may not consume all data in one call
let mut offset = 0;
while offset < bytes_data.len() {
let remaining = &bytes_data[offset..];
Expand All @@ -1533,12 +1566,33 @@ fn ssl_read_tls_records(
match conn.read_tls(&mut cursor) {
Ok(read_bytes) => {
if read_bytes == 0 {
// No more data can be consumed
break;
}
offset += read_bytes;
}
Err(e) => {
// Real error - propagate it
return Err(SslError::Io(e));
}
Expand Down Expand Up @@ -1599,8 +1653,10 @@ fn ssl_ensure_data_available(
.sock_wait_for_io_impl(SelectKind::Read, vm)
.map_err(SslError::Py)?;
if timed_out {
// Socket not ready within timeout
return Err(SslError::WantRead);
}
}
// else: non-blocking socket (timeout=0) or blocking socket (timeout=None) - skip select
Expand Down
Loading
Toggle all file notes Toggle all file annotations