summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-12-24 18:15:28 +0000
committerbors <bors@rust-lang.org>2018-12-24 18:15:28 +0000
commit26ffb5c10aeb2b9e60ab19972e3e64ebd8be74e1 (patch)
treefeebf29c85187739a8e7cce082b1cef161fe1e23
parent8ee27008ffb0dec2e79360e8e65d96446ac54dff (diff)
parentb9d86a6e8aad5710f3f05b0a0d107346d364a1e6 (diff)
downloadrust-libc-26ffb5c10aeb2b9e60ab19972e3e64ebd8be74e1.tar.gz
Auto merge of #1182 - xmclark:add-socket-functions-for-windows, r=alexcrichton
add some socket functions and a SOCKET type for windows This PR adds a few of the socket functions for windows. Some targets use the `stdcall` calling convention for these functions, so I put them in an `extern "system"` block ([see the nomicon](https://doc.rust-lang.org/nomicon/ffi.html#foreign-calling-conventions)).
-rw-r--r--src/windows/mod.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/windows/mod.rs b/src/windows/mod.rs
index e4db343ec2..73c5989b87 100644
--- a/src/windows/mod.rs
+++ b/src/windows/mod.rs
@@ -50,6 +50,8 @@ pub type ino_t = u16;
pub enum timezone {}
pub type time64_t = i64;
+pub type SOCKET = ::uintptr_t;
+
s! {
// note this is the struct called stat64 in Windows. Not stat, nor stati64.
pub struct stat {
@@ -93,6 +95,11 @@ s! {
pub tv_sec: time_t,
pub tv_nsec: c_long,
}
+
+ pub struct sockaddr {
+ pub sa_family: c_ushort,
+ pub sa_data: [c_char; 14],
+ }
}
pub const INT_MIN: c_int = -2147483648;
@@ -383,6 +390,34 @@ extern {
locale: *const wchar_t) -> *mut wchar_t;
}
+extern "system" {
+ pub fn listen(s: SOCKET, backlog: ::c_int) -> ::c_int;
+ pub fn accept(s: SOCKET, addr: *mut ::sockaddr,
+ addrlen: *mut ::c_int) -> SOCKET;
+ pub fn bind(s: SOCKET, name: *const ::sockaddr,
+ namelen: ::c_int) -> ::c_int;
+ pub fn connect(s: SOCKET, name: *const ::sockaddr,
+ namelen: ::c_int) -> ::c_int;
+ pub fn getpeername(s: SOCKET, name: *mut ::sockaddr,
+ nameln: *mut ::c_int) -> ::c_int;
+ pub fn getsockname(s: SOCKET, name: *mut ::sockaddr,
+ nameln: *mut ::c_int) -> ::c_int;
+ pub fn getsockopt(s: SOCKET, level: ::c_int, optname: ::c_int,
+ optval: *mut ::c_char,
+ optlen: *mut ::c_int) -> ::c_int;
+ pub fn recvfrom(s: SOCKET, buf: *mut ::c_char, len: ::c_int,
+ flags: ::c_int, from: *mut ::sockaddr,
+ fromlen: *mut ::c_int) -> ::c_int;
+ pub fn sendto(s: SOCKET, buf: *const ::c_char, len: ::c_int,
+ flags: ::c_int, to: *const ::sockaddr,
+ tolen: ::c_int) -> ::c_int;
+ pub fn setsockopt(s: SOCKET, level: ::c_int, optname: ::c_int,
+ optval: *const ::c_char,
+ optlen: ::c_int) -> ::c_int;
+ pub fn socket(af: ::c_int, socket_type: ::c_int,
+ protocol: ::c_int) -> SOCKET;
+}
+
cfg_if! {
if #[cfg(core_cvoid)] {
pub use core::ffi::c_void;