diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/nc/atomicio.c | 29 | ||||
-rw-r--r-- | src/usr.bin/nc/atomicio.h | 8 |
2 files changed, 24 insertions, 13 deletions
diff --git a/src/usr.bin/nc/atomicio.c b/src/usr.bin/nc/atomicio.c index c3f26846df..e9d98b3561 100644 --- a/src/usr.bin/nc/atomicio.c +++ b/src/usr.bin/nc/atomicio.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* $OpenBSD: atomicio.c,v 1.8 2006/02/11 19:31:18 otto Exp $ */ | 1 | /* $OpenBSD: atomicio.c,v 1.9 2007/09/07 14:50:44 tobias Exp $ */ |
2 | |||
3 | /* | 2 | /* |
4 | * Copyright (c) 2005 Anil Madhavapeddy. All rights served. | 3 | * Copyright (c) 2006 Damien Miller. All rights reserved. |
4 | * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved. | ||
5 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. | 5 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -26,32 +26,37 @@ | |||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <sys/types.h> | 29 | #include <sys/param.h> |
30 | #include <sys/uio.h> | 30 | |
31 | #include <errno.h> | 31 | #include <errno.h> |
32 | #include <poll.h> | ||
32 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | |||
33 | #include "atomicio.h" | 35 | #include "atomicio.h" |
34 | 36 | ||
35 | /* | 37 | /* |
36 | * ensure all of data on socket comes through. f==read || f==vwrite | 38 | * ensure all of data on socket comes through. f==read || f==vwrite |
37 | */ | 39 | */ |
38 | size_t | 40 | size_t |
39 | atomicio(f, fd, _s, n) | 41 | atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n) |
40 | ssize_t (*f) (int, void *, size_t); | ||
41 | int fd; | ||
42 | void *_s; | ||
43 | size_t n; | ||
44 | { | 42 | { |
45 | char *s = _s; | 43 | char *s = _s; |
46 | size_t pos = 0; | 44 | size_t pos = 0; |
47 | ssize_t res; | 45 | ssize_t res; |
46 | struct pollfd pfd; | ||
48 | 47 | ||
48 | pfd.fd = fd; | ||
49 | pfd.events = f == read ? POLLIN : POLLOUT; | ||
49 | while (n > pos) { | 50 | while (n > pos) { |
50 | res = (f) (fd, s + pos, n - pos); | 51 | res = (f) (fd, s + pos, n - pos); |
51 | switch (res) { | 52 | switch (res) { |
52 | case -1: | 53 | case -1: |
53 | if (errno == EINTR || errno == EAGAIN) | 54 | if (errno == EINTR) |
55 | continue; | ||
56 | if (errno == EAGAIN) { | ||
57 | (void)poll(&pfd, 1, -1); | ||
54 | continue; | 58 | continue; |
59 | } | ||
55 | return 0; | 60 | return 0; |
56 | case 0: | 61 | case 0: |
57 | errno = EPIPE; | 62 | errno = EPIPE; |
@@ -60,5 +65,5 @@ atomicio(f, fd, _s, n) | |||
60 | pos += (size_t)res; | 65 | pos += (size_t)res; |
61 | } | 66 | } |
62 | } | 67 | } |
63 | return pos; | 68 | return (pos); |
64 | } | 69 | } |
diff --git a/src/usr.bin/nc/atomicio.h b/src/usr.bin/nc/atomicio.h index 551a0565da..7bf5b25418 100644 --- a/src/usr.bin/nc/atomicio.h +++ b/src/usr.bin/nc/atomicio.h | |||
@@ -1,6 +1,7 @@ | |||
1 | /* $OpenBSD: atomicio.h,v 1.1 2005/05/24 20:13:28 avsm Exp $ */ | 1 | /* $OpenBSD: atomicio.h,v 1.2 2007/09/07 14:50:44 tobias Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2006 Damien Miller. All rights reserved. | ||
4 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. | 5 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. |
5 | * All rights reserved. | 6 | * All rights reserved. |
6 | * | 7 | * |
@@ -25,9 +26,14 @@ | |||
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 27 | */ |
27 | 28 | ||
29 | #ifndef _ATOMICIO_H | ||
30 | #define _ATOMICIO_H | ||
31 | |||
28 | /* | 32 | /* |
29 | * Ensure all of data on socket comes through. f==read || f==vwrite | 33 | * Ensure all of data on socket comes through. f==read || f==vwrite |
30 | */ | 34 | */ |
31 | size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t); | 35 | size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t); |
32 | 36 | ||
33 | #define vwrite (ssize_t (*)(int, void *, size_t))write | 37 | #define vwrite (ssize_t (*)(int, void *, size_t))write |
38 | |||
39 | #endif /* _ATOMICIO_H */ | ||