(
&self,
vm: &VirtualMachine,
select: SelectKind,
timeout: Option<Duration>,
mut f: F,
)
| 1091 | } |
| 1092 | |
| 1093 | fn sock_op_timeout_err<F, R>( |
| 1094 | &self, |
| 1095 | vm: &VirtualMachine, |
| 1096 | select: SelectKind, |
| 1097 | timeout: Option<Duration>, |
| 1098 | mut f: F, |
| 1099 | ) -> Result<R, IoOrPyException> |
| 1100 | where |
| 1101 | F: FnMut() -> io::Result<R>, |
| 1102 | { |
| 1103 | let deadline = timeout.map(Deadline::new); |
| 1104 | |
| 1105 | loop { |
| 1106 | if deadline.is_some() || matches!(select, SelectKind::Connect) { |
| 1107 | let interval = deadline.as_ref().map(|d| d.time_until()).transpose()?; |
| 1108 | let sock = self.sock()?; |
| 1109 | let res = vm.allow_threads(|| sock_select(&sock, select, interval)); |
| 1110 | match res { |
| 1111 | Ok(true) => return Err(IoOrPyException::Timeout), |
| 1112 | Err(e) if e.kind() == io::ErrorKind::Interrupted => { |
| 1113 | vm.check_signals()?; |
| 1114 | continue; |
| 1115 | } |
| 1116 | Err(e) => return Err(e.into()), |
| 1117 | Ok(false) => {} // no timeout, continue as normal |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | let err = loop { |
| 1122 | // Detach thread state around the blocking syscall so |
| 1123 | // stop-the-world can park this thread (e.g. before fork). |
| 1124 | match vm.allow_threads(&mut f) { |
| 1125 | Ok(x) => return Ok(x), |
| 1126 | Err(e) if e.kind() == io::ErrorKind::Interrupted => vm.check_signals()?, |
| 1127 | Err(e) => break e, |
| 1128 | } |
| 1129 | }; |
| 1130 | if timeout.is_some() && err.kind() == io::ErrorKind::WouldBlock { |
| 1131 | continue; |
| 1132 | } |
| 1133 | return Err(err.into()); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | fn extract_address( |
| 1138 | &self, |
no test coverage detected