Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
scaprile committed Mar 11, 2024
1 parent 39f3a38 commit 4f89183
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
9 changes: 5 additions & 4 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -4869,16 +4869,14 @@ void mg_mgr_init(struct mg_mgr *mgr) {
// Ignore SIGPIPE signal, so if client cancels the request, it
// won't kill the whole process.
signal(SIGPIPE, SIG_IGN);
#elif MG_ENABLE_TCPIP && MG_ENABLE_TCPIP_DRIVER_INIT
mg_tcpip_auto_init();
#endif
mgr->pipe = MG_INVALID_SOCKET;
mgr->dnstimeout = 3000;
mgr->dns4.url = "udp://8.8.8.8:53";
mgr->dns6.url = "udp://[2001:4860:4860::8888]:53";
mg_tls_ctx_init(mgr);

#if (MG_ENABLE_DRIVER_INIT == 1) && defined(MG_TCPIP_DRIVER_INIT)
MG_TCPIP_DRIVER_INIT(mgr);
#endif
}

#ifdef MG_ENABLE_LINES
Expand Down Expand Up @@ -6011,6 +6009,9 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
}
return res;
}

void mg_tcpip_auto_init(void) {}

#endif // MG_ENABLE_TCPIP

#ifdef MG_ENABLE_LINES
Expand Down
13 changes: 7 additions & 6 deletions mongoose.h
Original file line number Diff line number Diff line change
Expand Up @@ -833,20 +833,20 @@ struct timeval {
#define MG_ENABLE_PROFILE 0
#endif

#ifndef MG_ENABLE_DRIVER_INIT
#define MG_ENABLE_DRIVER_INIT 1
#endif
#ifndef MG_ENABLE_TCPIP_DRIVER_INIT // mg_mgr_init() will also initialize
#define MG_ENABLE_TCPIP_DRIVER_INIT 0 // enabled built-in driver for
#endif // Mongoose built-in network stack

#ifndef MG_TCPIP_IP
#define MG_TCPIP_IP 0
#define MG_TCPIP_IP mg_htonl(MG_U32(0, 0, 0, 0))
#endif

#ifndef MG_TCPIP_MASK
#define MG_TCPIP_MASK 0
#define MG_TCPIP_MASK mg_htonl(MG_U32(255, 255, 255, 0))
#endif

#ifndef MG_TCPIP_GW
#define MG_TCPIP_GW 0
#define MG_TCPIP_GW mg_htonl(MG_U32(0, 0, 0, 1))
#endif

#define MG_MAC_ADDRESS_RANDOM \
Expand Down Expand Up @@ -2786,6 +2786,7 @@ struct mg_tcpip_if {
#define MG_TCPIP_STATE_READY 3 // Interface is up and has an IP assigned
};

void mg_tcpip_auto_init(void);
void mg_tcpip_init(struct mg_mgr *, struct mg_tcpip_if *);
void mg_tcpip_free(struct mg_tcpip_if *);
void mg_tcpip_qwrite(void *buf, size_t len, struct mg_tcpip_if *ifp);
Expand Down
12 changes: 6 additions & 6 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@
#define MG_ENABLE_PROFILE 0
#endif

#ifndef MG_ENABLE_DRIVER_INIT
#define MG_ENABLE_DRIVER_INIT 1
#endif
#ifndef MG_ENABLE_TCPIP_DRIVER_INIT // mg_mgr_init() will also initialize
#define MG_ENABLE_TCPIP_DRIVER_INIT 0 // enabled built-in driver for
#endif // Mongoose built-in network stack

#ifndef MG_TCPIP_IP
#define MG_TCPIP_IP 0
#define MG_TCPIP_IP mg_htonl(MG_U32(0, 0, 0, 0))
#endif

#ifndef MG_TCPIP_MASK
#define MG_TCPIP_MASK 0
#define MG_TCPIP_MASK mg_htonl(MG_U32(255, 255, 255, 0))
#endif

#ifndef MG_TCPIP_GW
#define MG_TCPIP_GW 0
#define MG_TCPIP_GW mg_htonl(MG_U32(0, 0, 0, 1))
#endif

#define MG_MAC_ADDRESS_RANDOM \
Expand Down
6 changes: 2 additions & 4 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,12 @@ void mg_mgr_init(struct mg_mgr *mgr) {
// Ignore SIGPIPE signal, so if client cancels the request, it
// won't kill the whole process.
signal(SIGPIPE, SIG_IGN);
#elif MG_ENABLE_TCPIP && MG_ENABLE_TCPIP_DRIVER_INIT
mg_tcpip_auto_init();
#endif
mgr->pipe = MG_INVALID_SOCKET;
mgr->dnstimeout = 3000;
mgr->dns4.url = "udp://8.8.8.8:53";
mgr->dns6.url = "udp://[2001:4860:4860::8888]:53";
mg_tls_ctx_init(mgr);

#if (MG_ENABLE_DRIVER_INIT == 1) && defined(MG_TCPIP_DRIVER_INIT)
MG_TCPIP_DRIVER_INIT(mgr);
#endif
}
3 changes: 3 additions & 0 deletions src/net_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,4 +1125,7 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
}
return res;
}

void mg_tcpip_auto_init(void) {}

#endif // MG_ENABLE_TCPIP
1 change: 1 addition & 0 deletions src/net_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct mg_tcpip_if {
#define MG_TCPIP_STATE_READY 3 // Interface is up and has an IP assigned
};

void mg_tcpip_auto_init(void);
void mg_tcpip_init(struct mg_mgr *, struct mg_tcpip_if *);
void mg_tcpip_free(struct mg_tcpip_if *);
void mg_tcpip_qwrite(void *buf, size_t len, struct mg_tcpip_if *ifp);
Expand Down

0 comments on commit 4f89183

Please sign in to comment.