Skip to content

Commit

Permalink
Merge pull request #10 from Txuritan/master
Browse files Browse the repository at this point in the history
Fix for Android aarch64 socket type
  • Loading branch information
alexcrichton authored Apr 26, 2018
2 parents e9967bc + 9f9eb59 commit ec86ae1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use mio::unix::EventedFd;
use mio::{Poll, Token, Ready, PollOpt};

use cvt;
use Len;
use socket::{sockaddr_un, Socket};

/// A Unix datagram socket.
Expand All @@ -30,7 +31,7 @@ impl UnixDatagram {
let fd = try!(Socket::new(libc::SOCK_DGRAM));

let addr = &addr as *const _ as *const _;
try!(cvt(libc::bind(fd.fd(), addr, len)));
try!(cvt(libc::bind(fd.fd(), addr, len as Len)));

Ok(UnixDatagram::from_raw_fd(fd.into_fd()))
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub use stream::UnixStream;
pub use listener::UnixListener;
pub use datagram::UnixDatagram;

#[cfg(not(all(target_arch = "aarch64",target_os = "android")))]
type Len = u32;
#[cfg(all(target_arch = "aarch64",target_os = "android"))]
type Len = i32;

fn cvt(i: libc::c_int) -> io::Result<libc::c_int> {
if i == -1 {
Err(io::Error::last_os_error())
Expand Down
3 changes: 2 additions & 1 deletion src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use mio::{Poll, Token, Ready, PollOpt};

use UnixStream;
use cvt;
use Len;
use socket::{sockaddr_un, Socket};

/// A structure representing a Unix domain socket server.
Expand All @@ -34,7 +35,7 @@ impl UnixListener {
let fd = try!(Socket::new(libc::SOCK_STREAM));

let addr = &addr as *const _ as *const _;
try!(cvt(libc::bind(fd.fd(), addr, len)));
try!(cvt(libc::bind(fd.fd(), addr, len as Len)));
try!(cvt(libc::listen(fd.fd(), 128)));

Ok(UnixListener::from_raw_fd(fd.into_fd()))
Expand Down

0 comments on commit ec86ae1

Please sign in to comment.