common.c (176105) | common.c (177447) |
---|---|
1/*- 2 * Copyright (c) 1998-2004 Dag-Erling Co�dan 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-2004 Dag-Erling Co�dan 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 176105 2008-02-08 09:48:48Z des $"); | 30__FBSDID("$FreeBSD: head/lib/libfetch/common.c 177447 2008-03-20 09:55:27Z 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 --- 333 unchanged lines hidden (view full) --- 372 373 374/* 375 * Read a character from a connection w/ timeout 376 */ 377ssize_t 378fetch_read(conn_t *conn, char *buf, size_t len) 379{ | 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 --- 333 unchanged lines hidden (view full) --- 372 373 374/* 375 * Read a character from a connection w/ timeout 376 */ 377ssize_t 378fetch_read(conn_t *conn, char *buf, size_t len) 379{ |
380 struct timeval now, timeout, wait; | 380 struct timeval now, timeout, delta; |
381 fd_set readfds; 382 ssize_t rlen, total; 383 int r; 384 385 if (fetchTimeout) { 386 FD_ZERO(&readfds); 387 gettimeofday(&timeout, NULL); 388 timeout.tv_sec += fetchTimeout; 389 } 390 391 total = 0; 392 while (len > 0) { 393 while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) { 394 FD_SET(conn->sd, &readfds); 395 gettimeofday(&now, NULL); | 381 fd_set readfds; 382 ssize_t rlen, total; 383 int r; 384 385 if (fetchTimeout) { 386 FD_ZERO(&readfds); 387 gettimeofday(&timeout, NULL); 388 timeout.tv_sec += fetchTimeout; 389 } 390 391 total = 0; 392 while (len > 0) { 393 while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) { 394 FD_SET(conn->sd, &readfds); 395 gettimeofday(&now, NULL); |
396 wait.tv_sec = timeout.tv_sec - now.tv_sec; 397 wait.tv_usec = timeout.tv_usec - now.tv_usec; 398 if (wait.tv_usec < 0) { 399 wait.tv_usec += 1000000; 400 wait.tv_sec--; | 396 delta.tv_sec = timeout.tv_sec - now.tv_sec; 397 delta.tv_usec = timeout.tv_usec - now.tv_usec; 398 if (delta.tv_usec < 0) { 399 delta.tv_usec += 1000000; 400 delta.tv_sec--; |
401 } | 401 } |
402 if (wait.tv_sec < 0) { | 402 if (delta.tv_sec < 0) { |
403 errno = ETIMEDOUT; 404 fetch_syserr(); 405 return (-1); 406 } 407 errno = 0; | 403 errno = ETIMEDOUT; 404 fetch_syserr(); 405 return (-1); 406 } 407 errno = 0; |
408 r = select(conn->sd + 1, &readfds, NULL, NULL, &wait); | 408 r = select(conn->sd + 1, &readfds, NULL, NULL, &delta); |
409 if (r == -1) { 410 if (errno == EINTR && fetchRestartCalls) 411 continue; 412 fetch_syserr(); 413 return (-1); 414 } 415 } 416#ifdef WITH_SSL --- 81 unchanged lines hidden (view full) --- 498 499/* 500 * Write a vector to a connection w/ timeout 501 * Note: can modify the iovec. 502 */ 503ssize_t 504fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt) 505{ | 409 if (r == -1) { 410 if (errno == EINTR && fetchRestartCalls) 411 continue; 412 fetch_syserr(); 413 return (-1); 414 } 415 } 416#ifdef WITH_SSL --- 81 unchanged lines hidden (view full) --- 498 499/* 500 * Write a vector to a connection w/ timeout 501 * Note: can modify the iovec. 502 */ 503ssize_t 504fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt) 505{ |
506 struct timeval now, timeout, wait; | 506 struct timeval now, timeout, delta; |
507 fd_set writefds; 508 ssize_t wlen, total; 509 int r; 510 511 if (fetchTimeout) { 512 FD_ZERO(&writefds); 513 gettimeofday(&timeout, NULL); 514 timeout.tv_sec += fetchTimeout; 515 } 516 517 total = 0; 518 while (iovcnt > 0) { 519 while (fetchTimeout && !FD_ISSET(conn->sd, &writefds)) { 520 FD_SET(conn->sd, &writefds); 521 gettimeofday(&now, NULL); | 507 fd_set writefds; 508 ssize_t wlen, total; 509 int r; 510 511 if (fetchTimeout) { 512 FD_ZERO(&writefds); 513 gettimeofday(&timeout, NULL); 514 timeout.tv_sec += fetchTimeout; 515 } 516 517 total = 0; 518 while (iovcnt > 0) { 519 while (fetchTimeout && !FD_ISSET(conn->sd, &writefds)) { 520 FD_SET(conn->sd, &writefds); 521 gettimeofday(&now, NULL); |
522 wait.tv_sec = timeout.tv_sec - now.tv_sec; 523 wait.tv_usec = timeout.tv_usec - now.tv_usec; 524 if (wait.tv_usec < 0) { 525 wait.tv_usec += 1000000; 526 wait.tv_sec--; | 522 delta.tv_sec = timeout.tv_sec - now.tv_sec; 523 delta.tv_usec = timeout.tv_usec - now.tv_usec; 524 if (delta.tv_usec < 0) { 525 delta.tv_usec += 1000000; 526 delta.tv_sec--; |
527 } | 527 } |
528 if (wait.tv_sec < 0) { | 528 if (delta.tv_sec < 0) { |
529 errno = ETIMEDOUT; 530 fetch_syserr(); 531 return (-1); 532 } 533 errno = 0; | 529 errno = ETIMEDOUT; 530 fetch_syserr(); 531 return (-1); 532 } 533 errno = 0; |
534 r = select(conn->sd + 1, NULL, &writefds, NULL, &wait); | 534 r = select(conn->sd + 1, NULL, &writefds, NULL, &delta); |
535 if (r == -1) { 536 if (errno == EINTR && fetchRestartCalls) 537 continue; 538 return (-1); 539 } 540 } 541 errno = 0; 542#ifdef WITH_SSL --- 244 unchanged lines hidden --- | 535 if (r == -1) { 536 if (errno == EINTR && fetchRestartCalls) 537 continue; 538 return (-1); 539 } 540 } 541 errno = 0; 542#ifdef WITH_SSL --- 244 unchanged lines hidden --- |