diff options
author | kaiw <kaiw@FreeBSD.org> | 2014-01-28 19:12:31 +0000 |
---|---|---|
committer | kaiw <kaiw@FreeBSD.org> | 2014-01-28 19:12:31 +0000 |
commit | 9c3c6fdae0b43f1bbd5486754c20e403fc83c3b6 (patch) | |
tree | c000f1bf7a21df619e5cc1ac52b3edc991b884d0 /lib | |
parent | 0fb1cfad9518e33fe20de1d9d694d0d5c2044fa2 (diff) | |
parent | 17e24564634134c9b7145fcf8d1c7d51b93c3182 (diff) | |
download | FreeBSD-src-9c3c6fdae0b43f1bbd5486754c20e403fc83c3b6.zip FreeBSD-src-9c3c6fdae0b43f1bbd5486754c20e403fc83c3b6.tar.gz |
MFH@261240.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libfetch/common.c | 133 | ||||
-rw-r--r-- | lib/libfetch/common.h | 7 | ||||
-rw-r--r-- | lib/libfetch/http.c | 38 | ||||
-rw-r--r-- | lib/libsm/Makefile | 2 | ||||
-rw-r--r-- | lib/libusb/libusb10.c | 10 | ||||
-rw-r--r-- | lib/msun/arm/fenv.h | 18 | ||||
-rw-r--r-- | lib/msun/src/fenv-softfloat.h | 6 |
7 files changed, 75 insertions, 139 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c index fbacb02..ab81b58 100644 --- a/lib/libfetch/common.c +++ b/lib/libfetch/common.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <fcntl.h> #include <netdb.h> +#include <poll.h> #include <pwd.h> #include <stdarg.h> #include <stdlib.h> @@ -641,7 +642,7 @@ fetch_ssl_verify_hname(X509 *cert, const char *host) struct addrinfo *ip; STACK_OF(GENERAL_NAME) *altnames; X509_NAME *subject; - int ret; + int ret; ret = 0; ip = fetch_ssl_get_numeric_addrinfo(host, strlen(host)); @@ -913,33 +914,6 @@ fetch_ssl_read(SSL *ssl, char *buf, size_t len) } #endif -/* - * Cache some data that was read from a socket but cannot be immediately - * returned because of an interrupted system call. - */ -static int -fetch_cache_data(conn_t *conn, char *src, size_t nbytes) -{ - char *tmp; - - if (conn->cache.size < nbytes) { - tmp = realloc(conn->cache.buf, nbytes); - if (tmp == NULL) { - fetch_syserr(); - return (-1); - } - conn->cache.buf = tmp; - conn->cache.size = nbytes; - } - - memcpy(conn->cache.buf, src, nbytes); - conn->cache.len = nbytes; - conn->cache.pos = 0; - - return (0); -} - - static ssize_t fetch_socket_read(int sd, char *buf, size_t len) { @@ -962,46 +936,31 @@ ssize_t fetch_read(conn_t *conn, char *buf, size_t len) { struct timeval now, timeout, delta; - fd_set readfds; - ssize_t rlen, total; - char *start; + struct pollfd pfd; + ssize_t rlen; + int deltams; if (fetchTimeout > 0) { gettimeofday(&timeout, NULL); timeout.tv_sec += fetchTimeout; } - total = 0; - start = buf; + deltams = INFTIM; + memset(&pfd, 0, sizeof pfd); + pfd.fd = conn->sd; + pfd.events = POLLIN | POLLERR; - if (conn->cache.len > 0) { - /* - * The last invocation of fetch_read was interrupted by a - * signal after some data had been read from the socket. Copy - * the cached data into the supplied buffer before trying to - * read from the socket again. - */ - total = (conn->cache.len < len) ? conn->cache.len : len; - memcpy(buf, conn->cache.buf, total); - - conn->cache.len -= total; - conn->cache.pos += total; - len -= total; - buf += total; - } - - while (len > 0) { + for (;;) { /* * The socket is non-blocking. Instead of the canonical - * select() -> read(), we do the following: + * poll() -> read(), we do the following: * * 1) call read() or SSL_read(). - * 2) if an error occurred, return -1. - * 3) if we received data but we still expect more, - * update our counters and loop. + * 2) if we received some data, return it. + * 3) if an error occurred, return -1. * 4) if read() or SSL_read() signaled EOF, return. * 5) if we did not receive any data but we're not at EOF, - * call select(). + * call poll(). * * In the SSL case, this is necessary because if we * receive a close notification, we have to call @@ -1017,46 +976,34 @@ fetch_read(conn_t *conn, char *buf, size_t len) else #endif rlen = fetch_socket_read(conn->sd, buf, len); - if (rlen == 0) { + if (rlen > 0) { break; - } else if (rlen > 0) { - len -= rlen; - buf += rlen; - total += rlen; - continue; } else if (rlen == FETCH_READ_ERROR) { if (errno == EINTR) - fetch_cache_data(conn, start, total); + break; return (-1); } - // assert(rlen == FETCH_READ_WAIT); - FD_ZERO(&readfds); - while (!FD_ISSET(conn->sd, &readfds)) { - FD_SET(conn->sd, &readfds); - if (fetchTimeout > 0) { - gettimeofday(&now, NULL); - if (!timercmp(&timeout, &now, >)) { - errno = ETIMEDOUT; - fetch_syserr(); - return (-1); - } - timersub(&timeout, &now, &delta); - } - errno = 0; - if (select(conn->sd + 1, &readfds, NULL, NULL, - fetchTimeout > 0 ? &delta : NULL) < 0) { - if (errno == EINTR) { - if (fetchRestartCalls) - continue; - /* Save anything that was read. */ - fetch_cache_data(conn, start, total); - } + if (fetchTimeout > 0) { + gettimeofday(&now, NULL); + if (!timercmp(&timeout, &now, >)) { + errno = ETIMEDOUT; fetch_syserr(); return (-1); } + timersub(&timeout, &now, &delta); + deltams = delta.tv_sec * 1000 + + delta.tv_usec / 1000;; + } + errno = 0; + pfd.revents = 0; + if (poll(&pfd, 1, deltams) < 0) { + if (errno == EINTR && fetchRestartCalls) + continue; + fetch_syserr(); + return (-1); } } - return (total); + return (rlen); } @@ -1130,20 +1077,21 @@ ssize_t fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt) { struct timeval now, timeout, delta; - fd_set writefds; + struct pollfd pfd; ssize_t wlen, total; - int r; + int deltams, r; + memset(&pfd, 0, sizeof pfd); if (fetchTimeout) { - FD_ZERO(&writefds); + pfd.fd = conn->sd; + pfd.events = POLLOUT | POLLERR; gettimeofday(&timeout, NULL); timeout.tv_sec += fetchTimeout; } total = 0; while (iovcnt > 0) { - while (fetchTimeout && !FD_ISSET(conn->sd, &writefds)) { - FD_SET(conn->sd, &writefds); + while (fetchTimeout && pfd.revents == 0) { gettimeofday(&now, NULL); delta.tv_sec = timeout.tv_sec - now.tv_sec; delta.tv_usec = timeout.tv_usec - now.tv_usec; @@ -1156,9 +1104,9 @@ fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt) fetch_syserr(); return (-1); } + deltams = delta.tv_sec * 1000 + delta.tv_usec / 1000;; errno = 0; - r = select(conn->sd + 1, NULL, &writefds, NULL, &delta); - if (r == -1) { + if ((r = poll(&pfd, 1, deltams)) == -1) { if (errno == EINTR && fetchRestartCalls) continue; return (-1); @@ -1250,7 +1198,6 @@ fetch_close(conn_t *conn) } #endif ret = close(conn->sd); - free(conn->cache.buf); free(conn->buf); free(conn); return (ret); diff --git a/lib/libfetch/common.h b/lib/libfetch/common.h index 1d543a6..ba45534 100644 --- a/lib/libfetch/common.h +++ b/lib/libfetch/common.h @@ -52,13 +52,6 @@ struct fetchconn { size_t bufsize; /* buffer size */ size_t buflen; /* length of buffer contents */ int err; /* last protocol reply code */ - struct { /* data cached after an interrupted - read */ - char *buf; - size_t size; - size_t pos; - size_t len; - } cache; #ifdef WITH_SSL SSL *ssl; /* SSL handle */ SSL_CTX *ssl_ctx; /* SSL context */ diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index 87535f0..fc43a97 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -208,6 +208,7 @@ static int http_fillbuf(struct httpio *io, size_t len) { ssize_t nbytes; + char ch; if (io->error) return (-1); @@ -249,10 +250,8 @@ http_fillbuf(struct httpio *io, size_t len) io->chunksize -= io->buflen; if (io->chunksize == 0) { - char endl[2]; - - if (fetch_read(io->conn, endl, 2) != 2 || - endl[0] != '\r' || endl[1] != '\n') + if (fetch_read(io->conn, &ch, 1) != 1 || ch != '\r' || + fetch_read(io->conn, &ch, 1) != 1 || ch != '\n') return (-1); } @@ -268,31 +267,28 @@ static int http_readfn(void *v, char *buf, int len) { struct httpio *io = (struct httpio *)v; - int l, pos; + int rlen; if (io->error) return (-1); if (io->eof) return (0); - for (pos = 0; len > 0; pos += l, len -= l) { - /* empty buffer */ - if (!io->buf || io->bufpos == io->buflen) - if (http_fillbuf(io, len) < 1) - break; - l = io->buflen - io->bufpos; - if (len < l) - l = len; - memcpy(buf + pos, io->buf + io->bufpos, l); - io->bufpos += l; + /* empty buffer */ + if (!io->buf || io->bufpos == io->buflen) { + if (http_fillbuf(io, len) < 1) { + if (io->error == EINTR) + io->error = 0; + return (-1); + } } - if (!pos && io->error) { - if (io->error == EINTR) - io->error = 0; - return (-1); - } - return (pos); + rlen = io->buflen - io->bufpos; + if (len < rlen) + rlen = len; + memcpy(buf, io->buf + io->bufpos, rlen); + io->bufpos += rlen; + return (rlen); } /* diff --git a/lib/libsm/Makefile b/lib/libsm/Makefile index ce590d7..07172c7 100644 --- a/lib/libsm/Makefile +++ b/lib/libsm/Makefile @@ -31,7 +31,7 @@ SRCS+= assert.c debug.c errstring.c exc.c heap.c match.c rpool.c \ wbuf.c wsetup.c string.c stringf.c \ xtrap.c strto.c test.c path.c strcasecmp.c strrevcmp.c \ signal.c clock.c config.c sem.c shm.c mbdb.c strexit.c cf.c ldap.c \ - niprop.c mpeix.c memstat.c util.c + niprop.c mpeix.c memstat.c util.c inet6_ntop.c CLEANFILES+=sm_os.h INTERNALLIB= diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 79a570e..c795ecf 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -611,7 +611,6 @@ int libusb_claim_interface(struct libusb20_device *pdev, int interface_number) { libusb_device *dev; - int err = 0; dev = libusb_get_device(pdev); if (dev == NULL) @@ -621,13 +620,10 @@ libusb_claim_interface(struct libusb20_device *pdev, int interface_number) return (LIBUSB_ERROR_INVALID_PARAM); CTX_LOCK(dev->ctx); - if (dev->claimed_interfaces & (1 << interface_number)) - err = LIBUSB_ERROR_BUSY; - - if (!err) - dev->claimed_interfaces |= (1 << interface_number); + dev->claimed_interfaces |= (1 << interface_number); CTX_UNLOCK(dev->ctx); - return (err); + + return (0); } int diff --git a/lib/msun/arm/fenv.h b/lib/msun/arm/fenv.h index 07b05c8..0605819 100644 --- a/lib/msun/arm/fenv.h +++ b/lib/msun/arm/fenv.h @@ -98,6 +98,8 @@ int feupdateenv(const fenv_t *__envp); #define vmrs_fpscr(__r) __asm __volatile("vmrs %0, fpscr" : "=&r"(__r)) #define vmsr_fpscr(__r) __asm __volatile("vmsr fpscr, %0" : : "r"(__r)) +#define _FPU_MASK_SHIFT 8 + __fenv_static inline int feclearexcept(int __excepts) { @@ -213,29 +215,31 @@ feupdateenv(const fenv_t *__envp) /* We currently provide no external definitions of the functions below. */ -static inline int +__fenv_static inline int feenableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr; vmrs_fpscr(__old_fpsr); - __new_fpsr = __old_fpsr | (__mask & FE_ALL_EXCEPT); + __new_fpsr = __old_fpsr | + ((__mask & FE_ALL_EXCEPT) << _FPU_MASK_SHIFT); vmsr_fpscr(__new_fpsr); - return (__old_fpsr & FE_ALL_EXCEPT); + return ((__old_fpsr >> _FPU_MASK_SHIFT) & FE_ALL_EXCEPT); } -static inline int +__fenv_static inline int fedisableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr; vmrs_fpscr(__old_fpsr); - __new_fpsr = __old_fpsr & ~(__mask & FE_ALL_EXCEPT); + __new_fpsr = __old_fpsr & + ~((__mask & FE_ALL_EXCEPT) << _FPU_MASK_SHIFT); vmsr_fpscr(__new_fpsr); - return (__old_fpsr & FE_ALL_EXCEPT); + return ((__old_fpsr >> _FPU_MASK_SHIFT) & FE_ALL_EXCEPT); } -static inline int +__fenv_static inline int fegetexcept(void) { fenv_t __fpsr; diff --git a/lib/msun/src/fenv-softfloat.h b/lib/msun/src/fenv-softfloat.h index 02d2a2c..48c1277 100644 --- a/lib/msun/src/fenv-softfloat.h +++ b/lib/msun/src/fenv-softfloat.h @@ -156,7 +156,7 @@ feupdateenv(const fenv_t *__envp) /* We currently provide no external definitions of the functions below. */ -static inline int +__fenv_static inline int feenableexcept(int __mask) { int __omask = __softfloat_float_exception_mask; @@ -165,7 +165,7 @@ feenableexcept(int __mask) return (__omask); } -static inline int +__fenv_static inline int fedisableexcept(int __mask) { int __omask = __softfloat_float_exception_mask; @@ -174,7 +174,7 @@ fedisableexcept(int __mask) return (__omask); } -static inline int +__fenv_static inline int fegetexcept(void) { |