Skip to content

Add support for sendmsg(2), recvmsg(2), and cmsg(3), take 2 #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nix-test/src/const.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ get_int_const(const char* err) {
GET_CONST(MSG_OOB);
GET_CONST(MSG_PEEK);
GET_CONST(MSG_DONTWAIT);
GET_CONST(MSG_EOR);
GET_CONST(MSG_TRUNC);
GET_CONST(MSG_CTRUNC);
GET_CONST(SHUT_RD);
GET_CONST(SHUT_WR);
GET_CONST(SHUT_RDWR);
Expand All @@ -312,6 +315,7 @@ get_int_const(const char* err) {
// GET_CONST(SO_PEEK_OFF);
GET_CONST(SO_PEERCRED);
GET_CONST(SO_SNDBUFFORCE);
GET_CONST(MSG_ERRQUEUE);
#endif

return -1;
Expand Down
21 changes: 19 additions & 2 deletions src/sys/socket/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,23 @@ mod os {
pub const INADDR_NONE: InAddrT = 0xffffffff;
pub const INADDR_BROADCAST: InAddrT = 0xffffffff;

pub type SockMessageFlags = i32;
pub type SockMessageFlags = c_int;
// Flags for send/recv and their relatives
pub const MSG_OOB: SockMessageFlags = 0x1;
pub const MSG_PEEK: SockMessageFlags = 0x2;
pub const MSG_CTRUNC: SockMessageFlags = 0x08;
pub const MSG_TRUNC: SockMessageFlags = 0x20;
pub const MSG_DONTWAIT: SockMessageFlags = 0x40;
pub const MSG_EOR: SockMessageFlags = 0x80;
pub const MSG_ERRQUEUE: SockMessageFlags = 0x2000;

// shutdown flags
pub const SHUT_RD: c_int = 0;
pub const SHUT_WR: c_int = 1;
pub const SHUT_RDWR: c_int = 2;

// Ancillary message types
pub const SCM_RIGHTS: c_int = 1;
}

// Not all of these constants exist on freebsd
Expand Down Expand Up @@ -197,12 +204,18 @@ mod os {
// Flags for send/recv and their relatives
pub const MSG_OOB: SockMessageFlags = 0x1;
pub const MSG_PEEK: SockMessageFlags = 0x2;
pub const MSG_EOR: SockMessageFlags = 0x8;
pub const MSG_TRUNC: SockMessageFlags = 0x10;
pub const MSG_CTRUNC: SockMessageFlags = 0x20;
pub const MSG_DONTWAIT: SockMessageFlags = 0x80;

// shutdown flags
pub const SHUT_RD: c_int = 0;
pub const SHUT_WR: c_int = 1;
pub const SHUT_RDWR: c_int = 2;

// Ancillary message types
pub const SCM_RIGHTS: c_int = 1;
}

#[cfg(target_os = "dragonfly")]
Expand Down Expand Up @@ -340,6 +353,9 @@ mod test {
MSG_OOB,
MSG_PEEK,
MSG_DONTWAIT,
MSG_EOR,
MSG_TRUNC,
MSG_CTRUNC,
SHUT_RD,
SHUT_WR,
SHUT_RDWR
Expand Down Expand Up @@ -370,6 +386,7 @@ mod test {
SO_RCVBUFFORCE,
// SO_PEEK_OFF,
SO_PEERCRED,
SO_SNDBUFFORCE);
SO_SNDBUFFORCE,
MSG_ERRQUEUE);
}
}
9 changes: 8 additions & 1 deletion src/sys/socket/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use libc::{c_int, c_void, socklen_t};
// Silence invalid warnings due to rust-lang/rust#16719
#![allow(improper_ctypes)]

use libc::{c_int, c_void, socklen_t, ssize_t};
pub use libc::{socket, listen, bind, accept, connect, setsockopt, sendto, recvfrom, getsockname, getpeername, recv, send};
use super::msghdr;

extern {
pub fn getsockopt(
Expand All @@ -15,4 +19,7 @@ extern {
protocol: c_int,
sv: *mut c_int
) -> c_int;

pub fn sendmsg(sockfd: c_int, msg: *const msghdr, flags: c_int) -> ssize_t;
pub fn recvmsg(sockfd: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t;
}
Loading