-
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathmod.rs
More file actions
58 lines (46 loc) · 1.67 KB
/
Copy pathmod.rs
File metadata and controls
58 lines (46 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use smoltcp;
pub mod raw;
// pub mod icmp;
pub mod common;
pub mod datagram;
pub mod stream;
pub mod syscall;
pub use common::BoundInner;
pub use datagram::UdpSocket;
pub use raw::RawSocket;
use smoltcp::wire::IpAddress;
use smoltcp::wire::IpEndpoint;
use smoltcp::wire::Ipv4Address;
use smoltcp::wire::Ipv6Address;
pub use stream::TcpSocket;
// pub use syscall::Inet;
use crate::filesystem::epoll::event_poll::EventPoll;
use super::Socket;
/// A local endpoint, which indicates that the local endpoint is unspecified.
///
/// According to the Linux man pages and the Linux implementation, `getsockname()` will _not_ fail
/// even if the socket is unbound. Instead, it will return an unspecified socket address. This
/// unspecified endpoint helps with that.
pub const UNSPECIFIED_LOCAL_ENDPOINT_V4: IpEndpoint =
IpEndpoint::new(IpAddress::Ipv4(Ipv4Address::UNSPECIFIED), 0);
pub const UNSPECIFIED_LOCAL_ENDPOINT_V6: IpEndpoint =
IpEndpoint::new(IpAddress::Ipv6(Ipv6Address::UNSPECIFIED), 0);
pub trait InetSocket: Socket {
/// `on_iface_events`
/// 通知socket发生的事件
fn on_iface_events(&self);
fn notify(&self) {
self.on_iface_events();
// Wake threads blocked on this socket (send/recv/connect/accept).
// Without this, only epoll waiters are woken and blocking syscalls can hang.
let _woken = self.wait_queue().wake_all();
let events = self.check_io_event();
if let Err(e) = EventPoll::wakeup_epoll(self.epoll_items().as_ref(), events) {
log::warn!(
"InetSocket::notify: wakeup_epoll failed: {:?}, events={:?}",
e,
events
);
}
}
}