-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
socket统一改用
GlobalSocketHandle
,并且修复fcntl SETFD的错误 (#730)
* socket统一改用`GlobalSocketHandle`,并且修复fcntl SETFD的错误 --------- Co-authored-by: longjin <[email protected]>
- Loading branch information
Showing
8 changed files
with
253 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use ida::IdAllocator; | ||
use smoltcp::iface::SocketHandle; | ||
|
||
int_like!(KernelHandle, usize); | ||
|
||
/// # socket的句柄管理组件 | ||
/// 它在smoltcp的SocketHandle上封装了一层,增加更多的功能。 | ||
/// 比如,在socket被关闭时,自动释放socket的资源,通知系统的其他组件。 | ||
#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)] | ||
pub enum GlobalSocketHandle { | ||
Smoltcp(SocketHandle), | ||
Kernel(KernelHandle), | ||
} | ||
|
||
static KERNEL_HANDLE_IDA: IdAllocator = IdAllocator::new(0, usize::MAX); | ||
|
||
impl GlobalSocketHandle { | ||
pub fn new_smoltcp_handle(handle: SocketHandle) -> Self { | ||
return Self::Smoltcp(handle); | ||
} | ||
|
||
pub fn new_kernel_handle() -> Self { | ||
return Self::Kernel(KernelHandle::new(KERNEL_HANDLE_IDA.alloc().unwrap())); | ||
} | ||
|
||
pub fn smoltcp_handle(&self) -> Option<SocketHandle> { | ||
if let Self::Smoltcp(sh) = *self { | ||
return Some(sh); | ||
} | ||
None | ||
} | ||
|
||
pub fn kernel_handle(&self) -> Option<KernelHandle> { | ||
if let Self::Kernel(kh) = *self { | ||
return Some(kh); | ||
} | ||
None | ||
} | ||
} |
Oops, something went wrong.