summaryrefslogtreecommitdiff
path: root/atomicio.c
diff options
context:
space:
mode:
Diffstat (limited to 'atomicio.c')
-rw-r--r--atomicio.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/atomicio.c b/atomicio.c
index f854a06f5..e00c9f0d4 100644
--- a/atomicio.c
+++ b/atomicio.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: atomicio.c,v 1.28 2016/07/27 23:18:12 djm Exp $ */ 1/* $OpenBSD: atomicio.c,v 1.30 2019/01/24 02:42:23 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2006 Damien Miller. All rights reserved. 3 * Copyright (c) 2006 Damien Miller. All rights reserved.
4 * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved. 4 * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
@@ -57,20 +57,25 @@ atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n,
57 ssize_t res; 57 ssize_t res;
58 struct pollfd pfd; 58 struct pollfd pfd;
59 59
60#ifndef BROKEN_READ_COMPARISON
61 pfd.fd = fd; 60 pfd.fd = fd;
61#ifndef BROKEN_READ_COMPARISON
62 pfd.events = f == read ? POLLIN : POLLOUT; 62 pfd.events = f == read ? POLLIN : POLLOUT;
63#else
64 pfd.events = POLLIN|POLLOUT;
63#endif 65#endif
64 while (n > pos) { 66 while (n > pos) {
65 res = (f) (fd, s + pos, n - pos); 67 res = (f) (fd, s + pos, n - pos);
66 switch (res) { 68 switch (res) {
67 case -1: 69 case -1:
68 if (errno == EINTR) 70 if (errno == EINTR) {
71 /* possible SIGALARM, update callback */
72 if (cb != NULL && cb(cb_arg, 0) == -1) {
73 errno = EINTR;
74 return pos;
75 }
69 continue; 76 continue;
70 if (errno == EAGAIN || errno == EWOULDBLOCK) { 77 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
71#ifndef BROKEN_READ_COMPARISON
72 (void)poll(&pfd, 1, -1); 78 (void)poll(&pfd, 1, -1);
73#endif
74 continue; 79 continue;
75 } 80 }
76 return 0; 81 return 0;
@@ -114,20 +119,25 @@ atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd,
114 /* Make a copy of the iov array because we may modify it below */ 119 /* Make a copy of the iov array because we may modify it below */
115 memcpy(iov, _iov, (size_t)iovcnt * sizeof(*_iov)); 120 memcpy(iov, _iov, (size_t)iovcnt * sizeof(*_iov));
116 121
117#ifndef BROKEN_READV_COMPARISON
118 pfd.fd = fd; 122 pfd.fd = fd;
123#ifndef BROKEN_READV_COMPARISON
119 pfd.events = f == readv ? POLLIN : POLLOUT; 124 pfd.events = f == readv ? POLLIN : POLLOUT;
125#else
126 pfd.events = POLLIN|POLLOUT;
120#endif 127#endif
121 for (; iovcnt > 0 && iov[0].iov_len > 0;) { 128 for (; iovcnt > 0 && iov[0].iov_len > 0;) {
122 res = (f) (fd, iov, iovcnt); 129 res = (f) (fd, iov, iovcnt);
123 switch (res) { 130 switch (res) {
124 case -1: 131 case -1:
125 if (errno == EINTR) 132 if (errno == EINTR) {
133 /* possible SIGALARM, update callback */
134 if (cb != NULL && cb(cb_arg, 0) == -1) {
135 errno = EINTR;
136 return pos;
137 }
126 continue; 138 continue;
127 if (errno == EAGAIN || errno == EWOULDBLOCK) { 139 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
128#ifndef BROKEN_READV_COMPARISON
129 (void)poll(&pfd, 1, -1); 140 (void)poll(&pfd, 1, -1);
130#endif
131 continue; 141 continue;
132 } 142 }
133 return 0; 143 return 0;