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

Fix build errors #96

Closed
wants to merge 5 commits into from
Closed
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
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: rust
sudo: false
sudo: required

matrix:
include:
Expand All @@ -10,7 +10,7 @@ matrix:
- rust: nightly
script:
- cargo test
- cargo test --feature snightly
- cargo test --features nightly

- rust: nightly
before_script:
Expand All @@ -20,6 +20,13 @@ matrix:
after_success:
- travis-cargo doc-upload

before_script:
# Add an IPv6 config - see the corresponding Travis issue
# https://github.com/travis-ci/travis-ci/issues/8361
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6';
fi

script:
- cargo test

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ winapi = { version = "0.3", features = ["handleapi", "winsock2", "ws2def", "ws2i
libc = "0.2.54"

[dependencies]
cfg-if = "0.1"
cfg-if = "<0.1.10"

[features]
nightly = []
Expand Down
46 changes: 23 additions & 23 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ pub fn set_opt<T: Copy>(sock: Socket, opt: c_int, val: c_int,
let payload = &payload as *const T as *const c_void;
#[cfg(target_os = "redox")]
let sock = sock as c_int;
try!(::cvt(setsockopt(sock, opt, val, payload as *const _,
mem::size_of::<T>() as socklen_t)));
::cvt(setsockopt(sock, opt, val, payload as *const _,
mem::size_of::<T>() as socklen_t))?;
}
Ok(())
}
Expand All @@ -90,9 +90,9 @@ pub fn get_opt<T: Copy>(sock: Socket, opt: c_int, val: c_int) -> io::Result<T> {
let mut len = mem::size_of::<T>() as socklen_t;
#[cfg(target_os = "redox")]
let sock = sock as c_int;
try!(::cvt(getsockopt(sock, opt, val,
::cvt(getsockopt(sock, opt, val,
&mut slot as *mut _ as *mut _,
&mut len)));
&mut len))?;
assert_eq!(len as usize, mem::size_of::<T>());
Ok(slot)
}
Expand Down Expand Up @@ -715,47 +715,47 @@ impl TcpStreamExt for TcpStream {

#[cfg(target_os = "redox")]
fn set_keepalive_ms(&self, keepalive: Option<u32>) -> io::Result<()> {
try!(set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
keepalive.is_some() as c_int));
set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
keepalive.is_some() as c_int)?;
if let Some(dur) = keepalive {
try!(set_opt(self.as_sock(), v(IPPROTO_TCP), KEEPALIVE_OPTION,
(dur / 1000) as c_int));
set_opt(self.as_sock(), v(IPPROTO_TCP), KEEPALIVE_OPTION,
(dur / 1000) as c_int)?;
}
Ok(())
}

#[cfg(target_os = "redox")]
fn keepalive_ms(&self) -> io::Result<Option<u32>> {
let keepalive = try!(get_opt::<c_int>(self.as_sock(), SOL_SOCKET,
SO_KEEPALIVE));
let keepalive = get_opt::<c_int>(self.as_sock(), SOL_SOCKET,
SO_KEEPALIVE)?;
if keepalive == 0 {
return Ok(None)
}
let secs = try!(get_opt::<c_int>(self.as_sock(), v(IPPROTO_TCP),
KEEPALIVE_OPTION));
let secs = get_opt::<c_int>(self.as_sock(), v(IPPROTO_TCP),
KEEPALIVE_OPTION)?;
Ok(Some((secs as u32) * 1000))
}

#[cfg(unix)]
fn set_keepalive_ms(&self, keepalive: Option<u32>) -> io::Result<()> {
try!(set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
keepalive.is_some() as c_int));
set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
keepalive.is_some() as c_int)?;
if let Some(dur) = keepalive {
try!(set_opt(self.as_sock(), v(IPPROTO_TCP), KEEPALIVE_OPTION,
(dur / 1000) as c_int));
set_opt(self.as_sock(), v(IPPROTO_TCP), KEEPALIVE_OPTION,
(dur / 1000) as c_int)?;
}
Ok(())
}

#[cfg(unix)]
fn keepalive_ms(&self) -> io::Result<Option<u32>> {
let keepalive = try!(get_opt::<c_int>(self.as_sock(), SOL_SOCKET,
SO_KEEPALIVE));
let keepalive = get_opt::<c_int>(self.as_sock(), SOL_SOCKET,
SO_KEEPALIVE)?;
if keepalive == 0 {
return Ok(None)
}
let secs = try!(get_opt::<c_int>(self.as_sock(), v(IPPROTO_TCP),
KEEPALIVE_OPTION));
let secs = get_opt::<c_int>(self.as_sock(), v(IPPROTO_TCP),
KEEPALIVE_OPTION)?;
Ok(Some((secs as u32) * 1000))
}

Expand Down Expand Up @@ -798,15 +798,15 @@ impl TcpStreamExt for TcpStream {
keepaliveinterval: 0,
};
unsafe {
try!(::cvt_win(WSAIoctl(self.as_sock(),
::cvt_win(WSAIoctl(self.as_sock(),
SIO_KEEPALIVE_VALS,
0 as *mut _,
0,
&mut ka as *mut _ as *mut _,
mem::size_of_val(&ka) as DWORD,
0 as *mut _,
0 as *mut _,
None)));
None))?;
}
Ok({
if ka.onoff == 0 {
Expand Down Expand Up @@ -1290,7 +1290,7 @@ impl UdpSocketExt for UdpSocket {
fn do_connect<A: ToSocketAddrs>(sock: Socket, addr: A) -> io::Result<()> {
let err = io::Error::new(io::ErrorKind::Other,
"no socket addresses resolved");
let addrs = try!(addr.to_socket_addrs());
let addrs = addr.to_socket_addrs()?;
let sys = sys::Socket::from_inner(sock);
let sock = socket::Socket::from_inner(sys);
let ret = addrs.fold(Err(err), |prev, addr| {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub use udp::UdpBuilder;
pub use ext::{TcpStreamExt, TcpListenerExt, UdpSocketExt};

fn one_addr<T: ToSocketAddrs>(tsa: T) -> io::Result<SocketAddr> {
let mut addrs = try!(tsa.to_socket_addrs());
let mut addrs = tsa.to_socket_addrs()?;
let addr = match addrs.next() {
Some(addr) => addr,
None => return Err(io::Error::new(io::ErrorKind::Other,
Expand Down
6 changes: 3 additions & 3 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Socket {

impl Socket {
pub fn new(family: c_int, ty: c_int) -> io::Result<Socket> {
Ok(Socket { inner: try!(sys::Socket::new(family, ty)) })
Ok(Socket { inner: sys::Socket::new(family, ty)? })
}

pub fn bind(&self, addr: &SocketAddr) -> io::Result<()> {
Expand All @@ -53,9 +53,9 @@ impl Socket {
unsafe {
let mut storage: c::sockaddr_storage = mem::zeroed();
let mut len = mem::size_of_val(&storage) as c::socklen_t;
try!(::cvt(c::getsockname(self.inner.raw(),
::cvt(c::getsockname(self.inner.raw(),
&mut storage as *mut _ as *mut _,
&mut len)));
&mut len))?;
raw2addr(&storage, len)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Socket {
Err(e) => return Err(e),
}

let fd = try!(::cvt(libc::socket(family, ty, 0)));
let fd = ::cvt(libc::socket(family, ty, 0))?;
ioctl(fd, FIOCLEX);
Ok(Socket { fd: fd })
}
Expand All @@ -61,7 +61,7 @@ impl Socket {
#[cfg(any(target_os = "solaris", target_os = "emscripten"))]
pub fn new(family: c_int, ty: c_int) -> io::Result<Socket> {
unsafe {
let fd = try!(::cvt(libc::socket(family, ty, 0)));
let fd = ::cvt(libc::socket(family, ty, 0))?;
libc::fcntl(fd, libc::FD_CLOEXEC);
Ok(Socket { fd: fd })
}
Expand Down
10 changes: 5 additions & 5 deletions src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::io;
use std::mem;
use std::net::{TcpListener, TcpStream, UdpSocket};
use std::os::windows::io::{RawSocket, FromRawSocket};
use std::sync::{Once, ONCE_INIT};
use std::sync::Once;

const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;

Expand Down Expand Up @@ -53,7 +53,7 @@ use self::c::*;
mod impls;

fn init() {
static INIT: Once = ONCE_INIT;
static INIT: Once = Once::new();

INIT.call_once(|| {
// Initialize winsock through the standard library by just creating a
Expand All @@ -70,14 +70,14 @@ pub struct Socket {
impl Socket {
pub fn new(family: c_int, ty: c_int) -> io::Result<Socket> {
init();
let socket = try!(unsafe {
let socket = unsafe {
match WSASocketW(family, ty, 0, 0 as *mut _, 0,
WSA_FLAG_OVERLAPPED) {
INVALID_SOCKET => Err(io::Error::last_os_error()),
n => Ok(Socket { socket: n }),
}
});
try!(socket.set_no_inherit());
}?;
socket.set_no_inherit()?;
Ok(socket)
}

Expand Down
4 changes: 2 additions & 2 deletions src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TcpBuilder {
where T: ToSocketAddrs
{
self.with_socket(|sock| {
let addr = try!(::one_addr(addr));
let addr = ::one_addr(addr)?;
sock.bind(&addr)
}).map(|()| self)
}
Expand Down Expand Up @@ -85,7 +85,7 @@ impl TcpBuilder {
self.with_socket(|sock| {
let err = io::Error::new(io::ErrorKind::Other,
"no socket addresses resolved");
try!(addr.to_socket_addrs()).fold(Err(err), |prev, addr| {
addr.to_socket_addrs()?.fold(Err(err), |prev, addr| {
prev.or_else(|_| sock.connect(&addr))
})
}).and_then(|()| {
Expand Down
6 changes: 3 additions & 3 deletions src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ impl UdpBuilder {
pub fn bind<T>(&self, addr: T) -> io::Result<UdpSocket>
where T: ToSocketAddrs
{
try!(self.with_socket(|sock| {
let addr = try!(::one_addr(addr));
self.with_socket(|sock| {
let addr = ::one_addr(addr)?;
sock.bind(&addr)
}));
})?;
Ok(self.socket.borrow_mut().take().unwrap().into_inner().into_udp_socket())
}

Expand Down