mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 19:33:23 +00:00
Add syscall getsockopt
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
dcfbeb270d
commit
9d06f60ecc
@ -9,9 +9,7 @@ use crate::{
|
||||
iface::{AnyBoundSocket, AnyUnboundSocket, RawUdpSocket},
|
||||
poll_ifaces,
|
||||
socket::{
|
||||
util::{
|
||||
send_recv_flags::SendRecvFlags, sock_options::SockOptionName, sockaddr::SocketAddr,
|
||||
},
|
||||
util::{send_recv_flags::SendRecvFlags, sockaddr::SocketAddr},
|
||||
Socket,
|
||||
},
|
||||
},
|
||||
@ -216,11 +214,6 @@ impl Socket for DatagramSocket {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_sock_option(&self, optname: SockOptionName, option_val: &[u8]) -> Result<()> {
|
||||
// FIXME: deal with sock options here
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// FIXME: respect RecvFromFlags
|
||||
fn recvfrom(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<(usize, SocketAddr)> {
|
||||
debug_assert!(flags.is_all_supported());
|
||||
|
@ -162,11 +162,6 @@ impl Socket for StreamSocket {
|
||||
return_errno_with_message!(Errno::EINVAL, "getsockopt not implemented");
|
||||
}
|
||||
|
||||
fn set_sock_option(&self, optname: SockOptionName, option_val: &[u8]) -> Result<()> {
|
||||
// TODO: implement setsockopt
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn recvfrom(&self, buf: &mut [u8], flags: SendRecvFlags) -> Result<(usize, SocketAddr)> {
|
||||
let state = self.state.read();
|
||||
let (recv_size, remote_endpoint) = match &*state {
|
||||
|
@ -2,7 +2,7 @@ use crate::{fs::file_handle::FileLike, prelude::*};
|
||||
|
||||
pub use self::util::send_recv_flags::SendRecvFlags;
|
||||
pub use self::util::shutdown_cmd::SockShutdownCmd;
|
||||
pub use self::util::sock_options::SockOptionName;
|
||||
pub use self::util::sock_options::{SockOptionLevel, SockOptionName};
|
||||
pub use self::util::sockaddr::SocketAddr;
|
||||
|
||||
pub mod ip;
|
||||
@ -51,7 +51,12 @@ pub trait Socket: FileLike + Send + Sync {
|
||||
}
|
||||
|
||||
/// Set options on the socket
|
||||
fn set_sock_option(&self, optname: SockOptionName, option_val: &[u8]) -> Result<()> {
|
||||
fn set_sock_option(
|
||||
&self,
|
||||
opt_level: SockOptionLevel,
|
||||
optname: SockOptionName,
|
||||
option_val: &[u8],
|
||||
) -> Result<()> {
|
||||
return_errno_with_message!(Errno::EINVAL, "setsockopt not implemented");
|
||||
}
|
||||
|
||||
|
@ -23,4 +23,19 @@ pub enum SockOptionName {
|
||||
SO_LINGER = 13,
|
||||
SO_BSDCOMPAT = 14,
|
||||
SO_REUSEPORT = 15,
|
||||
SO_RCVTIMEO_NEW = 66,
|
||||
SO_SNDTIMEO_NEW = 67,
|
||||
}
|
||||
|
||||
#[repr(i32)]
|
||||
#[derive(Debug, Clone, Copy, TryFromInt, PartialEq, Eq)]
|
||||
#[allow(non_camel_case_types)]
|
||||
/// Sock Opt level. The definition is from https://elixir.bootlin.com/linux/v6.0.9/source/include/linux/socket.h#L343
|
||||
pub enum SockOptionLevel {
|
||||
SOL_IP = 0,
|
||||
SOL_SOCKET = 1,
|
||||
SOL_TCP = 6,
|
||||
SOL_UDP = 17,
|
||||
SOL_IPV6 = 41,
|
||||
SOL_RAW = 255,
|
||||
}
|
||||
|
Reference in New Issue
Block a user