pkgsrc/sysutils/xentools20/patches/patch-aw
bouyer 73cc7fc036 Add patch from Jed Davis on port-xen:
| xfrd reads from the network socket using
| fread() on an _IONBF'ed stream; under NetBSD, this results in a
| sequence of one-character reads.  This behavior, as far as I can tell,
| goes back all the way to V7 Unix; i.e., it's older than me.
|
| So I've modified libxutil, which has its own IO indirection layer, to
| switch to read(2) in the "unbuffered" case"

bump PKGREVISION
2005-09-16 18:14:49 +00:00

59 lines
1.6 KiB
Text

$NetBSD: patch-aw,v 1.1 2005/09/16 18:14:49 bouyer Exp $
--- libxutil/file_stream.c.orig 2005-09-13 17:02:16.000000000 -0400
+++ libxutil/file_stream.c 2005-09-13 17:31:39.000000000 -0400
@@ -21,11 +21,13 @@
*/
#ifndef __KERNEL__
#include <stdio.h>
+#include <unistd.h>
#include <stdlib.h>
#include "allocate.h"
#include "file_stream.h"
static int file_read(IOStream *s, void *buf, size_t n);
+static int file_read_nbuf(IOStream *s, void* buf, size_t n);
static int file_write(IOStream *s, const void *buf, size_t n);
static int file_error(IOStream *s);
static int file_close(IOStream *s);
@@ -42,6 +44,16 @@
flush: file_flush,
};
+/** Methods used by a FILE* IOStream that's unbuffered. */
+static const IOMethods file_methods_nbuf = {
+ read: file_read_nbuf,
+ write: file_write,
+ error: file_error,
+ close: file_close,
+ free: file_free,
+ flush: file_flush,
+};
+
/** IOStream for stdin. */
static IOStream _iostdin = {
methods: &file_methods,
@@ -102,6 +114,7 @@
* @return 0 on success, non-zero otherwise
*/
int file_stream_setvbuf(IOStream *io, char *buf, int mode, size_t size){
+ io->methods = (mode == _IONBF) ? &file_methods_nbuf : &file_methods;
return setvbuf(get_file(io), buf, mode, size);
}
@@ -126,6 +139,15 @@
static int file_read(IOStream *s, void *buf, size_t n){
return fread(buf, 1, n, get_file(s));
}
+static int file_read_nbuf(IOStream *s, void *buf, size_t n){
+ int fd = fileno(get_file(s)), rv, nr=0;
+ while(n > nr) {
+ rv = read(fd, buf+nr, n-nr);
+ if (rv <= 0) break;
+ nr += rv;
+ }
+ return nr;
+}
/** Fush the underlying stream using fflush().
*