@@ -4243,7 +4243,7 @@ static uint16_t ipcsum(const void *buf, size_t len) {
42434243}
42444244
42454245static void settmout(struct mg_connection *c, uint8_t type) {
4246-   struct mg_tcpip_if *ifp = (struct mg_tcpip_if *)  c->mgr->priv ;
4246+   struct mg_tcpip_if *ifp = c->mgr->ifp ;
42474247  struct connstate *s = (struct connstate *) (c + 1);
42484248  unsigned n = type == MIP_TTYPE_ACK   ? MIP_TCP_ACK_MS
42494249               : type == MIP_TTYPE_ARP ? MIP_ARP_RESP_MS
@@ -4668,7 +4668,7 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
46684668}
46694669
46704670static size_t trim_len(struct mg_connection *c, size_t len) {
4671-   struct mg_tcpip_if *ifp = (struct mg_tcpip_if *)  c->mgr->priv ;
4671+   struct mg_tcpip_if *ifp = c->mgr->ifp ;
46724672  size_t eth_h_len = 14, ip_max_h_len = 24, tcp_max_h_len = 60, udp_h_len = 8;
46734673  size_t max_headers_len =
46744674      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) {
46954695}
46964696
46974697long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
4698-   struct mg_tcpip_if *ifp = (struct mg_tcpip_if *)  c->mgr->priv ;
4698+   struct mg_tcpip_if *ifp = c->mgr->ifp ;
46994699  struct connstate *s = (struct connstate *) (c + 1);
47004700  uint32_t dst_ip = *(uint32_t *) c->rem.ip;
47014701  len = trim_len(c, len);
@@ -4758,8 +4758,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
47584758      c->is_draining = 1;
47594759      settmout(c, MIP_TTYPE_FIN);
47604760    }
4761-     tx_tcp((struct mg_tcpip_if *)  c->mgr->priv , s->mac, rem_ip, flags,
4762-            c->loc.port, c->rem.port,  mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
4761+     tx_tcp(c->mgr->ifp , s->mac, rem_ip, flags, c->loc.port, c->rem.port ,
4762+            mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
47634763  } else if (pkt->pay.len == 0) {
47644764    // TODO(cpq): handle this peer's ACK
47654765  } else if (seq != s->ack) {
@@ -4768,9 +4768,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
47684768      MG_VERBOSE(("ignoring duplicate pkt"));
47694769    } else {
47704770      MG_VERBOSE(("SEQ != ACK: %x %x %x", seq, s->ack, ack));
4771-       tx_tcp((struct mg_tcpip_if *) c->mgr->priv, s->mac, rem_ip, TH_ACK,
4772-              c->loc.port, c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), "",
4773-              0);
4771+       tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
4772+              mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
47744773    }
47754774  } else if (io->size - io->len < pkt->pay.len &&
47764775             !mg_iobuf_resize(io, io->len + pkt->pay.len)) {
@@ -4792,9 +4791,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
47924791    if (s->unacked > MIP_TCP_WIN / 2 && s->acked != s->ack) {
47934792      // Send ACK immediately
47944793      MG_VERBOSE(("%lu imm ACK %lu", c->id, s->acked));
4795-       tx_tcp((struct mg_tcpip_if *) c->mgr->priv, s->mac, rem_ip, TH_ACK,
4796-              c->loc.port, c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), NULL,
4797-              0);
4794+       tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
4795+              mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
47984796      s->unacked = 0;
47994797      s->acked = s->ack;
48004798      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) {
51115109      ifp->recv_queue.size = ifp->driver->rx ? framesize : 8192;
51125110    ifp->recv_queue.buf = (char *) calloc(1, ifp->recv_queue.size);
51135111    ifp->timer_1000ms = mg_millis();
5114-     mgr->priv  = ifp;
5112+     mgr->ifp  = ifp;
51155113    ifp->mgr = mgr;
51165114    ifp->mtu = MG_TCPIP_MTU_DEFAULT;
51175115    mgr->extraconnsize = sizeof(struct connstate);
@@ -5132,11 +5130,10 @@ void mg_tcpip_free(struct mg_tcpip_if *ifp) {
51325130static void send_syn(struct mg_connection *c) {
51335131  struct connstate *s = (struct connstate *) (c + 1);
51345132  uint32_t isn = mg_htonl((uint32_t) mg_ntohs(c->loc.port));
5135-   struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->mgr->priv;
51365133  uint32_t rem_ip;
51375134  memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
5138-   tx_tcp(ifp, s->mac, rem_ip, TH_SYN, c->loc.port, c->rem.port, isn, 0, NULL ,
5139-          0);
5135+   tx_tcp(c->mgr-> ifp, s->mac, rem_ip, TH_SYN, c->loc.port, c->rem.port, isn, 0,
5136+          NULL,  0);
51405137}
51415138
51425139static void mac_resolved(struct mg_connection *c) {
@@ -5150,7 +5147,7 @@ static void mac_resolved(struct mg_connection *c) {
51505147}
51515148
51525149void mg_connect_resolved(struct mg_connection *c) {
5153-   struct mg_tcpip_if *ifp = (struct mg_tcpip_if *)  c->mgr->priv ;
5150+   struct mg_tcpip_if *ifp = c->mgr->ifp ;
51545151  uint32_t rem_ip;
51555152  memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
51565153  c->is_resolving = 0;
@@ -5206,12 +5203,10 @@ static void init_closure(struct mg_connection *c) {
52065203  struct connstate *s = (struct connstate *) (c + 1);
52075204  if (c->is_udp == false && c->is_listening == false &&
52085205      c->is_connecting == false) {  // For TCP conns,
5209-     struct mg_tcpip_if *ifp =
5210-         (struct mg_tcpip_if *) c->mgr->priv;  // send TCP FIN
52115206    uint32_t rem_ip;
52125207    memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
5213-     tx_tcp(ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port, c->rem .port,
5214-            mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
5208+     tx_tcp(c->mgr-> ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port,
5209+            c->rem.port,  mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
52155210    settmout(c, MIP_TTYPE_FIN);
52165211  }
52175212}
@@ -5228,12 +5223,11 @@ static bool can_write(struct mg_connection *c) {
52285223}
52295224
52305225void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
5231-   struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) mgr->priv;
52325226  struct mg_connection *c, *tmp;
52335227  uint64_t now = mg_millis();
52345228  mg_timer_poll(&mgr->timers, now);
5235-   if (ifp == NULL || ifp->driver == NULL) return;
5236-   mg_tcpip_poll(ifp, now);
5229+   if (mgr-> ifp == NULL || mgr-> ifp->driver == NULL) return;
5230+   mg_tcpip_poll(mgr-> ifp, now);
52375231  for (c = mgr->conns; c != NULL; c = tmp) {
52385232    tmp = c->next;
52395233    struct connstate *s = (struct connstate *) (c + 1);
@@ -5251,7 +5245,7 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
52515245}
52525246
52535247bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
5254-   struct mg_tcpip_if *ifp = (struct mg_tcpip_if *)  c->mgr->priv ;
5248+   struct mg_tcpip_if *ifp = c->mgr->ifp ;
52555249  bool res = false;
52565250  uint32_t rem_ip;
52575251  memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
0 commit comments