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

Commit 40dadc9

Browse files
committed
Optimize code [2]
1 parent 7f0509d commit 40dadc9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

swoole_postgresql_coro.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,21 @@ static PHP_METHOD(swoole_postgresql_coro, query) {
761761
RETURN_FALSE;
762762
}
763763

764-
while (PQflush(pgsql) == 1) {
764+
int retval = 0;
765+
while ((retval = PQflush(pgsql)) == 1) {
765766
if (System::wait_event(PQsocket(pgsql), SW_EVENT_WRITE, object->timeout) <= 0) {
766767
zend_update_property_string(swoole_postgresql_coro_ce, SW_Z8_OBJ_P(ZEND_THIS), ZEND_STRL("error"),
767768
swoole_strerror(swoole_get_last_error()));
768769
RETURN_FALSE;
769770
}
770771
}
771772

773+
if (retval == -1) {
774+
char *err_msg = PQerrorMessage(pgsql);
775+
zend_update_property_string(swoole_postgresql_coro_ce, SW_Z8_OBJ_P(ZEND_THIS), ZEND_STRL("error"), err_msg);
776+
RETURN_FALSE;
777+
}
778+
772779
FutureTask *context = php_swoole_postgresql_coro_get_context(ZEND_THIS);
773780
context->coro_params = *ZEND_THIS;
774781

0 commit comments

Comments
 (0)