Get socket timeout as Duration
(&self, vm: &VirtualMachine)
| 2403 | |
| 2404 | // Get socket timeout as Duration |
| 2405 | pub(crate) fn get_socket_timeout(&self, vm: &VirtualMachine) -> PyResult<Option<Duration>> { |
| 2406 | if self.is_bio_mode() { |
| 2407 | return Ok(None); |
| 2408 | } |
| 2409 | |
| 2410 | // Get timeout from socket |
| 2411 | let timeout_obj = self.sock.get_attr("gettimeout", vm)?.call((), vm)?; |
| 2412 | |
| 2413 | // timeout can be None (blocking), 0.0 (non-blocking), or positive float |
| 2414 | if vm.is_none(&timeout_obj) { |
| 2415 | // None means blocking forever |
| 2416 | Ok(None) |
| 2417 | } else { |
| 2418 | let timeout_float: f64 = timeout_obj.try_into_value(vm)?; |
| 2419 | if timeout_float <= 0.0 { |
| 2420 | // 0 means non-blocking |
| 2421 | Ok(Some(Duration::from_secs(0))) |
| 2422 | } else { |
| 2423 | // Positive timeout |
| 2424 | Ok(Some(Duration::from_secs_f64(timeout_float))) |
| 2425 | } |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | // Create and store a session object after successful handshake |
| 2430 | fn create_session_after_handshake(&self, vm: &VirtualMachine) -> PyResult<()> { |
no test coverage detected