Skip to content
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

Fd ist now RawFd (rustup) #92

Merged
merged 2 commits into from
Apr 7, 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
6 changes: 3 additions & 3 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use self::consts::*;
pub use self::ffi::flock;

// Re-export Fd defined in std
pub type Fd = ::std::os::unix::io::Fd;
pub type Fd = ::std::os::unix::io::RawFd;

#[allow(dead_code)]
mod ffi {
Expand All @@ -19,7 +19,7 @@ mod ffi {
use libc::{c_int, c_short, off_t, pid_t};

#[repr(C)]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct flock {
pub l_type: c_short,
pub l_whence: c_short,
Expand Down Expand Up @@ -47,7 +47,7 @@ mod ffi {
use libc::{c_int, c_short, off_t, pid_t};

#[repr(C)]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct flock {
pub l_start: off_t,
pub l_len: off_t,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! defined in.
#![crate_name = "nix"]

#![feature(collections, core, io_ext, linkage, std_misc)]
#![feature(collections, core, linkage, std_misc)]
#![allow(non_camel_case_types)]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub type CpuMask = c_ulong;

// Structure representing the CPU set to apply
#[repr(C)]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct CpuSet {
cpu_mask: [CpuMask; cpuset_attribs::CPU_SETSIZE/cpuset_attribs::CPU_MASK_BITS]
}
Expand Down
4 changes: 2 additions & 2 deletions src/sys/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl fmt::Debug for EpollEventKind {
}
}

#[derive(Copy)]
#[derive(Clone, Copy)]
#[repr(C)]
pub enum EpollOp {
EpollCtlAdd = 1,
Expand All @@ -94,7 +94,7 @@ fn test_epoll_event_size() {
}

#[cfg(any(not(target_os = "android"), target_arch = "x86_64"))]
#[derive(Copy)]
#[derive(Clone, Copy)]
#[repr(C, packed)]
pub struct EpollEvent {
pub events: EpollEventKind,
Expand Down
4 changes: 2 additions & 2 deletions src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod ffi {
pub use libc::{c_int, c_void, uintptr_t, intptr_t, timespec};
use super::{EventFilter, EventFlag, FilterFlag};

#[derive(Copy)]
#[derive(Clone, Copy)]
#[repr(C)]
pub struct kevent {
pub ident: uintptr_t, // 8
Expand All @@ -40,7 +40,7 @@ mod ffi {
}

#[repr(i16)]
#[derive(Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum EventFilter {
EVFILT_READ = -1,
EVFILT_WRITE = -2,
Expand Down
2 changes: 1 addition & 1 deletion src/sys/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use self::IoctlArg::*;
mod ffi {
use libc::c_ushort;

#[derive(Copy, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct Winsize {
pub ws_row: c_ushort,
pub ws_col: c_ushort,
Expand Down
10 changes: 5 additions & 5 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub mod signal {
// actually a giant union. Currently we're only interested in these fields,
// however.
#[repr(C)]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct siginfo {
si_signo: libc::c_int,
si_errno: libc::c_int,
Expand All @@ -117,14 +117,14 @@ pub mod signal {

#[repr(C)]
#[cfg(target_pointer_width = "32")]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct sigset_t {
__val: [libc::c_ulong; 32],
}

#[repr(C)]
#[cfg(target_pointer_width = "64")]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct sigset_t {
__val: [libc::c_ulong; 16],
}
Expand Down Expand Up @@ -249,7 +249,7 @@ pub mod signal {
// This structure has more fields, but we're not all that interested in
// them.
#[repr(C)]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct siginfo {
pub si_signo: libc::c_int,
pub si_errno: libc::c_int,
Expand Down Expand Up @@ -297,7 +297,7 @@ mod ffi {
}
}

#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct SigSet {
sigset: sigset_t
}
Expand Down
2 changes: 1 addition & 1 deletion src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl fmt::Display for Ipv4Addr {
*
*/

#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct Ipv6Addr(pub libc::in6_addr);

impl Ipv6Addr {
Expand Down
36 changes: 18 additions & 18 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct sockaddr_storage {
pub __ss_pad2: [u8; 120],
}

#[derive(Copy, PartialEq, Eq, Debug, FromPrimitive)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, FromPrimitive)]
#[repr(i32)]
pub enum SockType {
Stream = consts::SOCK_STREAM,
Expand All @@ -78,7 +78,7 @@ bitflags!(
/// Create an endpoint for communication
///
/// [Further reading](http://man7.org/linux/man-pages/man2/socket.2.html)
pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result<Fd> {
pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result<RawFd> {
let mut ty = ty as c_int;
let feat_atomic = features::socket_atomic_cloexec();

Expand Down Expand Up @@ -109,15 +109,15 @@ pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result<Fd
/// Listen for connections on a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/listen.2.html)
pub fn listen(sockfd: Fd, backlog: usize) -> Result<()> {
pub fn listen(sockfd: RawFd, backlog: usize) -> Result<()> {
let res = unsafe { ffi::listen(sockfd, backlog as c_int) };
from_ffi(res)
}

/// Bind a name to a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html)
pub fn bind(fd: Fd, addr: &SockAddr) -> Result<()> {
pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
let res = unsafe {
let (ptr, len) = addr.as_ffi_pair();
ffi::bind(fd, ptr, len)
Expand All @@ -129,7 +129,7 @@ pub fn bind(fd: Fd, addr: &SockAddr) -> Result<()> {
/// Accept a connection on a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
pub fn accept(sockfd: Fd) -> Result<Fd> {
pub fn accept(sockfd: RawFd) -> Result<RawFd> {
let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) };

if res < 0 {
Expand All @@ -143,7 +143,7 @@ pub fn accept(sockfd: Fd) -> Result<Fd> {
///
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
use libc::sockaddr;

type F = unsafe extern "C" fn(c_int, *mut sockaddr, *mut socklen_t, c_int) -> c_int;
Expand Down Expand Up @@ -173,12 +173,12 @@ pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
///
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
accept4_polyfill(sockfd, flags)
}

#[inline]
fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
fn accept4_polyfill(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) };

if res < 0 {
Expand All @@ -199,7 +199,7 @@ fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
/// Initiate a connection on a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/connect.2.html)
pub fn connect(fd: Fd, addr: &SockAddr) -> Result<()> {
pub fn connect(fd: RawFd, addr: &SockAddr) -> Result<()> {
let res = unsafe {
let (ptr, len) = addr.as_ffi_pair();
ffi::connect(fd, ptr, len)
Expand All @@ -212,7 +212,7 @@ pub fn connect(fd: Fd, addr: &SockAddr) -> Result<()> {
/// the number of bytes read and the socket address of the sender.
///
/// [Further reading](http://man7.org/linux/man-pages/man2/recvmsg.2.html)
pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
unsafe {
let addr: sockaddr_storage = mem::zeroed();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
Expand All @@ -234,7 +234,7 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
}
}

pub fn sendto(fd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> Result<usize> {
pub fn sendto(fd: RawFd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> Result<usize> {
let ret = unsafe {
let (ptr, len) = addr.as_ffi_pair();
ffi::sendto(fd, buf.as_ptr() as *const c_void, buf.len() as size_t, flags, ptr, len)
Expand All @@ -248,7 +248,7 @@ pub fn sendto(fd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> R
}

#[repr(C)]
#[derive(Copy, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct linger {
pub l_onoff: c_int,
pub l_linger: c_int
Expand Down Expand Up @@ -284,30 +284,30 @@ pub trait SockOpt : Copy + fmt::Debug {
type Set;

#[doc(hidden)]
fn get(&self, fd: Fd, level: c_int) -> Result<Self::Get>;
fn get(&self, fd: RawFd, level: c_int) -> Result<Self::Get>;

#[doc(hidden)]
fn set(&self, fd: Fd, level: c_int, val: Self::Set) -> Result<()>;
fn set(&self, fd: RawFd, level: c_int, val: Self::Set) -> Result<()>;
}

/// Get the current value for the requested socket option
///
/// [Further reading](http://man7.org/linux/man-pages/man2/setsockopt.2.html)
pub fn getsockopt<O: SockOpt>(fd: Fd, level: SockLevel, opt: O) -> Result<O::Get> {
pub fn getsockopt<O: SockOpt>(fd: RawFd, level: SockLevel, opt: O) -> Result<O::Get> {
opt.get(fd, level as c_int)
}

/// Sets the value for the requested socket option
///
/// [Further reading](http://man7.org/linux/man-pages/man2/setsockopt.2.html)
pub fn setsockopt<O: SockOpt>(fd: Fd, level: SockLevel, opt: O, val: O::Set) -> Result<()> {
pub fn setsockopt<O: SockOpt>(fd: RawFd, level: SockLevel, opt: O, val: O::Set) -> Result<()> {
opt.set(fd, level as c_int, val)
}

/// Get the address of the peer connected to the socket `fd`.
///
/// [Further reading](http://man7.org/linux/man-pages/man2/getpeername.2.html)
pub fn getpeername(fd: Fd) -> Result<SockAddr> {
pub fn getpeername(fd: RawFd) -> Result<SockAddr> {
unsafe {
let addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
Expand All @@ -325,7 +325,7 @@ pub fn getpeername(fd: Fd) -> Result<SockAddr> {
/// Get the current address to which the socket `fd` is bound.
///
/// [Further reading](http://man7.org/linux/man-pages/man2/getsockname.2.html)
pub fn getsockname(fd: Fd) -> Result<SockAddr> {
pub fn getsockname(fd: RawFd) -> Result<SockAddr> {
unsafe {
let addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
Expand Down
2 changes: 1 addition & 1 deletion src/sys/socket/multicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libc::in_addr;
use std::fmt;

#[repr(C)]
#[derive(Copy)]
#[derive(Clone, Copy)]
pub struct ip_mreq {
pub imr_multiaddr: in_addr,
pub imr_interface: in_addr,
Expand Down
8 changes: 4 additions & 4 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use errno::Errno;
use sys::time::TimeVal;
use libc::{c_int, uint8_t, c_void, socklen_t};
use std::mem;
use std::os::unix::io::Fd;
use std::os::unix::io::RawFd;

// Helper to generate the sockopt accessors
// TODO: Figure out how to ommit gets when not supported by opt
Expand All @@ -22,14 +22,14 @@ macro_rules! sockopt_impl {
};

($name:ident, $flag:path, $get_ty:ty, $getter:ty, $set_ty:ty, $setter:ty) => {
#[derive(Copy, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct $name;

impl<'a> SockOpt for $name {
type Get = $get_ty;
type Set = $set_ty;

fn get(&self, fd: Fd, level: c_int) -> Result<$get_ty> {
fn get(&self, fd: RawFd, level: c_int) -> Result<$get_ty> {
unsafe {
let mut getter: $getter = Get::blank();

Expand All @@ -46,7 +46,7 @@ macro_rules! sockopt_impl {
}
}

fn set(&self, fd: Fd, level: c_int, val: $set_ty) -> Result<()> {
fn set(&self, fd: RawFd, level: c_int, val: $set_ty) -> Result<()> {
unsafe {
let setter: $setter = Set::new(val);

Expand Down
Loading