Skip to content

Commit

Permalink
Version 4.8.13 (#4988)
Browse files Browse the repository at this point in the history
* merge master

* fix

* fix 2

* fix 3, a variable with the same name is defined in the php macro

* fix 4

* fix 5

* fix php81

* revert

* revert 2

* revert 3

* fix 6

* fix 7

* pecl package
  • Loading branch information
matyhtf committed Feb 22, 2023
1 parent 800fa85 commit 48c8a40
Show file tree
Hide file tree
Showing 36 changed files with 650 additions and 366 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROJECT(libswoole)

ENABLE_LANGUAGE(ASM)
set(SWOOLE_VERSION 4.8.12)
set(SWOOLE_VERSION 4.8.13)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -g")
Expand Down
41 changes: 33 additions & 8 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ END_EXTERN_C()
#include "swoole_mime_type.h"
#include "swoole_server.h"
#include "swoole_util.h"
#include "swoole_http2.h"

#include <netinet/in.h>
#include <arpa/inet.h>
Expand Down Expand Up @@ -348,17 +349,19 @@ void php_swoole_set_global_option(HashTable *vht) {

#ifdef SW_DEBUG
if (php_swoole_array_get_value(vht, "debug_mode", ztmp) && zval_is_true(ztmp)) {
sw_logger()->set_level(0);
swoole_set_log_level(0);
}
#endif
// [Logger]
// ======================================================================
if (php_swoole_array_get_value(vht, "trace_flags", ztmp)) {
SwooleG.trace_flags = (uint32_t) SW_MAX(0, zval_get_long(ztmp));
swoole_set_trace_flags(zval_get_long(ztmp));
}
if (php_swoole_array_get_value(vht, "log_file", ztmp)) {
sw_logger()->open(zend::String(ztmp).val());
swoole_set_log_file(zend::String(ztmp).val());
}
if (php_swoole_array_get_value(vht, "log_level", ztmp)) {
sw_logger()->set_level(zval_get_long(ztmp));
swoole_set_log_level(zval_get_long(ztmp));
}
if (php_swoole_array_get_value(vht, "log_date_format", ztmp)) {
sw_logger()->set_date_format(zend::String(ztmp).val());
Expand All @@ -372,10 +375,13 @@ void php_swoole_set_global_option(HashTable *vht) {
if (php_swoole_array_get_value(vht, "display_errors", ztmp)) {
SWOOLE_G(display_errors) = zval_is_true(ztmp);
}
// [DNS]
// ======================================================================
if (php_swoole_array_get_value(vht, "dns_server", ztmp)) {
swoole_set_dns_server(zend::String(ztmp).to_std_string());
}

// [Socket]
// ======================================================================
auto timeout_format = [](zval *v) -> double {
double timeout = zval_get_double(v);
if (timeout <= 0 || timeout > INT_MAX) {
Expand All @@ -384,7 +390,6 @@ void php_swoole_set_global_option(HashTable *vht) {
return timeout;
}
};

if (php_swoole_array_get_value(vht, "socket_dns_timeout", ztmp)) {
Socket::default_dns_timeout = timeout_format(ztmp);
}
Expand All @@ -405,6 +410,26 @@ void php_swoole_set_global_option(HashTable *vht) {
if (php_swoole_array_get_value(vht, "socket_timeout", ztmp)) {
Socket::default_read_timeout = Socket::default_write_timeout = timeout_format(ztmp);
}
// [HTTP2]
// ======================================================================
if (php_swoole_array_get_value(vht, "http2_header_table_size", ztmp)) {
swoole::http2::put_default_setting(SW_HTTP2_SETTING_HEADER_TABLE_SIZE, zval_get_long(ztmp));
}
if (php_swoole_array_get_value(vht, "http2_enable_push", ztmp)) {
swoole::http2::put_default_setting(SW_HTTP2_SETTINGS_ENABLE_PUSH, zval_get_long(ztmp));
}
if (php_swoole_array_get_value(vht, "http2_max_concurrent_streams", ztmp)) {
swoole::http2::put_default_setting(SW_HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, zval_get_long(ztmp));
}
if (php_swoole_array_get_value(vht, "http2_init_window_size", ztmp)) {
swoole::http2::put_default_setting(SW_HTTP2_SETTINGS_INIT_WINDOW_SIZE, zval_get_long(ztmp));
}
if (php_swoole_array_get_value(vht, "http2_max_frame_size", ztmp)) {
swoole::http2::put_default_setting(SW_HTTP2_SETTINGS_MAX_FRAME_SIZE, zval_get_long(ztmp));
}
if (php_swoole_array_get_value(vht, "http2_max_header_list_size", ztmp)) {
swoole::http2::put_default_setting(SW_HTTP2_SETTINGS_MAX_HEADER_LIST_SIZE, zval_get_long(ztmp));
}
}

void php_swoole_register_rshutdown_callback(swoole::Callback cb, void *private_data) {
Expand Down Expand Up @@ -725,6 +750,7 @@ PHP_MINIT_FUNCTION(swoole) {
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_TABLE", SW_TRACE_TABLE);
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_CO_CURL", SW_TRACE_CO_CURL);
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_CARES", SW_TRACE_CARES);
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_ZLIB", SW_TRACE_ZLIB);
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_ALL", SW_TRACE_ALL);

/**
Expand Down Expand Up @@ -833,10 +859,9 @@ PHP_MINIT_FUNCTION(swoole) {
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(swoole) {
swoole_clean();
zend::known_strings_dtor();
php_swoole_runtime_mshutdown();

swoole_clean();
return SUCCESS;
}
/* }}} */
Expand Down
9 changes: 7 additions & 2 deletions ext-src/php_swoole_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@
#include "thirdparty/nghttp2/nghttp2.h"
#endif

enum http_header_flag {
enum swHttpHeaderFlag {
HTTP_HEADER_SERVER = 1u << 1,
HTTP_HEADER_CONNECTION = 1u << 2,
HTTP_HEADER_CONTENT_LENGTH = 1u << 3,
HTTP_HEADER_DATE = 1u << 4,
HTTP_HEADER_CONTENT_TYPE = 1u << 5,
HTTP_HEADER_TRANSFER_ENCODING = 1u << 6,
HTTP_HEADER_ACCEPT_ENCODING = 1u << 7,
HTTP_HEADER_CONTENT_ENCODING = 1u << 8,
};

enum http_compress_method {
enum swHttpCompressMethod {
HTTP_COMPRESS_NONE,
HTTP_COMPRESS_GZIP,
HTTP_COMPRESS_DEFLATE,
Expand Down Expand Up @@ -250,6 +251,10 @@ class Session {
http2::Settings local_settings = {};
http2::Settings remote_settings = {};

// flow control
uint32_t remote_window_size;
uint32_t local_window_size;

uint32_t last_stream_id;
bool shutting_down;
bool is_coro;
Expand Down
14 changes: 13 additions & 1 deletion ext-src/php_swoole_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/

/* $Id: 5a6baee052afc12b2affa070eed0339b1a007a42 */
/* $Id: 1beb33c9d754aa391ec1da613ca41755aafcad1f */

static const char* swoole_library_source_constants =
"\n"
Expand Down Expand Up @@ -167,6 +167,18 @@ static const char* swoole_library_source_core_constant =
"\n"
" public const OPTION_SOCKET_TIMEOUT = 'socket_timeout';\n"
"\n"
" public const OPTION_HTTP2_HEADER_TABLE_SIZE = 'http2_header_table_size';\n"
"\n"
" public const OPTION_HTTP2_ENABLE_PUSH = 'http2_enable_push';\n"
"\n"
" public const OPTION_HTTP2_MAX_CONCURRENT_STREAMS = 'http2_max_concurrent_streams';\n"
"\n"
" public const OPTION_HTTP2_INIT_WINDOW_SIZE = 'http2_init_window_size';\n"
"\n"
" public const OPTION_HTTP2_MAX_FRAME_SIZE = 'http2_max_frame_size';\n"
"\n"
" public const OPTION_HTTP2_MAX_HEADER_LIST_SIZE = 'http2_max_header_list_size';\n"
"\n"
" public const OPTION_AIO_CORE_WORKER_NUM = 'aio_core_worker_num';\n"
"\n"
" public const OPTION_AIO_WORKER_NUM = 'aio_worker_num';\n"
Expand Down
35 changes: 29 additions & 6 deletions ext-src/php_swoole_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ extern PHPAPI int php_array_merge(zend_array *dest, zend_array *src);
} else { \
RETURN_TRUE; \
}

#define SW_LOCK_CHECK_RETURN(s) \
zend_long ___tmp_return_value = s; \
if (___tmp_return_value == 0) { \
Expand Down Expand Up @@ -458,6 +459,12 @@ static sw_inline zend_bool ZVAL_IS_TRUE(zval *v) {
}
#endif

#ifndef ZVAL_IS_UNDEF
static sw_inline zend_bool ZVAL_IS_UNDEF(zval *v) {
return Z_TYPE_P(v) == IS_UNDEF;
}
#endif

#ifndef ZVAL_IS_FALSE
static sw_inline zend_bool ZVAL_IS_FALSE(zval *v) {
return Z_TYPE_P(v) == IS_FALSE;
Expand Down Expand Up @@ -543,7 +550,7 @@ static sw_inline void sw_zval_free(zval *val) {
static sw_inline zend_string *sw_zend_string_recycle(zend_string *s, size_t alloc_len, size_t real_len) {
SW_ASSERT(!ZSTR_IS_INTERNED(s));
if (UNEXPECTED(alloc_len != real_len)) {
if (alloc_len > SwooleG.pagesize && alloc_len > real_len * 2) {
if (alloc_len > swoole_pagesize() && alloc_len > real_len * 2) {
s = zend_string_realloc(s, real_len, 0);
} else {
ZSTR_LEN(s) = real_len;
Expand Down Expand Up @@ -799,7 +806,7 @@ static sw_inline void sw_zend_class_unset_property_deny(zend_object *object, zen
}
#endif

static sw_inline zval *sw_zend_read_property(zend_class_entry *ce, zval *obj, const char *s, int len, int silent) {
static sw_inline zval *sw_zend_read_property(zend_class_entry *ce, zval *obj, const char *s, size_t len, int silent) {
zval rv, *property = zend_read_property(ce, SW_Z8_OBJ_P(obj), s, len, silent, &rv);
if (UNEXPECTED(property == &EG(uninitialized_zval))) {
zend_update_property_null(ce, SW_Z8_OBJ_P(obj), s, len);
Expand All @@ -825,7 +832,7 @@ static sw_inline zval *sw_zend_read_property_ex(zend_class_entry *ce, zval *obj,
}

static sw_inline zval *sw_zend_read_property_not_null(
zend_class_entry *ce, zval *obj, const char *s, int len, int silent) {
zend_class_entry *ce, zval *obj, const char *s, size_t len, int silent) {
zval rv, *property = zend_read_property(ce, SW_Z8_OBJ_P(obj), s, len, silent, &rv);
zend_uchar type = Z_TYPE_P(property);
return (type == IS_NULL || UNEXPECTED(type == IS_UNDEF)) ? NULL : property;
Expand All @@ -837,7 +844,7 @@ static sw_inline zval *sw_zend_read_property_not_null_ex(zend_class_entry *ce, z
return (type == IS_NULL || UNEXPECTED(type == IS_UNDEF)) ? NULL : property;
}

static sw_inline zval *sw_zend_update_and_read_property_array(zend_class_entry *ce, zval *obj, const char *s, int len) {
static sw_inline zval *sw_zend_update_and_read_property_array(zend_class_entry *ce, zval *obj, const char *s, size_t len) {
zval ztmp;
array_init(&ztmp);
zend_update_property(ce, SW_Z8_OBJ_P(obj), s, len, &ztmp);
Expand All @@ -846,7 +853,7 @@ static sw_inline zval *sw_zend_update_and_read_property_array(zend_class_entry *
}

static sw_inline zval *sw_zend_read_and_convert_property_array(
zend_class_entry *ce, zval *obj, const char *s, int len, int silent) {
zend_class_entry *ce, zval *obj, const char *s, size_t len, int silent) {
zval rv, *property = zend_read_property(ce, SW_Z8_OBJ_P(obj), s, len, silent, &rv);
if (Z_TYPE_P(property) != IS_ARRAY) {
// NOTICE: if user unset the property, zend_read_property will return uninitialized_zval instead of NULL pointer
Expand Down Expand Up @@ -1066,7 +1073,7 @@ static sw_inline char *php_swoole_format_date(char *format, size_t format_len, t
return return_str;
}

static sw_inline char *php_swoole_url_encode(const char *value, size_t value_len, int *exten) {
static sw_inline char *php_swoole_url_encode(const char *value, size_t value_len, size_t *exten) {
zend_string *str = php_url_encode(value, value_len);
*exten = ZSTR_LEN(str);
char *return_str = estrndup(ZSTR_VAL(str), ZSTR_LEN(str));
Expand Down Expand Up @@ -1096,6 +1103,22 @@ static sw_inline char *php_swoole_http_build_query(zval *zdata, size_t *length,
return formstr->s->val;
}

static inline const char *php_swoole_get_last_error_message() {
#if PHP_VERSION_ID >= 80000
return PG(last_error_message) ? PG(last_error_message)->val : nullptr;
#else
return PG(last_error_message);
#endif
}

static inline const char *php_swoole_get_last_error_file() {
#if PHP_VERSION_ID >= 80100
return PG(last_error_file) ? PG(last_error_file)->val : "-";
#else
return PG(last_error_file) ? PG(last_error_file) : "-";
#endif
}

END_EXTERN_C()

#endif /* PHP_SWOOLE_PRIVATE_H */
10 changes: 7 additions & 3 deletions ext-src/swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ static const zend_function_entry swoole_coroutine_methods[] =
static PHP_METHOD(swoole_exit_exception, getFlags);
static PHP_METHOD(swoole_exit_exception, getStatus);

// clang-format off
static const zend_function_entry swoole_exit_exception_methods[] = {
PHP_ME(swoole_exit_exception, getFlags, arginfo_swoole_coroutine_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_exit_exception, getStatus, arginfo_swoole_coroutine_void, ZEND_ACC_PUBLIC) PHP_FE_END};
PHP_ME(swoole_exit_exception, getStatus, arginfo_swoole_coroutine_void, ZEND_ACC_PUBLIC)
PHP_FE_END
};
// clang-format on

static int coro_exit_handler(zend_execute_data *execute_data) {
zval ex;
Expand All @@ -234,7 +238,7 @@ static int coro_exit_handler(zend_execute_data *execute_data) {
}
if (flags) {
const zend_op *opline = EX(opline);
zval _exit_status;
zval _exit_status{};
zval *exit_status = nullptr;

if (opline->op1_type != IS_UNUSED) {
Expand Down Expand Up @@ -1297,7 +1301,7 @@ static PHP_METHOD(swoole_coroutine, getBackTrace) {

static PHP_METHOD(swoole_coroutine, printBackTrace) {
zend_long cid = 0;
zend_long options = DEBUG_BACKTRACE_PROVIDE_OBJECT;
zend_long options = 0;
zend_long limit = 0;

ZEND_PARSE_PARAMETERS_START(0, 3)
Expand Down
7 changes: 3 additions & 4 deletions ext-src/swoole_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void event_object_free(void *data) {
efree(peo);
}

static int event_readable_callback(Reactor *reactor, swEvent *event) {
static int event_readable_callback(Reactor *reactor, Event *event) {
EventObject *peo = (EventObject *) event->socket->object;

zval argv[1];
Expand Down Expand Up @@ -180,7 +180,7 @@ static int event_writable_callback(Reactor *reactor, Event *event) {
return SW_OK;
}

static int event_error_callback(Reactor *reactor, swEvent *event) {
static int event_error_callback(Reactor *reactor, Event *event) {
if (!(event->socket->events & SW_EVENT_ERROR)) {
if (event->socket->events & SW_EVENT_READ) {
return reactor->get_handler(SW_EVENT_READ, event->socket->fd_type)(reactor, event);
Expand Down Expand Up @@ -738,7 +738,7 @@ static PHP_FUNCTION(swoole_event_wait) {
static PHP_FUNCTION(swoole_event_rshutdown) {
/* prevent the program from jumping out of the rshutdown */
zend_try {
if (!sw_reactor()) {
if (php_swoole_is_fatal_error() || !sw_reactor()) {
return;
}
// when throw Exception, do not show the info
Expand All @@ -765,7 +765,6 @@ static PHP_FUNCTION(swoole_event_dispatch) {
if (sw_reactor()->wait(nullptr) < 0) {
php_swoole_sys_error(E_ERROR, "reactor wait failed");
}

sw_reactor()->once = false;
RETURN_TRUE;
}
Expand Down
Loading

0 comments on commit 48c8a40

Please sign in to comment.