Write TLS handshake data to socket/BIO Drains all pending TLS data from rustls and sends it to the peer. Returns whether any progress was made.
(
conn: &mut TlsConnection,
socket: &PySSLSocket,
force_initial_write: bool,
vm: &VirtualMachine,
)
| 1114 | /// Drains all pending TLS data from rustls and sends it to the peer. |
| 1115 | /// Returns whether any progress was made. |
| 1116 | fn handshake_write_loop( |
| 1117 | conn: &mut TlsConnection, |
| 1118 | socket: &PySSLSocket, |
| 1119 | force_initial_write: bool, |
| 1120 | vm: &VirtualMachine, |
| 1121 | ) -> SslResult<bool> { |
| 1122 | let mut made_progress = false; |
| 1123 | |
| 1124 | // Flush any previously pending TLS data before generating new output |
| 1125 | // Must succeed before sending new data to maintain order |
| 1126 | socket |
| 1127 | .flush_pending_tls_output(vm, None) |
| 1128 | .map_err(SslError::Py)?; |
| 1129 | |
| 1130 | while conn.wants_write() || force_initial_write { |
| 1131 | if force_initial_write && !conn.wants_write() { |
| 1132 | // No data to write on first iteration - break to avoid infinite loop |
| 1133 | break; |
| 1134 | } |
| 1135 | |
| 1136 | let mut buf = Vec::new(); |
| 1137 | let written = conn |
| 1138 | .write_tls(&mut buf as &mut dyn std::io::Write) |
| 1139 | .map_err(SslError::Io)?; |
| 1140 | |
| 1141 | if written > 0 && !buf.is_empty() { |
| 1142 | // Send all bytes to socket, handling partial sends |
| 1143 | send_all_bytes(socket, buf, vm, None)?; |
| 1144 | made_progress = true; |
| 1145 | } else if written == 0 { |
| 1146 | // No data written but wants_write is true - should not happen normally |
| 1147 | // Break to avoid infinite loop |
| 1148 | break; |
| 1149 | } |
| 1150 | |
| 1151 | // Check if there's more to write |
| 1152 | if !conn.wants_write() { |
| 1153 | break; |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | Ok(made_progress) |
| 1158 | } |
| 1159 | |
| 1160 | /// Read TLS handshake data from socket/BIO |
| 1161 | /// |
no test coverage detected