Skip to content

Commit 2ee1446

Browse files
fslongjinBrahmaMantra
authored andcommitted
fix: tcp poll没有正确处理posix socket的listen状态的问题 (DragonOS-Community#859)
1 parent 3e8e2cb commit 2ee1446

File tree

5 files changed

+222
-122
lines changed

5 files changed

+222
-122
lines changed

kernel/src/net/event_poll/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ impl EventPoll {
436436
}
437437
// 判断epoll上有没有就绪事件
438438
let mut available = epoll_guard.ep_events_available();
439+
439440
drop(epoll_guard);
440441
loop {
441442
if available {
@@ -759,6 +760,7 @@ impl EventPoll {
759760
/// 与C兼容的Epoll事件结构体
760761
#[derive(Copy, Clone, Default)]
761762
#[repr(packed)]
763+
#[repr(C)]
762764
pub struct EPollEvent {
763765
/// 表示触发的事件
764766
events: u32,
@@ -870,5 +872,8 @@ bitflags! {
870872

871873
/// 表示epoll已经被释放,但是在目前的设计中未用到
872874
const POLLFREE = 0x4000;
875+
876+
/// listen状态的socket可以接受连接
877+
const EPOLL_LISTEN_CAN_ACCEPT = Self::EPOLLIN.bits | Self::EPOLLRDNORM.bits;
873878
}
874879
}

kernel/src/net/net_core.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,25 @@ fn send_event(sockets: &smoltcp::iface::SocketSet) -> Result<(), SystemError> {
191191
for (handle, socket_type) in sockets.iter() {
192192
let handle_guard = HANDLE_MAP.read_irqsave();
193193
let global_handle = GlobalSocketHandle::new_smoltcp_handle(handle);
194-
let item = handle_guard.get(&global_handle);
194+
let item: Option<&super::socket::SocketHandleItem> = handle_guard.get(&global_handle);
195195
if item.is_none() {
196196
continue;
197197
}
198198

199199
let handle_item = item.unwrap();
200+
let posix_item = handle_item.posix_item();
201+
if posix_item.is_none() {
202+
continue;
203+
}
204+
let posix_item = posix_item.unwrap();
200205

201206
// 获取socket上的事件
202-
let mut events =
203-
SocketPollMethod::poll(socket_type, handle_item.shutdown_type()).bits() as u64;
207+
let mut events = SocketPollMethod::poll(socket_type, handle_item).bits() as u64;
204208

205209
// 分发到相应类型socket处理
206210
match socket_type {
207211
smoltcp::socket::Socket::Raw(_) | smoltcp::socket::Socket::Udp(_) => {
208-
handle_guard
209-
.get(&global_handle)
210-
.unwrap()
211-
.wait_queue
212-
.wakeup_any(events);
212+
posix_item.wakeup_any(events);
213213
}
214214
smoltcp::socket::Socket::Icmp(_) => unimplemented!("Icmp socket hasn't unimplemented"),
215215
smoltcp::socket::Socket::Tcp(inner_socket) => {
@@ -222,17 +222,14 @@ fn send_event(sockets: &smoltcp::iface::SocketSet) -> Result<(), SystemError> {
222222
if inner_socket.state() == smoltcp::socket::tcp::State::CloseWait {
223223
events |= EPollEventType::EPOLLHUP.bits() as u64;
224224
}
225-
handle_guard
226-
.get(&global_handle)
227-
.unwrap()
228-
.wait_queue
229-
.wakeup_any(events);
225+
226+
posix_item.wakeup_any(events);
230227
}
231228
smoltcp::socket::Socket::Dhcpv4(_) => {}
232229
smoltcp::socket::Socket::Dns(_) => unimplemented!("Dns socket hasn't unimplemented"),
233230
}
234231
EventPoll::wakeup_epoll(
235-
&handle_item.epitems,
232+
&posix_item.epitems,
236233
EPollEventType::from_bits_truncate(events as u32),
237234
)?;
238235
drop(handle_guard);

0 commit comments

Comments
 (0)