Ver código fonte

[iobuf] Add iob_split() to split an I/O buffer into portions

RNDIS devices may provide multiple packets encapsulated into a single
message.  Provide an API to allow the RNDIS driver to split an I/O
buffer into smaller portions.

The current implementation will always copy the underlying data,
rather than splitting the buffer in situ.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 anos atrás
pai
commit
c86b22221d
2 arquivos alterados com 31 adições e 0 exclusões
  1. 30
    0
      src/core/iobuf.c
  2. 1
    0
      src/include/ipxe/iobuf.h

+ 30
- 0
src/core/iobuf.c Ver arquivo

@@ -200,3 +200,33 @@ struct io_buffer * iob_concatenate ( struct list_head *list ) {
200 200
 
201 201
 	return concatenated;
202 202
 }
203
+
204
+/**
205
+ * Split I/O buffer
206
+ *
207
+ * @v iobuf		I/O buffer
208
+ * @v len		Length to split into a new I/O buffer
209
+ * @ret split		New I/O buffer, or NULL on allocation failure
210
+ *
211
+ * Split the first @c len bytes of the existing I/O buffer into a
212
+ * separate I/O buffer.  The resulting buffers are likely to have no
213
+ * headroom or tailroom.
214
+ *
215
+ * If this call fails, then the original buffer will be unmodified.
216
+ */
217
+struct io_buffer * iob_split ( struct io_buffer *iobuf, size_t len ) {
218
+	struct io_buffer *split;
219
+
220
+	/* Sanity checks */
221
+	assert ( len <= iob_len ( iobuf ) );
222
+
223
+	/* Allocate new I/O buffer */
224
+	split = alloc_iob ( len );
225
+	if ( ! split )
226
+		return NULL;
227
+
228
+	/* Copy in data */
229
+	memcpy ( iob_put ( split, len ), iobuf->data, len );
230
+	iob_pull ( iobuf, len );
231
+	return split;
232
+}

+ 1
- 0
src/include/ipxe/iobuf.h Ver arquivo

@@ -217,5 +217,6 @@ extern void free_iob ( struct io_buffer *iobuf );
217 217
 extern void iob_pad ( struct io_buffer *iobuf, size_t min_len );
218 218
 extern int iob_ensure_headroom ( struct io_buffer *iobuf, size_t len );
219 219
 extern struct io_buffer * iob_concatenate ( struct list_head *list );
220
+extern struct io_buffer * iob_split ( struct io_buffer *iobuf, size_t len );
220 221
 
221 222
 #endif /* _IPXE_IOBUF_H */

Carregando…
Cancelar
Salvar