MCPcopy Index your code
hub / github.com/RustPython/RustPython / try_read_close_notify

Method try_read_close_notify

crates/stdlib/src/ssl.rs:4299–4344  ·  view source on GitHub ↗

Helper: Try to read incoming data from socket/BIO Returns true if peer closed connection (with or without close_notify)

(
            &self,
            conn: &mut TlsConnection,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

4297 // Helper: Try to read incoming data from socket/BIO
4298 // Returns true if peer closed connection (with or without close_notify)
4299 fn try_read_close_notify(
4300 &self,
4301 conn: &mut TlsConnection,
4302 vm: &VirtualMachine,
4303 ) -> PyResult<bool> {
4304 // In socket mode, peek first to avoid consuming post-TLS cleartext
4305 // data. During STARTTLS, after close_notify exchange, the socket
4306 // transitions to cleartext. Without peeking, sock_recv may consume
4307 // cleartext data meant for the application after unwrap().
4308 if self.incoming_bio.is_none() {
4309 return self.try_read_close_notify_socket(conn, vm);
4310 }
4311
4312 // BIO mode: read from incoming BIO
4313 match self.sock_recv(SSL3_RT_MAX_PLAIN_LENGTH, vm) {
4314 Ok(bytes_obj) => {
4315 let bytes = ArgBytesLike::try_from_object(vm, bytes_obj)?;
4316 let data = bytes.borrow_buf();
4317
4318 if data.is_empty() {
4319 if let Some(ref bio) = self.incoming_bio {
4320 // BIO mode: check if EOF was signaled via write_eof()
4321 let bio_obj: PyObjectRef = bio.clone().into();
4322 let eof_attr = bio_obj.get_attr("eof", vm)?;
4323 let is_eof = eof_attr.try_to_bool(vm)?;
4324 if !is_eof {
4325 return Ok(false);
4326 }
4327 }
4328 return Ok(true);
4329 }
4330
4331 let data_slice: &[u8] = data.as_ref();
4332 let mut cursor = std::io::Cursor::new(data_slice);
4333 let _ = conn.read_tls(&mut cursor);
4334 let _ = conn.process_new_packets();
4335 Ok(false)
4336 }
4337 Err(e) => {
4338 if is_blocking_io_error(&e, vm) {
4339 return Ok(false);
4340 }
4341 Ok(true)
4342 }
4343 }
4344 }
4345
4346 /// Socket-mode close_notify reader that respects TLS record boundaries.
4347 /// Uses MSG_PEEK to inspect data before consuming, preventing accidental

Callers 1

shutdownMethod · 0.80

Calls 13

newFunction · 0.85
is_blocking_io_errorFunction · 0.85
try_to_boolMethod · 0.80
read_tlsMethod · 0.80
process_new_packetsMethod · 0.80
is_noneMethod · 0.45
sock_recvMethod · 0.45
borrow_bufMethod · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45
get_attrMethod · 0.45

Tested by

no test coverage detected