Skip to content

Instantly share code, notes, and snippets.

@cpq
Created October 16, 2014 17:08
Show Gist options
  • Select an option

  • Save cpq/d172f3ee8e872a544f23 to your computer and use it in GitHub Desktop.

Select an option

Save cpq/d172f3ee8e872a544f23 to your computer and use it in GitHub Desktop.
Callback APIs
// Task: user needs to set up a simple HTTP server
// Option 1
static void my_handler(struct ns_connection *nc, int ev, void *ev_data) {
switch (ev) {
case NS_HTTP_REQUEST:
mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n hi there!! ");
nc->flags |= NSF_FINISHED_SENDING_DATA; // Schedule connection close
break;
default: // We can catch low-level events like NS_RECV, etc
break;
}
}
ns_bind_http(&mgr, "8000", my_handler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment