Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <microhttpd.h>
- static int dh(void *cls, struct MHD_Connection *con, const char *url, const char *method, const char *version,
- const char *upload_data, size_t *upload_data_size, void **con_cls) {
- const char *page = "<html><body>I love MHD!</body></html>";
- struct MHD_Response *response;
- int ret;
- if (NULL != *con_cls) {
- *con_cls = (void *) 1;
- return MHD_YES;
- }
- /* simulating a long processing, like hard query in a database ... */
- unsigned char i = 1;
- while (i < 100) {
- sleep(1);
- i++;
- }
- response = MHD_create_response_from_buffer(strlen(page), (void *) page, MHD_RESPMEM_PERSISTENT);
- ret = MHD_queue_response(con, MHD_HTTP_OK, response);
- MHD_destroy_response(response);
- return ret;
- }
- int main() {
- struct MHD_Daemon *d;
- MHD_socket fd;
- d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_ITC | MHD_USE_DEBUG, 8080, NULL, NULL, &dh, NULL,
- /* MHD_OPTION_CONNECTION_TIMEOUT, unsigned int 5, no need because I'm simulating a really busy client ... */
- MHD_OPTION_END);
- getchar();
- fd = MHD_quiesce_daemon(d);
- if (fd != MHD_INVALID_SOCKET)
- close(fd);
- else
- fprintf(stderr, "Server quiesce failed.\n");
- MHD_stop_daemon(d);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement