Page MenuHomePhorge

retry.c
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
/* retry.c -- keep trying write system calls
$Id: retry.c,v 1.10 1998/05/15 21:52:55 neplokh Exp $
# Copyright 1998 by Carnegie Mellon University
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of CMU not be
# used in advertising or publicity pertaining to distribution of the
# software without specific, written prior permission.
#
# CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
# CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
*
*/
#include <errno.h>
#include <sys/types.h>
#include <sys/uio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "retry.h"
extern int errno;
/*
* Keep calling the write() system call with 'fd', 'buf', and 'nbyte'
* until all the data is written out or an error occurs.
*/
int
retry_write(fd, buf, nbyte)
int fd;
const char *buf;
unsigned nbyte;
{
int n;
int written = 0;
if (nbyte == 0) return 0;
for (;;) {
n = write(fd, buf, nbyte);
if (n == -1) {
if (errno == EINTR) continue;
return -1;
}
written += n;
if (n >= nbyte) return written;
buf += n;
nbyte -= n;
}
}
/*
* Keep calling the writev() system call with 'fd', 'iov', and 'iovcnt'
* until all the data is written out or an error occurs.
*/
int
retry_writev(fd, iov, iovcnt)
int fd;
struct iovec *iov;
int iovcnt;
{
int n;
int i;
int written = 0;
static int iov_max =
#ifdef MAXIOV
MAXIOV
#else
#ifdef IOV_MAX
IOV_MAX
#else
8192
#endif
#endif
;
for (;;) {
while (iovcnt && iov[0].iov_len == 0) {
iov++;
iovcnt--;
}
if (!iovcnt) return written;
n = writev(fd, iov, iovcnt > iov_max ? iov_max : iovcnt);
if (n == -1) {
if (errno == EINVAL && iov_max > 10) {
iov_max /= 2;
continue;
}
if (errno == EINTR) continue;
return -1;
}
written += n;
for (i = 0; i < iovcnt; i++) {
if (iov[i].iov_len > n) {
iov[i].iov_base = (char *)iov[i].iov_base + n;
iov[i].iov_len -= n;
break;
}
n -= iov[i].iov_len;
iov[i].iov_len = 0;
}
if (i == iovcnt) return written;
}
}

File Metadata

Mime Type
text/x-c
Expires
Sat, Apr 4, 1:48 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18822016
Default Alt Text
retry.c (2 KB)

Event Timeline