Thanks to visit codestin.com
Credit goes to github.com

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
11 changes: 6 additions & 5 deletions library/std/src/sys/net/connection/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::time::Duration;
mod tcp;
pub(crate) mod tcp4;

pub struct TcpStream(#[expect(dead_code)] tcp::Tcp);
pub struct TcpStream(tcp::Tcp);

impl TcpStream {
pub fn connect(addr: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
Expand Down Expand Up @@ -54,12 +54,13 @@ impl TcpStream {
false
}

pub fn write(&self, _: &[u8]) -> io::Result<usize> {
unsupported()
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
}

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 implement that.
crate::io::default_write_vectored(|b| self.write(b), buf)
}

pub fn is_write_vectored(&self) -> bool {
Expand Down
8 changes: 7 additions & 1 deletion library/std/src/sys/net/connection/uefi/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::io;
use crate::net::SocketAddr;

pub(crate) enum Tcp {
V4(#[expect(dead_code)] tcp4::Tcp4),
V4(tcp4::Tcp4),
}

impl Tcp {
Expand All @@ -18,4 +18,10 @@ impl Tcp {
SocketAddr::V6(_) => todo!(),
}
}

pub(crate) fn write(&self, buf: &[u8]) -> io::Result<usize> {
match self {
Self::V4(client) => client.write(buf),
}
}
}
40 changes: 40 additions & 0 deletions library/std/src/sys/net/connection/uefi/tcp4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,46 @@ impl Tcp4 {
}
}

pub(crate) fn write(&self, buf: &[u8]) -> io::Result<usize> {
let evt = unsafe { self.create_evt() }?;
let completion_token =
tcp4::CompletionToken { event: evt.as_ptr(), status: Status::SUCCESS };
let data_len = u32::try_from(buf.len()).unwrap_or(u32::MAX);

let fragment = tcp4::FragmentData {
fragment_length: data_len,
fragment_buffer: buf.as_ptr().cast::<crate::ffi::c_void>().cast_mut(),
};
let mut tx_data = tcp4::TransmitData {
push: r_efi::efi::Boolean::FALSE,
urgent: r_efi::efi::Boolean::FALSE,
data_length: data_len,
fragment_count: 1,
fragment_table: [fragment],
};

let protocol = self.protocol.as_ptr();
let mut token = tcp4::IoToken {
completion_token,
packet: tcp4::IoTokenPacket {
tx_data: (&raw mut tx_data).cast::<tcp4::TransmitData<0>>(),
},
};

let r = unsafe { ((*protocol).transmit)(protocol, &mut token) };
if r.is_error() {
return Err(io::Error::from_raw_os_error(r.as_usize()));
}

self.wait_for_flag();

if completion_token.status.is_error() {
Err(io::Error::from_raw_os_error(completion_token.status.as_usize()))
} else {
Ok(data_len as usize)
}
}

unsafe fn create_evt(&self) -> io::Result<helpers::OwnedEvent> {
self.flag.store(false, Ordering::Relaxed);
helpers::OwnedEvent::new(
Expand Down