Created
July 16, 2020 13:54
-
-
Save aep/6241e20ffb9cd68540e5cf72abd11b9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct UdpLogger | |
{ | |
udp::Socket sock; | |
string::String+1000 buf; | |
udp::ReceiveEvent ev; | |
} | |
fn my_udp_logger_poll(UdpLogger mut*self, async::Eq mut*eq) | |
{ | |
switch self->ev.state() { | |
async::State::Parked => { | |
return; | |
}, | |
async::State::Error => { | |
ev->error.abort(); | |
return; | |
} | |
async::State::Ready => { | |
log::info("got %s", self->buf.mem); | |
} | |
async::State::Invalid => { | |
} | |
} | |
self->ev = self->sock.recv(self->buf.to_mut_slice()); | |
} | |
fn main() { | |
new eq = async::eventqueue(); | |
for (;;) { | |
my_udp_logger_poll(eq); | |
eq.wait(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment