Browse Source

Put the TCP connection periodic processing in tcp.c, where it belongs.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
9c9208a132
3 changed files with 66 additions and 8 deletions
  1. 2
    0
      src/arch/i386/include/latch.h
  2. 2
    8
      src/include/gpxe/ip.h
  3. 62
    0
      src/net/tcp.c

+ 2
- 0
src/arch/i386/include/latch.h View File

@@ -7,4 +7,6 @@
7 7
  * sleep_latch and the definitions of it's length here...
8 8
  */
9 9
 
10
+extern unsigned long currticks ( void );
11
+
10 12
 #endif /* LATCH_H */

+ 2
- 8
src/include/gpxe/ip.h View File

@@ -5,16 +5,10 @@
5 5
  *
6 6
  * IP protocol
7 7
  *
8
- * This file defines the gPXE IP API.
9
- *
10 8
  */
11 9
 
12
-#include <gpxe/in.h>
10
+struct net_protocol;
13 11
 
14
-extern void set_ipaddr ( struct in_addr address );
15
-extern void set_netmask ( struct in_addr address );
16
-extern void set_gateway ( struct in_addr address );
17
-extern void init_tcpip ( void );
18
-extern void run_tcpip ( void );
12
+extern struct net_protocol ipv4_protocol;
19 13
 
20 14
 #endif /* _GPXE_IP_H */

+ 62
- 0
src/net/tcp.c View File

@@ -1,6 +1,12 @@
1 1
 #include <string.h>
2 2
 #include <assert.h>
3 3
 #include <byteswap.h>
4
+#include <latch.h>
5
+#include <gpxe/process.h>
6
+#include <gpxe/init.h>
7
+#include <gpxe/netdevice.h>
8
+#include <gpxe/pkbuff.h>
9
+#include <gpxe/ip.h>
4 10
 #include <gpxe/tcp.h>
5 11
 #include "uip/uip.h"
6 12
 
@@ -162,3 +168,59 @@ void uip_tcp_appcall ( void ) {
162 168
  */
163 169
 void uip_udp_appcall ( void ) {
164 170
 }
171
+
172
+/**
173
+ * Perform periodic processing of all TCP connections
174
+ *
175
+ * This allows TCP connections to retransmit data if necessary.
176
+ */
177
+static void tcp_periodic ( void ) {
178
+	struct pk_buff *pkb;
179
+	int i;
180
+
181
+	for ( i = 0 ; i < UIP_CONNS ; i++ ) {
182
+		uip_periodic ( i );
183
+		if ( uip_len > 0 ) {
184
+			pkb = alloc_pkb ( uip_len + MAX_LL_HEADER_LEN);
185
+			if ( ! pkb )
186
+				continue;
187
+				
188
+			pkb_reserve ( pkb, MAX_LL_HEADER_LEN );
189
+			pkb_put ( pkb, uip_len );
190
+			memcpy ( pkb->data, uip_buf, uip_len );
191
+			pkb->net_protocol = &ipv4_protocol;
192
+			
193
+			net_transmit ( pkb );
194
+		}
195
+	}
196
+}
197
+
198
+/**
199
+ * Single-step the TCP stack
200
+ *
201
+ * @v process	TCP process
202
+ *
203
+ * This calls tcp_periodic() at regular intervals.
204
+ */
205
+static void tcp_step ( struct process *process ) {
206
+	static long timeout = 0;
207
+
208
+	if ( currticks() > timeout ) {
209
+		timeout = currticks() + ( TICKS_PER_SEC / 10 );
210
+		tcp_periodic ();
211
+	}
212
+
213
+	schedule ( process );
214
+}
215
+
216
+/** TCP stack process */
217
+static struct process tcp_process = {
218
+	.step = tcp_step,
219
+};
220
+
221
+/** Initialise the TCP stack */
222
+static void init_tcp ( void ) {
223
+	schedule ( &tcp_process );
224
+}
225
+
226
+INIT_FN ( INIT_PROCESS, init_tcp, NULL, NULL );

Loading…
Cancel
Save