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&H, event: io::HostEvent) -> Option<io::NetEvent>
where H: io::HostInterface
pub fn process_host_event<H>(&mut self, host: &H, event: HostEvent) -> Option<NetEvent>
where H: HostInterface
let net = IpInterface::open(config);
event_loop.register(&net,
NET_EVENT,
mio::EventSet::readable() |
mio::EventSet::writable(),
mio::PollOpt::oneshot()).unwrap();
let net = try!(IpInterface::open(config));
try!(event_loop.register(&net,
NET_EVENT,
EventSet::readable() |
EventSet::writable(),
PollOpt::oneshot()));
self.net.send_to(&[io::NetEvent::Cluster(self.cluster.clone())], &addr);
self.state = State::Connected;
match self.net.send_to(NetEvent::Cluster(self.cluster.clone()), addr) {
Ok(_) => self.state = State::Connected,
Err(err) => error!("Failed to connect: {}", err),
};
fn send_to(&self, events: &[NetEvent], addr: &SocketAddr) -> Option<usize>;
fn send_to_all(&self, events: &[NetEvent]) -> Option<usize>;
fn recv_from(&self) -> Option<(Vec<NetEvent>, SocketAddr)>;
fn send_to(&self, event: NetEvent, addr: &SocketAddr) -> io::Result<Option<()>>;
fn send_to_all(&self, event: NetEvent) -> io::Result<Option<()>>;
fn recv_from(&self) -> io::Result<Option<(NetEvent, SocketAddr)>>;
pub fn open(config: &'a Config) -> Self {
let socket = mio::udp::UdpSocket::v4().unwrap();
socket.set_multicast_loop(false).unwrap();
socket.join_multicast(&config.multicast_addr).unwrap();
socket.bind(&match config.server_addr {
mio::IpAddr::V4(addr) => net::SocketAddr::V4((net::SocketAddrV4::new(addr, config.port))),
mio::IpAddr::V6(addr) => net::SocketAddr::V6((net::SocketAddrV6::new(addr, config.port, 0, 0))),
}).unwrap();
pub fn open(config: &'a Config) -> io::Result<Self> {
let socket = try!(UdpSocket::v4());
try!(socket.set_multicast_loop(false));
try!(socket.join_multicast(&config.multicast_addr));
try!(socket.bind(&match config.server_addr {
IpAddr::V4(addr) => SocketAddr::V4((SocketAddrV4::new(addr, config.port))),
IpAddr::V6(addr) => SocketAddr::V6((SocketAddrV6::new(addr, config.port, 0, 0))),
}));
fn send_to(&self, events: &[io::NetEvent], addr: &net::SocketAddr) -> Option<usize> {
let id = self.out_packets.get();
let msg = serde_json::to_string(&(id, events)).unwrap();
debug!("=> {} {}", addr, msg);
match self.socket.send_to(msg.as_bytes(), &addr).unwrap() {
Some(size) => {
self.out_packets.set(id + 1);
Some(size)
},
None => {
error!("Failed to send: {}", msg);
None
},
fn send_to(&self, event: NetEvent, addr: &SocketAddr) -> io::Result<Option<()>> {
debug!("=> {} <= {:#?}", addr, event);
let packet = serde_json::to_vec(&event).unwrap();
match self.socket.send_to(&packet, addr) {
Ok(Some(_)) => Ok(Some(())),
Ok(None) => Err(io::Error::new(
io::ErrorKind::WouldBlock,
"The OS socket buffer is probably full"
)),
Err(err) => Err(err),
mio::IpAddr::V4(addr) => net::SocketAddr::V4((net::SocketAddrV4::new(addr, self.config.port))),
mio::IpAddr::V6(addr) => net::SocketAddr::V6((net::SocketAddrV6::new(addr, self.config.port, 0, 0))),
IpAddr::V4(addr) => SocketAddr::V4((SocketAddrV4::new(addr, self.config.port))),
IpAddr::V6(addr) => SocketAddr::V6((SocketAddrV6::new(addr, self.config.port, 0, 0))),
match self.socket.recv_from(&mut buf).unwrap() {
Some((len, addr)) => {
let msg = str::from_utf8(&buf[..len]).unwrap();
debug!("<= {} {}", addr, msg);
let (id, events): (usize, Vec<io::NetEvent>) = serde_json::from_str(msg).unwrap();
let expected_id = self.in_packets.get();
if id < expected_id {
warn!("^ out of sync packet");
} else {
if id > expected_id {
warn!("^ lost {} packets", id - expected_id)
}
self.in_packets.set(id + 1);
}
Some((events, addr))
match self.socket.recv_from(&mut buf) {
Ok(Some((len, addr))) => match serde_json::from_slice(&buf[..len]) {
Ok(event) => {
debug!("<= {} => {:#?}", addr, event);
Ok(Some((event, addr)))
},
Err(err) => Err(io::Error::new(io::ErrorKind::InvalidData, err)),
impl<'a> mio::Evented for IpInterface<'a> {
fn register(&self, selector: &mut mio::Selector, token: mio::Token, interest: mio::EventSet, opts: mio::PollOpt) -> ::std::io::Result<()> {
impl<'a> Evented for IpInterface<'a> {
fn register(&self, selector: &mut Selector, token: Token, interest: EventSet, opts: PollOpt) -> io::Result<()> {
fn reregister(&self, selector: &mut mio::Selector, token: mio::Token, interest: mio::EventSet, opts: mio::PollOpt) -> ::std::io::Result<()> {
fn reregister(&self, selector: &mut Selector, token: Token, interest: EventSet, opts: PollOpt) -> io::Result<()> {
fn recv_button_event(&self, event: xlib::XButtonEvent, state: bool) -> Option<io::HostEvent> {
Some(io::HostEvent::Button(io::ButtonEvent {
fn recv_button_event(&self, event: xlib::XButtonEvent, state: bool) -> Option<HostEvent> {
Some(HostEvent::Button(ButtonEvent {
io::HostEvent::Position(event) => self.send_position_event(event),
io::HostEvent::Motion(event) => self.send_motion_event(event),
io::HostEvent::Button(event) => self.send_button_event(event),
io::HostEvent::Key(event) => self.send_key_event(event),
HostEvent::Position(event) => self.send_position_event(event),
HostEvent::Motion(event) => self.send_motion_event(event),
HostEvent::Button(event) => self.send_button_event(event),
HostEvent::Key(event) => self.send_key_event(event),
impl mio::Evented for X11Interface {
fn register(&self, selector: &mut mio::Selector, token: mio::Token, interest: mio::EventSet, opts: mio::PollOpt) -> ::std::io::Result<()> {
impl Evented for X11Interface {
fn register(&self, selector: &mut Selector, token: Token, interest: EventSet, opts: PollOpt) -> io::Result<()> {
fn reregister(&self, selector: &mut mio::Selector, token: mio::Token, interest: mio::EventSet, opts: mio::PollOpt) -> ::std::io::Result<()> {
fn reregister(&self, selector: &mut Selector, token: Token, interest: EventSet, opts: PollOpt) -> io::Result<()> {