5 #include <sys/select.h>
9 #define BIG_PIPE_SIZE 64*1024 /* From sys/pipe.h */
12 * Test for the non-blocking big pipe bug (write(2) returning
13 * EAGAIN while select(2) returns the descriptor as ready for write).
18 void write_frame(int fd
, char *buf
, unsigned long buflen
)
26 i
= select(fd
+1, NULL
, &wfd
, NULL
, NULL
);
32 fprintf(stderr
, "select returned unexpected value %d\n", i
);
35 i
= write(fd
, buf
, buflen
);
48 char buf
[BIG_PIPE_SIZE
]; /* any value over PIPE_SIZE should do */
53 if (pipe(fd
) < 0) { perror("pipe"); exit(1); }
55 flags
= fcntl(fd
[1], F_GETFL
);
56 if (flags
== -1 || fcntl(fd
[1], F_SETFL
, flags
|O_NONBLOCK
) == -1) {
68 i
= read(fd
[0], buf
, 256); /* any small size should do */
70 if (i
< 0) { perror("read"); exit(1); }
78 memset(buf
, 0, sizeof buf
);
79 for (i
= 0; i
< 1000; i
++) write_frame(fd
[1], buf
, sizeof buf
);