Browse Source

Reserve space for lower-layer headers when allocating packet buffer.

Use pkb_available() rather than pkb_len() (which will always return 0
on a freshly allocated buffer).

udp_send() should assume that the buffer has already been allocated.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
ab633f6a73
1 changed files with 5 additions and 33 deletions
  1. 5
    33
      src/net/udp.c

+ 5
- 33
src/net/udp.c View File

87
 	}
87
 	}
88
 }
88
 }
89
 
89
 
90
-/**
91
- * Allocate space to the UDP buffer
92
- *
93
- * @v conn      UDP connection
94
- * @v len       Length to allocate
95
- * @ret rc      Status
96
- *
97
- * Allocate "len" amount of space in the transmit buffer
98
- */
99
-int udp_buf_alloc ( struct udp_connection *conn, size_t len ) {
100
-	if ( conn->tx_pkb != NULL ) {
101
-		free_pkb ( conn->tx_pkb );
102
-		conn->tx_pkb = NULL;
103
-	}
104
-	conn->tx_pkb = alloc_pkb ( len < UDP_MIN_TXPKB ? UDP_MIN_TXPKB : len );
105
-	return !conn ? -ENOMEM : 0;
106
-}
107
-
108
 /**
90
 /**
109
  * User request to send data via a UDP connection
91
  * User request to send data via a UDP connection
110
  *
92
  *
120
 							UDP_MAX_TXPKB );
102
 							UDP_MAX_TXPKB );
121
 		return -ENOMEM;
103
 		return -ENOMEM;
122
 	}
104
 	}
123
-	conn->udp_op->senddata ( conn, conn->tx_pkb, pkb_len ( conn->tx_pkb ) );
105
+	pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
106
+	conn->udp_op->senddata ( conn, conn->tx_pkb, 
107
+				 pkb_available ( conn->tx_pkb ) );
124
 	return 0;
108
 	return 0;
125
 }
109
 }
126
 		
110
 		
127
-
128
 /**
111
 /**
129
  * Transmit data via a UDP connection
112
  * Transmit data via a UDP connection
130
  *
113
  *
140
        	struct udp_header *udphdr;		/* UDP header */
123
        	struct udp_header *udphdr;		/* UDP header */
141
 	struct sockaddr *sock = &conn->sin;	/* Destination sockaddr */
124
 	struct sockaddr *sock = &conn->sin;	/* Destination sockaddr */
142
 	uint16_t *dest;
125
 	uint16_t *dest;
143
-	int rc;
144
 
126
 
145
-	/* Copy data into packet buffer, if necessary */
146
-	if ( data != conn->tx_pkb->data ) {
147
-		/* Allocate space for data and lower layer headers */
148
-		if ( ( rc = udp_buf_alloc ( conn, len + UDP_MAX_HLEN ) ) != 0 ) {
149
-			DBG ( "Error allocating buffer" );
150
-			return rc;
151
-		}
152
-
153
-		/* Reserve space for the headers and copy contents */
154
-		pkb_reserve ( conn->tx_pkb, UDP_MAX_HLEN );
155
-		memmove ( pkb_put ( conn->tx_pkb, len ), data, len );
156
-	}
127
+	/* Copy payload */
128
+	memmove ( pkb_put ( conn->tx_pkb, len ), data, len );
157
 
129
 
158
 	/*
130
 	/*
159
 	 * Add the UDP header
131
 	 * Add the UDP header

Loading…
Cancel
Save