auto merge of #11334 : alexcrichton/rust/fix-native-tcp, r=pcwalton
libnative erroneously would attempt to fill the entire buffer in a call to `read` before returning, when rather it should return immediately because there's not guaranteed to be any data that will ever be received again. Close #11328
This commit is contained in:
commit
0da105a8b7
|
@ -275,12 +275,12 @@ impl TcpStream {
|
||||||
|
|
||||||
impl rtio::RtioTcpStream for TcpStream {
|
impl rtio::RtioTcpStream for TcpStream {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
|
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
|
||||||
let ret = keep_going(buf, |buf, len| {
|
let ret = retry(|| {
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::recv(self.fd,
|
libc::recv(self.fd,
|
||||||
buf as *mut libc::c_void,
|
buf.as_ptr() as *mut libc::c_void,
|
||||||
len as wrlen,
|
buf.len() as wrlen,
|
||||||
0) as i64
|
0) as libc::c_int
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
|
|
|
@ -589,4 +589,25 @@ mod test {
|
||||||
//peer_name(next_test_ip6());
|
//peer_name(next_test_ip6());
|
||||||
socket_name(next_test_ip6());
|
socket_name(next_test_ip6());
|
||||||
})
|
})
|
||||||
|
|
||||||
|
iotest!(fn partial_read() {
|
||||||
|
let addr = next_test_ip4();
|
||||||
|
let (p, c) = Chan::new();
|
||||||
|
do spawn {
|
||||||
|
let mut srv = TcpListener::bind(addr).listen();
|
||||||
|
c.send(());
|
||||||
|
let mut cl = srv.accept().unwrap();
|
||||||
|
cl.write([10]);
|
||||||
|
let mut b = [0];
|
||||||
|
cl.read(b);
|
||||||
|
c.send(());
|
||||||
|
}
|
||||||
|
|
||||||
|
p.recv();
|
||||||
|
let mut c = TcpStream::connect(addr).unwrap();
|
||||||
|
let mut b = [0, ..10];
|
||||||
|
assert_eq!(c.read(b), Some(1));
|
||||||
|
c.write([1]);
|
||||||
|
p.recv();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue