Add a simple UDP test

This commit is contained in:
Alex Crichton
2016-08-02 23:56:01 -07:00
parent c458e23940
commit 1d7098eece
3 changed files with 75 additions and 6 deletions
+13
View File
@@ -1,3 +1,4 @@
use std::fmt;
use std::io::{self, ErrorKind, Read, Write};
use std::mem;
use std::net::{self, SocketAddr, Shutdown};
@@ -127,6 +128,12 @@ impl Iterator for NonblockingIter {
}
}
impl fmt::Debug for TcpListener {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.listener.io().fmt(f)
}
}
impl Stream for TcpListener {
type Item = Ready;
type Error = io::Error;
@@ -335,6 +342,12 @@ impl<'a> Write for &'a TcpStream {
}
}
impl fmt::Debug for TcpStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.source.io().fmt(f)
}
}
impl Stream for TcpStream {
type Item = Ready;
type Error = io::Error;
+19 -6
View File
@@ -1,6 +1,7 @@
use std::io;
use std::net::{self, SocketAddr, Ipv4Addr, Ipv6Addr};
use std::sync::Arc;
use std::fmt;
use futures::stream::Stream;
use futures::{Future, failed, Task, Poll};
@@ -71,16 +72,22 @@ impl UdpSocket {
///
/// Address type can be any implementor of `ToSocketAddrs` trait. See its
/// documentation for concrete examples.
pub fn send_to(&self, buf: &[u8], target: &SocketAddr)
-> io::Result<Option<usize>> {
self.source.io().send_to(buf, target)
pub fn send_to(&self, buf: &[u8], target: &SocketAddr) -> io::Result<usize> {
match self.source.io().send_to(buf, target) {
Ok(Some(n)) => Ok(n),
Ok(None) => Err(io::Error::new(io::ErrorKind::WouldBlock, "would block")),
Err(e) => Err(e),
}
}
/// Receives data from the socket. On success, returns the number of bytes
/// read and the address from whence the data came.
pub fn recv_from(&self, buf: &mut [u8])
-> io::Result<Option<(usize, SocketAddr)>> {
self.source.io().recv_from(buf)
pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
match self.source.io().recv_from(buf) {
Ok(Some(n)) => Ok(n),
Ok(None) => Err(io::Error::new(io::ErrorKind::WouldBlock, "would block")),
Err(e) => Err(e),
}
}
/// Gets the value of the `SO_BROADCAST` option for this socket.
@@ -224,6 +231,12 @@ impl UdpSocket {
}
}
impl fmt::Debug for UdpSocket {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.source.io().fmt(f)
}
}
impl Stream for UdpSocket {
type Item = Ready;
type Error = io::Error;