Browse Source

Added tcp_buffer, to give applications a zero-cost place to build data to

be transmitted.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
c8a7133e9f
2 changed files with 40 additions and 2 deletions
  1. 2
    0
      src/include/gpxe/tcp.h
  2. 38
    2
      src/proto/tcp.c

+ 2
- 0
src/include/gpxe/tcp.h View File

@@ -92,6 +92,8 @@ struct tcp_connection {
92 92
 	struct tcp_operations *tcp_op;
93 93
 };
94 94
 
95
+extern void *tcp_buffer;
96
+extern size_t tcp_buflen;
95 97
 extern int tcp_connect ( struct tcp_connection *conn );
96 98
 extern void tcp_send ( struct tcp_connection *conn, const void *data,
97 99
 		       size_t len );

+ 38
- 2
src/proto/tcp.c View File

@@ -24,6 +24,36 @@
24 24
  *
25 25
  */
26 26
 
27
+/**
28
+ * TCP transmit buffer
29
+ *
30
+ * When a tcp_operations::senddata() method is called, it is
31
+ * guaranteed to be able to use this buffer as temporary space for
32
+ * constructing the data to be sent.  For example, code such as
33
+ *
34
+ * @code
35
+ *
36
+ *     static void my_senddata ( struct tcp_connection *conn ) {
37
+ *         int len;
38
+ *
39
+ *         len = snprintf ( tcp_buffer, tcp_buflen, "FETCH %s\r\n", filename );
40
+ *         tcp_send ( conn, tcp_buffer + already_sent, len - already_sent );
41
+ *     }
42
+ *
43
+ * @endcode
44
+ *
45
+ * is allowed, and is probably the best way to deal with
46
+ * variably-sized data.
47
+ *
48
+ * Note that you cannot use this simple mechanism if you want to be
49
+ * able to construct single data blocks of more than #tcp_buflen
50
+ * bytes.
51
+ */
52
+void *tcp_buffer = uip_buf + ( 40 + UIP_LLH_LEN );
53
+
54
+/** Size of #tcp_buffer */
55
+size_t tcp_buflen = UIP_BUFSIZE - ( 40 + UIP_LLH_LEN );
56
+
27 57
 /**
28 58
  * Open a TCP connection
29 59
  *
@@ -67,13 +97,19 @@ int tcp_connect ( struct tcp_connection *conn ) {
67 97
  * Data will be automatically limited to the current TCP window size.
68 98
  *
69 99
  * If retransmission is required, the connection's
70
- * tcp_operations::newdata() method will be called again in order to
100
+ * tcp_operations::senddata() method will be called again in order to
71 101
  * regenerate the data.
72 102
  */
73 103
 void tcp_send ( struct tcp_connection *conn __unused,
74 104
 		const void *data, size_t len ) {
105
+
75 106
 	assert ( conn = *( ( void ** ) uip_conn->appstate ) );
76
-	uip_send ( ( void * ) data, len );
107
+
108
+	if ( len > tcp_buflen )
109
+		len = tcp_buflen;
110
+	memmove ( tcp_buffer, data, len );
111
+
112
+	uip_send ( tcp_buffer, len );
77 113
 }
78 114
 
79 115
 /**

Loading…
Cancel
Save