Merge pull request #2987 from cesanta/ifp

mgr::priv -> mgr::ifp, use explicit type
This commit is contained in:
Sergio R. Caprile 2024-12-16 11:36:36 -03:00 committed by GitHub
commit 4a164c39b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 66 deletions

View File

@ -4243,7 +4243,7 @@ static uint16_t ipcsum(const void *buf, size_t len) {
} }
static void settmout(struct mg_connection *c, uint8_t type) { static void settmout(struct mg_connection *c, uint8_t type) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
unsigned n = type == MIP_TTYPE_ACK ? MIP_TCP_ACK_MS unsigned n = type == MIP_TTYPE_ACK ? MIP_TCP_ACK_MS
: type == MIP_TTYPE_ARP ? MIP_ARP_RESP_MS : type == MIP_TTYPE_ARP ? MIP_ARP_RESP_MS
@ -4668,7 +4668,7 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
} }
static size_t trim_len(struct mg_connection *c, size_t len) { static size_t trim_len(struct mg_connection *c, size_t len) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
size_t eth_h_len = 14, ip_max_h_len = 24, tcp_max_h_len = 60, udp_h_len = 8; size_t eth_h_len = 14, ip_max_h_len = 24, tcp_max_h_len = 60, udp_h_len = 8;
size_t max_headers_len = size_t max_headers_len =
eth_h_len + ip_max_h_len + (c->is_udp ? udp_h_len : tcp_max_h_len); eth_h_len + ip_max_h_len + (c->is_udp ? udp_h_len : tcp_max_h_len);
@ -4695,7 +4695,7 @@ static size_t trim_len(struct mg_connection *c, size_t len) {
} }
long mg_io_send(struct mg_connection *c, const void *buf, size_t len) { long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
uint32_t dst_ip = *(uint32_t *) c->rem.ip; uint32_t dst_ip = *(uint32_t *) c->rem.ip;
len = trim_len(c, len); len = trim_len(c, len);
@ -4758,8 +4758,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
c->is_draining = 1; c->is_draining = 1;
settmout(c, MIP_TTYPE_FIN); settmout(c, MIP_TTYPE_FIN);
} }
tx_tcp((struct mg_tcpip_if *) c->mgr->priv, s->mac, rem_ip, flags, tx_tcp(c->mgr->ifp, s->mac, rem_ip, flags, c->loc.port, c->rem.port,
c->loc.port, c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), "", 0); mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
} else if (pkt->pay.len == 0) { } else if (pkt->pay.len == 0) {
// TODO(cpq): handle this peer's ACK // TODO(cpq): handle this peer's ACK
} else if (seq != s->ack) { } else if (seq != s->ack) {
@ -4768,9 +4768,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
MG_VERBOSE(("ignoring duplicate pkt")); MG_VERBOSE(("ignoring duplicate pkt"));
} else { } else {
MG_VERBOSE(("SEQ != ACK: %x %x %x", seq, s->ack, ack)); MG_VERBOSE(("SEQ != ACK: %x %x %x", seq, s->ack, ack));
tx_tcp((struct mg_tcpip_if *) c->mgr->priv, s->mac, rem_ip, TH_ACK, tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
c->loc.port, c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), "", mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
0);
} }
} else if (io->size - io->len < pkt->pay.len && } else if (io->size - io->len < pkt->pay.len &&
!mg_iobuf_resize(io, io->len + pkt->pay.len)) { !mg_iobuf_resize(io, io->len + pkt->pay.len)) {
@ -4792,9 +4791,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
if (s->unacked > MIP_TCP_WIN / 2 && s->acked != s->ack) { if (s->unacked > MIP_TCP_WIN / 2 && s->acked != s->ack) {
// Send ACK immediately // Send ACK immediately
MG_VERBOSE(("%lu imm ACK %lu", c->id, s->acked)); MG_VERBOSE(("%lu imm ACK %lu", c->id, s->acked));
tx_tcp((struct mg_tcpip_if *) c->mgr->priv, s->mac, rem_ip, TH_ACK, tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
c->loc.port, c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), NULL, mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
0);
s->unacked = 0; s->unacked = 0;
s->acked = s->ack; s->acked = s->ack;
if (s->ttype != MIP_TTYPE_KEEPALIVE) settmout(c, MIP_TTYPE_KEEPALIVE); if (s->ttype != MIP_TTYPE_KEEPALIVE) settmout(c, MIP_TTYPE_KEEPALIVE);
@ -5111,7 +5109,7 @@ void mg_tcpip_init(struct mg_mgr *mgr, struct mg_tcpip_if *ifp) {
ifp->recv_queue.size = ifp->driver->rx ? framesize : 8192; ifp->recv_queue.size = ifp->driver->rx ? framesize : 8192;
ifp->recv_queue.buf = (char *) calloc(1, ifp->recv_queue.size); ifp->recv_queue.buf = (char *) calloc(1, ifp->recv_queue.size);
ifp->timer_1000ms = mg_millis(); ifp->timer_1000ms = mg_millis();
mgr->priv = ifp; mgr->ifp = ifp;
ifp->mgr = mgr; ifp->mgr = mgr;
ifp->mtu = MG_TCPIP_MTU_DEFAULT; ifp->mtu = MG_TCPIP_MTU_DEFAULT;
mgr->extraconnsize = sizeof(struct connstate); mgr->extraconnsize = sizeof(struct connstate);
@ -5132,11 +5130,10 @@ void mg_tcpip_free(struct mg_tcpip_if *ifp) {
static void send_syn(struct mg_connection *c) { static void send_syn(struct mg_connection *c) {
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
uint32_t isn = mg_htonl((uint32_t) mg_ntohs(c->loc.port)); uint32_t isn = mg_htonl((uint32_t) mg_ntohs(c->loc.port));
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv;
uint32_t rem_ip; uint32_t rem_ip;
memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t)); memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
tx_tcp(ifp, s->mac, rem_ip, TH_SYN, c->loc.port, c->rem.port, isn, 0, NULL, tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_SYN, c->loc.port, c->rem.port, isn, 0,
0); NULL, 0);
} }
static void mac_resolved(struct mg_connection *c) { static void mac_resolved(struct mg_connection *c) {
@ -5150,7 +5147,7 @@ static void mac_resolved(struct mg_connection *c) {
} }
void mg_connect_resolved(struct mg_connection *c) { void mg_connect_resolved(struct mg_connection *c) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
uint32_t rem_ip; uint32_t rem_ip;
memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t)); memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
c->is_resolving = 0; c->is_resolving = 0;
@ -5206,12 +5203,10 @@ static void init_closure(struct mg_connection *c) {
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
if (c->is_udp == false && c->is_listening == false && if (c->is_udp == false && c->is_listening == false &&
c->is_connecting == false) { // For TCP conns, c->is_connecting == false) { // For TCP conns,
struct mg_tcpip_if *ifp =
(struct mg_tcpip_if *) c->mgr->priv; // send TCP FIN
uint32_t rem_ip; uint32_t rem_ip;
memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t)); memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
tx_tcp(ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port, c->rem.port, tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port,
mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0); c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
settmout(c, MIP_TTYPE_FIN); settmout(c, MIP_TTYPE_FIN);
} }
} }
@ -5228,12 +5223,11 @@ static bool can_write(struct mg_connection *c) {
} }
void mg_mgr_poll(struct mg_mgr *mgr, int ms) { void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) mgr->priv;
struct mg_connection *c, *tmp; struct mg_connection *c, *tmp;
uint64_t now = mg_millis(); uint64_t now = mg_millis();
mg_timer_poll(&mgr->timers, now); mg_timer_poll(&mgr->timers, now);
if (ifp == NULL || ifp->driver == NULL) return; if (mgr->ifp == NULL || mgr->ifp->driver == NULL) return;
mg_tcpip_poll(ifp, now); mg_tcpip_poll(mgr->ifp, now);
for (c = mgr->conns; c != NULL; c = tmp) { for (c = mgr->conns; c != NULL; c = tmp) {
tmp = c->next; tmp = c->next;
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
@ -5251,7 +5245,7 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
} }
bool mg_send(struct mg_connection *c, const void *buf, size_t len) { bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
bool res = false; bool res = false;
uint32_t rem_ip; uint32_t rem_ip;
memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t)); memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));

View File

@ -2150,6 +2150,7 @@ enum {
struct mg_dns { struct mg_dns {
const char *url; // DNS server URL const char *url; // DNS server URL
struct mg_connection *c; // DNS server connection struct mg_connection *c; // DNS server connection
@ -2176,8 +2177,8 @@ struct mg_mgr {
void *active_dns_requests; // DNS requests in progress void *active_dns_requests; // DNS requests in progress
struct mg_timer *timers; // Active timers struct mg_timer *timers; // Active timers
int epoll_fd; // Used when MG_EPOLL_ENABLE=1 int epoll_fd; // Used when MG_EPOLL_ENABLE=1
void *priv; // Used by the MIP stack struct mg_tcpip_if *ifp; // Builtin TCP/IP stack only. Interface pointer
size_t extraconnsize; // Used by the MIP stack size_t extraconnsize; // Builtin TCP/IP stack only. Extra space
MG_SOCKET_TYPE pipe; // Socketpair end for mg_wakeup() MG_SOCKET_TYPE pipe; // Socketpair end for mg_wakeup()
#if MG_ENABLE_FREERTOS_TCP #if MG_ENABLE_FREERTOS_TCP
SocketSet_t ss; // NOTE(lsm): referenced from socket struct SocketSet_t ss; // NOTE(lsm): referenced from socket struct
@ -2711,9 +2712,7 @@ bool mg_ota_flash_end(struct mg_flash *flash);
#if defined(MG_ENABLE_TCPIP) && MG_ENABLE_TCPIP
struct mg_tcpip_if; // Mongoose TCP/IP network interface struct mg_tcpip_if; // Mongoose TCP/IP network interface
#define MG_TCPIP_IFACE(mgr_) ((struct mg_tcpip_if *) (mgr_)->priv)
struct mg_tcpip_driver { struct mg_tcpip_driver {
bool (*init)(struct mg_tcpip_if *); // Init driver bool (*init)(struct mg_tcpip_if *); // Init driver
@ -2799,8 +2798,6 @@ struct mg_tcpip_spi {
uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply
}; };
#endif
// Macros to record timestamped events that happens with a connection. // Macros to record timestamped events that happens with a connection.

View File

@ -4,6 +4,7 @@
#include "config.h" #include "config.h"
#include "event.h" #include "event.h"
#include "iobuf.h" #include "iobuf.h"
#include "net_builtin.h"
#include "str.h" #include "str.h"
#include "timer.h" #include "timer.h"
@ -33,8 +34,8 @@ struct mg_mgr {
void *active_dns_requests; // DNS requests in progress void *active_dns_requests; // DNS requests in progress
struct mg_timer *timers; // Active timers struct mg_timer *timers; // Active timers
int epoll_fd; // Used when MG_EPOLL_ENABLE=1 int epoll_fd; // Used when MG_EPOLL_ENABLE=1
void *priv; // Used by the MIP stack struct mg_tcpip_if *ifp; // Builtin TCP/IP stack only. Interface pointer
size_t extraconnsize; // Used by the MIP stack size_t extraconnsize; // Builtin TCP/IP stack only. Extra space
MG_SOCKET_TYPE pipe; // Socketpair end for mg_wakeup() MG_SOCKET_TYPE pipe; // Socketpair end for mg_wakeup()
#if MG_ENABLE_FREERTOS_TCP #if MG_ENABLE_FREERTOS_TCP
SocketSet_t ss; // NOTE(lsm): referenced from socket struct SocketSet_t ss; // NOTE(lsm): referenced from socket struct

View File

@ -167,7 +167,7 @@ static uint16_t ipcsum(const void *buf, size_t len) {
} }
static void settmout(struct mg_connection *c, uint8_t type) { static void settmout(struct mg_connection *c, uint8_t type) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
unsigned n = type == MIP_TTYPE_ACK ? MIP_TCP_ACK_MS unsigned n = type == MIP_TTYPE_ACK ? MIP_TCP_ACK_MS
: type == MIP_TTYPE_ARP ? MIP_ARP_RESP_MS : type == MIP_TTYPE_ARP ? MIP_ARP_RESP_MS
@ -592,7 +592,7 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
} }
static size_t trim_len(struct mg_connection *c, size_t len) { static size_t trim_len(struct mg_connection *c, size_t len) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
size_t eth_h_len = 14, ip_max_h_len = 24, tcp_max_h_len = 60, udp_h_len = 8; size_t eth_h_len = 14, ip_max_h_len = 24, tcp_max_h_len = 60, udp_h_len = 8;
size_t max_headers_len = size_t max_headers_len =
eth_h_len + ip_max_h_len + (c->is_udp ? udp_h_len : tcp_max_h_len); eth_h_len + ip_max_h_len + (c->is_udp ? udp_h_len : tcp_max_h_len);
@ -619,7 +619,7 @@ static size_t trim_len(struct mg_connection *c, size_t len) {
} }
long mg_io_send(struct mg_connection *c, const void *buf, size_t len) { long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
uint32_t dst_ip = *(uint32_t *) c->rem.ip; uint32_t dst_ip = *(uint32_t *) c->rem.ip;
len = trim_len(c, len); len = trim_len(c, len);
@ -682,8 +682,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
c->is_draining = 1; c->is_draining = 1;
settmout(c, MIP_TTYPE_FIN); settmout(c, MIP_TTYPE_FIN);
} }
tx_tcp((struct mg_tcpip_if *) c->mgr->priv, s->mac, rem_ip, flags, tx_tcp(c->mgr->ifp, s->mac, rem_ip, flags, c->loc.port, c->rem.port,
c->loc.port, c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), "", 0); mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
} else if (pkt->pay.len == 0) { } else if (pkt->pay.len == 0) {
// TODO(cpq): handle this peer's ACK // TODO(cpq): handle this peer's ACK
} else if (seq != s->ack) { } else if (seq != s->ack) {
@ -692,9 +692,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
MG_VERBOSE(("ignoring duplicate pkt")); MG_VERBOSE(("ignoring duplicate pkt"));
} else { } else {
MG_VERBOSE(("SEQ != ACK: %x %x %x", seq, s->ack, ack)); MG_VERBOSE(("SEQ != ACK: %x %x %x", seq, s->ack, ack));
tx_tcp((struct mg_tcpip_if *) c->mgr->priv, s->mac, rem_ip, TH_ACK, tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
c->loc.port, c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), "", mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
0);
} }
} else if (io->size - io->len < pkt->pay.len && } else if (io->size - io->len < pkt->pay.len &&
!mg_iobuf_resize(io, io->len + pkt->pay.len)) { !mg_iobuf_resize(io, io->len + pkt->pay.len)) {
@ -716,9 +715,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
if (s->unacked > MIP_TCP_WIN / 2 && s->acked != s->ack) { if (s->unacked > MIP_TCP_WIN / 2 && s->acked != s->ack) {
// Send ACK immediately // Send ACK immediately
MG_VERBOSE(("%lu imm ACK %lu", c->id, s->acked)); MG_VERBOSE(("%lu imm ACK %lu", c->id, s->acked));
tx_tcp((struct mg_tcpip_if *) c->mgr->priv, s->mac, rem_ip, TH_ACK, tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
c->loc.port, c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), NULL, mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
0);
s->unacked = 0; s->unacked = 0;
s->acked = s->ack; s->acked = s->ack;
if (s->ttype != MIP_TTYPE_KEEPALIVE) settmout(c, MIP_TTYPE_KEEPALIVE); if (s->ttype != MIP_TTYPE_KEEPALIVE) settmout(c, MIP_TTYPE_KEEPALIVE);
@ -1035,7 +1033,7 @@ void mg_tcpip_init(struct mg_mgr *mgr, struct mg_tcpip_if *ifp) {
ifp->recv_queue.size = ifp->driver->rx ? framesize : 8192; ifp->recv_queue.size = ifp->driver->rx ? framesize : 8192;
ifp->recv_queue.buf = (char *) calloc(1, ifp->recv_queue.size); ifp->recv_queue.buf = (char *) calloc(1, ifp->recv_queue.size);
ifp->timer_1000ms = mg_millis(); ifp->timer_1000ms = mg_millis();
mgr->priv = ifp; mgr->ifp = ifp;
ifp->mgr = mgr; ifp->mgr = mgr;
ifp->mtu = MG_TCPIP_MTU_DEFAULT; ifp->mtu = MG_TCPIP_MTU_DEFAULT;
mgr->extraconnsize = sizeof(struct connstate); mgr->extraconnsize = sizeof(struct connstate);
@ -1056,11 +1054,10 @@ void mg_tcpip_free(struct mg_tcpip_if *ifp) {
static void send_syn(struct mg_connection *c) { static void send_syn(struct mg_connection *c) {
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
uint32_t isn = mg_htonl((uint32_t) mg_ntohs(c->loc.port)); uint32_t isn = mg_htonl((uint32_t) mg_ntohs(c->loc.port));
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv;
uint32_t rem_ip; uint32_t rem_ip;
memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t)); memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
tx_tcp(ifp, s->mac, rem_ip, TH_SYN, c->loc.port, c->rem.port, isn, 0, NULL, tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_SYN, c->loc.port, c->rem.port, isn, 0,
0); NULL, 0);
} }
static void mac_resolved(struct mg_connection *c) { static void mac_resolved(struct mg_connection *c) {
@ -1074,7 +1071,7 @@ static void mac_resolved(struct mg_connection *c) {
} }
void mg_connect_resolved(struct mg_connection *c) { void mg_connect_resolved(struct mg_connection *c) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
uint32_t rem_ip; uint32_t rem_ip;
memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t)); memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
c->is_resolving = 0; c->is_resolving = 0;
@ -1130,12 +1127,10 @@ static void init_closure(struct mg_connection *c) {
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
if (c->is_udp == false && c->is_listening == false && if (c->is_udp == false && c->is_listening == false &&
c->is_connecting == false) { // For TCP conns, c->is_connecting == false) { // For TCP conns,
struct mg_tcpip_if *ifp =
(struct mg_tcpip_if *) c->mgr->priv; // send TCP FIN
uint32_t rem_ip; uint32_t rem_ip;
memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t)); memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
tx_tcp(ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port, c->rem.port, tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port,
mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0); c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
settmout(c, MIP_TTYPE_FIN); settmout(c, MIP_TTYPE_FIN);
} }
} }
@ -1152,12 +1147,11 @@ static bool can_write(struct mg_connection *c) {
} }
void mg_mgr_poll(struct mg_mgr *mgr, int ms) { void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) mgr->priv;
struct mg_connection *c, *tmp; struct mg_connection *c, *tmp;
uint64_t now = mg_millis(); uint64_t now = mg_millis();
mg_timer_poll(&mgr->timers, now); mg_timer_poll(&mgr->timers, now);
if (ifp == NULL || ifp->driver == NULL) return; if (mgr->ifp == NULL || mgr->ifp->driver == NULL) return;
mg_tcpip_poll(ifp, now); mg_tcpip_poll(mgr->ifp, now);
for (c = mgr->conns; c != NULL; c = tmp) { for (c = mgr->conns; c != NULL; c = tmp) {
tmp = c->next; tmp = c->next;
struct connstate *s = (struct connstate *) (c + 1); struct connstate *s = (struct connstate *) (c + 1);
@ -1175,7 +1169,7 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
} }
bool mg_send(struct mg_connection *c, const void *buf, size_t len) { bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv; struct mg_tcpip_if *ifp = c->mgr->ifp;
bool res = false; bool res = false;
uint32_t rem_ip; uint32_t rem_ip;
memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t)); memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));

View File

@ -3,10 +3,9 @@
#include "arch.h" #include "arch.h"
#include "net.h" #include "net.h"
#include "queue.h" #include "queue.h"
#include "str.h"
#if defined(MG_ENABLE_TCPIP) && MG_ENABLE_TCPIP
struct mg_tcpip_if; // Mongoose TCP/IP network interface struct mg_tcpip_if; // Mongoose TCP/IP network interface
#define MG_TCPIP_IFACE(mgr_) ((struct mg_tcpip_if *) (mgr_)->priv)
struct mg_tcpip_driver { struct mg_tcpip_driver {
bool (*init)(struct mg_tcpip_if *); // Init driver bool (*init)(struct mg_tcpip_if *); // Init driver
@ -91,5 +90,3 @@ struct mg_tcpip_spi {
void (*end)(void *); // SPI end: slave select high void (*end)(void *); // SPI end: slave select high
uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply
}; };
#endif

View File

@ -161,9 +161,7 @@ MG_IRAM static bool mg_stm32f_swap(void) {
static bool s_flash_irq_disabled; static bool s_flash_irq_disabled;
MG_IRAM static bool mg_stm32f_write(void *addr, MG_IRAM static bool mg_stm32f_write(void *addr, const void *buf, size_t len) {
const void *buf,
size_t len) {
if ((len % s_mg_flash_stm32f.align) != 0) { if ((len % s_mg_flash_stm32f.align) != 0) {
MG_ERROR(("%lu is not aligned to %lu", len, s_mg_flash_stm32f.align)); MG_ERROR(("%lu is not aligned to %lu", len, s_mg_flash_stm32f.align));
return false; return false;
@ -194,8 +192,7 @@ MG_IRAM static bool mg_stm32f_write(void *addr,
} }
// just overwrite instead of swap // just overwrite instead of swap
MG_IRAM void single_bank_swap(char *p1, char *p2, MG_IRAM void single_bank_swap(char *p1, char *p2, size_t size) {
size_t size) {
// no stdlib calls here // no stdlib calls here
mg_stm32f_write(p1, p2, size); mg_stm32f_write(p1, p2, size);
*(volatile unsigned long *) 0xe000ed0c = 0x5fa0004; *(volatile unsigned long *) 0xe000ed0c = 0x5fa0004;