|
|
@ -261,29 +261,51 @@ pub fn sys_write_socket(proc: &mut Process, fd: usize, base: *const u8, len: usi
|
|
|
|
pub fn sys_read_socket(proc: &mut Process, fd: usize, base: *mut u8, len: usize) -> SysResult {
|
|
|
|
pub fn sys_read_socket(proc: &mut Process, fd: usize, base: *mut u8, len: usize) -> SysResult {
|
|
|
|
let iface = &mut *(NET_DRIVERS.lock()[0]);
|
|
|
|
let iface = &mut *(NET_DRIVERS.lock()[0]);
|
|
|
|
let wrapper = proc.get_socket(fd)?;
|
|
|
|
let wrapper = proc.get_socket(fd)?;
|
|
|
|
if let SocketType::Udp = wrapper.socket_type {
|
|
|
|
if let SocketType::Tcp = wrapper.socket_type {
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let mut sockets = iface.sockets();
|
|
|
|
let mut sockets = iface.sockets();
|
|
|
|
let mut socket = sockets.get::<UdpSocket>(wrapper.handle);
|
|
|
|
let mut socket = sockets.get::<TcpSocket>(wrapper.handle);
|
|
|
|
|
|
|
|
|
|
|
|
let mut slice = unsafe { slice::from_raw_parts_mut(base, len) };
|
|
|
|
|
|
|
|
if socket.is_open() {
|
|
|
|
if socket.is_open() {
|
|
|
|
if socket.can_recv() {
|
|
|
|
let mut slice = unsafe { slice::from_raw_parts_mut(base, len) };
|
|
|
|
match socket.recv_slice(&mut slice) {
|
|
|
|
if let Ok(size) = socket.recv_slice(&mut slice) {
|
|
|
|
Ok((size, _)) => {
|
|
|
|
|
|
|
|
// avoid deadlock
|
|
|
|
// avoid deadlock
|
|
|
|
drop(socket);
|
|
|
|
drop(socket);
|
|
|
|
drop(sockets);
|
|
|
|
drop(sockets);
|
|
|
|
|
|
|
|
|
|
|
|
iface.poll();
|
|
|
|
iface.poll();
|
|
|
|
Ok(size as isize)
|
|
|
|
return Ok(size as isize);
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(err) => Err(SysError::ENOBUFS),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Err(SysError::ENOBUFS)
|
|
|
|
return Err(SysError::ENOTCONN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// avoid deadlock
|
|
|
|
|
|
|
|
drop(socket);
|
|
|
|
|
|
|
|
SOCKET_ACTIVITY._wait()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if let SocketType::Udp = wrapper.socket_type {
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
|
|
|
let mut sockets = iface.sockets();
|
|
|
|
|
|
|
|
let mut socket = sockets.get::<UdpSocket>(wrapper.handle);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if socket.is_open() {
|
|
|
|
|
|
|
|
let mut slice = unsafe { slice::from_raw_parts_mut(base, len) };
|
|
|
|
|
|
|
|
if let Ok((size, _)) = socket.recv_slice(&mut slice) {
|
|
|
|
|
|
|
|
// avoid deadlock
|
|
|
|
|
|
|
|
drop(socket);
|
|
|
|
|
|
|
|
drop(sockets);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
iface.poll();
|
|
|
|
|
|
|
|
return Ok(size as isize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Err(SysError::ENOTCONN)
|
|
|
|
return Err(SysError::ENOTCONN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// avoid deadlock
|
|
|
|
|
|
|
|
drop(socket);
|
|
|
|
|
|
|
|
SOCKET_ACTIVITY._wait()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
unimplemented!("socket type")
|
|
|
|
unimplemented!("socket type")
|
|
|
|