Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 4 additions & 13 deletions core/src/syscall/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,7 @@ macro_rules! impl_nio_read_iovec {
let mut received = 0usize;
let mut r = -1;
let mut index = 0;
for iovec in &vec {
let mut offset = received.saturating_sub(length);
'outer: for iovec in &vec {
length += iovec.iov_len;
if received > length {
Comment on lines 569 to 573
index += 1;
Expand All @@ -578,12 +577,6 @@ macro_rules! impl_nio_read_iovec {
arg.push(*i);
}
while received < length && left_time > 0 {
if 0 != offset {
arg[0] = libc::iovec {
iov_base: (arg[0].iov_base as usize + offset) as *mut std::ffi::c_void,
iov_len: arg[0].iov_len - offset,
};
}
r = self.inner.$syscall(
fn_ptr,
$fd,
Expand All @@ -603,11 +596,9 @@ macro_rules! impl_nio_read_iovec {
} else if r != -1 {
$crate::syscall::reset_errno();
received += libc::size_t::try_from(r).expect("r overflow");
if received >= length {
r = received.try_into().expect("received overflow");
break;
}
offset = received.saturating_sub(length);
r = received.try_into().expect("received overflow");
// readv returns as soon as any data is received
break 'outer;
}
let error_kind = std::io::Error::last_os_error().kind();
if error_kind == std::io::ErrorKind::WouldBlock {
Expand Down
18 changes: 9 additions & 9 deletions core/src/syscall/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ macro_rules! impl_nio_read_iovec {
let mut received = 0usize;
let mut r = windows_sys::Win32::Networking::WinSock::SOCKET_ERROR;
let mut index = 0;
for iovec in &vec {
'outer: for iovec in &vec {
let mut offset = received.saturating_sub(length);
length += iovec.len as usize;
if received > length {
Expand Down Expand Up @@ -563,13 +563,12 @@ 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");
if received >= length {
r = 0;
unsafe{ $recvd.write(received.try_into().expect("overflow")) };
break;
}
offset = received.saturating_sub(length);
// WSARecv returns 0 on success; actual byte count is in *$recvd
received += unsafe { *$recvd } as usize;
r = 0;
unsafe{ $recvd.write(received.try_into().expect("overflow")) };
// WSARecv returns as soon as any data is received
break 'outer;
}
let error_kind = std::io::Error::last_os_error().kind();
if error_kind == std::io::ErrorKind::WouldBlock {
Expand Down Expand Up @@ -803,7 +802,8 @@ 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");
// WSASend returns 0 on success; actual byte count is in *$sent
sent += unsafe { *$sent } as usize;
if sent >= length {
r = 0;
Comment on lines 807 to 811
unsafe{ $sent.write(sent.try_into().expect("overflow")) };
Expand Down
Loading