Implement socket sys_close

master
Jiajie Chen 6 years ago
parent 1b104029ce
commit d9e05012f0

@ -107,8 +107,10 @@ pub fn sys_open(path: *const u8, flags: usize, mode: usize) -> SysResult {
pub fn sys_close(fd: usize) -> SysResult {
info!("close: fd: {:?}", fd);
match process().files.remove(&fd) {
Some(_) => Ok(0),
let mut proc = process();
match proc.files.remove(&fd) {
Some(FileLike::File(_)) => Ok(0),
Some(FileLike::Socket(handle)) => sys_close_socket(&mut proc, fd, handle),
None => Err(SysError::EINVAL),
}
}

@ -206,3 +206,15 @@ pub fn sys_recvfrom(
warn!("sys_recvfrom is unimplemented");
Err(SysError::EINVAL)
}
pub fn sys_close_socket(proc: &mut Process, fd: usize, handle: SocketHandle) -> SysResult {
let mut socket = proc.sockets.remove(handle);
match socket {
Socket::Tcp(ref mut tcp_socket) => {
tcp_socket.close();
}
_ => {}
}
Ok(0)
}
Loading…
Cancel
Save