Skip to content

Commit

Permalink
update socket rx handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalium committed Aug 31, 2024
1 parent ecdbc6a commit 9004a8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 9 additions & 0 deletions os/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ pub async fn run(cmdline: &str) -> Result<()> {
sock.tx_data()
.lock()
.extend(format!("GET / HTTP/1.0\nHost: {host}\n\n").bytes());
let mut received = Vec::new();
while sock.is_established() {
sock.wait_on_rx().await;
let mut rx_data_locked = sock.rx_data().lock();
received.extend(rx_data_locked.drain(..))
}
if let Ok(received) = core::str::from_utf8(&received) {
println!("{received}");
}
}
"arp" => {
println!("{:?}", network.arp_table_cloned())
Expand Down
1 change: 0 additions & 1 deletion os/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ fn run_tasks() -> Result<()> {
let mut tx_data_locked = sock.tx_data().lock();
tx_data_locked.extend(data.iter());
}
sock.poll_tx()?;
}
yield_execution().await;
}
Expand Down
14 changes: 8 additions & 6 deletions os/src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,6 @@ impl TcpSocket {
fin = true;
*self.state.lock() = TcpSocketState::LastAck;
}
if let Ok(s) = core::str::from_utf8(in_tcp_data) {
info!(
"net: tcp: recv: data(str) size = {}: {s}",
in_tcp_data.len()
);
}
seq_to_ack = seq_to_ack.wrapping_add(in_tcp_data.len() as u32);
self.rx_data.lock().extend(in_tcp_data);
// Send ACK
Expand Down Expand Up @@ -479,4 +473,12 @@ impl TcpSocket {
yield_execution().await;
}
}
pub async fn wait_on_rx(&self) {
while *self.state.lock() == TcpSocketState::Established && self.rx_data.lock().is_empty() {
yield_execution().await;
}
}
pub fn is_established(&self) -> bool {
*self.state.lock() == TcpSocketState::Established
}
}

0 comments on commit 9004a8f

Please sign in to comment.