Index: doc/sys_arch.txt
===================================================================
RCS file: /sources/lwip/lwip/doc/sys_arch.txt,v
retrieving revision 1.15
diff -u -r1.15 sys_arch.txt
--- doc/sys_arch.txt	5 Sep 2007 16:14:28 -0000	1.15
+++ doc/sys_arch.txt	5 Jan 2008 01:50:20 -0000
@@ -69,9 +69,9 @@
   Notice that lwIP implements a function with a similar name,
   sys_sem_wait(), that uses the sys_arch_sem_wait() function.
 
-- sys_mbox_t sys_mbox_new(void)
+- sys_mbox_t sys_mbox_new(int size)
 
-  Creates an empty mailbox.
+  Creates an empty mailbox for maximum "size" elements.
 
 - void sys_mbox_free(sys_mbox_t mbox)
 
@@ -83,6 +83,11 @@
 
   Posts the "msg" to the mailbox.
 
+- err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg)
+
+  Try to post the "msg" to the mailbox. Returns ERR_MEM if this one
+  is full, else, ERR_OK if the "msg" is posted.
+
 - u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
 
   Blocks the thread until a message arrives in the mailbox, but does
Index: src/api/api_msg.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/api_msg.c,v
retrieving revision 1.91
diff -u -r1.91 api_msg.c
--- src/api/api_msg.c	4 Jan 2008 23:07:45 -0000	1.91
+++ src/api/api_msg.c	5 Jan 2008 01:54:50 -0000
@@ -98,7 +98,9 @@
     SYS_ARCH_INC(conn->recv_avail, p->tot_len);
     /* Register event with callback */
     API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
-    sys_mbox_post(conn->recvmbox, buf);
+    if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) {
+      netbuf_delete(buf);
+    }
   }
 
   return 0; /* do not eat the packet */
@@ -153,7 +155,10 @@
   SYS_ARCH_INC(conn->recv_avail, p->tot_len);
   /* Register event with callback */
   API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
-  sys_mbox_post(conn->recvmbox, buf);
+  if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) {
+    netbuf_delete(buf);
+    return;
+  }
 }
 #endif /* LWIP_UDP */
 
@@ -190,7 +195,10 @@
   }
   /* Register event with callback */
   API_EVENT(conn, NETCONN_EVT_RCVPLUS, len);
-  sys_mbox_post(conn->recvmbox, p);
+  if (sys_mbox_trypost(conn->recvmbox, p) != ERR_OK) {
+    pbuf_free(p);
+    return ERR_MEM;
+  }
 
   return ERR_OK;
 }
@@ -348,7 +356,10 @@
   /* Register event with callback */
   API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
 
-  sys_mbox_post(conn->acceptmbox, newconn);
+  if (sys_mbox_trypost(conn->acceptmbox, newconn) != ERR_OK) {
+    /** @todo call here a "netconn_free" */
+    return ERR_MEM;
+  }
   return ERR_OK;
 }
 #endif /* LWIP_TCP */
@@ -460,11 +471,11 @@
   conn->type = t;
   conn->pcb.tcp = NULL;
 
-  if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) {
+  if ((conn->mbox = sys_mbox_new(1)) == SYS_MBOX_NULL) {
     memp_free(MEMP_NETCONN, conn);
     return NULL;
   }
-  if ((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
+  if ((conn->recvmbox = sys_mbox_new(DEFAULT_RECVMBOX_SIZE)) == SYS_MBOX_NULL) {
     sys_mbox_free(conn->mbox);
     memp_free(MEMP_NETCONN, conn);
     return NULL;
@@ -732,7 +743,7 @@
               msg->conn->recvmbox = NULL;
             }
             if (msg->conn->acceptmbox == SYS_MBOX_NULL) {
-              if ((msg->conn->acceptmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
+              if ((msg->conn->acceptmbox = sys_mbox_new(DEFAULT_ACCEPTMBOX_SIZE)) == SYS_MBOX_NULL) {
                 msg->conn->err = ERR_MEM;
               }
             }
Index: src/api/tcpip.c
===================================================================
RCS file: /sources/lwip/lwip/src/api/tcpip.c,v
retrieving revision 1.66
diff -u -r1.66 tcpip.c
--- src/api/tcpip.c	24 Nov 2007 22:13:25 -0000	1.66
+++ src/api/tcpip.c	5 Jan 2008 01:55:24 -0000
@@ -332,7 +332,10 @@
     msg->type = TCPIP_MSG_INPKT;
     msg->msg.inp.p = p;
     msg->msg.inp.netif = inp;
-    sys_mbox_post(mbox, msg);
+    if (sys_mbox_trypost(mbox, msg) != ERR_OK) {
+      memp_free(MEMP_TCPIP_MSG_INPKT, msg);
+      return ERR_MEM;
+    }
     return ERR_OK;
   }
   return ERR_VAL;
@@ -499,7 +502,7 @@
 
   tcpip_init_done = initfunc;
   tcpip_init_done_arg = arg;
-  mbox = sys_mbox_new();
+  mbox = sys_mbox_new(TCPIP_MBOX_SIZE);
 #if LWIP_TCPIP_CORE_LOCKING
   lock_tcpip_core = sys_sem_new(1);
 #endif /* LWIP_TCPIP_CORE_LOCKING */
Index: src/include/lwip/opt.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/opt.h,v
retrieving revision 1.110
diff -u -r1.110 opt.h
--- src/include/lwip/opt.h	4 Jan 2008 22:18:28 -0000	1.110
+++ src/include/lwip/opt.h	5 Jan 2008 01:29:53 -0000
@@ -875,6 +875,15 @@
 #endif
 
 /**
+ * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages
+ * The queue size value itself is platform-dependent, but is passed to
+ * sys_mbox_new() when tcpip_init is called.
+ */
+#ifndef TCPIP_MBOX_SIZE
+#define TCPIP_MBOX_SIZE                 0
+#endif
+
+/**
  * SLIPIF_THREAD_NAME: The name assigned to the slipif_loop thread.
  */
 #ifndef SLIPIF_THREAD_NAME
@@ -949,6 +958,24 @@
 #define DEFAULT_THREAD_PRIO             1
 #endif
 
+/**
+ * DEFAULT_RECVMBOX_SIZE: The mailbox size for the incoming packets.
+ * The queue size value itself is platform-dependent, but is passed to
+ * sys_mbox_new() when the recvmbox is created.
+ */
+#ifndef DEFAULT_RECVMBOX_SIZE
+#define DEFAULT_RECVMBOX_SIZE           0
+#endif
+
+/**
+ * DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections.
+ * The queue size value itself is platform-dependent, but is passed to
+ * sys_mbox_new() when the acceptmbox is created.
+ */
+#ifndef DEFAULT_ACCEPTMBOX_SIZE
+#define DEFAULT_ACCEPTMBOX_SIZE         0
+#endif
+
 /*
    ----------------------------------------------
    ---------- Sequential layer options ----------
Index: src/include/lwip/sys.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/sys.h,v
retrieving revision 1.31
diff -u -r1.31 sys.h
--- src/include/lwip/sys.h	21 Dec 2007 14:59:11 -0000	1.31
+++ src/include/lwip/sys.h	5 Jan 2008 01:30:33 -0000
@@ -56,9 +56,11 @@
 #define sys_sem_wait_timeout(s,t)
 #define sys_arch_sem_wait(s,t)
 #define sys_sem_free(s)
-#define sys_mbox_new() 0
+#define sys_mbox_new(s) 0
 #define sys_mbox_fetch(m,d)
+#define sys_mbox_tryfetch(m,d)
 #define sys_mbox_post(m,d)
+#define sys_mbox_trypost(m,d)
 #define sys_mbox_free(m)
 
 #define sys_thread_new(n,t,a,s,p)
@@ -73,6 +75,7 @@
  */
 #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT 
 
+#include "lwip/err.h"
 #include "arch/sys_arch.h"
 
 typedef void (* sys_timeout_handler)(void *arg);
@@ -121,8 +124,9 @@
 #endif
 
 /* Mailbox functions. */
-sys_mbox_t sys_mbox_new(void);
+sys_mbox_t sys_mbox_new(int size);
 void sys_mbox_post(sys_mbox_t mbox, void *msg);
+err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg);
 u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout);
 #ifndef sys_arch_mbox_tryfetch /* Allow port to override with a macro */
 u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg);

