Skip to content

Commit

Permalink
httpget command works!
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalium committed Aug 31, 2024
1 parent 97f67d0 commit 68da9c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion os/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::net::icmp::IcmpPacket;
use crate::net::manager::Network;
use crate::println;
use crate::x86_64::trigger_debug_interrupt;
use alloc::format;
use alloc::vec::Vec;
use core::str::FromStr;
use noli::mem::Sliceable;
Expand Down Expand Up @@ -117,7 +118,12 @@ pub async fn run(cmdline: &str) -> Result<()> {
} else {
return Ok(());
};
let _sock = network.open_tcp_socket(ip, port)?;
let sock = network.open_tcp_socket(ip, port)?;
sock.wait_until_connection_is_established().await;
sock.tx_data()
.lock()
.extend(format!("GET / HTTP/1.0\nHost: {host}\n\n").bytes());
sock.poll_tx()?;
}
"arp" => {
println!("{:?}", network.arp_table_cloned())
Expand Down
6 changes: 6 additions & 0 deletions os/src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate alloc;

use crate::error::Error;
use crate::error::Result;
use crate::executor::yield_execution;
use crate::info;
use crate::mutex::Mutex;
use crate::net::checksum::InternetChecksum;
Expand Down Expand Up @@ -473,4 +474,9 @@ impl TcpSocket {
Network::take().send_ip_packet(syn_packet.into_boxed_slice());
Ok(())
}
pub async fn wait_until_connection_is_established(&self) {
while *self.state.lock() != TcpSocketState::Established {
yield_execution().await;
}
}
}

0 comments on commit 68da9c9

Please sign in to comment.