Skip to content

Commit

Permalink
Merge pull request #1081 from stlankes/socket
Browse files Browse the repository at this point in the history
improve compatibility to BSD sockets
  • Loading branch information
mkroening authored Feb 28, 2024
2 parents a62285d + 7a55f6a commit 3e8f308
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/fd/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,18 @@ impl ObjectInterface for Socket {
let ret = event & available;

if ret.is_empty() {
socket.register_recv_waker(cx.waker());
socket.register_send_waker(cx.waker());
if event.intersects(
PollEvent::POLLIN | PollEvent::POLLRDNORM | PollEvent::POLLRDBAND,
) {
socket.register_recv_waker(cx.waker());
}

if event.intersects(
PollEvent::POLLOUT | PollEvent::POLLWRNORM | PollEvent::POLLWRBAND,
) {
socket.register_send_waker(cx.waker());
}

Poll::Pending
} else {
Poll::Ready(Ok(ret))
Expand Down
14 changes: 12 additions & 2 deletions src/fd/socket/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,18 @@ impl ObjectInterface for Socket {
};

if ret.is_empty() {
socket.register_recv_waker(cx.waker());
socket.register_send_waker(cx.waker());
if event.intersects(
PollEvent::POLLIN | PollEvent::POLLRDNORM | PollEvent::POLLRDBAND,
) {
socket.register_recv_waker(cx.waker());
}

if event.intersects(
PollEvent::POLLOUT | PollEvent::POLLWRNORM | PollEvent::POLLWRBAND,
) {
socket.register_send_waker(cx.waker());
}

Poll::Pending
} else {
Poll::Ready(Ok(ret))
Expand Down
16 changes: 10 additions & 6 deletions src/syscalls/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ pub const IPV6_ADD_MEMBERSHIP: i32 = 12;
pub const IPV6_DROP_MEMBERSHIP: i32 = 13;
pub const IPV6_MULTICAST_LOOP: i32 = 19;
pub const IPV6_V6ONLY: i32 = 27;
pub const IP_TOS: i32 = 1;
pub const IP_TTL: i32 = 2;
pub const IP_MULTICAST_TTL: i32 = 5;
pub const IP_MULTICAST_LOOP: i32 = 7;
pub const IP_ADD_MEMBERSHIP: i32 = 3;
pub const IP_DROP_MEMBERSHIP: i32 = 4;
pub const SOL_SOCKET: i32 = 4095;
pub const SO_BROADCAST: i32 = 32;
pub const SO_ERROR: i32 = 4103;
pub const SO_RCVTIMEO: i32 = 4102;
pub const SO_REUSEADDR: i32 = 4;
pub const SO_SNDTIMEO: i32 = 4101;
pub const SO_LINGER: i32 = 128;
pub const SO_REUSEADDR: i32 = 0x0004;
pub const SO_KEEPALIVE: i32 = 0x0008;
pub const SO_BROADCAST: i32 = 0x0020;
pub const SO_LINGER: i32 = 0x0080;
pub const SO_SNDBUF: i32 = 0x1001;
pub const SO_RCVBUF: i32 = 0x1002;
pub const SO_SNDTIMEO: i32 = 0x1005;
pub const SO_RCVTIMEO: i32 = 0x1006;
pub const SO_ERROR: i32 = 0x1007;
pub const TCP_NODELAY: i32 = 1;
pub const MSG_PEEK: i32 = 1;
pub const EAI_NONAME: i32 = -2200;
Expand Down

0 comments on commit 3e8f308

Please sign in to comment.