about summary refs log tree commit diff
path: root/src/libstd/libc.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-12-27 17:50:16 -0800
committerAlex Crichton <alex@alexcrichton.com>2013-12-27 23:09:31 -0800
commit2a4f9d69afd19603ed3354fa8e64ab0e67c6a915 (patch)
tree411a20151bace8706b50d0e19aa682cfee652ee3 /src/libstd/libc.rs
parent1763f36c9d47550838793e129f2297ecfc8bebd1 (diff)
Implement native TCP I/O
Diffstat (limited to 'src/libstd/libc.rs')
-rw-r--r--src/libstd/libc.rs308
1 files changed, 308 insertions, 0 deletions
diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs
index 556009c2838..2696e27c373 100644
--- a/src/libstd/libc.rs
+++ b/src/libstd/libc.rs
@@ -76,6 +76,7 @@ pub use libc::types::common::posix01::*;
 pub use libc::types::common::posix08::*;
 pub use libc::types::common::bsd44::*;
 pub use libc::types::os::common::posix01::*;
+pub use libc::types::os::common::bsd44::*;
 pub use libc::types::os::arch::c95::*;
 pub use libc::types::os::arch::c99::*;
 pub use libc::types::os::arch::posix88::*;
@@ -111,6 +112,7 @@ pub use libc::funcs::posix01::glob::*;
 pub use libc::funcs::posix01::mman::*;
 pub use libc::funcs::posix08::unistd::*;
 
+pub use libc::funcs::bsd43::*;
 pub use libc::funcs::bsd44::*;
 pub use libc::funcs::extra::*;
 
@@ -240,6 +242,40 @@ pub mod types {
                     __unused5: *c_void,
                 }
             }
+            pub mod bsd44 {
+                pub type socklen_t = u32;
+                pub type sa_family_t = u16;
+                pub type in_port_t = u16;
+                pub type in_addr_t = u32;
+                pub struct sockaddr {
+                    sa_family: sa_family_t,
+                    sa_data: [u8, ..14],
+                }
+                pub struct sockaddr_storage {
+                    ss_family: sa_family_t,
+                    __ss_align: i64,
+                    __ss_pad2: [u8, ..112],
+                }
+                pub struct sockaddr_in {
+                    sin_family: sa_family_t,
+                    sin_port: in_port_t,
+                    sin_addr: in_addr,
+                    sin_zero: [u8, ..8],
+                }
+                pub struct in_addr {
+                    s_addr: in_addr_t,
+                }
+                pub struct sockaddr_in6 {
+                    sin6_family: sa_family_t,
+                    sin6_port: in_port_t,
+                    sin6_flowinfo: u32,
+                    sin6_addr: in6_addr,
+                    sin6_scope_id: u32,
+                }
+                pub struct in6_addr {
+                    s6_addr: [u16, ..8]
+                }
+            }
         }
 
         #[cfg(target_arch = "x86")]
@@ -538,6 +574,45 @@ pub mod types {
                     __unused8: *c_void,
                 }
             }
+            pub mod bsd44 {
+                pub type socklen_t = u32;
+                pub type sa_family_t = u8;
+                pub type in_port_t = u16;
+                pub type in_addr_t = u32;
+                pub struct sockaddr {
+                    sa_len: u8,
+                    sa_family: sa_family_t,
+                    sa_data: [u8, ..14],
+                }
+                pub struct sockaddr_storage {
+                    ss_len: u8,
+                    ss_family: sa_family_t,
+                    __ss_pad1: [u8, ..6],
+                    __ss_align: i64,
+                    __ss_pad2: [u8, ..112],
+                }
+                pub struct sockaddr_in {
+                    sin_len: u8,
+                    sin_family: sa_family_t,
+                    sin_port: in_port_t,
+                    sin_addr: in_addr,
+                    sin_zero: [u8, ..8],
+                }
+                pub struct in_addr {
+                    s_addr: in_addr_t,
+                }
+                pub struct sockaddr_in6 {
+                    sin6_len: u8,
+                    sin6_family: sa_family_t,
+                    sin6_port: in_port_t,
+                    sin6_flowinfo: u32,
+                    sin6_addr: in6_addr,
+                    sin6_scope_id: u32,
+                }
+                pub struct in6_addr {
+                    s6_addr: [u16, ..8]
+                }
+            }
         }
 
         #[cfg(target_arch = "x86_64")]
@@ -661,6 +736,44 @@ pub mod types {
                     modtime: time64_t,
                 }
             }
+
+            pub mod bsd44 {
+                use libc::types::os::arch::c95::{c_int, c_uint};
+
+                pub type SOCKET = c_uint;
+                pub type socklen_t = c_int;
+                pub type sa_family_t = u16;
+                pub type in_port_t = u16;
+                pub type in_addr_t = u32;
+                pub struct sockaddr {
+                    sa_family: sa_family_t,
+                    sa_data: [u8, ..14],
+                }
+                pub struct sockaddr_storage {
+                    ss_family: sa_family_t,
+                    __ss_align: i64,
+                    __ss_pad2: [u8, ..112],
+                }
+                pub struct sockaddr_in {
+                    sin_family: sa_family_t,
+                    sin_port: in_port_t,
+                    sin_addr: in_addr,
+                    sin_zero: [u8, ..8],
+                }
+                pub struct in_addr {
+                    s_addr: in_addr_t,
+                }
+                pub struct sockaddr_in6 {
+                    sin6_family: sa_family_t,
+                    sin6_port: in_port_t,
+                    sin6_flowinfo: u32,
+                    sin6_addr: in6_addr,
+                    sin6_scope_id: u32,
+                }
+                pub struct in6_addr {
+                    s6_addr: [u16, ..8]
+                }
+            }
         }
 
         pub mod arch {
@@ -900,6 +1013,48 @@ pub mod types {
                     __unused8: *c_void,
                 }
             }
+
+            pub mod bsd44 {
+                use libc::types::os::arch::c95::c_int;
+
+                pub type socklen_t = c_int;
+                pub type sa_family_t = u8;
+                pub type in_port_t = u16;
+                pub type in_addr_t = u32;
+                pub struct sockaddr {
+                    sa_len: u8,
+                    sa_family: sa_family_t,
+                    sa_data: [u8, ..14],
+                }
+                pub struct sockaddr_storage {
+                    ss_len: u8,
+                    ss_family: sa_family_t,
+                    __ss_pad1: [u8, ..6],
+                    __ss_align: i64,
+                    __ss_pad2: [u8, ..112],
+                }
+                pub struct sockaddr_in {
+                    sin_len: u8,
+                    sin_family: sa_family_t,
+                    sin_port: in_port_t,
+                    sin_addr: in_addr,
+                    sin_zero: [u8, ..8],
+                }
+                pub struct in_addr {
+                    s_addr: in_addr_t,
+                }
+                pub struct sockaddr_in6 {
+                    sin6_len: u8,
+                    sin6_family: sa_family_t,
+                    sin6_port: in_port_t,
+                    sin6_flowinfo: u32,
+                    sin6_addr: in6_addr,
+                    sin6_scope_id: u32,
+                }
+                pub struct in6_addr {
+                    s6_addr: [u16, ..8]
+                }
+            }
         }
 
         #[cfg(target_arch = "x86")]
@@ -1109,6 +1264,59 @@ pub mod consts {
             pub static FILENAME_MAX : c_uint = 260_u32;
             pub static L_tmpnam : c_uint = 16_u32;
             pub static TMP_MAX : c_uint = 32767_u32;
+
+            pub static WSAEINTR: c_int = 10004;
+            pub static WSAEBADF: c_int = 10009;
+            pub static WSAEACCES: c_int = 10013;
+            pub static WSAEFAULT: c_int = 10014;
+            pub static WSAEINVAL: c_int = 10022;
+            pub static WSAEMFILE: c_int = 10024;
+            pub static WSAEWOULDBLOCK: c_int = 10035;
+            pub static WSAEINPROGRESS: c_int = 10036;
+            pub static WSAEALREADY: c_int = 10037;
+            pub static WSAENOTSOCK: c_int = 10038;
+            pub static WSAEDESTADDRREQ: c_int = 10039;
+            pub static WSAEMSGSIZE: c_int = 10040;
+            pub static WSAEPROTOTYPE: c_int = 10041;
+            pub static WSAENOPROTOOPT: c_int = 10042;
+            pub static WSAEPROTONOSUPPORT: c_int = 10043;
+            pub static WSAESOCKTNOSUPPORT: c_int = 10044;
+            pub static WSAEOPNOTSUPP: c_int = 10045;
+            pub static WSAEPFNOSUPPORT: c_int = 10046;
+            pub static WSAEAFNOSUPPORT: c_int = 10047;
+            pub static WSAEADDRINUSE: c_int = 10048;
+            pub static WSAEADDRNOTAVAIL: c_int = 10049;
+            pub static WSAENETDOWN: c_int = 10050;
+            pub static WSAENETUNREACH: c_int = 10051;
+            pub static WSAENETRESET: c_int = 10052;
+            pub static WSAECONNABORTED: c_int = 10053;
+            pub static WSAECONNRESET: c_int = 10054;
+            pub static WSAENOBUFS: c_int = 10055;
+            pub static WSAEISCONN: c_int = 10056;
+            pub static WSAENOTCONN: c_int = 10057;
+            pub static WSAESHUTDOWN: c_int = 10058;
+            pub static WSAETOOMANYREFS: c_int = 10059;
+            pub static WSAETIMEDOUT: c_int = 10060;
+            pub static WSAECONNREFUSED: c_int = 10061;
+            pub static WSAELOOP: c_int = 10062;
+            pub static WSAENAMETOOLONG: c_int = 10063;
+            pub static WSAEHOSTDOWN: c_int = 10064;
+            pub static WSAEHOSTUNREACH: c_int = 10065;
+            pub static WSAENOTEMPTY: c_int = 10066;
+            pub static WSAEPROCLIM: c_int = 10067;
+            pub static WSAEUSERS: c_int = 10068;
+            pub static WSAEDQUOT: c_int = 10069;
+            pub static WSAESTALE: c_int = 10070;
+            pub static WSAEREMOTE: c_int = 10071;
+            pub static WSASYSNOTREADY: c_int = 10091;
+            pub static WSAVERNOTSUPPORTED: c_int = 10092;
+            pub static WSANOTINITIALISED: c_int = 10093;
+            pub static WSAEDISCON: c_int = 10101;
+            pub static WSAENOMORE: c_int = 10102;
+            pub static WSAECANCELLED: c_int = 10103;
+            pub static WSAEINVALIDPROCTABLE: c_int = 10104;
+            pub static WSAEINVALIDPROVIDER: c_int = 10105;
+            pub static WSAEPROVIDERFAILEDINIT: c_int = 10106;
         }
         pub mod c99 {
         }
@@ -1149,6 +1357,17 @@ pub mod consts {
         pub mod posix08 {
         }
         pub mod bsd44 {
+            use libc::types::os::arch::c95::c_int;
+
+            pub static AF_INET: c_int = 2;
+            pub static AF_INET6: c_int = 23;
+            pub static SOCK_STREAM: c_int = 1;
+            pub static SOCK_DGRAM: c_int = 2;
+            pub static IPPROTO_TCP: c_int = 6;
+
+            pub static TCP_NODELAY: c_int = 0x0001;
+            pub static SOL_SOCKET: c_int = 0xffff;
+            pub static SO_KEEPALIVE: c_int = 8;
         }
         pub mod extra {
             use libc::types::os::arch::c95::c_int;
@@ -1845,6 +2064,16 @@ pub mod consts {
             pub static MADV_MERGEABLE : c_int = 12;
             pub static MADV_UNMERGEABLE : c_int = 13;
             pub static MADV_HWPOISON : c_int = 100;
+
+            pub static AF_INET: c_int = 2;
+            pub static AF_INET6: c_int = 10;
+            pub static SOCK_STREAM: c_int = 1;
+            pub static SOCK_DGRAM: c_int = 2;
+            pub static IPPROTO_TCP: c_int = 6;
+
+            pub static TCP_NODELAY: c_int = 1;
+            pub static SOL_SOCKET: c_int = 1;
+            pub static SO_KEEPALIVE: c_int = 9;
         }
         #[cfg(target_arch = "x86")]
         #[cfg(target_arch = "x86_64")]
@@ -2262,6 +2491,17 @@ pub mod consts {
             pub static MINCORE_REFERENCED_OTHER : c_int = 0x8;
             pub static MINCORE_MODIFIED_OTHER : c_int = 0x10;
             pub static MINCORE_SUPER : c_int = 0x20;
+
+            pub static AF_INET: c_int = 2;
+            pub static AF_INET6: c_int = 28;
+            pub static SOCK_STREAM: c_int = 1;
+            pub static SOCK_DGRAM: c_int = 2;
+            pub static IPPROTO_TCP: c_int = 6;
+
+            pub static TCP_NODELAY: c_int = 1;
+            pub static TCP_KEEPIDLE: c_int = 256;
+            pub static SOL_SOCKET: c_int = 0xffff;
+            pub static SO_KEEPALIVE: c_int = 0x0008;
         }
         pub mod extra {
             use libc::types::os::arch::c95::c_int;
@@ -2616,6 +2856,17 @@ pub mod consts {
             pub static MINCORE_MODIFIED : c_int = 0x4;
             pub static MINCORE_REFERENCED_OTHER : c_int = 0x8;
             pub static MINCORE_MODIFIED_OTHER : c_int = 0x10;
+
+            pub static AF_INET: c_int = 2;
+            pub static AF_INET6: c_int = 30;
+            pub static SOCK_STREAM: c_int = 1;
+            pub static SOCK_DGRAM: c_int = 2;
+            pub static IPPROTO_TCP: c_int = 6;
+
+            pub static TCP_NODELAY: c_int = 0x01;
+            pub static TCP_KEEPALIVE: c_int = 0x10;
+            pub static SOL_SOCKET: c_int = 0xffff;
+            pub static SO_KEEPALIVE: c_int = 0x0008;
         }
         pub mod extra {
             use libc::types::os::arch::c95::c_int;
@@ -3296,6 +3547,63 @@ pub mod funcs {
         }
     }
 
+    #[cfg(not(windows))]
+    pub mod bsd43 {
+        use libc::types::common::c95::{c_void};
+        use libc::types::os::common::bsd44::{socklen_t, sockaddr};
+        use libc::types::os::arch::c95::{c_int, size_t};
+        use libc::types::os::arch::posix88::ssize_t;
+
+        extern "system" {
+            pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> c_int;
+            pub fn connect(socket: c_int, address: *sockaddr,
+                           len: socklen_t) -> c_int;
+            pub fn bind(socket: c_int, address: *sockaddr,
+                        address_len: socklen_t) -> c_int;
+            pub fn listen(socket: c_int, backlog: c_int) -> c_int;
+            pub fn accept(socket: c_int, address: *mut sockaddr,
+                          address_len: *mut socklen_t) -> c_int;
+            pub fn getpeername(socket: c_int, address: *mut sockaddr,
+                               address_len: *mut socklen_t) -> c_int;
+            pub fn getsockname(socket: c_int, address: *mut sockaddr,
+                               address_len: *mut socklen_t) -> c_int;
+            pub fn setsockopt(socket: c_int, level: c_int, name: c_int,
+                              value: *c_void, option_len: socklen_t) -> c_int;
+            pub fn recv(socket: c_int, buf: *mut c_void, len: size_t,
+                        flags: c_int) -> ssize_t;
+            pub fn send(socket: c_int, buf: *mut c_void, len: size_t,
+                        flags: c_int) -> ssize_t;
+        }
+    }
+
+    #[cfg(windows)]
+    pub mod bsd43 {
+        use libc::types::common::c95::{c_void};
+        use libc::types::os::common::bsd44::{socklen_t, sockaddr, SOCKET};
+        use libc::types::os::arch::c95::c_int;
+
+        extern "system" {
+            pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> SOCKET;
+            pub fn connect(socket: SOCKET, address: *sockaddr,
+                           len: socklen_t) -> c_int;
+            pub fn bind(socket: SOCKET, address: *sockaddr,
+                        address_len: socklen_t) -> c_int;
+            pub fn listen(socket: SOCKET, backlog: c_int) -> c_int;
+            pub fn accept(socket: SOCKET, address: *mut sockaddr,
+                          address_len: *mut socklen_t) -> SOCKET;
+            pub fn getpeername(socket: SOCKET, address: *mut sockaddr,
+                               address_len: *mut socklen_t) -> c_int;
+            pub fn getsockname(socket: SOCKET, address: *mut sockaddr,
+                               address_len: *mut socklen_t) -> c_int;
+            pub fn setsockopt(socket: SOCKET, level: c_int, name: c_int,
+                              value: *c_void, option_len: socklen_t) -> c_int;
+            pub fn closesocket(socket: SOCKET) -> c_int;
+            pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int,
+                        flags: c_int) -> c_int;
+            pub fn send(socket: SOCKET, buf: *mut c_void, len: c_int,
+                        flags: c_int) -> c_int;
+        }
+    }
 
     #[cfg(target_os = "macos")]
     #[cfg(target_os = "freebsd")]