mirror of
https://github.com/cesanta/mongoose.git
synced 2025-06-11 12:14:41 +08:00
Mongoose examples fixes
PUBLISHED_FROM=b47a5b6987ee8d9e7c9bae2bd4d2943d2e7f76a9
This commit is contained in:
parent
ebdd18769b
commit
17cfecc5c3
@ -1,4 +1,3 @@
|
|||||||
PROG = captive_dns_server
|
PROG = captive_dns_server
|
||||||
MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER -DMG_ENABLE_IPV6
|
MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER -DMG_ENABLE_IPV6
|
||||||
SSL_LIB=openssl
|
|
||||||
include ../examples.mk
|
include ../examples.mk
|
||||||
|
@ -36,9 +36,15 @@ static void server_handler(struct mg_connection *nc, int ev, void *p) {
|
|||||||
struct mg_connection *c;
|
struct mg_connection *c;
|
||||||
|
|
||||||
for (c = mg_next(nc->mgr, NULL); c != NULL; c = mg_next(nc->mgr, c)) {
|
for (c = mg_next(nc->mgr, NULL); c != NULL; c = mg_next(nc->mgr, c)) {
|
||||||
|
if (!(c->flags |= MG_F_USER_2)) continue; // Skip non-client connections
|
||||||
mg_send(c, io->buf, io->len);
|
mg_send(c, io->buf, io->len);
|
||||||
}
|
}
|
||||||
mbuf_remove(io, io->len);
|
mbuf_remove(io, io->len);
|
||||||
|
} else if (ev == MG_EV_ACCEPT) {
|
||||||
|
char addr[32];
|
||||||
|
mg_sock_addr_to_str(p, addr, sizeof(addr),
|
||||||
|
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
|
||||||
|
printf("New client connected from %s\n", addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +93,7 @@ int main(int argc, char *argv[]) {
|
|||||||
fprintf(stderr, "Cannot connect to port %s\n", argv[1]);
|
fprintf(stderr, "Cannot connect to port %s\n", argv[1]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
server_conn->flags |= MG_F_USER_2; // Mark this as a client connection
|
||||||
|
|
||||||
// Create a socketpair and give one end to the thread that reads stdin
|
// Create a socketpair and give one end to the thread that reads stdin
|
||||||
mg_socketpair(fds, SOCK_STREAM);
|
mg_socketpair(fds, SOCK_STREAM);
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "mongoose.h"
|
|
||||||
#include "../../../slre/slre.h"
|
#include "../../../slre/slre.h"
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static const char *initial_url = "http://test.mosquitto.org";
|
||||||
static const char *regex = "href=\"((https?://)[^\\s/'\"<>]+/?[^\\s'\"<>]*)";
|
static const char *regex = "href=\"((https?://)[^\\s/'\"<>]+/?[^\\s'\"<>]*)";
|
||||||
const int max_depth = 2;
|
const int max_depth = 2;
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ int main(void) {
|
|||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
mg_mgr_init(&mgr, NULL);
|
||||||
crawl_page(&mgr, "http://www.simpleweb.org/", ~0, 0);
|
crawl_page(&mgr, initial_url, ~0, 0);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
mg_mgr_poll(&mgr, 1000);
|
mg_mgr_poll(&mgr, 1000);
|
||||||
@ -69,7 +70,12 @@ void crawl_page(struct mg_mgr *mgr, const char *url, size_t url_len,
|
|||||||
data->depth = depth;
|
data->depth = depth;
|
||||||
|
|
||||||
nc = mg_connect_http(mgr, event_handler, url, NULL, NULL);
|
nc = mg_connect_http(mgr, event_handler, url, NULL, NULL);
|
||||||
nc->user_data = data;
|
if (nc != NULL) {
|
||||||
|
nc->user_data = data;
|
||||||
|
} else {
|
||||||
|
printf("Error connecting to [%s]\n", url);
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_reply(struct mg_connection *nc, struct http_message *hm) {
|
void handle_reply(struct mg_connection *nc, struct http_message *hm) {
|
||||||
|
Loading…
Reference in New Issue
Block a user