Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass part echo CI in windows #248

Merged
merged 8 commits into from
Mar 18, 2024
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
22 changes: 9 additions & 13 deletions monoio/src/driver/op/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
std::ffi::c_void,
windows_sys::Win32::{
Foundation::TRUE,
Networking::WinSock::{WSAGetLastError, WSARecv, SOCKET_ERROR},
Networking::WinSock::{WSAGetLastError, WSARecv},
Storage::FileSystem::{ReadFile, SetFilePointer, FILE_CURRENT, INVALID_SET_FILE_POINTER},
},
};
Expand Down Expand Up @@ -155,9 +155,7 @@ impl<T: IoVecBufMut> Op<ReadVec<T>> {

if let Ok(n) = res {
// Safety: the kernel wrote `n` bytes to the buffer.
unsafe {
buf_vec.set_init(n);
}
unsafe { buf_vec.set_init(n) };
}
(res, buf_vec)
}
Expand Down Expand Up @@ -188,26 +186,24 @@ impl<T: IoVecBufMut> OpAble for ReadVec<T> {

#[cfg(all(any(feature = "legacy", feature = "poll-io"), windows))]
fn legacy_call(&mut self) -> io::Result<u32> {
let mut bytes_recved = 0;
let mut bytes_received = 0;
let ret = unsafe {
WSARecv(
self.fd.raw_socket() as _,
self.buf_vec.write_wsabuf_ptr(),
self.buf_vec.write_wsabuf_len() as _,
&mut bytes_recved,
std::ptr::null_mut(),
self.buf_vec.write_wsabuf_len().min(u32::MAX as usize) as _,
&mut bytes_received,
&mut 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lpFlags here is used as both in and out. So it has to be able to read and write.
Have you tried to implement it like rust std? In std impl, it declare 2 temp variable nread and flags, and then pass the mut references.

https://github.com/rust-lang/rust/blob/master/library/std/src/sys/pal/windows/net.rs#L253

Copy link
Contributor Author

@loongs-zhang loongs-zhang Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is equivalent.
image

Still blocked in monoio/tests/tcp_echo.rs:45

std::ptr::null_mut(),
None,
)
};
match ret {
0 => return Err(std::io::ErrorKind::WouldBlock.into()),
SOCKET_ERROR => {
0 => Ok(bytes_received),
_ => {
let error = unsafe { WSAGetLastError() };
return Err(std::io::Error::from_raw_os_error(error));
Err(io::Error::from_raw_os_error(error))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails in here, got a WSAEFAULT, but I think there should be no problem with the pointers. Could you please provide some help? @ihciah

}
_ => (),
}
Ok(bytes_recved)
}
}
10 changes: 4 additions & 6 deletions monoio/src/driver/op/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use io_uring::{opcode, types};
#[cfg(all(windows, any(feature = "legacy", feature = "poll-io")))]
use windows_sys::Win32::{
Foundation::TRUE,
Networking::WinSock::{WSAGetLastError, WSASend, SOCKET_ERROR},
Networking::WinSock::{WSAGetLastError, WSASend},
Storage::FileSystem::{SetFilePointer, WriteFile, FILE_CURRENT, INVALID_SET_FILE_POINTER},
};
#[cfg(all(unix, any(feature = "legacy", feature = "poll-io")))]
Expand Down Expand Up @@ -188,13 +188,11 @@ impl<T: IoVecBuf> OpAble for WriteVec<T> {
)
};
match ret {
0 => return Err(std::io::ErrorKind::WouldBlock.into()),
SOCKET_ERROR => {
0 => Ok(bytes_sent),
_ => {
let error = unsafe { WSAGetLastError() };
return Err(std::io::Error::from_raw_os_error(error));
Err(io::Error::from_raw_os_error(error))
}
_ => (),
}
Ok(bytes_sent)
}
}
2 changes: 0 additions & 2 deletions monoio/tests/tcp_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use monoio::{
net::{TcpListener, TcpStream},
};

// todo fix these CI in windows
#[cfg(not(windows))]
#[monoio::test_all]
async fn echo_server() {
const ITER: usize = 1024;
Expand Down
Loading