mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 07:06:47 +00:00
feat(socket): 添加shutdown方法并实现ShutdownTemp的TryFrom转换
This commit is contained in:
parent
57e0b2e96a
commit
bbea79ec19
@ -1,4 +1,6 @@
|
|||||||
use core::sync::atomic::AtomicU8;
|
use core::{default, sync::atomic::AtomicU8};
|
||||||
|
|
||||||
|
use system_error::SystemError;
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
/// @brief 用于指定socket的关闭类型
|
/// @brief 用于指定socket的关闭类型
|
||||||
@ -101,8 +103,8 @@ impl ShutdownTemp {
|
|||||||
self.bit == 0
|
self.bit == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_how(how: usize) -> Self {
|
pub fn bits(&self) -> ShutdownBit {
|
||||||
Self { bit: how as u8 + 1 }
|
ShutdownBit { bits: self.bit }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,3 +118,16 @@ impl From<ShutdownBit> for ShutdownTemp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<usize> for ShutdownTemp {
|
||||||
|
type Error = SystemError;
|
||||||
|
|
||||||
|
fn try_from(value: usize) -> Result<Self, Self::Error> {
|
||||||
|
match value {
|
||||||
|
0 | 1 | 2 => Ok(ShutdownTemp {
|
||||||
|
bit: value as u8 + 1,
|
||||||
|
}),
|
||||||
|
_ => Err(SystemError::EINVAL),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -338,6 +338,28 @@ impl Socket for TcpSocket {
|
|||||||
.recv_buffer_size()
|
.recv_buffer_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn shutdown(&self, how: ShutdownTemp) -> Result<(), SystemError> {
|
||||||
|
let self_shutdown = self.shutdown.get().bits();
|
||||||
|
let diff = how.bits().difference(self_shutdown);
|
||||||
|
match diff.is_empty(){
|
||||||
|
true => {
|
||||||
|
return Ok(())
|
||||||
|
},
|
||||||
|
false => {
|
||||||
|
if diff.contains(ShutdownBit::SHUT_RD){
|
||||||
|
self.shutdown.recv_shutdown();
|
||||||
|
// TODO 协议栈处理
|
||||||
|
}
|
||||||
|
if diff.contains(ShutdownBit::SHUT_WR){
|
||||||
|
self.shutdown.send_shutdown();
|
||||||
|
// TODO 协议栈处理
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn close(&self) -> Result<(), SystemError> {
|
fn close(&self) -> Result<(), SystemError> {
|
||||||
let inner = self.inner
|
let inner = self.inner
|
||||||
.write()
|
.write()
|
||||||
|
@ -367,7 +367,7 @@ impl Syscall {
|
|||||||
let socket: Arc<socket::Inode> = ProcessManager::current_pcb()
|
let socket: Arc<socket::Inode> = ProcessManager::current_pcb()
|
||||||
.get_socket(fd as i32)
|
.get_socket(fd as i32)
|
||||||
.ok_or(SystemError::EBADF)?;
|
.ok_or(SystemError::EBADF)?;
|
||||||
socket.shutdown(socket::ShutdownTemp::from_how(how))?;
|
socket.shutdown(how.try_into()?)?;
|
||||||
return Ok(0);
|
return Ok(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user