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 #![allow(type_overflow)]
14
15 use libc;
16
17 pub static WSADESCRIPTION_LEN: uint = 256;
18 pub static WSASYS_STATUS_LEN: uint = 128;
19 pub static FIONBIO: libc::c_long = 0x8004667e;
20 static FD_SETSIZE: uint = 64;
21 pub static MSG_DONTWAIT: libc::c_int = 0;
22
23 pub struct WSADATA {
24 pub wVersion: libc::WORD,
25 pub wHighVersion: libc::WORD,
26 pub szDescription: [u8, ..WSADESCRIPTION_LEN + 1],
27 pub szSystemStatus: [u8, ..WSASYS_STATUS_LEN + 1],
28 pub iMaxSockets: u16,
29 pub iMaxUdpDg: u16,
30 pub lpVendorInfo: *u8,
31 }
32
33 pub type LPWSADATA = *mut WSADATA;
34
35 pub struct fd_set {
36 fd_count: libc::c_uint,
37 fd_array: [libc::SOCKET, ..FD_SETSIZE],
38 }
39
40 pub fn fd_set(set: &mut fd_set, s: libc::SOCKET) {
41 set.fd_array[set.fd_count as uint] = s;
42 set.fd_count += 1;
43 }
44
45 #[link(name = "ws2_32")]
46 extern "system" {
47 pub fn WSAStartup(wVersionRequested: libc::WORD,
48 lpWSAData: LPWSADATA) -> libc::c_int;
49 pub fn WSAGetLastError() -> libc::c_int;
50
51 pub fn ioctlsocket(s: libc::SOCKET, cmd: libc::c_long,
52 argp: *mut libc::c_ulong) -> libc::c_int;
53 pub fn select(nfds: libc::c_int,
54 readfds: *fd_set,
55 writefds: *fd_set,
56 exceptfds: *fd_set,
57 timeout: *libc::timeval) -> libc::c_int;
58 pub fn getsockopt(sockfd: libc::SOCKET,
59 level: libc::c_int,
60 optname: libc::c_int,
61 optval: *mut libc::c_char,
62 optlen: *mut libc::c_int) -> libc::c_int;
63
64 pub fn CancelIo(hFile: libc::HANDLE) -> libc::BOOL;
65 pub fn CancelIoEx(hFile: libc::HANDLE,
66 lpOverlapped: libc::LPOVERLAPPED) -> libc::BOOL;
67 }