mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
add TcpStream::peek (#291)
This commit is contained in:
committed by
Alex Crichton
parent
b395ccb6d9
commit
ce014943ec
+1
-1
@@ -19,7 +19,7 @@ appveyor = { repository = "alexcrichton/tokio-core" }
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mio = "0.6.10"
|
mio = "0.6.12"
|
||||||
scoped-tls = "0.1.0"
|
scoped-tls = "0.1.0"
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
iovec = "0.1"
|
iovec = "0.1"
|
||||||
|
|||||||
@@ -364,6 +364,24 @@ impl TcpStream {
|
|||||||
self.io.get_ref().peer_addr()
|
self.io.get_ref().peer_addr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Receives data on the socket from the remote address to which it is
|
||||||
|
/// connected, without removing that data from the queue. On success,
|
||||||
|
/// returns the number of bytes peeked.
|
||||||
|
///
|
||||||
|
/// Successive calls return the same data. This is accomplished by passing
|
||||||
|
/// `MSG_PEEK` as a flag to the underlying recv system call.
|
||||||
|
pub fn peek(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
|
if let Async::NotReady = self.poll_read() {
|
||||||
|
return Err(io::ErrorKind::WouldBlock.into())
|
||||||
|
}
|
||||||
|
let r = self.io.get_ref().peek(buf);
|
||||||
|
if is_wouldblock(&r) {
|
||||||
|
self.io.need_read();
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// Shuts down the read, write, or both halves of this connection.
|
/// Shuts down the read, write, or both halves of this connection.
|
||||||
///
|
///
|
||||||
/// This function will cause all pending and future I/O on the specified
|
/// This function will cause all pending and future I/O on the specified
|
||||||
|
|||||||
@@ -289,6 +289,9 @@ impl Core {
|
|||||||
|
|
||||||
// Process all the events that came in, dispatching appropriately
|
// Process all the events that came in, dispatching appropriately
|
||||||
let mut fired = false;
|
let mut fired = false;
|
||||||
|
|
||||||
|
// events.len() and .get() deprecated in favor of iter()
|
||||||
|
#[allow(deprecated)]
|
||||||
for i in 0..self.events.len() {
|
for i in 0..self.events.len() {
|
||||||
let event = self.events.get(i).unwrap();
|
let event = self.events.get(i).unwrap();
|
||||||
let token = event.token();
|
let token = event.token();
|
||||||
@@ -841,6 +844,8 @@ mod platform {
|
|||||||
use mio::Ready;
|
use mio::Ready;
|
||||||
use mio::unix::UnixReady;
|
use mio::unix::UnixReady;
|
||||||
|
|
||||||
|
// aio() deprecated
|
||||||
|
#[allow(deprecated)]
|
||||||
pub fn aio() -> Ready {
|
pub fn aio() -> Ready {
|
||||||
UnixReady::aio().into()
|
UnixReady::aio().into()
|
||||||
}
|
}
|
||||||
@@ -857,6 +862,8 @@ mod platform {
|
|||||||
const ERROR: usize = 1 << 3;
|
const ERROR: usize = 1 << 3;
|
||||||
const AIO: usize = 1 << 4;
|
const AIO: usize = 1 << 4;
|
||||||
|
|
||||||
|
// is_aio() deprecated
|
||||||
|
#[allow(deprecated)]
|
||||||
pub fn ready2usize(ready: Ready) -> usize {
|
pub fn ready2usize(ready: Ready) -> usize {
|
||||||
let ready = UnixReady::from(ready);
|
let ready = UnixReady::from(ready);
|
||||||
let mut bits = 0;
|
let mut bits = 0;
|
||||||
@@ -872,6 +879,8 @@ mod platform {
|
|||||||
bits
|
bits
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is_aio() deprecated
|
||||||
|
#[allow(deprecated)]
|
||||||
pub fn usize2ready(bits: usize) -> Ready {
|
pub fn usize2ready(bits: usize) -> Ready {
|
||||||
let mut ready = UnixReady::from(Ready::empty());
|
let mut ready = UnixReady::from(Ready::empty());
|
||||||
if bits & AIO != 0 {
|
if bits & AIO != 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user