Quellcode durchsuchen

Allow buffers to be pre-expanded on demand.

tags/v0.9.3
Michael Brown vor 18 Jahren
Ursprung
Commit
c8b3e969a0
2 geänderte Dateien mit 22 neuen und 5 gelöschten Zeilen
  1. 1
    5
      src/core/buffer.c
  2. 21
    0
      src/include/gpxe/buffer.h

+ 1
- 5
src/core/buffer.c Datei anzeigen

@@ -167,11 +167,7 @@ int fill_buffer ( struct buffer *buffer, const void *data,
167 167
 
168 168
 	/* Check that block fits within buffer, expand if necessary */
169 169
 	if ( data_end > buffer->len ) {
170
-		if ( ! buffer->expand ) {
171
-			DBGC ( buffer, "BUFFER %p not expandable\n", buffer );
172
-			return -ENOBUFS;
173
-		}
174
-		if ( ( rc = buffer->expand ( buffer, data_end ) ) != 0 ) {
170
+		if ( ( rc = expand_buffer ( buffer, data_end ) ) != 0 ) {
175 171
 			DBGC ( buffer, "BUFFER %p could not expand :%s\n",
176 172
 			       buffer, strerror ( rc ) );
177 173
 			return rc;

+ 21
- 0
src/include/gpxe/buffer.h Datei anzeigen

@@ -2,6 +2,7 @@
2 2
 #define _GPXE_BUFFER_H
3 3
 
4 4
 #include <stdint.h>
5
+#include <errno.h>
5 6
 #include <gpxe/uaccess.h>
6 7
 
7 8
 /** @file
@@ -101,4 +102,24 @@ struct buffer {
101 102
 extern int fill_buffer ( struct buffer *buffer, const void *data,
102 103
 			 size_t offset, size_t len );
103 104
 
105
+/** Expand data buffer
106
+ *
107
+ * @v buffer		Data buffer
108
+ * @v new_len		New length
109
+ * @ret rc		Return status code
110
+ *
111
+ * Expand the data buffer to accommodate more data.  Some buffers may
112
+ * not support being expanded.
113
+ */
114
+static inline int expand_buffer ( struct buffer *buffer, size_t new_len ) {
115
+
116
+	if ( new_len <= buffer->len )
117
+		return 0;
118
+
119
+	if ( ! buffer->expand )
120
+		return -ENOBUFS;
121
+
122
+	return buffer->expand ( buffer, new_len );
123
+}
124
+
104 125
 #endif /* _GPXE_BUFFER_H */

Laden…
Abbrechen
Speichern