Created
October 16, 2014 17:08
-
-
Save cpq/d172f3ee8e872a544f23 to your computer and use it in GitHub Desktop.
Callback APIs
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
| // 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