Skip to content

Commit

Permalink
Fix pgsql non blocking error (#5486)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman authored Sep 20, 2024
1 parent 964b97f commit 249fcd0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 6 additions & 5 deletions ext-src/swoole_oracle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#ifdef SW_USE_ORACLE

using swoole::Coroutine;

static bool swoole_oracle_blocking = true;
void swoole_oracle_set_blocking(bool blocking) {
swoole_oracle_blocking = blocking;
Expand All @@ -49,7 +47,8 @@ sword swoole_oci_stmt_prepare(
OCIStmt *stmtp, OCIError *errhp, const OraText *stmt, ub4 stmt_len, ub4 language, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_prepare");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtPrepare(stmtp, errhp, stmt, stmt_len, language, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtPrepare(stmtp, errhp, stmt, stmt_len, language, mode); });

return result;
}
Expand All @@ -64,7 +63,8 @@ sword swoole_oci_stmt_execute(OCISvcCtx *svchp,
ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_execute");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtExecute(svchp, stmtp, errhp, iters, rowoff, snap_in, snap_out, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtExecute(svchp, stmtp, errhp, iters, rowoff, snap_in, snap_out, mode); });

return result;
}
Expand All @@ -80,7 +80,8 @@ sword swoole_oci_stmt_fetch(OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orie
sword swoole_oci_stmt_fetch2(OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orientation, sb4 scrollOffset, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_fetch2");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtFetch2(stmtp, errhp, nrows, orientation, scrollOffset, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtFetch2(stmtp, errhp, nrows, orientation, scrollOffset, mode); });

return result;
}
Expand Down
9 changes: 7 additions & 2 deletions ext-src/swoole_pgsql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "thirdparty/php80/pdo_pgsql/php_pdo_pgsql_int.h"
#endif

using swoole::Coroutine;
using swoole::Reactor;
using swoole::coroutine::Socket;
using swoole::coroutine::translate_events_to_poll;
Expand All @@ -42,7 +43,7 @@ static int swoole_pgsql_socket_poll(PGconn *conn, swEventType event, double time

int result = 0;
do {
result = poll(fds, 1, timeout);
result = poll(fds, 1, timeout);
} while (result < 0 && errno == EINTR);

return result > 0 ? 1 : errno == ETIMEDOUT ? 0 : -1;
Expand Down Expand Up @@ -97,7 +98,11 @@ PGconn *swoole_pgsql_connectdb(const char *conninfo) {
return conn;
}

PQsetnonblocking(conn, 1);
if (!swoole_pgsql_blocking && Coroutine::get_current()) {
PQsetnonblocking(conn, 1);
} else {
PQsetnonblocking(conn, 0);
}

SW_LOOP {
int r = PQconnectPoll(conn);
Expand Down

0 comments on commit 249fcd0

Please sign in to comment.