mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-24 11:54:49 +00:00
Move mip/ -> src/tcpip/, rename mip_ -> mg_tcpip_
This commit is contained in:
1 parent
efc54375dd
commit
2c62e58dbd
64 files changed
+515
-516
No files matched your search
+5
-5
@@ -1,21 +1,21 @@
|
||||
static bool mock_init(struct mip_if *ifp) {
|
||||
static bool mock_init(struct mg_tcpip_if *ifp) {
|
||||
(void) ifp;
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t mock_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t mock_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
(void) buf, (void) len, (void) ifp;
|
||||
return len;
|
||||
}
|
||||
|
||||
static size_t mock_rx(void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t mock_rx(void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
(void) buf, (void) len, (void) ifp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool mock_up(struct mip_if *ifp) {
|
||||
static bool mock_up(struct mg_tcpip_if *ifp) {
|
||||
(void) ifp;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct mip_driver mip_driver_mock = {mock_init, mock_tx, mock_rx, mock_up};
|
||||
struct mg_tcpip_driver mg_tcpip_driver_mock = {mock_init, mock_tx, mock_rx, mock_up};
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
#define MG_ENABLE_SOCKET 0
|
||||
#define MG_ENABLE_LOG 0
|
||||
#define MG_ENABLE_LINES 1
|
||||
#define MG_ENABLE_MIP 1
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
|
||||
#include "mongoose.c"
|
||||
|
||||
@@ -58,13 +58,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
mg_json_get(mg_str_n((char *) data, size), "$[0]", &n);
|
||||
|
||||
if (size > 0) {
|
||||
struct mip_if mif = {.ip = 0x01020304,
|
||||
struct mg_tcpip_if mif = {.ip = 0x01020304,
|
||||
.mask = 255,
|
||||
.gw = 0x01010101,
|
||||
.driver = &mip_driver_mock};
|
||||
.driver = &mg_tcpip_driver_mock};
|
||||
struct mg_mgr mgr;
|
||||
mg_mgr_init(&mgr);
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
|
||||
// Make a copy of the random data, in order to modify it
|
||||
void *pkt = malloc(size);
|
||||
@@ -78,7 +78,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (i >= sizeof(eth_types) / sizeof(eth_types[0])) i = 0;
|
||||
}
|
||||
|
||||
mip_rx(&mif, pkt, size);
|
||||
mg_tcpip_rx(&mif, pkt, size);
|
||||
mg_mgr_free(&mgr);
|
||||
free(pkt);
|
||||
free((char *) mif.rx.ptr);
|
||||
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
#define MG_ENABLE_MIP 1
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_SOCKET 0
|
||||
#define MG_USING_DHCP 1
|
||||
#define MG_ENABLE_PACKED_FS 0
|
||||
@@ -30,14 +30,14 @@ static int s_num_tests = 0;
|
||||
} while (0)
|
||||
|
||||
// MIP TUNTAP driver
|
||||
static size_t tap_rx(void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t tap_rx(void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
ssize_t received = read(*(int *) ifp->driver_data, buf, len);
|
||||
usleep(1); // This is to avoid 100% CPU
|
||||
if (received < 0) return 0;
|
||||
return (size_t) received;
|
||||
}
|
||||
|
||||
static size_t tap_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
static size_t tap_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
ssize_t res = write(*(int *) ifp->driver_data, buf, len);
|
||||
if (res < 0) {
|
||||
MG_ERROR(("tap_tx failed: %d", errno));
|
||||
@@ -46,7 +46,7 @@ static size_t tap_tx(const void *buf, size_t len, struct mip_if *ifp) {
|
||||
return (size_t) res;
|
||||
}
|
||||
|
||||
static bool tap_up(struct mip_if *ifp) {
|
||||
static bool tap_up(struct mg_tcpip_if *ifp) {
|
||||
return ifp->driver_data ? true : false;
|
||||
}
|
||||
|
||||
@@ -161,14 +161,14 @@ static void test_http_fetch(void) {
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
|
||||
// MIP driver
|
||||
struct mip_driver driver;
|
||||
struct mg_tcpip_driver driver;
|
||||
memset(&driver, 0, sizeof(driver));
|
||||
|
||||
driver.tx = tap_tx;
|
||||
driver.up = tap_up;
|
||||
driver.rx = tap_rx;
|
||||
|
||||
struct mip_if mif;
|
||||
struct mg_tcpip_if mif;
|
||||
memset(&mif, 0, sizeof(mif));
|
||||
|
||||
mif.driver = &driver;
|
||||
@@ -184,7 +184,7 @@ static void test_http_fetch(void) {
|
||||
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mif.mac[0], &mif.mac[1],
|
||||
&mif.mac[2], &mif.mac[3], &mif.mac[4], &mif.mac[5]);
|
||||
|
||||
mip_init(&mgr, &mif);
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
MG_INFO(("Init done, starting main loop"));
|
||||
|
||||
// Stack initialization, Network configuration (DHCP lease, ...)
|
||||
@@ -236,7 +236,7 @@ static void test_http_fetch(void) {
|
||||
|
||||
// Clear
|
||||
mg_mgr_free(&mgr);
|
||||
mip_free(&mif); // Release after mg_mgr
|
||||
mg_tcpip_free(&mif); // Release after mg_mgr
|
||||
ASSERT(mgr.conns == NULL); // Deconstruction OK
|
||||
close(fd);
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
#define MG_ENABLE_SOCKET 0
|
||||
#define MG_ENABLE_LINES 1
|
||||
#define MG_ENABLE_MIP 1
|
||||
#define MG_ENABLE_TCPIP 1
|
||||
#define MG_ENABLE_PACKED_FS 0
|
||||
|
||||
#include <assert.h>
|
||||
@@ -50,12 +50,12 @@ static void test_queue(void) {
|
||||
|
||||
static void test_statechange(void) {
|
||||
char tx[1540];
|
||||
struct mip_if iface;
|
||||
struct mg_tcpip_if iface;
|
||||
memset(&iface, 0, sizeof(iface));
|
||||
iface.ip = mg_htonl(0x01020304);
|
||||
iface.state = MIP_STATE_READY;
|
||||
iface.tx.ptr = tx, iface.tx.len = sizeof(tx);
|
||||
iface.driver = &mip_driver_mock;
|
||||
iface.driver = &mg_tcpip_driver_mock;
|
||||
onstatechange(&iface);
|
||||
}
|
||||
|
||||
@@ -68,14 +68,14 @@ static void test_poll(void) {
|
||||
int count = 0, i;
|
||||
struct mg_mgr mgr;
|
||||
mg_mgr_init(&mgr);
|
||||
struct mip_if mif;
|
||||
struct mg_tcpip_if mif;
|
||||
memset(&mif, 0, sizeof(mif));
|
||||
mif.driver = &mip_driver_mock;
|
||||
mip_init(&mgr, &mif);
|
||||
mif.driver = &mg_tcpip_driver_mock;
|
||||
mg_tcpip_init(&mgr, &mif);
|
||||
mg_http_listen(&mgr, "http://127.0.0.1:12346", ph, &count);
|
||||
for (i = 0; i < 10; i++) mg_mgr_poll(&mgr, 0);
|
||||
ASSERT(count == 10);
|
||||
mip_free(&mif);
|
||||
mg_tcpip_free(&mif);
|
||||
mg_mgr_free(&mgr);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user