Guest User

Untitled

a guest
Mar 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. extern crate tokio_core;
  2. extern crate mio;
  3.  
  4. use mio::*;
  5. use std::io;
  6. use mio::unix::*;
  7. use std::net::TcpListener;
  8. use std::os::unix::prelude::*;
  9. use tokio_core::reactor::{Core, PollEvented};
  10.  
  11. fn main() {
  12. let a = Core::new().unwrap();
  13. let b = Core::new().unwrap();
  14.  
  15. let l = TcpListener::bind("127.0.0.1:0").unwrap();
  16.  
  17. println!("{:?}", PollEvented::new(Custom(l.as_raw_fd()), &a.handle()));
  18. println!("{:?}", PollEvented::new(Custom(l.as_raw_fd()), &b.handle()));
  19. }
  20.  
  21. #[derive(Debug)]
  22. struct Custom(i32);
  23.  
  24. impl Evented for Custom {
  25. fn register(&self, poll: &Poll, token: Token, events: Ready, opts: PollOpt) -> io::Result<()> {
  26. EventedFd(&self.0).register(poll, token, events, opts)
  27. }
  28. fn reregister(&self, poll: &Poll, token: Token, events: Ready, opts: PollOpt) -> io::Result<()> {
  29. EventedFd(&self.0).reregister(poll, token, events, opts)
  30. }
  31. fn deregister(&self, poll: &Poll) -> io::Result<()> {
  32. EventedFd(&self.0).deregister(poll)
  33. }
  34. }
Add Comment
Please, Sign In to add comment