Guest User

Untitled

a guest
May 20th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. extern crate mio;
  2. extern crate slab;
  3.  
  4. use mio::Poll;
  5. use slab::Slab;
  6.  
  7. fn main() {
  8. let server = Server::new();
  9. server.example();
  10. }
  11.  
  12. struct Server {
  13. poll: Poll,
  14. conns: Slab<Connection>,
  15. }
  16.  
  17. impl Server {
  18. pub fn new() -> Server {
  19. let poll = Poll::new().expect("failed to create poll");
  20. Server {
  21. poll,
  22. conns: Slab::with_capacity(1000),
  23. }
  24. }
  25.  
  26. pub fn example(&self) {
  27. let conn = Connection::new(&mut self.poll, 0);
  28. }
  29. }
  30.  
  31. struct Connection {
  32. poll: &mut Poll,
  33. // sock ...
  34. // addr ...
  35. x: u8,
  36. }
  37.  
  38. impl Connection {
  39. pub fn new(poll: &mut Poll, x: u8) -> Connection {
  40. Connection { poll, x }
  41. }
  42. }
Add Comment
Please, Sign In to add comment