mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 16:13:27 +00:00
Refactor sock option implementations
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
782cd05ade
commit
f8eca84a99
@ -1,3 +1,4 @@
|
||||
pub mod options;
|
||||
pub mod send_recv_flags;
|
||||
pub mod shutdown_cmd;
|
||||
pub mod sockaddr;
|
||||
pub mod socket_addr;
|
||||
|
53
services/libs/aster-std/src/net/socket/util/options.rs
Normal file
53
services/libs/aster-std/src/net/socket/util/options.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use core::time::Duration;
|
||||
|
||||
use crate::net::iface::{RECV_BUF_LEN, SEND_BUF_LEN};
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, CopyGetters, Setters)]
|
||||
#[get_copy = "pub"]
|
||||
#[set = "pub"]
|
||||
pub struct SocketOptionSet {
|
||||
sock_errors: Option<Error>,
|
||||
reuse_addr: bool,
|
||||
reuse_port: bool,
|
||||
send_buf: u32,
|
||||
recv_buf: u32,
|
||||
linger: LingerOption,
|
||||
}
|
||||
|
||||
impl SocketOptionSet {
|
||||
/// Return the default socket level options for tcp socket.
|
||||
pub fn new_tcp() -> Self {
|
||||
Self {
|
||||
sock_errors: None,
|
||||
reuse_addr: false,
|
||||
reuse_port: false,
|
||||
send_buf: SEND_BUF_LEN as u32,
|
||||
recv_buf: RECV_BUF_LEN as u32,
|
||||
linger: LingerOption::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const MIN_SENDBUF: u32 = 2304;
|
||||
pub const MIN_RECVBUF: u32 = 2304;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
pub struct LingerOption {
|
||||
is_on: bool,
|
||||
timeout: Duration,
|
||||
}
|
||||
|
||||
impl LingerOption {
|
||||
pub fn new(is_on: bool, timeout: Duration) -> Self {
|
||||
Self { is_on, timeout }
|
||||
}
|
||||
|
||||
pub fn is_on(&self) -> bool {
|
||||
self.is_on
|
||||
}
|
||||
|
||||
pub fn timeout(&self) -> Duration {
|
||||
self.timeout
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user