Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Jul 5, 2024
1 parent 9820e71 commit 788a697
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions ext-src/swoole_pgsql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "php_swoole_pgsql.h"
#include "php_swoole_private.h"
#include "swoole_coroutine_socket.h"
#include "swoole_coroutine_system.h"

#ifdef SW_USE_PGSQL
#if PHP_VERSION_ID > 80100
Expand All @@ -29,26 +30,15 @@

using swoole::Reactor;
using swoole::coroutine::Socket;
using swoole::coroutine::translate_events_to_poll;

static bool swoole_pgsql_blocking = true;

static int swoole_pgsql_socket_poll(PGconn *conn, swEventType event, double timeout = -1) {
if (swoole_pgsql_blocking) {
struct pollfd fds[1] = {};
struct pollfd fds[1];
fds[0].fd = PQsocket(conn);
fds[0].events = 0;

if (Reactor::isset_read_event(event)) {
fds[0].events |= POLLIN;
}

if (Reactor::isset_write_event(event)) {
fds[0].events |= POLLOUT;
}

if (Reactor::isset_error_event(event)) {
fds[0].events |= POLLHUP;
}
fds[0].events |= translate_events_to_poll(event);

int result = 0;
do {
Expand Down

0 comments on commit 788a697

Please sign in to comment.