Skip to content

Commit

Permalink
Upgrade hiredis and nghttp2 library (#4276)
Browse files Browse the repository at this point in the history
* sync hiredis-v1.0.0

* upgrade nghttp2

* improve redis result parser

* fix tests

* fix tests [2]

* update library

* fix tests
  • Loading branch information
matyhtf authored Jun 25, 2021
1 parent 5fdb4e0 commit 5b2a926
Show file tree
Hide file tree
Showing 28 changed files with 5,662 additions and 4,800 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ endif(CODE_COVERAGE)

file(GLOB_RECURSE SRC_LIST FOLLOW_SYMLINKS src/*.c src/*.cc
thirdparty/boost/asm/combined.S
thirdparty/hiredis/alloc.c
thirdparty/hiredis/async.c
thirdparty/hiredis/hiredis.c
thirdparty/hiredis/net.c
Expand Down
1 change: 1 addition & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ if test "$PHP_SWOOLE" != "no"; then

swoole_source_file="$swoole_source_file \
thirdparty/hiredis/hiredis.c \
thirdparty/hiredis/alloc.c \
thirdparty/hiredis/net.c \
thirdparty/hiredis/read.c \
thirdparty/hiredis/sds.c"
Expand Down
57 changes: 35 additions & 22 deletions ext-src/php_swoole_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated by build-library.php, Please DO NOT modify!
*/

/* $Id: 65ea83f61739de6203f1368150350fd3f91e3a7e */
/* $Id: 1ed49dbae3a1850b3a67d9904e07dac9b96adb43 */

static const char* swoole_library_source_constants =
"\n"
Expand Down Expand Up @@ -81,43 +81,56 @@ static const char* swoole_library_source_core_constant =
"\n"
"class Constant\n"
"{\n"
" public const EVENT_RECEIVE = 'receive';\n"
"\n"
" public const EVENT_CONNECT = 'connect';\n"
"\n"
" public const EVENT_CLOSE = 'close';\n"
" /* {{{ EVENT */\n"
" public const EVENT_START = 'start';\n"
"\n"
" public const EVENT_PACKET = 'packet';\n"
" public const EVENT_SHUTDOWN = 'shutdown';\n"
"\n"
" public const EVENT_REQUEST = 'request';\n"
" public const EVENT_WORKER_START = 'workerStart';\n"
"\n"
" public const EVENT_MESSAGE = 'message';\n"
" public const EVENT_WORKER_STOP = 'workerStop';\n"
"\n"
" public const EVENT_OPEN = 'open';\n"
" public const EVENT_BEFORE_RELOAD = 'beforeReload';\n"
"\n"
" public const EVENT_HANDSHAKE = 'handshake';\n"
" public const EVENT_AFTER_RELOAD = 'afterReload';\n"
"\n"
" public const EVENT_TASK = 'task';\n"
"\n"
" public const EVENT_FINISH = 'finish';\n"
"\n"
" public const EVENT_START = 'start';\n"
"\n"
" public const EVENT_SHUTDOWN = 'shutdown';\n"
"\n"
" public const EVENT_WORKER_START = 'workerStart';\n"
"\n"
" public const EVENT_WORKER_EXIT = 'workerExit';\n"
"\n"
" public const EVENT_WORKER_ERROR = 'workerError';\n"
"\n"
" public const EVENT_WORKER_STOP = 'workerStop';\n"
" public const EVENT_MANAGER_START = 'managerStart';\n"
"\n"
" public const EVENT_MANAGER_STOP = 'managerStop';\n"
"\n"
" public const EVENT_PIPE_MESSAGE = 'pipeMessage';\n"
"\n"
" public const EVENT_MANAGER_START = 'managerStart';\n"
" public const EVENT_CONNECT = 'connect';\n"
"\n"
" public const EVENT_MANAGER_STOP = 'managerStop';\n"
" public const EVENT_RECEIVE = 'receive';\n"
"\n"
" public const EVENT_CLOSE = 'close';\n"
"\n"
" public const EVENT_PACKET = 'packet';\n"
"\n"
" public const EVENT_BUFFER_FULL = 'bufferFull';\n"
"\n"
" public const EVENT_BUFFER_EMPTY = 'bufferEmpty';\n"
"\n"
" public const EVENT_REQUEST = 'request';\n"
"\n"
" public const EVENT_HANDSHAKE = 'handshake';\n"
"\n"
" public const EVENT_OPEN = 'open';\n"
"\n"
" public const EVENT_MESSAGE = 'message';\n"
"\n"
" public const EVENT_DISCONNECT = 'disconnect';\n"
"\n"
" /* }}} EVENT */\n"
"\n"
" public const EVENT_ERROR = 'error';\n"
"\n"
Expand Down Expand Up @@ -2031,15 +2044,15 @@ static const char* swoole_library_source_core_connection_pool =
" }\n"
" }\n"
"\n"
" public function get()\n"
" public function get(float $timeout = -1)\n"
" {\n"
" if ($this->pool === null) {\n"
" throw new RuntimeException('Pool has been closed');\n"
" }\n"
" if ($this->pool->isEmpty() && $this->num < $this->size) {\n"
" $this->make();\n"
" }\n"
" return $this->pool->pop();\n"
" return $this->pool->pop($timeout);\n"
" }\n"
"\n"
" public function put($connection): void\n"
Expand Down
8 changes: 8 additions & 0 deletions ext-src/swoole_redis_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4413,6 +4413,14 @@ static void swoole_redis_coro_parse_result(RedisClient *redis, zval *return_valu
ZVAL_LONG(return_value, reply->integer);
break;

case REDIS_REPLY_DOUBLE:
ZVAL_DOUBLE(return_value, reply->dval);
break;

case REDIS_REPLY_BOOL:
ZVAL_BOOL(return_value, reply->integer);
break;

case REDIS_REPLY_ERROR:
ZVAL_FALSE(return_value);
if (redis->context->err == 0) {
Expand Down
1 change: 1 addition & 0 deletions include/swoole_coroutine_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ int swoole_coroutine_close(int fd);
int swoole_coroutine_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int swoole_coroutine_poll(struct pollfd *fds, nfds_t nfds, int timeout);
int swoole_coroutine_socket_set_timeout(int fd, int which, double timeout);
int swoole_coroutine_socket_set_connect_timeout(int fd, double timeout);
int swoole_coroutine_socket_wait_event(int fd, int event, double timeout);
int swoole_coroutine_getaddrinfo(const char *name,
const char *service,
Expand Down
10 changes: 10 additions & 0 deletions src/coroutine/hook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,16 @@ int swoole_coroutine_socket_set_timeout(int sockfd, int which, double timeout) {
}
}

int swoole_coroutine_socket_set_connect_timeout(int sockfd, double timeout) {
Socket *socket = get_socket_ex(sockfd);
if (sw_unlikely(socket == NULL)) {
errno = EINVAL;
return -1;
}
socket->set_timeout(timeout, Socket::TIMEOUT_DNS | Socket::TIMEOUT_CONNECT);
return 0;
}

int swoole_coroutine_socket_wait_event(int sockfd, int event, double timeout) {
Socket *socket = get_socket_ex(sockfd);
if (sw_unlikely(socket == NULL)) {
Expand Down
86 changes: 86 additions & 0 deletions thirdparty/hiredis/alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2020, Michael Grunder <michael dot grunder at gmail dot com>
*
* 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 "alloc.h"
#include <string.h>
#include <stdlib.h>

hiredisAllocFuncs hiredisAllocFns = {
.mallocFn = malloc,
.callocFn = calloc,
.reallocFn = realloc,
.strdupFn = strdup,
.freeFn = free,
};

/* Override hiredis' allocators with ones supplied by the user */
hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *override) {
hiredisAllocFuncs orig = hiredisAllocFns;

hiredisAllocFns = *override;

return orig;
}

/* Reset allocators to use libc defaults */
void hiredisResetAllocators(void) {
hiredisAllocFns = (hiredisAllocFuncs) {
.mallocFn = malloc,
.callocFn = calloc,
.reallocFn = realloc,
.strdupFn = strdup,
.freeFn = free,
};
}

#ifdef _WIN32

void *hi_malloc(size_t size) {
return hiredisAllocFns.mallocFn(size);
}

void *hi_calloc(size_t nmemb, size_t size) {
return hiredisAllocFns.callocFn(nmemb, size);
}

void *hi_realloc(void *ptr, size_t size) {
return hiredisAllocFns.reallocFn(ptr, size);
}

char *hi_strdup(const char *str) {
return hiredisAllocFns.strdupFn(str);
}

void hi_free(void *ptr) {
hiredisAllocFns.freeFn(ptr);
}

#endif
91 changes: 91 additions & 0 deletions thirdparty/hiredis/alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2020, Michael Grunder <michael dot grunder at gmail dot com>
*
* 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.
*/

#ifndef HIREDIS_ALLOC_H
#define HIREDIS_ALLOC_H

#include <stddef.h> /* for size_t */

#ifdef __cplusplus
extern "C" {
#endif

/* Structure pointing to our actually configured allocators */
typedef struct hiredisAllocFuncs {
void *(*mallocFn)(size_t);
void *(*callocFn)(size_t,size_t);
void *(*reallocFn)(void*,size_t);
char *(*strdupFn)(const char*);
void (*freeFn)(void*);
} hiredisAllocFuncs;

hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *ha);
void hiredisResetAllocators(void);

#ifndef _WIN32

/* Hiredis' configured allocator function pointer struct */
extern hiredisAllocFuncs hiredisAllocFns;

static inline void *hi_malloc(size_t size) {
return hiredisAllocFns.mallocFn(size);
}

static inline void *hi_calloc(size_t nmemb, size_t size) {
return hiredisAllocFns.callocFn(nmemb, size);
}

static inline void *hi_realloc(void *ptr, size_t size) {
return hiredisAllocFns.reallocFn(ptr, size);
}

static inline char *hi_strdup(const char *str) {
return hiredisAllocFns.strdupFn(str);
}

static inline void hi_free(void *ptr) {
hiredisAllocFns.freeFn(ptr);
}

#else

void *hi_malloc(size_t size);
void *hi_calloc(size_t nmemb, size_t size);
void *hi_realloc(void *ptr, size_t size);
char *hi_strdup(const char *str);
void hi_free(void *ptr);

#endif

#ifdef __cplusplus
}
#endif

#endif /* HIREDIS_ALLOC_H */
Loading

0 comments on commit 5b2a926

Please sign in to comment.