Hi all.
I'm trying to add webserver functionality to a GUI project, with some
success, but after about three minutes of inacitvity it the server stops
responding to new connections.
I can have two client apps running, sending GET requests to localhost:8080
ten times a second and the server continues to respond for hours. If I
close one app and restart it then it gets no response (although the app I
left running still gets responses)
The server is running in it's own boost::thread.
As an experiment I have tried running a simple console server app (with
MSVC++ 2010 Express) using the following hello world example:
#include "stdafx.h"
#include <string.h>#include "mongoose.h"
static int event_handler(struct mg_connection *conn, enum mg_event ev) {
if (ev == MG_AUTH) {
return MG_TRUE; // Authorize all requests
} else if (ev == MG_REQUEST && !strcmp(conn->uri, "/hello")) {
mg_printf_data(conn, "%s", "Hello world");
return MG_TRUE; // Mark as processed
} else {
return MG_FALSE; // Rest of the events are not processed
}
}
int main(void) {
struct mg_server *server = mg_create_server(NULL, event_handler);
mg_set_option(server, "document_root", ".");
mg_set_option(server, "listening_port", "8080");
for (;;) {
mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop
}
mg_destroy_server(&server);
return 0;
}
This gives the same result...
Using Firefox I'm going to "localhost:8080/hello" and receiving the "Hello
World" as expected, and this continues each time I reload the page. If
however I wait more than three minutes between reloads I get "Page not
found" displayed.
With the server app in debug mode I can set a breakpoint at
mg_poll_server(...); and it breaks there once a second, so the infinite
loop is still looping.
Before it stops responding, setting a breakpoint in the event_handler I can
pick up ev == MG_AUTH and ev == MG_REQUEST followed by ev == MG_POLL about
120 times before ev == MG_CLOSE
Reloading the page will still work after this, but not if I wait too long!
Once the server has stopped responding the breakpoint in event_handler
never gets reached.
I'd really appreciate it if anyone can help me out with some advice.
Many thanks.
Ian.
--
You received this message because you are subscribed to the Google Groups
"mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/d/optout.