Hello,

Those patches cleanup and simplify the example from 
contrib/ports/unix/proj/minimal/.
I considered these changes useful while learning about lwip by reading the 
example program.

1/3: tmr_intervals.patch
Use the lwip constants ARP_TMR_INTERVAL and IP_TMR_INTERVAL instead of 
hardcoded values. The program already uses the constants TCP_FAST_INTERVAL and
TCP_SLOW_INTERVAL. This also changes the ARP timer value from hardcoded 20s 
to the lwip default of 5s.

2/3: ethernet_input.patch
The program has own code that does just what ethernet_input() does. 
Use ethernet_input() instead.

3/3: pbuf_cat.patch
The program uses pbuf_chain() where pbuf_cat() would be more appropriate. 
This makes freeing the buffer (chain) unnecessarily complicated.
Use pbuf_cat() and simplify freeing.

I would be pleased if someone with CVS write access could tell me if those 
patches are suitable for inclusion and do so if appropriate.

Bye,
Wolfgang Koebler

diff -Naur orig/contrib/ports/unix/proj/minimal/main.c patched/contrib/ports/unix/proj/minimal/main.c
--- orig/contrib/ports/unix/proj/minimal/main.c	2008-01-02 14:57:21.000000000 +0100
+++ patched/contrib/ports/unix/proj/minimal/main.c	2009-04-17 23:46:30.000000000 +0200
@@ -198,11 +198,11 @@
   echo_init();
   
   timer_init();
-  timer_set_interval(TIMER_EVT_ETHARPTMR,2000);
+  timer_set_interval(TIMER_EVT_ETHARPTMR, ARP_TMR_INTERVAL / 10);
   timer_set_interval(TIMER_EVT_TCPFASTTMR, TCP_FAST_INTERVAL / 10);
   timer_set_interval(TIMER_EVT_TCPSLOWTMR, TCP_SLOW_INTERVAL / 10);
 #if IP_REASSEMBLY
-  timer_set_interval(TIMER_EVT_IPREASSTMR,100);
+  timer_set_interval(TIMER_EVT_IPREASSTMR, IP_TMR_INTERVAL / 10);
 #endif
   
   printf("Applications started.\n");
diff -Naur orig/contrib/ports/unix/proj/minimal/main.c patched/contrib/ports/unix/proj/minimal/main.c
--- orig/contrib/ports/unix/proj/minimal/main.c	2008-01-02 14:57:21.000000000 +0100
+++ patched/contrib/ports/unix/proj/minimal/main.c	2009-04-17 23:56:20.000000000 +0200
@@ -179,7 +179,7 @@
 
   printf("TCP/IP initialized.\n");
   
-  netif_add(&netif, &ipaddr, &netmask, &gw, NULL, mintapif_init, ip_input);  
+  netif_add(&netif, &ipaddr, &netmask, &gw, NULL, mintapif_init, ethernet_input);  
   netif_set_default(&netif);
   netif_set_up(&netif);
 
diff -Naur orig/contrib/ports/unix/proj/minimal/mintapif.c patched/contrib/ports/unix/proj/minimal/mintapif.c
--- orig/contrib/ports/unix/proj/minimal/mintapif.c	2007-12-19 21:26:53.000000000 +0100
+++ patched/contrib/ports/unix/proj/minimal/mintapif.c	2009-04-17 23:58:30.000000000 +0200
@@ -242,41 +242,16 @@
 static void
 mintapif_input(struct netif *netif)
 {
-  struct mintapif *mintapif;
-  struct eth_hdr *ethhdr;
   struct pbuf *p;
 
-
-  mintapif = netif->state;
-  
   p = low_level_input(netif);
-
   if (p != NULL) {
 
 #if LINK_STATS
     lwip_stats.link.recv++;
 #endif /* LINK_STATS */
 
-    ethhdr = p->payload;
-
-    switch (htons(ethhdr->type)) {
-    case ETHTYPE_IP:
-#if 0
-/* CSi disabled ARP table update on ingress IP packets.
-   This seems to work but needs thorough testing. */
-      etharp_ip_input(netif, p);
-#endif
-      pbuf_header(p, -14);
-      netif->input(p, netif);
-      break;
-    case ETHTYPE_ARP:
-      etharp_arp_input(netif, mintapif->ethaddr, p);
-      break;
-    default:
-      LWIP_ASSERT("p != NULL", p != NULL);
-      pbuf_free(p);
-      break;
-    }
+    netif->input(p, netif);
   }
 }
 /*-----------------------------------------------------------------------------------*/
diff -Naur orig/contrib/ports/unix/proj/minimal/echo.c patched/contrib/ports/unix/proj/minimal/echo.c
--- orig/contrib/ports/unix/proj/minimal/echo.c	2006-09-27 13:00:42.000000000 +0200
+++ patched/contrib/ports/unix/proj/minimal/echo.c	2009-04-18 00:10:04.000000000 +0200
@@ -189,7 +189,7 @@
 
       /* chain pbufs to the end of what we recv'ed previously  */
       ptr = es->p;
-      pbuf_chain(ptr,p);
+      pbuf_cat(ptr,p);
     }
     ret_err = ERR_OK;
   }
@@ -311,12 +311,9 @@
        pbuf_ref(es->p);
      }
      /* chop first pbuf from chain */
-      do
-      {
-        /* try hard to free pbuf */
-        freed = pbuf_free(ptr);
-      }
-      while(freed == 0);
+     /* free pbuf */
+     freed = pbuf_free(ptr);
+     LWIP_ASSERT("freed != 0", freed != 0);
      /* we can read more data now */
      tcp_recved(tpcb, plen);
    }
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to