Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions core/src/syscall/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ macro_rules! impl_nio_read_iovec {
let mut r = -1;
let mut index = 0;
for iovec in &vec {
let mut offset = received.saturating_sub(length);
let stage = length;
let mut offset = received.saturating_sub(stage);
length += iovec.iov_len;
if received > length {
Comment on lines 569 to 573
index += 1;
Expand All @@ -578,6 +579,7 @@ macro_rules! impl_nio_read_iovec {
arg.push(*i);
}
while received < length && left_time > 0 {
// Assuming iov_len is 4, but only 1 is read, at this point we should continue trying to fill the current iovec
if 0 != offset {
arg[0] = libc::iovec {
iov_base: (arg[0].iov_base as usize + offset) as *mut std::ffi::c_void,
Expand Down Expand Up @@ -607,7 +609,7 @@ macro_rules! impl_nio_read_iovec {
r = received.try_into().expect("received overflow");
break;
}
offset = received.saturating_sub(length);
offset = received.saturating_sub(stage);
}
let error_kind = std::io::Error::last_os_error().kind();
if error_kind == std::io::ErrorKind::WouldBlock {
Expand Down Expand Up @@ -790,7 +792,8 @@ macro_rules! impl_nio_write_iovec {
let mut r = -1;
let mut index = 0;
for iovec in &vec {
let mut offset = sent.saturating_sub(length);
let stage = length;
let mut offset = sent.saturating_sub(stage);
length += iovec.iov_len;
if sent > length {
index += 1;
Expand Down Expand Up @@ -823,7 +826,7 @@ macro_rules! impl_nio_write_iovec {
r = sent.try_into().expect("sent overflow");
break;
}
offset = sent.saturating_sub(length);
offset = sent.saturating_sub(stage);
}
let error_kind = std::io::Error::last_os_error().kind();
if error_kind == std::io::ErrorKind::WouldBlock {
Expand Down
15 changes: 9 additions & 6 deletions core/src/syscall/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ macro_rules! impl_nio_read_iovec {
let mut r = windows_sys::Win32::Networking::WinSock::SOCKET_ERROR;
let mut index = 0;
for iovec in &vec {
let mut offset = received.saturating_sub(length);
let stage = length;
let mut offset = received.saturating_sub(stage);
length += iovec.len as usize;
if received > length {
index += 1;
Expand All @@ -545,6 +546,7 @@ macro_rules! impl_nio_read_iovec {
arg.push(*i);
}
while received < length && left_time > 0 {
// Assuming len is 4, but only 1 is read, at this point we should continue trying to fill the current WSABUF
if 0 != offset {
arg[0] = windows_sys::Win32::Networking::WinSock::WSABUF {
buf: (arg[0].buf as usize + offset) as windows_sys::core::PSTR,
Expand All @@ -563,13 +565,13 @@ macro_rules! impl_nio_read_iovec {
);
if r != windows_sys::Win32::Networking::WinSock::SOCKET_ERROR {
$crate::syscall::reset_errno();
received += usize::try_from(r).expect("overflow");
received += unsafe{ usize::try_from(*$recvd).expect("overflow") };
if received >= length {
Comment on lines 565 to 569
r = 0;
unsafe{ $recvd.write(received.try_into().expect("overflow")) };
break;
}
offset = received.saturating_sub(length);
offset = received.saturating_sub(stage);
}
let error_kind = std::io::Error::last_os_error().kind();
if error_kind == std::io::ErrorKind::WouldBlock {
Expand Down Expand Up @@ -774,7 +776,8 @@ macro_rules! impl_nio_write_iovec {
let mut r = windows_sys::Win32::Networking::WinSock::SOCKET_ERROR;
let mut index = 0;
for iovec in &vec {
let mut offset = sent.saturating_sub(length);
let stage = length;
let mut offset = sent.saturating_sub(stage);
length += iovec.len as usize;
if sent > length {
index += 1;
Expand Down Expand Up @@ -803,13 +806,13 @@ macro_rules! impl_nio_write_iovec {
);
if r != windows_sys::Win32::Networking::WinSock::SOCKET_ERROR {
$crate::syscall::reset_errno();
sent += usize::try_from(r).expect("overflow");
sent += unsafe{ usize::try_from(*$sent).expect("overflow")};
if sent >= length {
r = 0;
Comment on lines 807 to 811
unsafe{ $sent.write(sent.try_into().expect("overflow")) };
break;
}
offset = sent.saturating_sub(length);
offset = sent.saturating_sub(stage);
}
let error_kind = std::io::Error::last_os_error().kind();
if error_kind == std::io::ErrorKind::WouldBlock {
Expand Down
Loading