Skip to content

Commit

Permalink
Replace more FFI instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Susurrus committed Aug 26, 2017
1 parent 28c5b4a commit 5378945
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub fn socket<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: SockType
}

// TODO: Check the kernel version
let res = try!(Errno::result(unsafe { ffi::socket(domain as c_int, ty, protocol) }));
let res = try!(Errno::result(unsafe { libc::socket(domain as c_int, ty, protocol) }));

#[cfg(any(target_os = "android",
target_os = "dragonfly",
Expand Down Expand Up @@ -509,7 +509,7 @@ pub fn socketpair<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: Sock
}
let mut fds = [-1, -1];
let res = unsafe {
ffi::socketpair(domain as c_int, ty, protocol, fds.as_mut_ptr())
libc::socketpair(domain as c_int, ty, protocol, fds.as_mut_ptr())
};
try!(Errno::result(res));

Expand Down Expand Up @@ -542,7 +542,7 @@ pub fn socketpair<T: Into<Option<SockProtocol>>>(domain: AddressFamily, ty: Sock
///
/// [Further reading](http://man7.org/linux/man-pages/man2/listen.2.html)
pub fn listen(sockfd: RawFd, backlog: usize) -> Result<()> {
let res = unsafe { ffi::listen(sockfd, backlog as c_int) };
let res = unsafe { libc::listen(sockfd, backlog as c_int) };

Errno::result(res).map(drop)
}
Expand All @@ -554,7 +554,7 @@ pub fn listen(sockfd: RawFd, backlog: usize) -> Result<()> {
pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
let res = unsafe {
let (ptr, len) = addr.as_ffi_pair();
ffi::bind(fd, ptr, len)
libc::bind(fd, ptr, len)
};

Errno::result(res).map(drop)
Expand All @@ -569,7 +569,7 @@ pub fn bind(fd: RawFd, 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 as c_int)
libc::bind(fd, ptr, len as c_int)
};

Errno::result(res).map(drop)
Expand All @@ -579,7 +579,7 @@ pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
///
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
pub fn accept(sockfd: RawFd) -> Result<RawFd> {
let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) };
let res = unsafe { libc::accept(sockfd, ptr::null_mut(), ptr::null_mut()) };

Errno::result(res)
}
Expand All @@ -593,7 +593,7 @@ pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {

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

#[cfg(any(target_os = "android",
target_os = "dragonfly",
Expand Down Expand Up @@ -635,7 +635,7 @@ fn accept4_polyfill(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
pub fn connect(fd: RawFd, addr: &SockAddr) -> Result<()> {
let res = unsafe {
let (ptr, len) = addr.as_ffi_pair();
ffi::connect(fd, ptr, len)
libc::connect(fd, ptr, len)
};

Errno::result(res).map(drop)
Expand Down Expand Up @@ -682,7 +682,7 @@ pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
pub fn sendto(fd: RawFd, buf: &[u8], addr: &SockAddr, flags: MsgFlags) -> 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.bits(), ptr, len)
libc::sendto(fd, buf.as_ptr() as *const c_void, buf.len() as size_t, flags.bits(), ptr, len)
};

Errno::result(ret).map(|r| r as usize)
Expand All @@ -693,7 +693,7 @@ pub fn sendto(fd: RawFd, buf: &[u8], addr: &SockAddr, flags: MsgFlags) -> Result
/// [Further reading](http://man7.org/linux/man-pages/man2/send.2.html)
pub fn send(fd: RawFd, buf: &[u8], flags: MsgFlags) -> Result<usize> {
let ret = unsafe {
ffi::send(fd, buf.as_ptr() as *const c_void, buf.len() as size_t, flags.bits())
libc::send(fd, buf.as_ptr() as *const c_void, buf.len() as size_t, flags.bits())
};

Errno::result(ret).map(|r| r as usize)
Expand Down Expand Up @@ -775,7 +775,7 @@ pub fn getpeername(fd: RawFd) -> Result<SockAddr> {
let addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;

let ret = ffi::getpeername(fd, mem::transmute(&addr), &mut len);
let ret = libc::getpeername(fd, mem::transmute(&addr), &mut len);

try!(Errno::result(ret));

Expand All @@ -791,7 +791,7 @@ pub fn getsockname(fd: RawFd) -> Result<SockAddr> {
let addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;

let ret = ffi::getsockname(fd, mem::transmute(&addr), &mut len);
let ret = libc::getsockname(fd, mem::transmute(&addr), &mut len);

try!(Errno::result(ret));

Expand Down
14 changes: 7 additions & 7 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{ffi, GetSockOpt, SetSockOpt};
use super::{GetSockOpt, SetSockOpt};
use {Errno, Result};
use sys::time::TimeVal;
use libc::{self, c_int, uint8_t, c_void, socklen_t};
Expand All @@ -14,9 +14,9 @@ macro_rules! setsockopt_impl {
unsafe {
let setter: $setter = Set::new(val);

let res = ffi::setsockopt(fd, $level, $flag,
setter.ffi_ptr(),
setter.ffi_len());
let res = libc::setsockopt(fd, $level, $flag,
setter.ffi_ptr(),
setter.ffi_len());
Errno::result(res).map(drop)
}
}
Expand All @@ -33,9 +33,9 @@ macro_rules! getsockopt_impl {
unsafe {
let mut getter: $getter = Get::blank();

let res = ffi::getsockopt(fd, $level, $flag,
getter.ffi_ptr(),
getter.ffi_len());
let res = libc::getsockopt(fd, $level, $flag,
getter.ffi_ptr(),
getter.ffi_len());
try!(Errno::result(res));

Ok(getter.unwrap())
Expand Down

0 comments on commit 5378945

Please sign in to comment.