summaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorMarc Lasch <mlasch@mailbox.org>2015-08-11 15:13:25 +0200
committerMarc Lasch <mlasch@mailbox.org>2015-08-11 15:13:25 +0200
commit9f7530aa40c4197a8c1979b37baab43ba2e6205f (patch)
treebd60be0948ea1b3895c49a096dfeb50bf5c84d69 /src/server.cpp
downloadnetgraph-9f7530aa40c4197a8c1979b37baab43ba2e6205f.tar.gz
netgraph-9f7530aa40c4197a8c1979b37baab43ba2e6205f.zip
hello world test for mongoose
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/server.cpp b/src/server.cpp
new file mode 100644
index 0000000..222e8ea
--- /dev/null
+++ b/src/server.cpp
@@ -0,0 +1,34 @@
+#include <iostream>
+#include <string>
+#include "mongoose.h"
+
+using namespace std;
+
+int event_handler(struct mg_connection *conn, enum mg_event ev) {
+ switch (ev) {
+ case MG_AUTH: return MG_TRUE;
+ case MG_REQUEST:
+ if (conn->uri) {
+ cout<<conn->request_method<<" "<<conn->uri<<endl;
+ } else return MG_FALSE;
+ default: return MG_FALSE;
+ }
+}
+
+int main(int argc, char **argv) {
+ string server_port = "8080";
+
+ struct mg_server *server = mg_create_server(NULL, event_handler);
+
+ mg_set_option(server, "document_root", "./www/");
+ mg_set_option(server, "listening_port", server_port.c_str());
+
+ cout<<"Staring server on port "<<server_port<<"."<<endl;
+ while (true) {
+ mg_poll_server(server, 1000);
+ }
+
+ mg_destroy_server(&server);
+
+ return 0;
+}