Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
sync v4.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Nov 8, 2020
1 parent d6e78a5 commit ab616db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 52 deletions.
62 changes: 14 additions & 48 deletions swoole_postgresql_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ static PHP_METHOD(swoole_postgresql_coro, connect) {
static void swoole_pgsql_coro_onTimeout(Timer *timer, TimerNode *tnode) {
zval _result;
zval *result = &_result;
zval *retval = NULL;
PGconn *pgsql;
FutureTask *ctx = (FutureTask *) tnode->data;
const char *feedback;
Expand Down Expand Up @@ -415,10 +414,7 @@ static void swoole_pgsql_coro_onTimeout(Timer *timer, TimerNode *tnode) {
}

zend_update_property_string(swoole_postgresql_coro_ce, zobject, "error", 5, "ontimeout");
int ret = PHPCoroutine::resume_m(ctx, result, retval);
if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}
PHPCoroutine::resume_m(ctx, result);
zval_ptr_dtor(result);
}

Expand Down Expand Up @@ -466,24 +462,19 @@ static void connect_callback(pg_object *object, Reactor *reactor, Event *event)

FutureTask *context = php_swoole_postgresql_coro_get_context(object->object);

zval *retval = NULL;
zval return_value;
ZVAL_BOOL(&return_value, object->connected);

if (object->connected == 1) {
zend_update_property_null(swoole_postgresql_coro_ce, object->object, ZEND_STRL("error"));
}

int ret = PHPCoroutine::resume_m(context, &return_value, retval);
if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}
PHPCoroutine::resume_m(context, &return_value);
}

static int swoole_pgsql_coro_onWrite(swReactor *reactor, swEvent *event) {
pg_object *object = (pg_object *) event->socket->object;
if (object->connected) {
return swReactor_onWrite(sw_reactor(), event);
return sw_reactor()->default_write_handler(sw_reactor(), event);
} else {
connect_callback(object, reactor, event);
}
Expand Down Expand Up @@ -532,7 +523,6 @@ static int meta_data_result_parse(pg_object *object) {

zval return_value;
array_init(&return_value);
zval *retval = NULL;
array_init(&elem);
for (i = 0; i < num_rows; i++) {
object->result = pg_result;
Expand Down Expand Up @@ -567,10 +557,7 @@ static int meta_data_result_parse(pg_object *object) {
FutureTask *context = php_swoole_postgresql_coro_get_context(object->object);
zend_update_property_null(swoole_postgresql_coro_ce, object->object, ZEND_STRL("error"));
zend_update_property_null(swoole_postgresql_coro_ce, object->object, ZEND_STRL("resultDiag"));
int ret = PHPCoroutine::resume_m(context, &return_value, retval);
if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}
PHPCoroutine::resume_m(context, &return_value);
swoole_event_del(object->socket);
zval_ptr_dtor(&return_value);
return SW_OK;
Expand Down Expand Up @@ -643,8 +630,7 @@ static int query_result_parse(pg_object *object) {

int error = 0;
char *err_msg;
int ret, res;
zval *retval = NULL;
int res;
zval return_value;
FutureTask *context = php_swoole_postgresql_coro_get_context(object->object);

Expand All @@ -665,10 +651,7 @@ static int query_result_parse(pg_object *object) {
ZVAL_FALSE(&return_value);
swoole_event_del(object->socket);
zend_update_property_string(swoole_postgresql_coro_ce, object->object, ZEND_STRL("error"), err_msg);
ret = PHPCoroutine::resume_m(context, &return_value, retval);
if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}
PHPCoroutine::resume_m(context, &return_value);
break;
case PGRES_COMMAND_OK: /* successful command that did not return rows */
default:
Expand All @@ -680,13 +663,11 @@ static int query_result_parse(pg_object *object) {
ZVAL_RES(&return_value, zend_register_resource(pgsql_result, le_result));
zend_update_property_null(swoole_postgresql_coro_ce, object->object, ZEND_STRL("error"));
zend_update_property_null(swoole_postgresql_coro_ce, object->object, ZEND_STRL("resultDiag"));
ret = PHPCoroutine::resume_m(context, &return_value, retval);
if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}
PHPCoroutine::resume_m(context, &return_value);
if (error != 0) {
php_swoole_fatal_error(E_WARNING, "socket error. Error: %s [%d]", strerror(error), error);
}
zval_ptr_dtor(&return_value);
break;
}
(void) res;
Expand All @@ -700,8 +681,7 @@ static int prepare_result_parse(pg_object *object) {

int error = 0;
char *err_msg;
int ret, res;
zval *retval = NULL;
int res;
zval return_value;
FutureTask *context = php_swoole_postgresql_coro_get_context(object->object);

Expand All @@ -722,10 +702,7 @@ static int prepare_result_parse(pg_object *object) {
ZVAL_FALSE(&return_value);
swoole_event_del(object->socket);
zend_update_property_string(swoole_postgresql_coro_ce, object->object, ZEND_STRL("error"), err_msg);
ret = PHPCoroutine::resume_m(context, &return_value, retval);
if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}
PHPCoroutine::resume_m(context, &return_value);
if (error != 0) {
php_swoole_fatal_error(E_WARNING, "socket error. Error: %s [%d]", strerror(error), error);
}
Expand All @@ -738,10 +715,7 @@ static int prepare_result_parse(pg_object *object) {
ZVAL_TRUE(&return_value);
zend_update_property_null(swoole_postgresql_coro_ce, object->object, ZEND_STRL("error"));
zend_update_property_null(swoole_postgresql_coro_ce, object->object, ZEND_STRL("resultDiag"));
ret = PHPCoroutine::resume_m(context, &return_value, retval);
if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}
PHPCoroutine::resume_m(context, &return_value);
if (error != 0) {
php_swoole_fatal_error(E_WARNING, "socket error. Error: %s [%d]", strerror(error), error);
}
Expand All @@ -751,10 +725,7 @@ static int prepare_result_parse(pg_object *object) {
swoole_event_del(object->socket);
ZVAL_FALSE(&return_value);
zend_update_property_string(swoole_postgresql_coro_ce, object->object, ZEND_STRL("error"), "Bad result returned to prepare");
ret = PHPCoroutine::resume_m(context, &return_value, retval);
if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}
PHPCoroutine::resume_m(context, &return_value);
if (error != 0) {
php_swoole_fatal_error(E_WARNING, "socket error. Error: %s [%d]", strerror(error), error);
}
Expand Down Expand Up @@ -1419,20 +1390,15 @@ static int swoole_pgsql_coro_onError(swReactor *reactor, swEvent *event) {
zval _result;
zval *result = &_result;
pg_object *object = (pg_object *) (event->socket->object);
zval *retval = NULL;
zval *zobject = object->object;

ZVAL_FALSE(result);

FutureTask *context = php_swoole_postgresql_coro_get_context(zobject);
zend_update_property_string(swoole_postgresql_coro_ce, zobject, "error", 5, "onerror");
int ret = PHPCoroutine::resume_m(context, result, retval);
PHPCoroutine::resume_m(context, result);
zval_ptr_dtor(result);

if (ret == Coroutine::ERR_END && retval) {
zval_ptr_dtor(retval);
}

return SW_OK;
}

Expand All @@ -1448,7 +1414,7 @@ static int swoole_postgresql_coro_close(zval *zobject) {
if (sw_reactor()) {
swSocket *_socket = object->socket;
if (!_socket->removed) {
sw_reactor()->del(sw_reactor(), _socket);
sw_reactor()->del(_socket);
}
_socket->object = nullptr;
_socket->free();
Expand Down
8 changes: 4 additions & 4 deletions swoole_postgresql_coro.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#define SWOOLE_POSTGRESQL_H_

#include "ext/swoole/config.h"
#include "ext/swoole/php_swoole_cxx.h"
#include "ext/swoole/ext-src/php_swoole_cxx.h"
#include "config.h"

#define PHP_SWOOLE_EXT_POSTGRESQL_VERSION "4.5.4"
#define PHP_SWOOLE_EXT_POSTGRESQL_VERSION_ID 40504
#define PHP_SWOOLE_EXT_POSTGRESQL_VERSION "4.5.7"
#define PHP_SWOOLE_EXT_POSTGRESQL_VERSION_ID 40507

#if SWOOLE_API_VERSION_ID < 0x202009a
#if SWOOLE_API_VERSION_ID < 0x202011a
#error "Ext version does not match the Swoole version"
#endif

Expand Down

0 comments on commit ab616db

Please sign in to comment.