Send all bytes to socket, handling partial sends with blocking wait Loops until all bytes are sent. For blocking sockets, this will wait until all data is sent. For non-blocking sockets, returns WantWrite if no progress can be made. Optional deadline parameter allows respecting a read deadline during flush.
(
socket: &PySSLSocket,
buf: Vec<u8>,
vm: &VirtualMachine,
deadline: Option<std::time::Instant>,
)
| 1012 | /// if no progress can be made. |
| 1013 | /// Optional deadline parameter allows respecting a read deadline during flush. |
| 1014 | fn send_all_bytes( |
| 1015 | socket: &PySSLSocket, |
| 1016 | buf: Vec<u8>, |
| 1017 | vm: &VirtualMachine, |
| 1018 | deadline: Option<std::time::Instant>, |
| 1019 | ) -> SslResult<()> { |
| 1020 | // First, flush any previously pending TLS data with deadline |
| 1021 | socket |
| 1022 | .flush_pending_tls_output(vm, deadline) |
| 1023 | .map_err(SslError::Py)?; |
| 1024 | |
| 1025 | if buf.is_empty() { |
| 1026 | return Ok(()); |
| 1027 | } |
| 1028 | |
| 1029 | let mut sent_total = 0; |
| 1030 | while sent_total < buf.len() { |
| 1031 | // Check deadline before each send attempt |
| 1032 | if let Some(dl) = deadline |
| 1033 | && std::time::Instant::now() >= dl |
| 1034 | { |
| 1035 | socket |
| 1036 | .pending_tls_output |
| 1037 | .lock() |
| 1038 | .extend_from_slice(&buf[sent_total..]); |
| 1039 | return Err(SslError::Timeout("The operation timed out".to_string())); |
| 1040 | } |
| 1041 | |
| 1042 | // Wait for socket to be writable before sending |
| 1043 | let timed_out = if let Some(dl) = deadline { |
| 1044 | let now = std::time::Instant::now(); |
| 1045 | if now >= dl { |
| 1046 | socket |
| 1047 | .pending_tls_output |
| 1048 | .lock() |
| 1049 | .extend_from_slice(&buf[sent_total..]); |
| 1050 | return Err(SslError::Timeout( |
| 1051 | "The write operation timed out".to_string(), |
| 1052 | )); |
| 1053 | } |
| 1054 | socket |
| 1055 | .sock_wait_for_io_with_timeout(SelectKind::Write, Some(dl - now), vm) |
| 1056 | .map_err(SslError::Py)? |
| 1057 | } else { |
| 1058 | socket |
| 1059 | .sock_wait_for_io_impl(SelectKind::Write, vm) |
| 1060 | .map_err(SslError::Py)? |
| 1061 | }; |
| 1062 | if timed_out { |
| 1063 | socket |
| 1064 | .pending_tls_output |
| 1065 | .lock() |
| 1066 | .extend_from_slice(&buf[sent_total..]); |
| 1067 | return Err(SslError::Timeout( |
| 1068 | "The write operation timed out".to_string(), |
| 1069 | )); |
| 1070 | } |
| 1071 |
no test coverage detected