This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch redboot tcp, suggestion


HTTP might require active close on the server side
repeatedly. The attached patch makes it possible to
mark a "socket" as reusable and ignores the RFC 793
2 minute MSL.

The code was defect for the state transition from
FIN_WAIT_1 to TIME_WAIT. An extra FIN was sent and
the state CLOSING was entered. Corrected.

Test case: active close in redboot tcp.

Brgrds,
Hendrik Ruijter
*** include/net/net.h	12 Dec 2001 11:56:46 -0000	1.1.1.1
--- include/net/net.h	26 Feb 2002 15:47:38 -0000	1.1.1.1.2.1
*************** typedef struct _tcp_socket {
*** 326,331 ****
--- 326,332 ----
      word               our_port;
      word               his_port;
      word               data_bytes;   /* number of data bytes in pkt */
+     char               reuse;        /* SO_REUSEADDR, no 2MSL */
      timer_t            timer;
      pktbuf_t           pkt;         /* dedicated xmit packet */
      pktbuf_t           *rxlist;     /* list of unread incoming data packets */
*************** extern void __tcp_poll(void);
*** 502,507 ****
--- 503,512 ----
   */
  extern int __tcp_listen(tcp_socket_t *s, word port);
  
+ /*
+  * SO_REUSEADDR, no 2MSL.
+  */
+ extern void __tcp_so_reuseaddr(tcp_socket_t *s);
  
  /*
   * Block while waiting for all outstanding socket data to

*** src/net/tcp.c	19 Feb 2002 09:12:19 -0000	1.1.1.1.2.1
--- src/net/tcp.c	26 Feb 2002 15:50:30 -0000	1.1.1.1.2.2
*************** tcp_send(tcp_socket_t *s, int flags, int
*** 152,159 ****
      BSPLOG(bsp_log("tcp_send: state[%d] flags[%s] ack[%u] data[%d].\n",
  		   s->state, flags_to_str(tcp->flags), s->ack, s->data_bytes));
  
!     if (s->state == _TIME_WAIT)
  	__timer_set(&s->timer, 120000, do_close, s);
      else if ((tcp->flags & (TCP_FLAG_FIN | TCP_FLAG_SYN)) || s->data_bytes)
  	__timer_set(&s->timer, 1000, do_retrans, s);
  }
--- 152,165 ----
      BSPLOG(bsp_log("tcp_send: state[%d] flags[%s] ack[%u] data[%d].\n",
  		   s->state, flags_to_str(tcp->flags), s->ack, s->data_bytes));
  
!     if (s->state == _TIME_WAIT) {
!       if (s->reuse) {
! 	__timer_set(&s->timer, 1000, do_close, s);
!       }
!       else {
  	__timer_set(&s->timer, 120000, do_close, s);
+       }
+     }
      else if ((tcp->flags & (TCP_FLAG_FIN | TCP_FLAG_SYN)) || s->data_bytes)
  	__timer_set(&s->timer, 1000, do_retrans, s);
  }
*************** __tcp_handler(pktbuf_t *pkt, ip_route_t 
*** 527,538 ****
  			}
  		    }
  		}
! 		if (tcp->flags & TCP_FLAG_FIN) {
  		    BSPLOG(bsp_log("_FIN_WAIT_1 --> _CLOSING\n"));
  		    __timer_cancel(&s->timer);
  		    s->ack++;
  		    s->state = _CLOSING;
! 		    tcp_send(s, TCP_FLAG_FIN | TCP_FLAG_ACK, 0);
  		}
  		break;
  
--- 533,544 ----
  			}
  		    }
  		}
! 		else if (tcp->flags & TCP_FLAG_FIN) {
  		    BSPLOG(bsp_log("_FIN_WAIT_1 --> _CLOSING\n"));
  		    __timer_cancel(&s->timer);
  		    s->ack++;
  		    s->state = _CLOSING;
! 		    tcp_send(s, TCP_FLAG_ACK, 0);
  		}
  		break;
  
*************** __tcp_listen(tcp_socket_t *s, word port)
*** 613,618 ****
--- 619,633 ----
      return 0;
  }
  
+ /*
+  * SO_REUSEADDR, no 2MSL.
+  */
+ void
+ __tcp_so_reuseaddr(tcp_socket_t *s)
+ {
+ //    BSPLOG(bsp_log("__tcp_so_reuseaddr.\n"));
+     s->reuse = 0x01;
+ }
  
  /*
   * Block while waiting for all data to be transmitted.

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]