mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-23 08:26:17 +04:00
Minor code cleanup
This commit is contained in:
parent
74cc05672a
commit
240f655ae4
@ -1,5 +1,3 @@
|
||||
mod structs;
|
||||
mod test;
|
||||
|
||||
pub use self::structs::*;
|
||||
pub use self::test::server;
|
||||
|
@ -1,82 +0,0 @@
|
||||
use crate::drivers::NET_DRIVERS;
|
||||
use crate::net::SOCKETS;
|
||||
use alloc::vec;
|
||||
use core::fmt::Write;
|
||||
use smoltcp::socket::*;
|
||||
|
||||
pub extern "C" fn server(_arg: usize) -> ! {
|
||||
if NET_DRIVERS.read().len() < 1 {
|
||||
loop {
|
||||
//thread::yield_now();
|
||||
}
|
||||
}
|
||||
|
||||
let udp_rx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY], vec![0; 64]);
|
||||
let udp_tx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY], vec![0; 128]);
|
||||
let udp_socket = UdpSocket::new(udp_rx_buffer, udp_tx_buffer);
|
||||
|
||||
let tcp_rx_buffer = TcpSocketBuffer::new(vec![0; 1024]);
|
||||
let tcp_tx_buffer = TcpSocketBuffer::new(vec![0; 1024]);
|
||||
let tcp_socket = TcpSocket::new(tcp_rx_buffer, tcp_tx_buffer);
|
||||
|
||||
let tcp2_rx_buffer = TcpSocketBuffer::new(vec![0; 1024]);
|
||||
let tcp2_tx_buffer = TcpSocketBuffer::new(vec![0; 1024]);
|
||||
let tcp2_socket = TcpSocket::new(tcp2_rx_buffer, tcp2_tx_buffer);
|
||||
|
||||
let mut sockets = SOCKETS.lock();
|
||||
let udp_handle = sockets.add(udp_socket);
|
||||
let tcp_handle = sockets.add(tcp_socket);
|
||||
let tcp2_handle = sockets.add(tcp2_socket);
|
||||
drop(sockets);
|
||||
|
||||
loop {
|
||||
{
|
||||
let mut sockets = SOCKETS.lock();
|
||||
|
||||
// udp server
|
||||
{
|
||||
let mut socket = sockets.get::<UdpSocket>(udp_handle);
|
||||
if !socket.is_open() {
|
||||
socket.bind(6969).unwrap();
|
||||
}
|
||||
|
||||
let client = match socket.recv() {
|
||||
Ok((_, endpoint)) => Some(endpoint),
|
||||
Err(_) => None,
|
||||
};
|
||||
if let Some(endpoint) = client {
|
||||
let hello = b"hello\n";
|
||||
socket.send_slice(hello, endpoint).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// simple http server
|
||||
{
|
||||
let mut socket = sockets.get::<TcpSocket>(tcp_handle);
|
||||
if !socket.is_open() {
|
||||
socket.listen(80).unwrap();
|
||||
}
|
||||
|
||||
if socket.can_send() {
|
||||
write!(socket, "HTTP/1.1 200 OK\r\nServer: rCore\r\nContent-Length: 13\r\nContent-Type: text/html\r\nConnection: Closed\r\n\r\nHello, world!\r\n").unwrap();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
// simple tcp server that just eats everything
|
||||
{
|
||||
let mut socket = sockets.get::<TcpSocket>(tcp2_handle);
|
||||
if !socket.is_open() {
|
||||
socket.listen(2222).unwrap();
|
||||
}
|
||||
|
||||
if socket.can_recv() {
|
||||
let mut data = [0u8; 2048];
|
||||
let _size = socket.recv_slice(&mut data).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//thread::yield_now();
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ use crate::drivers::SOCKET_ACTIVITY;
|
||||
use crate::fs::*;
|
||||
use crate::memory::MemorySet;
|
||||
use crate::sync::Condvar;
|
||||
use crate::trap::TICK_ACTIVITY;
|
||||
use alloc::boxed::Box;
|
||||
use core::future::Future;
|
||||
use core::pin::Pin;
|
||||
@ -129,9 +128,6 @@ impl Syscall<'_> {
|
||||
);
|
||||
}
|
||||
|
||||
// check whether the fds is valid and is owned by this process
|
||||
let condvars = alloc::vec![&(*TICK_ACTIVITY), &(*SOCKET_ACTIVITY)];
|
||||
|
||||
let polls = ufds.read_array(nfds).unwrap();
|
||||
|
||||
if !proc.pid.is_init() {
|
||||
@ -454,7 +450,7 @@ impl Syscall<'_> {
|
||||
drop(proc);
|
||||
}
|
||||
|
||||
let condvars = alloc::vec![&(*TICK_ACTIVITY), &(*SOCKET_ACTIVITY)];
|
||||
let condvars = alloc::vec![&(*SOCKET_ACTIVITY)];
|
||||
|
||||
let begin_time_ms = crate::trap::uptime_msec();
|
||||
let condition = move || {
|
||||
|
@ -4,7 +4,6 @@ use super::*;
|
||||
use crate::arch::cpu;
|
||||
use crate::consts::{ARCH, USER_STACK_SIZE};
|
||||
use crate::syscall::SysError::ETIMEDOUT;
|
||||
use crate::trap::TICK_ACTIVITY;
|
||||
use core::mem::size_of;
|
||||
use core::sync::atomic::{AtomicI32, Ordering};
|
||||
|
||||
|
@ -10,10 +10,6 @@ use trapframe::UserContext;
|
||||
|
||||
pub static mut TICK: usize = 0;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref TICK_ACTIVITY: Condvar = Condvar::new();
|
||||
}
|
||||
|
||||
pub fn uptime_msec() -> usize {
|
||||
unsafe { crate::trap::TICK * crate::consts::USEC_PER_TICK / 1000 }
|
||||
}
|
||||
|
2
user
2
user
@ -1 +1 @@
|
||||
Subproject commit 291df7f66ed42f642cd691554fa0c88e59cdb894
|
||||
Subproject commit 63342746297b9694676c82a716601d736ebab1a1
|
Loading…
Reference in New Issue
Block a user