Enlarge tcp send/recv buf, implement getsockopt for send/recv buf and add spin_and_wait

master
Jiajie Chen 6 years ago
parent 40ac510ecd
commit 33ce72703b

@ -8,6 +8,7 @@ use rcore_memory::VMError;
use rcore_fs::vfs::{FileType, FsError, INode, Metadata};
use crate::arch::interrupt::TrapFrame;
use crate::sync::Condvar;
use crate::process::*;
use crate::thread;
use crate::util;
@ -336,3 +337,21 @@ impl From<VMError> for SysError {
SysError::EFAULT
}
}
const SPIN_WAIT_TIMES: usize = 100;
pub fn spin_and_wait(condvars: &[&Condvar], mut action: impl FnMut() -> Option<SysResult>) -> SysResult {
for i in 0..SPIN_WAIT_TIMES {
if let Some(result) = action() {
return result;
}
}
loop {
if let Some(result) = action() {
return result;
}
Condvar::wait_any(&condvars);
}
}

@ -20,6 +20,9 @@ const IPPROTO_IP: usize = 0;
const IPPROTO_ICMP: usize = 1;
const IPPROTO_TCP: usize = 6;
const TCP_SENDBUF: usize = 128 * 1024; // 128K
const TCP_RECVBUF: usize = 128 * 1024;
fn get_ephemeral_port() -> u16 {
// TODO selects non-conflict high port
static mut EPHEMERAL_PORT: u16 = 49152;
@ -45,8 +48,8 @@ pub fn sys_socket(domain: usize, socket_type: usize, protocol: usize) -> SysResu
SOCK_STREAM => {
let fd = proc.get_free_fd();
let tcp_rx_buffer = TcpSocketBuffer::new(vec![0; 2048]);
let tcp_tx_buffer = TcpSocketBuffer::new(vec![0; 2048]);
let tcp_rx_buffer = TcpSocketBuffer::new(vec![0; TCP_RECVBUF]);
let tcp_tx_buffer = TcpSocketBuffer::new(vec![0; TCP_SENDBUF]);
let tcp_socket = TcpSocket::new(tcp_rx_buffer, tcp_tx_buffer);
let tcp_handle = iface.sockets().add(tcp_socket);
@ -151,10 +154,18 @@ pub fn sys_getsockopt(
match level {
SOL_SOCKET => {
match optname {
SO_SNDBUF | SO_RCVBUF => {
SO_SNDBUF => {
proc.memory_set.check_mut_array(optval, 4)?;
unsafe {
*(optval as *mut u32) = TCP_SENDBUF as u32;
*optlen = 4;
}
Ok(0)
}
SO_RCVBUF => {
proc.memory_set.check_mut_array(optval, 4)?;
unsafe {
*(optval as *mut u32) = 1024;
*(optval as *mut u32) = TCP_RECVBUF as u32;
*optlen = 4;
}
Ok(0)

Loading…
Cancel
Save