diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 1b996e1..7473e17 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -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), } } diff --git a/kernel/src/syscall/net.rs b/kernel/src/syscall/net.rs index a0428bc..2ff7371 100644 --- a/kernel/src/syscall/net.rs +++ b/kernel/src/syscall/net.rs @@ -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) +} \ No newline at end of file