Free (GPLv2) TCP/IP stack developed by TASS Belgium

Fork of PicoTCP by Daniele Lacamera

Files at this revision

API Documentation at this revision

Comitter:
daniele
Date:
Tue Jun 11 23:28:50 2013 +0000
Parent:
24:8bff2b51ea3b
Child:
26:dc3e7f96338f
Child:
31:d3b2dfcc358f
Commit message:
Fixed close

Changed in this revision

Socket/bsd/stack_endpoint.cpp Show annotated file Show diff for this revision Revisions of this file
include/arch/pico_mbed.h Show annotated file Show diff for this revision Revisions of this file
include/pico_queue.h Show annotated file Show diff for this revision Revisions of this file
include/pico_socket.h Show annotated file Show diff for this revision Revisions of this file
stack/pico_stack.c Show annotated file Show diff for this revision Revisions of this file
--- a/Socket/bsd/stack_endpoint.cpp	Tue Jun 11 21:10:23 2013 +0000
+++ b/Socket/bsd/stack_endpoint.cpp	Tue Jun 11 23:28:50 2013 +0000
@@ -189,9 +189,11 @@
 
 static void retry_close(struct stack_endpoint *ep)
 {
-  pico_socket_close(ep->s);
-  send_retval(ep, 0);
-  stack_Del(ep);
+  if (ep) {
+    pico_socket_close(ep->s);
+    send_retval(ep, 0);
+    stack_Del(ep);
+  }
 }
 
 static void retry_write(struct stack_endpoint *ep)
@@ -319,13 +321,9 @@
   
   
   
-  if (ev & PICO_SOCK_EV_CLOSE){
+  if (ev & (PICO_SOCK_EV_CLOSE | PICO_SOCK_EV_FIN)){
     printf("** CLOSE\n");
     ep->connected = 0;
-    send_error(ep);
-  }
-  if (ev & PICO_SOCK_EV_FIN) {
-      printf("** FIN\n");
   }
   
   if (ev & PICO_SOCK_EV_ERR) {
@@ -438,6 +436,7 @@
   while(1) {
     ret = stack_parse_requests();
     pico_stack_tick();
+    //Thread::wait(1);
     Thread::wait(1);
   }
 }
--- a/include/arch/pico_mbed.h	Tue Jun 11 21:10:23 2013 +0000
+++ b/include/arch/pico_mbed.h	Tue Jun 11 23:28:50 2013 +0000
@@ -10,6 +10,7 @@
 
 #ifndef PICO_SUPPORT_MBED
 #define PICO_SUPPORT_MBED
+#include <stdio.h>
 
 //#include "mbed.h"
 //#include "serial_api.h"
@@ -25,6 +26,33 @@
 #define pico_zalloc(x) calloc(x, 1)
 #define pico_free(x) free(x)
 
+#ifdef MEMORY_MEASURE // in case, comment out the two defines above me.
+extern uint32_t max_mem;
+extern uint32_t cur_mem;
+
+static inline void * pico_zalloc(int x)
+{
+    uint32_t *ptr;
+    if ((cur_mem + x )> (10 * 1024))
+        return NULL;
+        
+    ptr = (uint32_t *)calloc(x + 4, 1);
+    *ptr = (uint32_t)x;
+    cur_mem += x;
+    if (cur_mem > max_mem) {
+        max_mem = cur_mem;
+        printf("max mem: %lu\n", max_mem);
+    }
+    return (void*)(ptr + 1);
+}
+
+static inline void pico_free(void *x)
+{
+    uint32_t *ptr = (uint32_t*)(((uint8_t *)x) - 4);
+    cur_mem -= *ptr;
+    free(ptr);
+}
+#endif
 
 #define PICO_SUPPORT_MUTEX
 extern void *pico_mutex_init(void);
--- a/include/pico_queue.h	Tue Jun 11 21:10:23 2013 +0000
+++ b/include/pico_queue.h	Tue Jun 11 23:28:50 2013 +0000
@@ -9,7 +9,7 @@
 #include "pico_config.h"
 #include "pico_frame.h"
 
-#define Q_LIMIT 2048
+#define Q_LIMIT 0
 
 #ifndef NULL
 #define NULL ((void *)0)
--- a/include/pico_socket.h	Tue Jun 11 21:10:23 2013 +0000
+++ b/include/pico_socket.h	Tue Jun 11 23:28:50 2013 +0000
@@ -11,7 +11,7 @@
 #include "pico_protocol.h"
 
 //#define PICO_DEFAULT_SOCKETQ (128 * 1024)
-#define PICO_DEFAULT_SOCKETQ (2 * 1024)
+#define PICO_DEFAULT_SOCKETQ (4 * 1024)
 
 #define PICO_SHUT_RD   1
 #define PICO_SHUT_WR   2
--- a/stack/pico_stack.c	Tue Jun 11 21:10:23 2013 +0000
+++ b/stack/pico_stack.c	Tue Jun 11 23:28:50 2013 +0000
@@ -34,6 +34,10 @@
   const uint8_t PICO_ETHADDR_MCAST[6] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0x00};
 #endif
 
+uint32_t cur_mem = 0;
+uint32_t max_mem = 0;
+
+
 volatile unsigned long pico_tick;
 volatile pico_err_t pico_err;