-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fossa/examples/simplest_web_server
PUBLISHED_FROM=e7abf85ffa002279f9bf33cc80de9c1d163f4006
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
PROG = simplest_web_server | ||
SOURCES = $(PROG).c ../../fossa.c | ||
CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) | ||
|
||
all: $(PROG) | ||
|
||
$(PROG): $(SOURCES) | ||
$(CC) $(SOURCES) -o $@ $(CFLAGS) | ||
|
||
$(PROG).exe: $(SOURCES) | ||
cl $(SOURCES) /I../.. /MD /Fe$@ | ||
|
||
clean: | ||
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2015 Cesanta Software Limited | ||
// All rights reserved | ||
|
||
#include "fossa.h" | ||
|
||
static const char *s_http_port = "8000"; | ||
static struct ns_serve_http_opts s_http_server_opts; | ||
|
||
static void ev_handler(struct ns_connection *nc, int ev, void *p) { | ||
if (ev == NS_HTTP_REQUEST) { | ||
ns_serve_http(nc, p, s_http_server_opts); | ||
} | ||
} | ||
|
||
int main(void) { | ||
struct ns_mgr mgr; | ||
struct ns_connection *nc; | ||
|
||
ns_mgr_init(&mgr, NULL); | ||
nc = ns_bind(&mgr, s_http_port, ev_handler); | ||
|
||
// Set up HTTP server parameters | ||
ns_set_protocol_http_websocket(nc); | ||
s_http_server_opts.document_root = "."; // Serve current directory | ||
s_http_server_opts.enable_directory_listing = "yes"; | ||
|
||
printf("Starting web server on port %s\n", s_http_port); | ||
for (;;) { | ||
ns_mgr_poll(&mgr, 1000); | ||
} | ||
ns_mgr_free(&mgr); | ||
|
||
return 0; | ||
} |