X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-hsrv.c;h=f200a960e0bc89e9f3baf763c56bc0c6ab0aa394;hb=34acb0f8d191593c9761e027424f13ae42831133;hp=c58295a495402d24d2158ddf5ce6cc44f08a111e;hpb=56f9ef4581d567248b6f83a3b15f39a0aca42895;p=src%2Fapp-framework-binder.git diff --git a/src/afb-hsrv.c b/src/afb-hsrv.c index c58295a4..f200a960 100644 --- a/src/afb-hsrv.c +++ b/src/afb-hsrv.c @@ -65,19 +65,8 @@ struct afb_hsrv { static void reply_error(struct MHD_Connection *connection, unsigned int status) { - char *buffer; - int length; - struct MHD_Response *response; - - length = asprintf(&buffer, "error %u", status); - if (length > 0) - response = MHD_create_response_from_buffer((unsigned)length, buffer, MHD_RESPMEM_MUST_FREE); - else { - buffer = "error"; - response = MHD_create_response_from_buffer(strlen(buffer), buffer, MHD_RESPMEM_PERSISTENT); - } - if (!MHD_queue_response(connection, status, response)) - fprintf(stderr, "Failed to reply error code %u", status); + struct MHD_Response *response = MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT); + MHD_queue_response(connection, status, response); MHD_destroy_response(response); } @@ -214,6 +203,13 @@ static void end_handler(void *cls, struct MHD_Connection *connection, void **rec afb_hreq_free(hreq); } +static void handle_epoll_readable(struct afb_hsrv *hsrv) +{ + upoll_on_readable(hsrv->upoll, NULL); + MHD_run(hsrv->httpd); + upoll_on_readable(hsrv->upoll, (void*)handle_epoll_readable); +}; + static int new_client_handler(void *cls, const struct sockaddr *addr, socklen_t addrlen) { return MHD_YES; @@ -347,7 +343,7 @@ int afb_hsrv_start(struct afb_hsrv *hsrv, uint16_t port, unsigned int connection MHD_OPTION_END); /* options-end */ if (httpd == NULL) { - printf("Error: httpStart invalid httpd port: %d", (int)port); + fprintf(stderr, "Error: httpStart invalid httpd port: %d", (int)port); return 0; } @@ -358,13 +354,13 @@ int afb_hsrv_start(struct afb_hsrv *hsrv, uint16_t port, unsigned int connection return 0; } - upoll = upoll_open(info->listen_fd, httpd); + upoll = upoll_open(info->listen_fd, hsrv); if (upoll == NULL) { MHD_stop_daemon(httpd); fprintf(stderr, "Error: connection to upoll of httpd failed"); return 0; } - upoll_on_readable(upoll, (void*)MHD_run); + upoll_on_readable(upoll, (void*)handle_epoll_readable); hsrv->httpd = httpd; hsrv->upoll = upoll;