|
|
@@ -344,10 +344,10 @@ pub fn get_host_addresses(host: Option<&str>, servname: Option<&str>, |
|
|
|
// [1] http://twistedmatrix.com/pipermail/twisted-commits/2012-April/034692.html |
|
|
|
// [2] http://stackoverflow.com/questions/19819198/does-send-msg-dontwait |
|
|
|
|
|
|
|
pub fn read<T>(fd: sock_t, |
|
|
|
deadline: u64, |
|
|
|
lock: || -> T, |
|
|
|
read: |bool| -> libc::c_int) -> IoResult<uint> { |
|
|
|
pub fn read<T, L, R>(fd: sock_t, deadline: u64, mut lock: L, mut read: R) -> IoResult<uint> where |
|
|
|
L: FnMut() -> T, |
|
|
|
R: FnMut(bool) -> libc::c_int, |
|
|
|
{ |
|
|
|
let mut ret = -1; |
|
|
|
if deadline == 0 { |
|
|
|
ret = retry(|| read(false)); |
|
|
@@ -386,12 +386,15 @@ pub fn read<T>(fd: sock_t, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pub fn write<T>(fd: sock_t, |
|
|
|
deadline: u64, |
|
|
|
buf: &[u8], |
|
|
|
write_everything: bool, |
|
|
|
lock: || -> T, |
|
|
|
write: |bool, *const u8, uint| -> i64) -> IoResult<uint> { |
|
|
|
pub fn write<T, L, W>(fd: sock_t, |
|
|
|
deadline: u64, |
|
|
|
buf: &[u8], |
|
|
|
write_everything: bool, |
|
|
|
mut lock: L, |
|
|
|
mut write: W) -> IoResult<uint> where |
|
|
|
L: FnMut() -> T, |
|
|
|
W: FnMut(bool, *const u8, uint) -> i64, |
|
|
|
{ |
|
|
|
let mut ret = -1; |
|
|
|
let mut written = 0; |
|
|
|
if deadline == 0 { |
|
|
@@ -674,8 +677,8 @@ impl TcpStream { |
|
|
|
|
|
|
|
pub fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { |
|
|
|
let fd = self.fd(); |
|
|
|
let dolock = || self.lock_nonblocking(); |
|
|
|
let doread = |nb| unsafe { |
|
|
|
let dolock = |&:| self.lock_nonblocking(); |
|
|
|
let doread = |&mut: nb| unsafe { |
|
|
|
let flags = if nb {c::MSG_DONTWAIT} else {0}; |
|
|
|
libc::recv(fd, |
|
|
|
buf.as_mut_ptr() as *mut libc::c_void, |
|
|
@@ -687,8 +690,8 @@ impl TcpStream { |
|
|
|
|
|
|
|
pub fn write(&mut self, buf: &[u8]) -> IoResult<()> { |
|
|
|
let fd = self.fd(); |
|
|
|
let dolock = || self.lock_nonblocking(); |
|
|
|
let dowrite = |nb: bool, buf: *const u8, len: uint| unsafe { |
|
|
|
let dolock = |&:| self.lock_nonblocking(); |
|
|
|
let dowrite = |&: nb: bool, buf: *const u8, len: uint| unsafe { |
|
|
|
let flags = if nb {c::MSG_DONTWAIT} else {0}; |
|
|
|
libc::send(fd, |
|
|
|
buf as *const _, |
|
|
@@ -822,7 +825,7 @@ impl UdpSocket { |
|
|
|
let mut addrlen: libc::socklen_t = |
|
|
|
mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t; |
|
|
|
|
|
|
|
let dolock = || self.lock_nonblocking(); |
|
|
|
let dolock = |&:| self.lock_nonblocking(); |
|
|
|
let n = try!(read(fd, self.read_deadline, dolock, |nb| unsafe { |
|
|
|
let flags = if nb {c::MSG_DONTWAIT} else {0}; |
|
|
|
libc::recvfrom(fd, |
|
|
@@ -843,8 +846,8 @@ impl UdpSocket { |
|
|
|
let dstp = &storage as *const _ as *const libc::sockaddr; |
|
|
|
|
|
|
|
let fd = self.fd(); |
|
|
|
let dolock = || self.lock_nonblocking(); |
|
|
|
let dowrite = |nb, buf: *const u8, len: uint| unsafe { |
|
|
|
let dolock = |&: | self.lock_nonblocking(); |
|
|
|
let dowrite = |&mut: nb, buf: *const u8, len: uint| unsafe { |
|
|
|
let flags = if nb {c::MSG_DONTWAIT} else {0}; |
|
|
|
libc::sendto(fd, |
|
|
|
buf as *const libc::c_void, |
|
|
|