forked from iqlusioninc/tmkms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unix.rs
41 lines (35 loc) · 994 Bytes
/
unix.rs
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
//! Unix domain socket connection to a validator
use std::io;
use std::marker::{Send, Sync};
/// Protocol implementation of the UNIX socket domain connection
pub struct UnixConnection<IoHandler> {
socket: IoHandler,
}
impl<IoHandler> UnixConnection<IoHandler>
where
IoHandler: io::Read + io::Write + Send + Sync,
{
/// Create a new `UnixConnection` for the given socket
pub fn new(socket: IoHandler) -> Self {
Self { socket }
}
}
impl<IoHandler> io::Read for UnixConnection<IoHandler>
where
IoHandler: io::Read + io::Write + Send + Sync,
{
fn read(&mut self, data: &mut [u8]) -> Result<usize, io::Error> {
self.socket.read(data)
}
}
impl<IoHandler> io::Write for UnixConnection<IoHandler>
where
IoHandler: io::Read + io::Write + Send + Sync,
{
fn write(&mut self, data: &[u8]) -> Result<usize, io::Error> {
self.socket.write(data)
}
fn flush(&mut self) -> Result<(), io::Error> {
self.socket.flush()
}
}