Browse Source

[PXEXT] Avoid queueing zero-length buffers in posix_io.c

read_user() assumes that zero-length buffers don't exist, and optimises
around this.
tags/v0.9.4
Michael Brown 17 years ago
parent
commit
96edbd128f
1 changed files with 12 additions and 6 deletions
  1. 12
    6
      src/core/posix_io.c

+ 12
- 6
src/core/posix_io.c View File

114
 static int
114
 static int
115
 posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
115
 posix_file_xfer_deliver_iob ( struct xfer_interface *xfer,
116
 			      struct io_buffer *iobuf,
116
 			      struct io_buffer *iobuf,
117
-			      struct xfer_metadata *meta __unused ) {
117
+			      struct xfer_metadata *meta ) {
118
 	struct posix_file *file =
118
 	struct posix_file *file =
119
 		container_of ( xfer, struct posix_file, xfer );
119
 		container_of ( xfer, struct posix_file, xfer );
120
 
120
 
125
 	if ( file->filesize < file->pos )
125
 	if ( file->filesize < file->pos )
126
 		file->filesize = file->pos;
126
 		file->filesize = file->pos;
127
 
127
 
128
-	list_add_tail ( &iobuf->list, &file->data );
128
+	if ( iob_len ( iobuf ) ) {
129
+		list_add_tail ( &iobuf->list, &file->data );
130
+	} else {
131
+		free_iob ( iobuf );
132
+	}
133
+
129
 	return 0;
134
 	return 0;
130
 }
135
 }
131
 
136
 
293
 			free_iob ( iobuf );
298
 			free_iob ( iobuf );
294
 		}
299
 		}
295
 		file->pos += len;
300
 		file->pos += len;
296
-		if ( len )
301
+		assert ( len != 0 );
297
-			return len;
302
+		return len;
298
-		break;
299
 	}
303
 	}
300
 
304
 
301
 	/* If file has completed, return (after returning all data) */
305
 	/* If file has completed, return (after returning all data) */
302
-	if ( file->rc != -EINPROGRESS )
306
+	if ( file->rc != -EINPROGRESS ) {
307
+		assert ( list_empty ( &file->data ) );
303
 		return file->rc;
308
 		return file->rc;
309
+	}
304
 
310
 
305
 	/* No data ready and file still in progress; return -WOULDBLOCK */
311
 	/* No data ready and file still in progress; return -WOULDBLOCK */
306
 	return -EWOULDBLOCK;
312
 	return -EWOULDBLOCK;

Loading…
Cancel
Save