atomicio.c (181111) | atomicio.c (221420) |
---|---|
1/* $OpenBSD: atomicio.c,v 1.25 2007/06/25 12:02:27 dtucker Exp $ */ | 1/* $OpenBSD: atomicio.c,v 1.26 2010/09/22 22:58:51 djm Exp $ */ |
2/* 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. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 33 unchanged lines hidden (view full) --- 43#include <unistd.h> 44 45#include "atomicio.h" 46 47/* 48 * ensure all of data on socket comes through. f==read || f==vwrite 49 */ 50size_t | 2/* 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. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 33 unchanged lines hidden (view full) --- 43#include <unistd.h> 44 45#include "atomicio.h" 46 47/* 48 * ensure all of data on socket comes through. f==read || f==vwrite 49 */ 50size_t |
51atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n) | 51atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n, 52 int (*cb)(void *, size_t), void *cb_arg) |
52{ 53 char *s = _s; 54 size_t pos = 0; 55 ssize_t res; 56 struct pollfd pfd; 57 58 pfd.fd = fd; 59 pfd.events = f == read ? POLLIN : POLLOUT; --- 8 unchanged lines hidden (view full) --- 68 continue; 69 } 70 return 0; 71 case 0: 72 errno = EPIPE; 73 return pos; 74 default: 75 pos += (size_t)res; | 53{ 54 char *s = _s; 55 size_t pos = 0; 56 ssize_t res; 57 struct pollfd pfd; 58 59 pfd.fd = fd; 60 pfd.events = f == read ? POLLIN : POLLOUT; --- 8 unchanged lines hidden (view full) --- 69 continue; 70 } 71 return 0; 72 case 0: 73 errno = EPIPE; 74 return pos; 75 default: 76 pos += (size_t)res; |
77 if (cb != NULL && cb(cb_arg, (size_t)res) == -1) { 78 errno = EINTR; 79 return pos; 80 } |
|
76 } 77 } | 81 } 82 } |
78 return (pos); | 83 return pos; |
79} 80 | 84} 85 |
86size_t 87atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n) 88{ 89 return atomicio6(f, fd, _s, n, NULL, NULL); 90} 91 |
|
81/* 82 * ensure all of data on socket comes through. f==readv || f==writev 83 */ 84size_t | 92/* 93 * ensure all of data on socket comes through. f==readv || f==writev 94 */ 95size_t |
85atomiciov(ssize_t (*f) (int, const struct iovec *, int), int fd, 86 const struct iovec *_iov, int iovcnt) | 96atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd, 97 const struct iovec *_iov, int iovcnt, 98 int (*cb)(void *, size_t), void *cb_arg) |
87{ 88 size_t pos = 0, rem; 89 ssize_t res; 90 struct iovec iov_array[IOV_MAX], *iov = iov_array; 91 struct pollfd pfd; 92 93 if (iovcnt > IOV_MAX) { 94 errno = EINVAL; --- 37 unchanged lines hidden (view full) --- 132 return 0; 133 } 134 if (iovcnt == 0) 135 break; 136 /* update pointer in partially complete iov */ 137 iov[0].iov_base = ((char *)iov[0].iov_base) + rem; 138 iov[0].iov_len -= rem; 139 } | 99{ 100 size_t pos = 0, rem; 101 ssize_t res; 102 struct iovec iov_array[IOV_MAX], *iov = iov_array; 103 struct pollfd pfd; 104 105 if (iovcnt > IOV_MAX) { 106 errno = EINVAL; --- 37 unchanged lines hidden (view full) --- 144 return 0; 145 } 146 if (iovcnt == 0) 147 break; 148 /* update pointer in partially complete iov */ 149 iov[0].iov_base = ((char *)iov[0].iov_base) + rem; 150 iov[0].iov_len -= rem; 151 } |
152 if (cb != NULL && cb(cb_arg, (size_t)res) == -1) { 153 errno = EINTR; 154 return pos; 155 } |
|
140 } 141 return pos; 142} | 156 } 157 return pos; 158} |
159 160size_t 161atomiciov(ssize_t (*f) (int, const struct iovec *, int), int fd, 162 const struct iovec *_iov, int iovcnt) 163{ 164 return atomiciov6(f, fd, _iov, iovcnt, NULL, NULL); 165} |
|