(index<- ) ./libnative/io/c_unix.rs
git branch: * master 5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
modified: Fri May 9 13:02:28 2014
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! C definitions used by libnative that don't belong in liblibc
12
13 pub use self::select::fd_set;
14
15 use libc;
16
17 #[cfg(target_os = "macos")]
18 #[cfg(target_os = "freebsd")]
19 pub static FIONBIO: libc::c_ulong = 0x8004667e;
20 #[cfg(target_os = "linux")]
21 #[cfg(target_os = "android")]
22 pub static FIONBIO: libc::c_ulong = 0x5421;
23 #[cfg(target_os = "macos")]
24 #[cfg(target_os = "freebsd")]
25 pub static FIOCLEX: libc::c_ulong = 0x20006601;
26 #[cfg(target_os = "linux")]
27 #[cfg(target_os = "android")]
28 pub static FIOCLEX: libc::c_ulong = 0x5451;
29
30 #[cfg(target_os = "macos")]
31 #[cfg(target_os = "freebsd")]
32 pub static MSG_DONTWAIT: libc::c_int = 0x80;
33 #[cfg(target_os = "linux")]
34 #[cfg(target_os = "android")]
35 pub static MSG_DONTWAIT: libc::c_int = 0x40;
36
37 extern {
38 pub fn gettimeofday(timeval: *mut libc::timeval,
39 tzp: *libc::c_void) -> libc::c_int;
40 pub fn select(nfds: libc::c_int,
41 readfds: *fd_set,
42 writefds: *fd_set,
43 errorfds: *fd_set,
44 timeout: *libc::timeval) -> libc::c_int;
45 pub fn getsockopt(sockfd: libc::c_int,
46 level: libc::c_int,
47 optname: libc::c_int,
48 optval: *mut libc::c_void,
49 optlen: *mut libc::socklen_t) -> libc::c_int;
50 pub fn ioctl(fd: libc::c_int, req: libc::c_ulong, ...) -> libc::c_int;
51
52 }
53
54 #[cfg(target_os = "macos")]
55 mod select {
56 pub static FD_SETSIZE: uint = 1024;
57
58 pub struct fd_set {
59 fds_bits: [i32, ..(FD_SETSIZE / 32)]
60 }
61
62 pub fn fd_set(set: &mut fd_set, fd: i32) {
63 set.fds_bits[(fd / 32) as uint] |= 1 << (fd % 32);
64 }
65 }
66
67 #[cfg(target_os = "android")]
68 #[cfg(target_os = "freebsd")]
69 #[cfg(target_os = "linux")]
70 mod select {
71 use std::uint;
72
73 pub static FD_SETSIZE: uint = 1024;
74
75 pub struct fd_set {
76 fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
77 }
78
79 pub fn fd_set(set: &mut fd_set, fd: i32) {
80 let fd = fd as uint;
81 set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
82 }
83 }
libnative/io/c_unix.rs:79:4-79:4 -fn- definition:
pub fn fd_set(set: &mut fd_set, fd: i32) {
let fd = fd as uint;
set.fds_bits[fd / uint::BITS] |= 1 << (fd % uint::BITS);
references:- 3libnative/io/util.rs:
92: let mut set: c::fd_set = unsafe { mem::init() };
93: c::fd_set(&mut set, fd);
94: match await(fd, &mut set, timeout_ms) {
libnative/io/timer_unix.rs:
155: c::fd_set(&mut set, input);
156: match unsafe {
libnative/io/util.rs:
140: let mut set: c::fd_set = unsafe { mem::init() };
141: c::fd_set(&mut set, fd);
142: let (read, write) = match status {
libnative/io/c_unix.rs:75:4-75:4 -struct- definition:
pub struct fd_set {
fds_bits: [uint, ..(FD_SETSIZE / uint::BITS)]
}
references:- 841: readfds: *fd_set,
42: writefds: *fd_set,
43: errorfds: *fd_set,
44: timeout: *libc::timeval) -> libc::c_int;
--
79: pub fn fd_set(set: &mut fd_set, fd: i32) {
80: let fd = fd as uint;
libnative/io/util.rs:
117: #[cfg(unix)]
118: fn await(fd: net::sock_t, set: &mut c::fd_set,
119: timeout: u64) -> libc::c_int {
--
139: status: SocketStatus) -> IoResult<()> {
140: let mut set: c::fd_set = unsafe { mem::init() };
141: c::fd_set(&mut set, fd);
libnative/io/timer_unix.rs:
96: fn helper(input: libc::c_int, messages: Receiver<Req>) {
97: let mut set: c::fd_set = unsafe { mem::init() };