Merge dev branch code named Fossa as next stable Mongoose

This commit is contained in:
Marko Mikulicic committed 2015-09-08 14:34:30 +02:00
1 parent 28eb251ccd
commit 8927c9d22b
126 files changed
+162049 -8502

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
PROG = restful_client
SOURCES = $(PROG).c ../../mongoose.c
CFLAGS = -W -Wall -I../.. -pthread $(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)
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2014 Cesanta Software Limited
* All rights reserved
*/
#include "mongoose.h"
/* RESTful server host and request URI */
static const char *s_target_address = "ajax.googleapis.com:80";
static const char *s_request = "/ajax/services/search/web?v=1.0&q=cesanta";
static int s_exit_flag = 0;
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message *hm = (struct http_message *) ev_data;
int connect_status;
switch (ev) {
case NS_CONNECT:
connect_status = * (int *) ev_data;
if (connect_status == 0) {
printf("Connected to %s, sending request...\n", s_target_address);
mg_printf(nc, "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n",
s_request, s_target_address);
} else {
printf("Error connecting to %s: %s\n",
s_target_address, strerror(connect_status));
s_exit_flag = 1;
}
break;
case NS_HTTP_REPLY:
printf("Got reply:\n%.*s\n", (int) hm->body.len, hm->body.p);
nc->flags |= NSF_SEND_AND_CLOSE;
s_exit_flag = 1;
break;
default:
break;
}
}
int main(void) {
struct mg_mgr mgr;
struct mg_connection *nc;
mg_mgr_init(&mgr, NULL);
nc = mg_connect(&mgr, s_target_address, ev_handler);
mg_set_protocol_http_websocket(nc);
printf("Starting RESTful client against %s\n", s_target_address);
while (s_exit_flag == 0) {
mg_mgr_poll(&mgr, 1000);
}
mg_mgr_free(&mgr);
return 0;
}