blob: f4a714b1daf442da5a46a114e22a34cd0682684e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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<usize> {
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<usize> {
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(())
}
}
|