Skip to content

Commit

Permalink
Migrate admin api from ext-swoole_plus to swoole-src (#4441)
Browse files Browse the repository at this point in the history
* Migration admin api from ext-swoole_plus to swoole-src

* Optimize code
  • Loading branch information
matyhtf authored Oct 19, 2021
1 parent 0395148 commit a89e3ab
Show file tree
Hide file tree
Showing 45 changed files with 23,377 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ add_definitions(-DHAVE_CONFIG_H)
# test
#add_definitions(-DSW_USE_THREAD_CONTEXT)

include_directories(BEFORE ./include ./include/wrapper ext-src/ ./)
include_directories(BEFORE ./include ./include/wrapper ext-src/ thirdparty/ ./)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

# find OpenSSL
Expand Down
2 changes: 2 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ if test "$PHP_SWOOLE" != "no"; then
ext-src/swoole_table.cc \
ext-src/swoole_timer.cc \
ext-src/swoole_websocket_server.cc \
ext-src/swoole_admin_server.cc \
src/core/base.cc \
src/core/channel.cc \
src/core/crc32.cc \
Expand Down Expand Up @@ -760,6 +761,7 @@ if test "$PHP_SWOOLE" != "no"; then
PHP_ADD_INCLUDE([$ext_srcdir])
PHP_ADD_INCLUDE([$ext_srcdir/include])
PHP_ADD_INCLUDE([$ext_srcdir/ext-src])
PHP_ADD_INCLUDE([$ext_srcdir/thirdparty])
PHP_ADD_INCLUDE([$ext_srcdir/thirdparty/hiredis])

AC_MSG_CHECKING([swoole coverage])
Expand Down
6 changes: 6 additions & 0 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_mime_type_read, 0, 0, 1)
ZEND_ARG_INFO(0, filename)
ZEND_END_ARG_INFO()

#include "php_swoole_x_arginfo.h"

const zend_function_entry swoole_functions[] = {
PHP_FE(swoole_version, arginfo_swoole_void)
PHP_FE(swoole_cpu_num, arginfo_swoole_void)
Expand Down Expand Up @@ -230,6 +232,10 @@ const zend_function_entry swoole_functions[] = {
PHP_FE(swoole_substr_json_decode, arginfo_swoole_substr_json_decode)
#endif
PHP_FE(swoole_internal_call_user_shutdown_begin, arginfo_swoole_void)
// for admin server
ZEND_FE(swoole_get_objects, arginfo_swoole_get_objects)
ZEND_FE(swoole_get_vm_status, arginfo_swoole_get_vm_status)
ZEND_FE(swoole_get_object_by_handle, arginfo_swoole_get_object_by_handle)
PHP_FE_END /* Must be the last line in swoole_functions[] */
};

Expand Down
16 changes: 16 additions & 0 deletions ext-src/php_swoole.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* @generate-legacy-arginfo
* @generate-function-entries
*/
function swoole_get_objects() : array|bool {

}

function swoole_get_vm_status() : array|bool {

}

function swoole_get_object_by_handle(int $handle): object|bool {

}
24 changes: 24 additions & 0 deletions ext-src/php_swoole_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 7d05091fc87828ebabc77c6c797984366e7afd4a */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_get_objects, 0, 0, MAY_BE_ARRAY|MAY_BE_BOOL)
ZEND_END_ARG_INFO()

#define arginfo_swoole_get_vm_status arginfo_swoole_get_objects

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_get_object_by_handle, 0, 1, MAY_BE_OBJECT|MAY_BE_BOOL)
ZEND_ARG_TYPE_INFO(0, handle, IS_LONG, 0)
ZEND_END_ARG_INFO()


ZEND_FUNCTION(swoole_get_objects);
ZEND_FUNCTION(swoole_get_vm_status);
ZEND_FUNCTION(swoole_get_object_by_handle);


static const zend_function_entry ext_functions[] = {
ZEND_FE(swoole_get_objects, arginfo_swoole_get_objects)
ZEND_FE(swoole_get_vm_status, arginfo_swoole_get_vm_status)
ZEND_FE(swoole_get_object_by_handle, arginfo_swoole_get_object_by_handle)
ZEND_FE_END
};
33 changes: 20 additions & 13 deletions ext-src/php_swoole_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ extern zend_string **sw_zend_known_strings;
#define SW_SET_CLASS_CREATE_WITH_ITS_OWN_HANDLERS(module) \
module##_ce->create_object = [](zend_class_entry *ce) { return sw_zend_create_object(ce, &module##_handlers); }


SW_API bool php_swoole_is_enable_coroutine();
SW_API zend_object *php_swoole_create_socket_from_fd(int fd, enum swSocketType type);
SW_API bool php_swoole_export_socket(zval *zobject, swoole::coroutine::Socket *_socket);
Expand All @@ -91,7 +90,10 @@ SW_API bool php_swoole_socket_set_ssl(swoole::coroutine::Socket *sock, zval *zse
#endif
SW_API bool php_swoole_socket_set_protocol(swoole::coroutine::Socket *sock, zval *zset);
SW_API bool php_swoole_client_set(swoole::coroutine::Socket *cli, zval *zset);
SW_API php_stream *php_swoole_create_stream_from_socket(php_socket_t _fd, int domain, int type, int protocol STREAMS_DC);
SW_API php_stream *php_swoole_create_stream_from_socket(php_socket_t _fd,
int domain,
int type,
int protocol STREAMS_DC);
SW_API php_stream_ops *php_swoole_get_ori_php_stream_stdio_ops();
SW_API void php_swoole_register_rshutdown_callback(swoole::Callback cb, void *private_data);

Expand All @@ -114,24 +116,31 @@ static inline bool php_swoole_is_fatal_error() {
return false;
}

ssize_t php_swoole_length_func(swoole::Protocol *protocol, swoole::network::Socket *_socket, const char *data, uint32_t length);
ssize_t php_swoole_length_func(swoole::Protocol *protocol,
swoole::network::Socket *_socket,
const char *data,
uint32_t length);

#ifdef SW_HAVE_ZLIB
#define php_swoole_websocket_frame_pack php_swoole_websocket_frame_pack_ex
#define php_swoole_websocket_frame_pack php_swoole_websocket_frame_pack_ex
#define php_swoole_websocket_frame_object_pack php_swoole_websocket_frame_object_pack_ex
#else
#define php_swoole_websocket_frame_pack(buffer, zdata, opcode, flags, mask, allow_compress) \
php_swoole_websocket_frame_pack_ex(buffer, zdata, opcode, flags, mask, 0)
#define php_swoole_websocket_frame_object_pack(buffer, zdata, mask, allow_compress) \
php_swoole_websocket_frame_object_pack_ex(buffer, zdata, mask, 0)
#define php_swoole_websocket_frame_pack(buffer, zdata, opcode, flags, mask, allow_compress) \
php_swoole_websocket_frame_pack_ex(buffer, zdata, opcode, flags, mask, 0)
#define php_swoole_websocket_frame_object_pack(buffer, zdata, mask, allow_compress) \
php_swoole_websocket_frame_object_pack_ex(buffer, zdata, mask, 0)
#endif
int php_swoole_websocket_frame_pack_ex(swoole::String *buffer, zval *zdata, zend_long opcode, uint8_t flags, zend_bool mask, zend_bool allow_compress);
int php_swoole_websocket_frame_object_pack_ex(swoole::String *buffer, zval *zdata, zend_bool mask, zend_bool allow_compress);
int php_swoole_websocket_frame_pack_ex(
swoole::String *buffer, zval *zdata, zend_long opcode, uint8_t flags, zend_bool mask, zend_bool allow_compress);
int php_swoole_websocket_frame_object_pack_ex(swoole::String *buffer,
zval *zdata,
zend_bool mask,
zend_bool allow_compress);
void php_swoole_websocket_frame_unpack(swoole::String *data, zval *zframe);
void php_swoole_websocket_frame_unpack_ex(swoole::String *data, zval *zframe, uchar allow_uncompress);

swoole::TaskId php_swoole_task_pack(swoole::EventData *task, zval *data);
zval* php_swoole_task_unpack(swoole::EventData *task_result);
zval *php_swoole_task_unpack(swoole::EventData *task_result);

#ifdef SW_HAVE_ZLIB
int php_swoole_zlib_decompress(z_stream *stream, swoole::String *buffer, char *body, int length);
Expand Down Expand Up @@ -444,5 +453,3 @@ static inline void assign_zend_string_by_val(zval *zdata, char *addr, size_t len

//-----------------------------------namespace end--------------------------------------------
} // namespace zend


24 changes: 24 additions & 0 deletions ext-src/php_swoole_legacy_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 7d05091fc87828ebabc77c6c797984366e7afd4a */

ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_get_objects, 0, 0, 0)
ZEND_END_ARG_INFO()

#define arginfo_swoole_get_vm_status arginfo_swoole_get_objects

ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_get_object_by_handle, 0, 0, 1)
ZEND_ARG_INFO(0, handle)
ZEND_END_ARG_INFO()


ZEND_FUNCTION(swoole_get_objects);
ZEND_FUNCTION(swoole_get_vm_status);
ZEND_FUNCTION(swoole_get_object_by_handle);


static const zend_function_entry ext_functions[] = {
ZEND_FE(swoole_get_objects, arginfo_swoole_get_objects)
ZEND_FE(swoole_get_vm_status, arginfo_swoole_get_vm_status)
ZEND_FE(swoole_get_object_by_handle, arginfo_swoole_get_object_by_handle)
ZEND_FE_END
};
24 changes: 12 additions & 12 deletions ext-src/php_swoole_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ enum php_swoole_server_callback_type {
};
//--------------------------------------------------------
enum php_swoole_server_port_callback_type {
SW_SERVER_CB_onConnect, // stream, worker(event)
SW_SERVER_CB_onReceive, // stream, worker(event)
SW_SERVER_CB_onClose, // stream, worker(event)
SW_SERVER_CB_onPacket, // dgram, worker(event)
SW_SERVER_CB_onRequest, // http, worker(event)
SW_SERVER_CB_onHandShake, // websocket, worker(event)
SW_SERVER_CB_onOpen, // websocket, worker(event)
SW_SERVER_CB_onMessage, // websocket, worker(event)
SW_SERVER_CB_onDisconnect, // websocket (non websocket connection), worker(event)
SW_SERVER_CB_onBufferFull, // worker(event)
SW_SERVER_CB_onBufferEmpty, // worker(event)
SW_SERVER_CB_onConnect, // stream, worker(event)
SW_SERVER_CB_onReceive, // stream, worker(event)
SW_SERVER_CB_onClose, // stream, worker(event)
SW_SERVER_CB_onPacket, // dgram, worker(event)
SW_SERVER_CB_onRequest, // http, worker(event)
SW_SERVER_CB_onHandShake, // websocket, worker(event)
SW_SERVER_CB_onOpen, // websocket, worker(event)
SW_SERVER_CB_onMessage, // websocket, worker(event)
SW_SERVER_CB_onDisconnect, // websocket (non websocket connection), worker(event)
SW_SERVER_CB_onBufferFull, // worker(event)
SW_SERVER_CB_onBufferEmpty, // worker(event)
};

#define PHP_SWOOLE_SERVER_CALLBACK_NUM (SW_SERVER_CB_onPipeMessage + 1)
Expand Down Expand Up @@ -123,7 +123,7 @@ struct TaskCo {
uint32_t count;
zval *result;
};

void register_admin_server_commands(Server *serv);
} // namespace swoole

void php_swoole_server_register_callbacks(swServer *serv);
Expand Down
7 changes: 7 additions & 0 deletions ext-src/php_swoole_x_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN_EXTERN_C()
#if PHP_VERSION_ID < 80000
#include "php_swoole_legacy_arginfo.h"
#else
#include "php_swoole_arginfo.h"
#endif
END_EXTERN_C()
Loading

0 comments on commit a89e3ab

Please sign in to comment.