mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-18 12:06:43 +00:00
Refactor sock option implementations
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
782cd05ade
commit
f8eca84a99
@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user