Socket server test

Revision:
4:19dd8a25cc8a
Parent:
0:d2e0685698cc
Child:
5:2c2f993df16b
--- a/main.cpp	Tue Aug 23 21:01:49 2016 +0100
+++ b/main.cpp	Thu Aug 25 18:43:08 2016 +0100
@@ -1,15 +1,56 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
+#include "lwip/stats.h"
 
 #ifndef SRV_PORT
 #define SRV_PORT 8084
 #endif
 
+Serial pc(USBTX, USBRX);
 EthernetInterface eth;
 
+Thread stats_thread;
+
+void stats_main(void)
+{
+    int i;
+    while (true) {
+        int c = pc.getc();
+        switch (c) {
+        default: printf("lwip statistics: *=all"
+                        " l=LINK a=ETHARP"
+                        " i=IP f=IPFRAG c=ICMP g=IGMP"
+                        " u=UDP t=TCP"
+                        " h=HEAP m=MEMP* p=PCB n=NETBUF/NETCONN"
+                        " s=SYS\n"); break;
+        case '*': stats_display(); break;
+        case 'l': LINK_STATS_DISPLAY(); break;
+        case 'a': ETHARP_STATS_DISPLAY(); break;
+        case 'f': IPFRAG_STATS_DISPLAY(); break;
+        case 'i': IP_STATS_DISPLAY(); break;
+        case 'c': ICMP_STATS_DISPLAY(); break;
+        case 'g': IGMP_STATS_DISPLAY(); break;
+        case 'u': UDP_STATS_DISPLAY(); break;
+        case 't': TCP_STATS_DISPLAY(); break;
+        case 'h': MEM_STATS_DISPLAY(); break;
+        case 'm': for (i=0; i < MEMP_MAX; i++) MEMP_STATS_DISPLAY(i); break;
+        case 'p':
+            MEMP_STATS_DISPLAY(MEMP_UDP_PCB);
+            MEMP_STATS_DISPLAY(MEMP_TCP_PCB);
+            MEMP_STATS_DISPLAY(MEMP_TCP_PCB_LISTEN);
+            break;
+        case 'n':
+            MEMP_STATS_DISPLAY(MEMP_NETBUF);
+            MEMP_STATS_DISPLAY(MEMP_NETCONN);
+            break;
+        case 's': SYS_STATS_DISPLAY(); break;
+        }
+    }
+}
+
 void tcp_echo_conn(TCPSocket *sock)
 {
-    char buf[200];
+    static char buf[5000];
     int ret;
     while (true) {
         ret = sock->recv(buf, sizeof(buf));
@@ -45,6 +86,8 @@
 {
     int err;
     printf("\r\n== socket-test %s ==\r\n", __DATE__);
+    stats_init();
+    stats_thread.start(stats_main);
     err = eth.connect();
     if (err) error("connect: %d\n", err);
     printf("ip %s\r\n", eth.get_ip_address());
@@ -53,7 +96,7 @@
     if (err) error("open: %d\r\n", err);
     err = srv.bind(SRV_PORT);
     if (err) error("bind: %d\r\n", err);
-    err = srv.listen(1);
+    err = srv.listen(0);
     if (err) error("listen: %d\r\n", err);
     Thread srv_thread;
     srv_thread.start(Callback<void()>(&srv, tcp_echo));
@@ -61,4 +104,4 @@
     while (true) {
         wait(1.0);
     }
-}
\ No newline at end of file
+}