2014-09-10 06:23:29 +08:00
|
|
|
// Copyright (c) 2014 Cesanta Software
|
|
|
|
// All rights reserved
|
|
|
|
//
|
|
|
|
// This example demostrates how to send arbitrary files to the client.
|
|
|
|
|
2014-01-14 21:16:58 +08:00
|
|
|
#include "mongoose.h"
|
|
|
|
|
2014-06-04 01:03:13 +08:00
|
|
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
|
|
|
switch (ev) {
|
|
|
|
case MG_REQUEST:
|
2014-09-10 06:23:29 +08:00
|
|
|
mg_send_file(conn, "send_file.c"); // Also could be a directory, or CGI file
|
2014-06-04 01:03:13 +08:00
|
|
|
return MG_MORE; // It is important to return MG_MORE after mg_send_file!
|
|
|
|
case MG_AUTH: return MG_TRUE;
|
|
|
|
default: return MG_FALSE;
|
2014-01-14 21:16:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
2014-06-04 01:03:13 +08:00
|
|
|
struct mg_server *server = mg_create_server(NULL, ev_handler);
|
2014-01-14 21:16:58 +08:00
|
|
|
mg_set_option(server, "listening_port", "8080");
|
|
|
|
|
|
|
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
2014-06-04 01:03:13 +08:00
|
|
|
for (;;) mg_poll_server(server, 1000);
|
2014-01-14 21:16:58 +08:00
|
|
|
mg_destroy_server(&server);
|
|
|
|
|
|
|
|
return 0;
|
2014-09-10 06:23:29 +08:00
|
|
|
}
|