pub struct Producer<T: Copy> { /* private fields */ }Implementations§
Source§impl<T: Copy> Producer<T>
impl<T: Copy> Producer<T>
Sourcepub fn current_message(&mut self) -> &mut T
pub fn current_message(&mut self) -> &mut T
Examples found in repository?
examples/client.rs (line 84)
80 pub fn run(&mut self, cmds: &[MsgCommand]) {
81 let pause = time::Duration::from_millis(10);
82
83 for cmd in cmds {
84 self.command.current_message().clone_from(cmd);
85 self.command.force_push();
86
87 loop {
88 match self.response.pop() {
89 ConsumeResult::QueueError => panic!(),
90 ConsumeResult::NoMessage => {
91 thread::sleep(pause);
92 continue;
93 }
94 ConsumeResult::NoNewMessage => {
95 thread::sleep(pause);
96 continue;
97 }
98 ConsumeResult::Success => {}
99 ConsumeResult::SuccessMessagesDiscarded => {}
100 };
101
102 println!(
103 "client received response: {}",
104 self.response.current_message().unwrap()
105 );
106 break;
107 }
108 }
109 thread::sleep(time::Duration::from_millis(100));
110 STOP_EVENT_LISTERNER.store(true, Ordering::Relaxed);
111 self.event_listener.take().map(|h| h.join());
112 }More examples
examples/server.rs (line 68)
53 fn run(&mut self) {
54 let mut run = true;
55 let mut cnt = 0;
56
57 while run {
58 let eventfd = self.command.eventfd().unwrap();
59 let _ = wait_pollin(eventfd, Duration::from_millis(10));
60 match self.command.pop() {
61 ConsumeResult::QueueError => panic!(),
62 ConsumeResult::NoMessage => continue,
63 ConsumeResult::NoNewMessage => continue,
64 ConsumeResult::Success => {}
65 ConsumeResult::SuccessMessagesDiscarded => {}
66 };
67 let cmd = self.command.current_message().unwrap();
68 self.response.current_message().id = cmd.id;
69 let args: [i32; 3] = cmd.args;
70 println!("server received command: {}", cmd);
71
72 let cmdid: CommandId = unsafe { ::std::mem::transmute(cmd.id) };
73 self.response.current_message().result = match cmdid {
74 CommandId::Hello => 0,
75 CommandId::Stop => {
76 run = false;
77 0
78 }
79 CommandId::SendEvent => {
80 self.send_events(args[0] as u32, args[1] as u32, args[2] != 0)
81 }
82 CommandId::Div => {
83 let (err, res) = self.div(args[0], args[1]);
84 self.response.current_message().data = res;
85 err
86 }
87 };
88 self.response.force_push();
89
90 cnt = cnt + 1;
91 }
92 }
93 fn send_events(&mut self, id: u32, num: u32, force: bool) -> i32 {
94 for i in 0..num {
95 let event = self.event.current_message();
96 event.id = id;
97 event.nr = i;
98 if force {
99 self.event.force_push();
100 } else {
101 if self.event.try_push() == ProduceTryResult::QueueFull {
102 return i as i32;
103 }
104 }
105 }
106 num as i32
107 }Sourcepub fn force_push(&mut self) -> ProduceForceResult
pub fn force_push(&mut self) -> ProduceForceResult
Examples found in repository?
examples/client.rs (line 85)
80 pub fn run(&mut self, cmds: &[MsgCommand]) {
81 let pause = time::Duration::from_millis(10);
82
83 for cmd in cmds {
84 self.command.current_message().clone_from(cmd);
85 self.command.force_push();
86
87 loop {
88 match self.response.pop() {
89 ConsumeResult::QueueError => panic!(),
90 ConsumeResult::NoMessage => {
91 thread::sleep(pause);
92 continue;
93 }
94 ConsumeResult::NoNewMessage => {
95 thread::sleep(pause);
96 continue;
97 }
98 ConsumeResult::Success => {}
99 ConsumeResult::SuccessMessagesDiscarded => {}
100 };
101
102 println!(
103 "client received response: {}",
104 self.response.current_message().unwrap()
105 );
106 break;
107 }
108 }
109 thread::sleep(time::Duration::from_millis(100));
110 STOP_EVENT_LISTERNER.store(true, Ordering::Relaxed);
111 self.event_listener.take().map(|h| h.join());
112 }More examples
examples/server.rs (line 88)
53 fn run(&mut self) {
54 let mut run = true;
55 let mut cnt = 0;
56
57 while run {
58 let eventfd = self.command.eventfd().unwrap();
59 let _ = wait_pollin(eventfd, Duration::from_millis(10));
60 match self.command.pop() {
61 ConsumeResult::QueueError => panic!(),
62 ConsumeResult::NoMessage => continue,
63 ConsumeResult::NoNewMessage => continue,
64 ConsumeResult::Success => {}
65 ConsumeResult::SuccessMessagesDiscarded => {}
66 };
67 let cmd = self.command.current_message().unwrap();
68 self.response.current_message().id = cmd.id;
69 let args: [i32; 3] = cmd.args;
70 println!("server received command: {}", cmd);
71
72 let cmdid: CommandId = unsafe { ::std::mem::transmute(cmd.id) };
73 self.response.current_message().result = match cmdid {
74 CommandId::Hello => 0,
75 CommandId::Stop => {
76 run = false;
77 0
78 }
79 CommandId::SendEvent => {
80 self.send_events(args[0] as u32, args[1] as u32, args[2] != 0)
81 }
82 CommandId::Div => {
83 let (err, res) = self.div(args[0], args[1]);
84 self.response.current_message().data = res;
85 err
86 }
87 };
88 self.response.force_push();
89
90 cnt = cnt + 1;
91 }
92 }
93 fn send_events(&mut self, id: u32, num: u32, force: bool) -> i32 {
94 for i in 0..num {
95 let event = self.event.current_message();
96 event.id = id;
97 event.nr = i;
98 if force {
99 self.event.force_push();
100 } else {
101 if self.event.try_push() == ProduceTryResult::QueueFull {
102 return i as i32;
103 }
104 }
105 }
106 num as i32
107 }Sourcepub fn try_push(&mut self) -> ProduceTryResult
pub fn try_push(&mut self) -> ProduceTryResult
Examples found in repository?
examples/server.rs (line 101)
93 fn send_events(&mut self, id: u32, num: u32, force: bool) -> i32 {
94 for i in 0..num {
95 let event = self.event.current_message();
96 event.id = id;
97 event.nr = i;
98 if force {
99 self.event.force_push();
100 } else {
101 if self.event.try_push() == ProduceTryResult::QueueFull {
102 return i as i32;
103 }
104 }
105 }
106 num as i32
107 }pub fn eventfd(&self) -> Option<BorrowedFd<'_>>
pub fn take_eventfd(&mut self) -> Option<EventFd>
pub fn enable_cache(&mut self)
pub fn disable_cache(&mut self)
Auto Trait Implementations§
impl<T> Freeze for Producer<T>
impl<T> RefUnwindSafe for Producer<T>where
T: RefUnwindSafe,
impl<T> Send for Producer<T>where
T: Send,
impl<T> !Sync for Producer<T>
impl<T> Unpin for Producer<T>where
T: Unpin,
impl<T> UnwindSafe for Producer<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more