From 362dbf20d6b990a092bc220d36289144e86aaa6d Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 2 Jun 2016 17:18:44 -0400 Subject: start transition to UDT transport --- src/udt_extras.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/udt_extras.rs (limited to 'src/udt_extras.rs') diff --git a/src/udt_extras.rs b/src/udt_extras.rs new file mode 100644 index 0000000..f4a714b --- /dev/null +++ b/src/udt_extras.rs @@ -0,0 +1,44 @@ + +extern crate udt; + +use std::str::{self, FromStr}; +use udt::{UdtSocket}; +use std::io; +use std::io::{Read, Write, ErrorKind}; + +pub struct UdtStream { + socket: UdtSocket, +} + +impl UdtStream { + + pub fn new(socket: UdtSocket) -> UdtStream { + UdtStream { socket: socket } + + } +} + +impl Read for UdtStream { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + let buf_len = buf.len(); + match self.socket.recv(buf, buf_len) { + Ok(len) => Ok(len as usize), + Err(err) => Err(io::Error::new( + ErrorKind::Other, err.err_msg)), + } + } +} + +impl Write for UdtStream { + fn write(&mut self, buf: &[u8]) -> io::Result { + match self.socket.send(buf) { + Ok(len) => Ok(len as usize), + Err(err) => Err(io::Error::new( + ErrorKind::Other, err.err_msg)), + } + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} -- cgit v1.2.3