Deleted Added
full compact
common.c (230478) common.c (234837)
1/*-
2 * Copyright (c) 1998-2011 Dag-Erling Sm��rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998-2011 Dag-Erling Sm��rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/lib/libfetch/common.c 230478 2012-01-23 09:23:07Z des $");
30__FBSDID("$FreeBSD: head/lib/libfetch/common.c 234837 2012-04-30 12:11:45Z des $");
31
32#include <sys/param.h>
33#include <sys/socket.h>
34#include <sys/time.h>
35#include <sys/uio.h>
36
37#include <netinet/in.h>
38

--- 411 unchanged lines hidden (view full) ---

450 * Read a character from a connection w/ timeout
451 */
452ssize_t
453fetch_read(conn_t *conn, char *buf, size_t len)
454{
455 struct timeval now, timeout, delta;
456 fd_set readfds;
457 ssize_t rlen, total;
31
32#include <sys/param.h>
33#include <sys/socket.h>
34#include <sys/time.h>
35#include <sys/uio.h>
36
37#include <netinet/in.h>
38

--- 411 unchanged lines hidden (view full) ---

450 * Read a character from a connection w/ timeout
451 */
452ssize_t
453fetch_read(conn_t *conn, char *buf, size_t len)
454{
455 struct timeval now, timeout, delta;
456 fd_set readfds;
457 ssize_t rlen, total;
458 int r;
459 char *start;
460
458 char *start;
459
461 if (fetchTimeout) {
462 FD_ZERO(&readfds);
460 if (fetchTimeout > 0) {
463 gettimeofday(&timeout, NULL);
464 timeout.tv_sec += fetchTimeout;
465 }
466
467 total = 0;
468 start = buf;
469
470 if (conn->cache.len > 0) {

--- 47 unchanged lines hidden (view full) ---

518 total += rlen;
519 continue;
520 } else if (rlen == FETCH_READ_ERROR) {
521 if (errno == EINTR)
522 fetch_cache_data(conn, start, total);
523 return (-1);
524 }
525 // assert(rlen == FETCH_READ_WAIT);
461 gettimeofday(&timeout, NULL);
462 timeout.tv_sec += fetchTimeout;
463 }
464
465 total = 0;
466 start = buf;
467
468 if (conn->cache.len > 0) {

--- 47 unchanged lines hidden (view full) ---

516 total += rlen;
517 continue;
518 } else if (rlen == FETCH_READ_ERROR) {
519 if (errno == EINTR)
520 fetch_cache_data(conn, start, total);
521 return (-1);
522 }
523 // assert(rlen == FETCH_READ_WAIT);
526 while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) {
524 FD_ZERO(&readfds);
525 while (!FD_ISSET(conn->sd, &readfds)) {
527 FD_SET(conn->sd, &readfds);
526 FD_SET(conn->sd, &readfds);
528 gettimeofday(&now, NULL);
529 delta.tv_sec = timeout.tv_sec - now.tv_sec;
530 delta.tv_usec = timeout.tv_usec - now.tv_usec;
531 if (delta.tv_usec < 0) {
532 delta.tv_usec += 1000000;
533 delta.tv_sec--;
527 if (fetchTimeout > 0) {
528 gettimeofday(&now, NULL);
529 if (!timercmp(&timeout, &now, >)) {
530 errno = ETIMEDOUT;
531 fetch_syserr();
532 return (-1);
533 }
534 timersub(&timeout, &now, &delta);
534 }
535 }
535 if (delta.tv_sec < 0) {
536 errno = ETIMEDOUT;
537 fetch_syserr();
538 return (-1);
539 }
540 errno = 0;
536 errno = 0;
541 r = select(conn->sd + 1, &readfds, NULL, NULL, &delta);
542 if (r == -1) {
537 if (select(conn->sd + 1, &readfds, NULL, NULL,
538 fetchTimeout > 0 ? &delta : NULL) < 0) {
543 if (errno == EINTR) {
544 if (fetchRestartCalls)
545 continue;
546 /* Save anything that was read. */
547 fetch_cache_data(conn, start, total);
548 }
549 fetch_syserr();
550 return (-1);

--- 359 unchanged lines hidden ---
539 if (errno == EINTR) {
540 if (fetchRestartCalls)
541 continue;
542 /* Save anything that was read. */
543 fetch_cache_data(conn, start, total);
544 }
545 fetch_syserr();
546 return (-1);

--- 359 unchanged lines hidden ---