|
|
@ -82,6 +82,18 @@ struct SockaddrIn {
|
|
|
|
sin_zero: [u8; 8],
|
|
|
|
sin_zero: [u8; 8],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_handle(proc: &mut MutexGuard<'static, Process>, fd: usize) -> Result<SocketHandle, SysError> {
|
|
|
|
|
|
|
|
if let Some(file) = proc.files.get(&fd) {
|
|
|
|
|
|
|
|
if let FileLike::Socket(handle) = file {
|
|
|
|
|
|
|
|
return Ok((*handle).clone());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(SysError::ENOTSOCK)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(SysError::EBADF)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sys_connect(fd: usize, addr: *const u8, addrlen: usize) -> SysResult {
|
|
|
|
pub fn sys_connect(fd: usize, addr: *const u8, addrlen: usize) -> SysResult {
|
|
|
|
info!(
|
|
|
|
info!(
|
|
|
|
"sys_connect: fd: {}, addr: {:?}, addrlen: {}",
|
|
|
|
"sys_connect: fd: {}, addr: {:?}, addrlen: {}",
|
|
|
@ -110,9 +122,8 @@ pub fn sys_connect(fd: usize, addr: *const u8, addrlen: usize) -> SysResult {
|
|
|
|
let iface = &mut *NET_DRIVERS.lock()[0];
|
|
|
|
let iface = &mut *NET_DRIVERS.lock()[0];
|
|
|
|
iface.poll(&mut proc.sockets);
|
|
|
|
iface.poll(&mut proc.sockets);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(FileLike::Socket(handle)) = proc.files.get(&fd) {
|
|
|
|
|
|
|
|
// TODO: check its type
|
|
|
|
// TODO: check its type
|
|
|
|
let tcp_handle = (*handle).clone();
|
|
|
|
let tcp_handle = get_handle(&mut proc, fd)?;
|
|
|
|
let mut socket = proc.sockets.get::<TcpSocket>(tcp_handle);
|
|
|
|
let mut socket = proc.sockets.get::<TcpSocket>(tcp_handle);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO selects non-conflict high port
|
|
|
|
// TODO selects non-conflict high port
|
|
|
@ -130,9 +141,6 @@ pub fn sys_connect(fd: usize, addr: *const u8, addrlen: usize) -> SysResult {
|
|
|
|
Ok(()) => Ok(0),
|
|
|
|
Ok(()) => Ok(0),
|
|
|
|
Err(_) => Err(SysError::EISCONN),
|
|
|
|
Err(_) => Err(SysError::EISCONN),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(SysError::ENOTSOCK)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sys_write_socket(
|
|
|
|
pub fn sys_write_socket(
|
|
|
@ -145,9 +153,8 @@ pub fn sys_write_socket(
|
|
|
|
let iface = &mut *NET_DRIVERS.lock()[0];
|
|
|
|
let iface = &mut *NET_DRIVERS.lock()[0];
|
|
|
|
iface.poll(&mut proc.sockets);
|
|
|
|
iface.poll(&mut proc.sockets);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(FileLike::Socket(handle)) = proc.files.get(&fd) {
|
|
|
|
|
|
|
|
// TODO: check its type
|
|
|
|
// TODO: check its type
|
|
|
|
let tcp_handle = (*handle).clone();
|
|
|
|
let tcp_handle = get_handle(proc, fd)?;
|
|
|
|
let mut socket = proc.sockets.get::<TcpSocket>(tcp_handle);
|
|
|
|
let mut socket = proc.sockets.get::<TcpSocket>(tcp_handle);
|
|
|
|
let slice = unsafe { slice::from_raw_parts(base, len) };
|
|
|
|
let slice = unsafe { slice::from_raw_parts(base, len) };
|
|
|
|
if socket.is_open() {
|
|
|
|
if socket.is_open() {
|
|
|
@ -162,9 +169,6 @@ pub fn sys_write_socket(
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Err(SysError::ECONNREFUSED)
|
|
|
|
Err(SysError::ECONNREFUSED)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(SysError::ENOTSOCK)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sys_select(
|
|
|
|
pub fn sys_select(
|
|
|
|