changeset 2867:05a4930e2f1a

* src/net/tcp.c (__tcp_abort): Ensure the connection is closed before returning. This fixes a race condition which Ilko Iliev <iliev@ronetix.at> found when performing two back to back http transfers
author asl
date Mon, 20 Apr 2009 11:19:16 +0000
parents 124f0bf48ce8
children 6338fd43e9be
files packages/redboot/current/ChangeLog packages/redboot/current/src/net/tcp.c
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/packages/redboot/current/ChangeLog
+++ b/packages/redboot/current/ChangeLog
@@ -1,3 +1,10 @@
+2009-04-20  Andrew Lunn  <andrew@lunn.ch>
+
+	* src/net/tcp.c (__tcp_abort): Ensure the connection is closed
+	before returning. This fixes a race condition which Ilko Iliev
+	<iliev@ronetix.at> found when performing two back to back http
+	transfers.
+
 2009-04-02  Rene Schipp von Branitz Nielsen <rbn@vitesse.com>
 
 	* src/flash.c: Fix compilation warnings when redundant FIS
--- a/packages/redboot/current/src/net/tcp.c
+++ b/packages/redboot/current/src/net/tcp.c
@@ -710,10 +710,27 @@ do_abort(void *s)
     unlink_socket((tcp_socket_t *)s);
 }
 
+/*
+ * Abort a TCP connection, waiting for the connection to be closed, so
+ * it is save to reuse the tcp_socket_t structure. 
+ */
+
 void
 __tcp_abort(tcp_socket_t *s, unsigned long delay)
 {
+  int timeout = 1000;
+  
   __timer_set(&abort_timer, delay, do_abort, s);
+
+  while (s->state != _CLOSED)  {
+    if (--timeout <= 0)  {
+      diag_printf("TCP close - connection failed to close\n");
+      return;
+    }
+    
+    MS_TICKS_DELAY();
+    __tcp_poll();
+  }
 }
 
 /*