summaryrefslogtreecommitdiff
path: root/usr.bin/sendbug/atomicio.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/sendbug/atomicio.c')
-rw-r--r--usr.bin/sendbug/atomicio.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/usr.bin/sendbug/atomicio.c b/usr.bin/sendbug/atomicio.c
index 3478ab2e9f5..f85dec49b9b 100644
--- a/usr.bin/sendbug/atomicio.c
+++ b/usr.bin/sendbug/atomicio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atomicio.c,v 1.2 2007/07/31 03:44:21 ray Exp $ */
+/* $OpenBSD: atomicio.c,v 1.3 2007/09/07 14:50:44 tobias Exp $ */
/*
* Copyright (c) 2006 Damien Miller. All rights reserved.
* Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
@@ -27,9 +27,10 @@
*/
#include <sys/param.h>
-#include <sys/uio.h>
#include <errno.h>
+#include <poll.h>
+#include <unistd.h>
#include "atomicio.h"
@@ -42,13 +43,20 @@ atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
char *s = _s;
size_t pos = 0;
ssize_t res;
+ struct pollfd pfd;
+ pfd.fd = fd;
+ pfd.events = f == read ? POLLIN : POLLOUT;
while (n > pos) {
res = (f) (fd, s + pos, n - pos);
switch (res) {
case -1:
- if (errno == EINTR || errno == EAGAIN)
+ if (errno == EINTR)
continue;
+ if (errno == EAGAIN) {
+ (void)poll(&pfd, 1, -1);
+ continue;
+ }
return 0;
case 0:
errno = EPIPE;