Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created April 6, 2012 12:40
Show Gist options
  • Save piscisaureus/2319370 to your computer and use it in GitHub Desktop.
Save piscisaureus/2319370 to your computer and use it in GitHub Desktop.
static ev_io watcher;
static void stdin_cb (EV_P_ ev_io *w, int revents) {
puts("you can now read some data");
ev_io_stop(&watcher);
}
int main() {
...
ev_io_init(&watcher, read_cb, fd, EV_READ);
ev_io_start(loop, &watcher);
ev_run();
return 0;
}
----
uv_tcp_t stream;
void on_data(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
puts("we received: ");
write(1, buf.base, nread);
}
int main() {
uv_tcp_init(uv_default_loop(), &stream);
...
uv_read_start(&stream);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment