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
13 changes: 7 additions & 6 deletions library/std/src/sys/net/connection/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ impl TcpStream {
unsupported()
}

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

pub fn read_buf(&self, _buf: BorrowedCursor<'_>) -> io::Result<()> {
unsupported()
pub fn read_buf(&self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
crate::io::default_read_buf(|buf| self.read(buf), cursor)
}

pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
unsupported()
pub fn read_vectored(&self, buf: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
// FIXME: UEFI does support vectored read, so implement that.
crate::io::default_read_vectored(|b| self.read(b), buf)
}

pub fn is_read_vectored(&self) -> bool {
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/sys/net/connection/uefi/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ impl Tcp {
Self::V4(client) => client.write(buf),
}
}

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

pub(crate) fn read(&self, buf: &mut [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_mut_ptr().cast::<crate::ffi::c_void>(),
};
let mut tx_data = tcp4::ReceiveData {
urgent_flag: 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 {
rx_data: (&raw mut tx_data).cast::<tcp4::ReceiveData<0>>(),
},
};

let r = unsafe { ((*protocol).receive)(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
Loading