MCPcopy Index your code
hub / github.com/RustPython/RustPython / sock_op_timeout_err

Method sock_op_timeout_err

crates/stdlib/src/socket.rs:1093–1135  ·  view source on GitHub ↗
(
            &self,
            vm: &VirtualMachine,
            select: SelectKind,
            timeout: Option<Duration>,
            mut f: F,
        )

Source from the content-addressed store, hash-verified

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,

Callers 2

sock_opMethod · 0.80
sendallMethod · 0.80

Calls 9

sock_selectFunction · 0.85
time_untilMethod · 0.80
sockMethod · 0.80
allow_threadsMethod · 0.80
check_signalsMethod · 0.80
ErrClass · 0.50
mapMethod · 0.45
as_refMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected