-
Notifications
You must be signed in to change notification settings - Fork 13.5k
std: sys: net: uefi: tcp4: Implement write #141532
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
base: master
Are you sure you want to change the base?
Conversation
@rustbot label +O-UEFI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits but this looks reasonable to me. @nicholasbishop would you mind double checking since this is UEFI?
let protocol = self.protocol.as_ptr(); | ||
let mut token = tcp4::IoToken { | ||
completion_token, | ||
packet: tcp4::IoTokenPacket { tx_data: &mut tx_data as *mut _ as *mut _ }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packet: tcp4::IoTokenPacket { tx_data: ptr::from_mut(&mut tx_data).cast::<whatever>() },
What casts are needed? tx_data
should be tcp4::TransmitData
, and that looks like what is expected in https://docs.rs/r-efi/latest/r_efi/protocols/tcp4/union.IoTokenPacket.html.
Also, isn't rx_data
missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What casts are needed? tx_data should be tcp4::TransmitData, and that looks like what is expected in https://docs.rs/r-efi/latest/r_efi/protocols/tcp4/union.IoTokenPacket.html.
Well, tcp4::TransmitData
is a const generic. tcp4::IoTokenPacket
takes ZST (tcp4::TransmitData<0>
). So we are casting tcp4::TransmitData<1>
to tcp4::TransmitData<0>
.
Also, isn't rx_data missing?
It's a union.
|
||
let fragment = tcp4::FragmentData { | ||
fragment_length: data_len, | ||
fragment_buffer: buf.as_ptr() as *mut _, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit to make the cast obvious (especially since it includes a mutability change)
fragment_buffer: buf.as_ptr().cast::<c_void>().cast_mut()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
A blocking implementation of tcp4 write. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> { | ||
unsupported() | ||
pub fn write_vectored(&self, buf: &[IoSlice<'_>]) -> io::Result<usize> { | ||
// FIXME: UEFI does support vectored write, so implment that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implment -> implement
let evt = unsafe { self.create_evt() }?; | ||
let completion_token = | ||
tcp4::CompletionToken { event: evt.as_ptr(), status: Status::SUCCESS }; | ||
let data_len = crate::cmp::min(u32::MAX as u64, buf.len() as u64) as u32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I reading correctly that this is truncating the buffer length to a u32
? If so, might be clearer as:
let data_len = u32::try_from(buf.len()).unwrap_or(u32::MAX);
let mut token = tcp4::IoToken { | ||
completion_token, | ||
packet: tcp4::IoTokenPacket { | ||
tx_data: &mut tx_data as *mut tcp4::TransmitData<1> as *mut tcp4::TransmitData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this casting could be simplified:
tx_data: (&raw mut tx_data).cast::<tcp4::TransmitData<0>>(),
A blocking implementation of tcp4 write.