Skip to content

Commit 9d2493e

Browse files
committed
Add poll API
Signed-off-by: David Henningsson <diwic@ubuntu.com>
1 parent fb83189 commit 9d2493e

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

libc-test/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ fn main() {
8888
cfg.header("sys/uio.h");
8989
cfg.header("sched.h");
9090
cfg.header("termios.h");
91+
cfg.header("poll.h");
9192
}
9293

9394
if android {

src/unix/bsd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub type blkcnt_t = i64;
66
pub type socklen_t = u32;
77
pub type sa_family_t = u8;
88
pub type pthread_t = ::uintptr_t;
9+
pub type nfds_t = ::c_uint;
910

1011
s! {
1112
pub struct sockaddr {

src/unix/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ s! {
9191
pub iov_base: *mut ::c_void,
9292
pub iov_len: ::size_t,
9393
}
94+
95+
pub struct pollfd {
96+
pub fd: ::c_int,
97+
pub events: ::c_short,
98+
pub revents: ::c_short,
99+
}
94100
}
95101

96102
pub const WNOHANG: ::c_int = 1;
@@ -117,6 +123,13 @@ pub const S_ISUID: ::c_int = 0x800;
117123
pub const S_ISGID: ::c_int = 0x400;
118124
pub const S_ISVTX: ::c_int = 0x200;
119125

126+
pub const POLLIN: ::c_short = 0x1;
127+
pub const POLLPRI: ::c_short = 0x2;
128+
pub const POLLOUT: ::c_short = 0x4;
129+
pub const POLLERR: ::c_short = 0x8;
130+
pub const POLLHUP: ::c_short = 0x10;
131+
pub const POLLNVAL: ::c_short = 0x20;
132+
120133
cfg_if! {
121134
if #[cfg(feature = "default")] {
122135
// cargo build, don't pull in anything extra as the libstd dep
@@ -548,6 +561,9 @@ extern {
548561
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
549562
link_name = "recvmsg$UNIX2003")]
550563
pub fn recvmsg(fd: ::c_int, msg: *mut msghdr, flags: ::c_int) -> ::ssize_t;
564+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
565+
link_name = "poll$UNIX2003")]
566+
pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: ::c_int) -> ::c_int;
551567
}
552568

553569
// TODO: get rid of this #[cfg(not(...))]

src/unix/notbsd/android/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub type sigset_t = c_ulong;
2222
pub type time64_t = i64;
2323
pub type fsfilcnt_t = ::c_ulong;
2424
pub type fsblkcnt_t = ::c_ulong;
25+
pub type nfds_t = ::c_uint;
2526

2627
s! {
2728
pub struct stat {

src/unix/notbsd/linux/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub type fsfilcnt_t = ::c_ulong;
1414
pub type key_t = ::c_int;
1515
pub type shmatt_t = ::c_ulong;
1616
pub type mqd_t = ::c_int;
17+
pub type nfds_t = ::c_ulong;
1718

1819
pub enum fpos64_t {} // TODO: fill this out with a struct
1920

0 commit comments

Comments
 (0)