0

I have this server using mongoose, which take some request, parse the informations, do an action and return the result.

For exemple, I can query it this way server:port/action?arg1=test&arg2=...

My problem is that any time I query the server I get only "MG_OPEN_FILE" events. And for each request I get 3 of them.

I read that it may be normal to have some in http queries but the problem here is that I don't have any "MG_NEW_REQUEST" events.

Basically, whenever I start the server, the first connection (and all of them after) always returns the following events: MG_OPEN_FILE

MG_OPEN_FILE

MG_OPEN_FILE

MG_REQUEST_COMPLETE

I call my server this way :

int main(int argc, char* argv[]) {
  struct mg_context *ctx;
  const char *options[] = {"listening_ports", "8080", "num_threads","10",  NULL};
  ctx = mg_start(&callback, NULL, options);
  while(1){  
      getchar(); // Wait until user hits "enter"
  }
  mg_stop(ctx);
  return 0;
}

And the callback function starts with :

static void *callback(enum mg_event event, struct mg_connection *conn)
{

const struct mg_request_info *request_info = mg_get_request_info(conn);
if (event == MG_NEW_REQUEST)
{

But it is always a "MG_OPEN_FILE" event and I have no clue of the reason :( So if anyone has any idea on the reason of this, I would be extremely thankful !

Mark Nottingham
  • 5,546
  • 1
  • 25
  • 21

2 Answers2

1

When you're getting MG_OPEN_FILE, check (char *) mg_get_request_info(conn)->ev_data It contains file name mongoose wants to open. If you have that file in memory, return it's data and size. If you don't, return NULL.

valenok
  • 827
  • 7
  • 9
0

Is your callback returning that you procssed the event? I only return "yes" if I process the event.

Brian S
  • 3,096
  • 37
  • 55