/* Extracted from anet.c to work properly with Hiredis error reporting. * * Copyright (c) 2009-2011, Salvatore Sanfilippo * Copyright (c) 2010-2014, Pieter Noordhuis * Copyright (c) 2015, Matt Stancliff , * Jan-Erik Rediger * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Redis nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "fmacros.h" #include #include #include #include #include #include #include #include #include "net.h" #include "sds.h" #include "sockcompat.h" #include "win32.h" /* Defined in hiredis.c */ void __redisSetError(redisContext *c, int type, const char *str); int redisContextUpdateCommandTimeout(redisContext *c, const struct timeval *timeout); void redisNetClose(redisContext *c) { if (c && c->fd != REDIS_INVALID_FD) { close(c->fd); c->fd = REDIS_INVALID_FD; } } ssize_t redisNetRead(redisContext *c, char *buf, size_t bufcap) { ssize_t nread = recv(c->fd, buf, bufcap, 0); if (nread == -1) { if ((errno == EWOULDBLOCK && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) { /* Try again later */ return 0; } else if(errno == ETIMEDOUT && (c->flags & REDIS_BLOCK)) { /* especially in windows */ __redisSetError(c, REDIS_ERR_TIMEOUT, "recv timeout"); return -1; } else { __redisSetError(c, REDIS_ERR_IO, strerror(errno)); return -1; } } else if (nread == 0) { __redisSetError(c, REDIS_ERR_EOF, "Server closed the connection"); return -1; } else { return nread; } } ssize_t redisNetWrite(redisContext *c) { ssize_t nwritten; nwritten = send(c->fd, c->obuf, sdslen(c->obuf), 0); if (nwritten < 0) { if ((errno == EWOULDBLOCK && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) { /* Try again */ return 0; } else { __redisSetError(c, REDIS_ERR_IO, strerror(errno)); return -1; } } return nwritten; } static void __redisSetErrorFromErrno(redisContext *c, int type, const char *prefix) { int errorno = errno; /* snprintf() may change errno */ char buf[128] = { 0 }; size_t len = 0; if (prefix != NULL) len = snprintf(buf,sizeof(buf),"%s: ",prefix); strerror_r(errorno, (char *)(buf + len), sizeof(buf) - len); __redisSetError(c,type,buf); } static int redisSetReuseAddr(redisContext *c) { int on = 1; if (setsockopt(c->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); redisNetClose(c); return REDIS_ERR; } return REDIS_OK; } static int redisCreateSocket(redisContext *c, int type) { redisFD s; if ((s = socket(type, SOCK_STREAM, 0)) == REDIS_INVALID_FD) { __redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL); return REDIS_ERR; } c->fd = s; if (type == AF_INET) { if (redisSetReuseAddr(c) == REDIS_ERR) { return REDIS_ERR; } } return REDIS_OK; } static int redisSetBlocking(redisContext *c, int blocking) { #ifndef _WIN32 int flags; /* Set the socket nonblocking. * Note that fcntl(2) for F_GETFL and F_SETFL can't be * interrupted by a signal. */ if ((flags = fcntl(c->fd, F_GETFL)) == -1) { __redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_GETFL)"); redisNetClose(c); return REDIS_ERR; } if (blocking) flags &= ~O_NONBLOCK; else flags |= O_NONBLOCK; if (fcntl(c->fd, F_SETFL, flags) == -1) { __redisSetErrorFromErrno(c,REDIS_ERR_IO,"fcntl(F_SETFL)"); redisNetClose(c); return REDIS_ERR; } #else u_long mode = blocking ? 0 : 1; if (ioctl(c->fd, FIONBIO, &mode) == -1) { __redisSetErrorFromErrno(c, REDIS_ERR_IO, "ioctl(FIONBIO)"); redisNetClose(c); return REDIS_ERR; } #endif /* _WIN32 */ return REDIS_OK; } int redisKeepAlive(redisContext *c, int interval) { int val = 1; redisFD fd = c->fd; #ifndef _WIN32 if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){ __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); return REDIS_ERR; } val = interval; #if defined(__APPLE__) && defined(__MACH__) if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &val, sizeof(val)) < 0) { __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); return REDIS_ERR; } #else #if defined(__GLIBC__) && !defined(__FreeBSD_kernel__) if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) { __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); return REDIS_ERR; } val = interval/3; if (val == 0) val = 1; if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) { __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); return REDIS_ERR; } val = 3; if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) { __redisSetError(c,REDIS_ERR_OTHER,strerror(errno)); return REDIS_ERR; } #endif #endif #else int res; res = win32_redisKeepAlive(fd, interval * 1000); if (res != 0) { __redisSetError(c, REDIS_ERR_OTHER, strerror(res)); return REDIS_ERR; } #endif return REDIS_OK; } int redisSetTcpNoDelay(redisContext *c) { int yes = 1; if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) == -1) { __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(TCP_NODELAY)"); redisNetClose(c); return REDIS_ERR; } return REDIS_OK; } int redisContextSetTcpUserTimeout(redisContext *c, unsigned int timeout) { int res; #ifdef TCP_USER_TIMEOUT res = setsockopt(c->fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout)); #else res = -1; errno = ENOTSUP; (void)timeout; #endif if (res == -1) {
{
  "name": "vaadin-core",
  "authors": [
    "Vaadin Ltd"
  ],
  "description": "The Vaadin core components are an evolving set of free and open source, standards-based web components.",
  "license": "Apache-2.0",
  "keywords": [
    "vaadin",
    "core",
    "elements",
    "web",
    "components",
    "webcomponents",
    "web-components",
    "element-collection"
  ],
  "main": "vaadin-core.html",
  "ignore": [
    "**/.*",
    "**/node_modules",
    "**/bower_components",
    "**/test",
    "**/tests",
    "**/vaadin-core.js"
  ],
  "dependencies": {
    "iron-a11y-announcer": "iron-a11y-announcer#2.1.0",
    "iron-a11y-keys-behavior": "iron-a11y-keys-behavior#2.1.1",
    "iron-fit-behavior": "iron-fit-behavior#2.2.1",
    "iron-flex-layout": "iron-flex-layout#2.0.3",
    "iron-icon": "iron-icon#2.1.0",
    "iron-iconset-svg": "iron-iconset-svg#2.2.1",
    "iron-list": "iron-list#2.0.20",
    "iron-media-query": "iron-media-query#2.1.0",
    "iron-meta": "iron-meta#2.1.1",
    "iron-overlay-behavior": "iron-overlay-behavior#2.3.4",
    "iron-resizable-behavior": "iron-resizable-behavior#2.1.1",
    "iron-scroll-target-behavior": "iron-scroll-target-behavior#2.1.1",
    "polymer": "polymer#2.7.0",
    "shadycss": "shadycss#1.8.0",
    "vaadin-accordion": "vaadin/vaadin-accordion#1.2.0",
    "vaadin-app-layout": "vaadin/vaadin-app-layout#2.2.0",
    "vaadin-avatar": "vaadin/vaadin-avatar#1.0.4",
    "vaadin-button": "vaadin/vaadin-button#2.4.0",
    "vaadin-checkbox": "vaadin/vaadin-checkbox#2.5.1",
    "vaadin-combo-box": "vaadin/vaadin-combo-box#5.4.12",
    "vaadin-context-menu": "vaadin/vaadin-context-menu#4.6.0",
    "vaadin-control-state-mixin": "vaadin/vaadin-control-state-mixin#2.2.6",
    "vaadin-custom-field": "vaadin/vaadin-custom-field#1.3.1",
    "vaadin-date-picker": "vaadin/vaadin-date-picker#4.4.2",
    "vaadin-date-time-picker": "vaadin/vaadin-date-time-picker#1.4.0",
    "vaadin-details": "vaadin/vaadin-details#1.2.1",
    "vaadin-development-mode-detector": "vaadin/vaadin-development-mode-detector#2.0.5",
    "vaadin-dialog": "vaadin/vaadin-dialog#2.6.0",
    "vaadin-element-mixin": "vaadin/vaadin-element-mixin#2.4.2",
    "vaadin-form-layout": "vaadin/vaadin-form-layout#2.3.0",
    "vaadin-grid": "vaadin/vaadin-grid#5.9.4",
    "vaadin-icons": "vaadin/vaadin-icons#4.3.2",
    "vaadin-item": "vaadin/vaadin-item#2.3.0",
    "vaadin-list-box": "vaadin/vaadin-list-box#1.4.0",
    "vaadin-list-mixin": "vaadin/vaadin-list-mixin#2.5.1",
    "vaadin-login": "vaadin/vaadin-login#1.2.0",
    "vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#1.6.1",
    "vaadin-material-styles": "vaadin/vaadin-material-styles#1.3.2",
    "vaadin-menu-bar": "vaadin/vaadin-menu-bar#1.3.0",
    "vaadin-notification": "vaadin/vaadin-notification#1.6.2",
    "vaadin-ordered-layout": "vaadin/vaadin-ordered-layout#1.4.0",
    "vaadin-overlay": "vaadin/vaadin-overlay#3.5.1",
    "vaadin-progress-bar": "vaadin/vaadin-progress-bar#1.3.0",
    "vaadin-radio-button": "vaadin/vaadin-radio-button#1.5.4",
    "vaadin-select": "vaadin/vaadin-select#2.4.3",
    "vaadin-split-layout": "vaadin/vaadin-split-layout#4.3.1",
    "vaadin-tabs": "vaadin/vaadin-tabs#3.2.0",
    "vaadin-text-field": "vaadin/vaadin-text-field#2.9.2",
    "vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#1.6.2",
    "vaadin-time-picker": "vaadin/vaadin-time-picker#2.4.0",
    "vaadin-upload": "vaadin/vaadin-upload#4.4.3",
    "vaadin-usage-statistics": "vaadin/vaadin-usage-statistics#2.1.2",
    "webcomponentsjs": "webcomponentsjs#1.2.6"
  }
}