Skip to content
Newer
Older
100644 71 lines (61 sloc) 2.26 KB
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored Sep 13, 2012
1 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 #include <arpa/inet.h>
17 #include <fcntl.h>
18 #include <stdlib.h>
19 #include <sys/select.h>
20 #include <sys/socket.h>
21 #include <sys/time.h>
22 #include <sys/types.h>
23 #include <stdarg.h>
24
25 #include <microhttpd.h>
26
27 #include "status-server.h"
28 #include "file-handler-cache.h"
29
30 int StatusServer::HandleHttp(void* user_argument,
31 struct MHD_Connection *connection,
32 const char *url, const char *method,
33 const char *version,
34 const char *upload_data, size_t *upload_size,
35 void**) {
36 StatusServer* server = (StatusServer*) user_argument;
37 struct MHD_Response *response;
38 int ret;
39 const char *buffer;
40 size_t size;
41 server->CreatePage(&buffer, &size);
42 response = MHD_create_response_from_data(size, (void*) buffer,
43 MHD_NO, MHD_NO);
44 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
45 MHD_destroy_response(response);
46 return ret;
47 }
48
49 StatusServer::StatusServer(FileHandlerCache *cache)
50 : cache_(cache), daemon_(NULL) {
51 }
52
53 bool StatusServer::Start(int port) {
54 daemon_ = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, port, NULL, NULL,
55 &HandleHttp, this,
56 MHD_OPTION_END);
57 return daemon_ != NULL;
58 }
59
60 StatusServer::~StatusServer() {
61 if (daemon_)
62 MHD_stop_daemon(daemon_);
63 }
64
65
66 void StatusServer::CreatePage(const char **buffer, size_t *size) {
67 current_page_ = "Hello World";
68 *buffer = current_page_.data();
69 *size = current_page_.size();
70 }
Something went wrong with that request. Please try again.