Struct stakker_mio::Ready
source · pub struct Ready(_);
Expand description
Readiness information from mio
See mio::event::Event
for an explanation of what these flags
mean.
Implementations§
source§impl Ready
impl Ready
sourcepub fn is_readable(&self) -> bool
pub fn is_readable(&self) -> bool
Examples found in repository?
examples/echo_server.rs (line 181)
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
fn ready(&mut self, cx: CX![], ready: Ready) {
if ready.is_readable() {
loop {
match self.tcp.read(8192) {
ReadStatus::NewData => {
let data = self.tcp.inp[self.tcp.rd..self.tcp.wr].to_vec();
self.tcp.rd = self.tcp.wr;
self.check_special_chars(cx, &data);
after!(Duration::from_secs(1), [cx], send_data(data));
continue;
}
ReadStatus::WouldBlock => (),
ReadStatus::EndOfStream => {
after!(Duration::from_secs(1), [cx], send_eof());
}
ReadStatus::Error(e) => {
fail!(cx, "Read failure on TCP stream: {}", e);
}
}
break;
}
}
if ready.is_writable() {
self.flush(cx);
}
}
sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Examples found in repository?
examples/echo_server.rs (line 203)
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
fn ready(&mut self, cx: CX![], ready: Ready) {
if ready.is_readable() {
loop {
match self.tcp.read(8192) {
ReadStatus::NewData => {
let data = self.tcp.inp[self.tcp.rd..self.tcp.wr].to_vec();
self.tcp.rd = self.tcp.wr;
self.check_special_chars(cx, &data);
after!(Duration::from_secs(1), [cx], send_data(data));
continue;
}
ReadStatus::WouldBlock => (),
ReadStatus::EndOfStream => {
after!(Duration::from_secs(1), [cx], send_eof());
}
ReadStatus::Error(e) => {
fail!(cx, "Read failure on TCP stream: {}", e);
}
}
break;
}
}
if ready.is_writable() {
self.flush(cx);
}
}