Skip to content

Commit 860b6e6

Browse files
committed
Set EPOLLER flags when necessary
1 parent d05a38f commit 860b6e6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/shims/unix/unnamed_socket.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ impl FileDescription for AnonSocket {
9595
// for read and write.
9696
epoll_ready_events.epollin = true;
9797
epoll_ready_events.epollout = true;
98+
// If there is data lost in peer_fd, set EPOLLERR.
99+
if self.peer_lost_data.get() {
100+
epoll_ready_events.epollerr = true;
101+
}
98102
}
99103
Ok(epoll_ready_events)
100104
}
@@ -105,6 +109,13 @@ impl FileDescription for AnonSocket {
105109
ecx: &mut MiriInterpCx<'tcx>,
106110
) -> InterpResult<'tcx, io::Result<()>> {
107111
if let Some(peer_fd) = self.peer_fd().upgrade() {
112+
// If the current readbuf is non-empty when the file description is closed,
113+
// notify the peer that data lost has happened in current file description.
114+
if let Some(readbuf) = &self.readbuf {
115+
if !readbuf.borrow().buf.is_empty() {
116+
peer_fd.downcast::<AnonSocket>().unwrap().peer_lost_data.set(true);
117+
}
118+
}
108119
// Notify peer fd that close has happened, since that can unblock reads and writes.
109120
ecx.check_and_update_readiness(&peer_fd)?;
110121
}

0 commit comments

Comments
 (0)