Skip to content

Commit

Permalink
Revert Swoole\Async\Client
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Oct 30, 2024
1 parent f5b73c6 commit 834637c
Show file tree
Hide file tree
Showing 31 changed files with 1,662 additions and 69 deletions.
1 change: 1 addition & 0 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ PHP_MINIT_FUNCTION(swoole) {
// client
php_swoole_socket_coro_minit(module_number);
php_swoole_client_minit(module_number);
php_swoole_client_async_minit(module_number);
php_swoole_client_coro_minit(module_number);
php_swoole_http_client_coro_minit(module_number);
php_swoole_http2_client_coro_minit(module_number);
Expand Down
38 changes: 38 additions & 0 deletions ext-src/php_swoole_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,45 @@
#include "php_swoole_cxx.h"
#include "swoole_client.h"

struct AsyncClientObject {
zend::Callable *onConnect;
zend::Callable *onReceive;
zend::Callable *onClose;
zend::Callable *onError;
zend::Callable *onBufferFull;
zend::Callable *onBufferEmpty;
#ifdef SW_USE_OPENSSL
zend::Callable *onSSLReady;
#endif
zval _zobject;
};

struct ClientObject {
swoole::network::Client *cli;
#ifdef SWOOLE_SOCKETS_SUPPORT
zval *zsocket;
#endif
AsyncClientObject *async;
zend_object std;
};

static sw_inline ClientObject *php_swoole_client_fetch_object(zend_object *obj) {
return (ClientObject *) ((char *) obj - swoole_client_handlers.offset);
}

static sw_inline ClientObject *php_swoole_client_fetch_object(zval *zobj) {
return php_swoole_client_fetch_object(Z_OBJ_P(zobj));
}

static sw_inline swoole::network::Client *php_swoole_client_get_cli(zval *zobject) {
return php_swoole_client_fetch_object(Z_OBJ_P(zobject))->cli;
}

swoole::network::Client *php_swoole_client_get_cli_safe(zval *zobject);
void php_swoole_client_free(zval *zobject, swoole::network::Client *cli);
void php_swoole_client_async_free_object(ClientObject *client_obj);
bool php_swoole_client_check_setting(swoole::network::Client *cli, zval *zset);
#ifdef SW_USE_OPENSSL
void php_swoole_client_check_ssl_setting(swoole::network::Client *cli, zval *zset);
bool php_swoole_client_enable_ssl_encryption(swoole::network::Client *cli, zval *zobject);
#endif
2 changes: 2 additions & 0 deletions ext-src/php_swoole_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ extern zend_class_entry *swoole_event_ce;
extern zend_class_entry *swoole_timer_ce;
extern zend_class_entry *swoole_socket_coro_ce;
extern zend_class_entry *swoole_client_ce;
extern zend_object_handlers swoole_client_handlers;
extern zend_class_entry *swoole_server_ce;
extern zend_object_handlers swoole_server_handlers;
extern zend_class_entry *swoole_redis_server_ce;
Expand Down Expand Up @@ -271,6 +272,7 @@ void php_swoole_runtime_minit(int module_number);
// client
void php_swoole_socket_coro_minit(int module_number);
void php_swoole_client_minit(int module_number);
void php_swoole_client_async_minit(int module_number);
void php_swoole_client_coro_minit(int module_number);
void php_swoole_http_client_coro_minit(int module_number);
void php_swoole_http2_client_coro_minit(int module_number);
Expand Down
2 changes: 1 addition & 1 deletion ext-src/stubs/php_swoole.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function swoole_test_kernel_coroutine(int $count = 100, float $sleep_time = 1.0)
{
}

function swoole_client_select(array &$read_array, array &$write_array, array &$error_array, float $timeout = 0.5): false|int
function swoole_client_select(?array &$read, ?array &$write, ?array &$except, ?float $timeout = 0.5): false|int
{
}

Expand Down
10 changes: 5 additions & 5 deletions ext-src/stubs/php_swoole_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: f3b5724446b5118d9223c66a1045729c7c3ceff7 */
* Stub hash: 218af3f0a0165fc9bf9919be127b95e82c50536a */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_version, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -40,10 +40,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_test_kernel_coroutine, 0,
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_client_select, 0, 3, MAY_BE_FALSE|MAY_BE_LONG)
ZEND_ARG_TYPE_INFO(1, read_array, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(1, write_array, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(1, error_array, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 0, "0.5")
ZEND_ARG_TYPE_INFO(1, read, IS_ARRAY, 1)
ZEND_ARG_TYPE_INFO(1, write, IS_ARRAY, 1)
ZEND_ARG_TYPE_INFO(1, except, IS_ARRAY, 1)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 1, "0.5")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_set_process_name, 0, 1, _IS_BOOL, 0)
Expand Down
16 changes: 16 additions & 0 deletions ext-src/stubs/php_swoole_client_async.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace Swoole\Async {
class Client extends \Swoole\Client {
public function __construct(int $type) {}
public function __destruct() {}
public function connect(string $host, int $port = 0, float $timeout = 0.5, int $sock_flag = 0): bool {}
public function on(string $host, callable $callback): bool {}
#ifdef SW_USE_OPENSSL
public function enableSSL(): bool {}
#endif
public function isConnected(): bool {}
public function sleep(): bool {}
public function wakeup(): bool {}
public function close(bool $force = false): bool {}
}
}
37 changes: 37 additions & 0 deletions ext-src/stubs/php_swoole_client_async_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 46f71ec2f362f504a8a1f2d9682ed402186b077f */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Swoole_Async_Client___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Swoole_Async_Client___destruct, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Async_Client_connect, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, port, IS_LONG, 0, "0")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 0, "0.5")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sock_flag, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Async_Client_on, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
ZEND_END_ARG_INFO()

#if defined(SW_USE_OPENSSL)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Async_Client_enableSSL, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
#endif

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Async_Client_isConnected, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_Swoole_Async_Client_sleep arginfo_class_Swoole_Async_Client_isConnected

#define arginfo_class_Swoole_Async_Client_wakeup arginfo_class_Swoole_Async_Client_isConnected

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Async_Client_close, 0, 0, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, force, _IS_BOOL, 0, "false")
ZEND_END_ARG_INFO()
Loading

0 comments on commit 834637c

Please sign in to comment.