Refactor sock option implementations

This commit is contained in:
Jianfeng Jiang
2023-12-28 09:24:23 +00:00
committed by Tate, Hongliang Tian
parent 782cd05ade
commit f8eca84a99
36 changed files with 733 additions and 728 deletions

View File

@ -1,22 +1,17 @@
use crate::fs::file_table::FileDescripter;
use crate::log_syscall_entry;
use crate::net::socket::SockShutdownCmd;
use crate::{fs::file_table::FileDescripter, log_syscall_entry, prelude::*};
use crate::prelude::*;
use crate::util::net::get_socket_from_fd;
use super::SyscallReturn;
use super::SYS_SHUTDOWN;
use super::{SyscallReturn, SYS_SHUTDOWN};
pub fn sys_shutdown(sockfd: FileDescripter, how: i32) -> Result<SyscallReturn> {
log_syscall_entry!(SYS_SHUTDOWN);
let shutdown_cmd = SockShutdownCmd::try_from(how)?;
debug!("sockfd = {sockfd}, cmd = {shutdown_cmd:?}");
let current = current!();
let file_table = current.file_table().lock();
let socket = file_table
.get_file(sockfd)?
.as_socket()
.ok_or(Error::with_message(
Errno::ENOTSOCK,
"the file is not socket",
))?;
let socket = get_socket_from_fd(sockfd)?;
socket.shutdown(shutdown_cmd)?;
Ok(SyscallReturn::Return(0))
}