Browse Source

Allow buffers to be pre-expanded on demand.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
c8b3e969a0
2 changed files with 22 additions and 5 deletions
  1. 1
    5
      src/core/buffer.c
  2. 21
    0
      src/include/gpxe/buffer.h

+ 1
- 5
src/core/buffer.c View File

167
 
167
 
168
 	/* Check that block fits within buffer, expand if necessary */
168
 	/* Check that block fits within buffer, expand if necessary */
169
 	if ( data_end > buffer->len ) {
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
 			DBGC ( buffer, "BUFFER %p could not expand :%s\n",
171
 			DBGC ( buffer, "BUFFER %p could not expand :%s\n",
176
 			       buffer, strerror ( rc ) );
172
 			       buffer, strerror ( rc ) );
177
 			return rc;
173
 			return rc;

+ 21
- 0
src/include/gpxe/buffer.h View File

2
 #define _GPXE_BUFFER_H
2
 #define _GPXE_BUFFER_H
3
 
3
 
4
 #include <stdint.h>
4
 #include <stdint.h>
5
+#include <errno.h>
5
 #include <gpxe/uaccess.h>
6
 #include <gpxe/uaccess.h>
6
 
7
 
7
 /** @file
8
 /** @file
101
 extern int fill_buffer ( struct buffer *buffer, const void *data,
102
 extern int fill_buffer ( struct buffer *buffer, const void *data,
102
 			 size_t offset, size_t len );
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
 #endif /* _GPXE_BUFFER_H */
125
 #endif /* _GPXE_BUFFER_H */

Loading…
Cancel
Save