From 9c9208a13255ceebd59bd564eb2aa50a0761899d Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 30 Apr 2006 02:08:42 +0000 Subject: [PATCH] Put the TCP connection periodic processing in tcp.c, where it belongs. --- src/arch/i386/include/latch.h | 2 ++ src/include/gpxe/ip.h | 10 ++---- src/net/tcp.c | 62 +++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/arch/i386/include/latch.h b/src/arch/i386/include/latch.h index 38a8bd21..5000d582 100644 --- a/src/arch/i386/include/latch.h +++ b/src/arch/i386/include/latch.h @@ -7,4 +7,6 @@ * sleep_latch and the definitions of it's length here... */ +extern unsigned long currticks ( void ); + #endif /* LATCH_H */ diff --git a/src/include/gpxe/ip.h b/src/include/gpxe/ip.h index 94f906b5..44aee7d1 100644 --- a/src/include/gpxe/ip.h +++ b/src/include/gpxe/ip.h @@ -5,16 +5,10 @@ * * IP protocol * - * This file defines the gPXE IP API. - * */ -#include +struct net_protocol; -extern void set_ipaddr ( struct in_addr address ); -extern void set_netmask ( struct in_addr address ); -extern void set_gateway ( struct in_addr address ); -extern void init_tcpip ( void ); -extern void run_tcpip ( void ); +extern struct net_protocol ipv4_protocol; #endif /* _GPXE_IP_H */ diff --git a/src/net/tcp.c b/src/net/tcp.c index 69fe95f5..50c9731f 100644 --- a/src/net/tcp.c +++ b/src/net/tcp.c @@ -1,6 +1,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include "uip/uip.h" @@ -162,3 +168,59 @@ void uip_tcp_appcall ( void ) { */ void uip_udp_appcall ( void ) { } + +/** + * Perform periodic processing of all TCP connections + * + * This allows TCP connections to retransmit data if necessary. + */ +static void tcp_periodic ( void ) { + struct pk_buff *pkb; + int i; + + for ( i = 0 ; i < UIP_CONNS ; i++ ) { + uip_periodic ( i ); + if ( uip_len > 0 ) { + pkb = alloc_pkb ( uip_len + MAX_LL_HEADER_LEN); + if ( ! pkb ) + continue; + + pkb_reserve ( pkb, MAX_LL_HEADER_LEN ); + pkb_put ( pkb, uip_len ); + memcpy ( pkb->data, uip_buf, uip_len ); + pkb->net_protocol = &ipv4_protocol; + + net_transmit ( pkb ); + } + } +} + +/** + * Single-step the TCP stack + * + * @v process TCP process + * + * This calls tcp_periodic() at regular intervals. + */ +static void tcp_step ( struct process *process ) { + static long timeout = 0; + + if ( currticks() > timeout ) { + timeout = currticks() + ( TICKS_PER_SEC / 10 ); + tcp_periodic (); + } + + schedule ( process ); +} + +/** TCP stack process */ +static struct process tcp_process = { + .step = tcp_step, +}; + +/** Initialise the TCP stack */ +static void init_tcp ( void ) { + schedule ( &tcp_process ); +} + +INIT_FN ( INIT_PROCESS, init_tcp, NULL, NULL );