(
&mut self,
payload: &[u8],
continuation_prefix: impl FnOnce() -> Vec<u8>,
)
| 1190 | } |
| 1191 | |
| 1192 | pub(crate) fn send_protocol_pump( |
| 1193 | &mut self, |
| 1194 | payload: &[u8], |
| 1195 | continuation_prefix: impl FnOnce() -> Vec<u8>, |
| 1196 | ) -> Result<ProtocolPumpOutcome> { |
| 1197 | { |
| 1198 | let _phase = timing::phase("postgres.protocol.ensure_started"); |
| 1199 | self.start_protocol()?; |
| 1200 | } |
| 1201 | if payload.is_empty() { |
| 1202 | return Ok(ProtocolPumpOutcome::Buffered(Vec::new())); |
| 1203 | } |
| 1204 | ensure!( |
| 1205 | self.protocol_stdio_attachment.is_some(), |
| 1206 | "WASIX protocol pump requires an attached stream" |
| 1207 | ); |
| 1208 | let previous_mode = self.set_protocol_transport(ProtocolTransportMode::Hybrid)?; |
| 1209 | ensure!( |
| 1210 | previous_mode == ProtocolTransportMode::Buffered, |
| 1211 | "WASIX protocol transport was not buffered before protocol pump" |
| 1212 | ); |
| 1213 | let result = self.send_protocol_inner(payload); |
| 1214 | let active = self.protocol_stream_active().unwrap_or(false); |
| 1215 | if active { |
| 1216 | self.set_protocol_stream_prefix(continuation_prefix())?; |
| 1217 | let stream_result = result.and_then(|_| self.serve_protocol_stream_inner()); |
| 1218 | let restore_result = self.restore_protocol_transport(previous_mode); |
| 1219 | let clear_result = self.clear_protocol_stream_prefix(); |
| 1220 | stream_result.and(restore_result).and(clear_result)?; |
| 1221 | Ok(ProtocolPumpOutcome::Streamed) |
| 1222 | } else { |
| 1223 | let output = result; |
| 1224 | let restore_result = self.restore_protocol_transport(previous_mode); |
| 1225 | restore_result?; |
| 1226 | let output = output?; |
| 1227 | Ok(ProtocolPumpOutcome::Buffered(output)) |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | fn send_protocol_inner(&mut self, payload: &[u8]) -> Result<Vec<u8>> { |
| 1232 | self.reset_backend_c_timings()?; |
no test coverage detected