summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/common.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-10-27 15:08:21 +0000
committerdes <des@FreeBSD.org>2002-10-27 15:08:21 +0000
commitcd8380e0b156cfdccb144d199ab89d1e0758125b (patch)
tree049f7502162bea5b37a3afcbb4de1b56573bfbcb /lib/libfetch/common.c
parent0ef4b48b325b25c24a840a0a90f06816cd9b6221 (diff)
downloadFreeBSD-src-cd8380e0b156cfdccb144d199ab89d1e0758125b.zip
FreeBSD-src-cd8380e0b156cfdccb144d199ab89d1e0758125b.tar.gz
Back out the previous commit, and fix the bug rather than try to hide its
symptoms: make timeouts and short transfers fatal, and set errno to an appropriate value (ETIMEDOUT for a timeout, EPIPE for a short transfer). MFC after: 2 weeks
Diffstat (limited to 'lib/libfetch/common.c')
-rw-r--r--lib/libfetch/common.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index 07434c6..df6d870 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -364,13 +364,17 @@ _fetch_read(conn_t *conn, char *buf, size_t len)
wait.tv_usec += 1000000;
wait.tv_sec--;
}
- if (wait.tv_sec < 0)
- return (rlen);
+ if (wait.tv_sec < 0) {
+ errno = ETIMEDOUT;
+ _fetch_syserr();
+ return (-1);
+ }
errno = 0;
r = select(conn->sd + 1, &readfds, NULL, NULL, &wait);
if (r == -1) {
if (errno == EINTR && fetchRestartCalls)
continue;
+ _fetch_syserr();
return (-1);
}
}
@@ -380,8 +384,12 @@ _fetch_read(conn_t *conn, char *buf, size_t len)
else
#endif
rlen = read(conn->sd, buf, len);
- if (rlen == 0)
- break;
+ if (rlen == 0) {
+ /* we consider a short read a failure */
+ errno = EPIPE;
+ _fetch_syserr();
+ return (-1);
+ }
if (rlen < 0) {
if (errno == EINTR && fetchRestartCalls)
continue;
@@ -406,7 +414,6 @@ _fetch_getln(conn_t *conn)
char *tmp;
size_t tmpsize;
char c;
- int error;
if (conn->buf == NULL) {
if ((conn->buf = malloc(MIN_BUF_SIZE)) == NULL) {
@@ -420,11 +427,8 @@ _fetch_getln(conn_t *conn)
conn->buflen = 0;
do {
- error = _fetch_read(conn, &c, 1);
- if (error == -1)
+ if (_fetch_read(conn, &c, 1) == -1)
return (-1);
- else if (error == 0)
- break;
conn->buf[conn->buflen++] = c;
if (conn->buflen == conn->bufsize) {
tmp = conn->buf;
@@ -473,6 +477,7 @@ _fetch_write(conn_t *conn, const char *buf, size_t len)
}
if (wait.tv_sec < 0) {
errno = ETIMEDOUT;
+ _fetch_syserr();
return (-1);
}
errno = 0;
@@ -490,9 +495,12 @@ _fetch_write(conn_t *conn, const char *buf, size_t len)
else
#endif
wlen = write(conn->sd, buf, len);
- if (wlen == 0)
+ if (wlen == 0) {
/* we consider a short write a failure */
+ errno = EPIPE;
+ _fetch_syserr();
return (-1);
+ }
if (wlen < 0) {
if (errno == EINTR && fetchRestartCalls)
continue;
OpenPOWER on IntegriCloud