Skip to content

Instantly share code, notes, and snippets.

@aep
Created July 16, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aep/6241e20ffb9cd68540e5cf72abd11b9d to your computer and use it in GitHub Desktop.
Save aep/6241e20ffb9cd68540e5cf72abd11b9d to your computer and use it in GitHub Desktop.
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