Return to atomicio.c CVS log | Up to [local] / src / usr.bin / sendbug |
version 1.2, 2007/07/31 03:44:21 | version 1.3, 2007/09/07 14:50:44 | ||
---|---|---|---|
|
|
||
*/ | */ | ||
#include <sys/param.h> | #include <sys/param.h> | ||
#include <sys/uio.h> | |||
#include <errno.h> | #include <errno.h> | ||
#include <poll.h> | |||
#include <unistd.h> | |||
#include "atomicio.h" | #include "atomicio.h" | ||
|
|
||
char *s = _s; | char *s = _s; | ||
size_t pos = 0; | size_t pos = 0; | ||
ssize_t res; | ssize_t res; | ||
struct pollfd pfd; | |||
pfd.fd = fd; | |||
pfd.events = f == read ? POLLIN : POLLOUT; | |||
while (n > pos) { | while (n > pos) { | ||
res = (f) (fd, s + pos, n - pos); | res = (f) (fd, s + pos, n - pos); | ||
switch (res) { | switch (res) { | ||
case -1: | case -1: | ||
if (errno == EINTR || errno == EAGAIN) | if (errno == EINTR) | ||
continue; | continue; | ||
if (errno == EAGAIN) { | |||
(void)poll(&pfd, 1, -1); | |||
continue; | |||
} | |||
return 0; | return 0; | ||
case 0: | case 0: | ||
errno = EPIPE; | errno = EPIPE; |