From c662a37341e9787ca8c5e553b3d641a19e3b81c8 Mon Sep 17 00:00:00 2001 From: peavey Date: Thu, 11 Jan 2007 04:24:37 +0000 Subject: pgsql should now work thx to added posibility to force a fd out of the socketengine. This should only be used as a *last resort* when dealing with 3rd party libs that invalidates a file descriptor beyond your control. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6295 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_pgsql.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/modules') diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index 602e1ce77..ae655495e 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -516,19 +516,25 @@ class SQLConn : public EventHandler Instance->Log(DEBUG, "Couldn't allocate PGconn structure, aborting: %s", PQerrorMessage(sql)); return false; } + if(PQstatus(sql) == CONNECTION_BAD) { Instance->Log(DEBUG, "PQconnectStart failed: %s", PQerrorMessage(sql)); return false; } + ShowStatus(); + if(PQsetnonblocking(sql, 1) == -1) { Instance->Log(DEBUG, "Couldn't set connection nonblocking: %s", PQerrorMessage(sql)); return false; } - this->fd = PQsocket(sql); + /* OK, we've initalised the connection, now to get it hooked into the socket engine + * and then start polling it. + */ + this->fd = PQsocket(sql); Instance->Log(DEBUG, "New SQL socket: %d", this->fd); if(this->fd <= -1) @@ -550,7 +556,6 @@ class SQLConn : public EventHandler bool DoPoll() { - ShowStatus(); switch(PQconnectPoll(sql)) { case PGRES_POLLING_WRITING: @@ -588,11 +593,9 @@ class SQLConn : public EventHandler */ idle = this->Instance->Time(); - ShowStatus(); - if(PQisBusy(sql)) { - Instance->Log(DEBUG, "Still busy processing command though"); + //Instance->Log(DEBUG, "Still busy processing command though"); } else if(qinprog) { @@ -661,7 +664,6 @@ class SQLConn : public EventHandler } else { - ShowStatus(); Instance->Log(DEBUG, "Eh!? We just got a read event, and connection isn't busy..but no result :("); } return true; @@ -688,7 +690,7 @@ class SQLConn : public EventHandler //ServerInstance->Log(DEBUG, "PGresetPoll: PGRES_POLLING_WRITING"); Instance->SE->WantWrite(this); status = CWRITE; - return DoResetPoll(); + return true; case PGRES_POLLING_READING: //ServerInstance->Log(DEBUG, "PGresetPoll: PGRES_POLLING_READING"); status = CREAD; @@ -710,14 +712,6 @@ class SQLConn : public EventHandler { switch(PQstatus(sql)) { - case CONNECTION_OK: - Instance->Log(DEBUG, "PQstatus: CONNECTION_OK: Ok."); - break; - - case CONNECTION_BAD: - Instance->Log(DEBUG, "PQstatus: CONNECTION_BAD: Bad."); - break; - case CONNECTION_STARTED: Instance->Log(DEBUG, "PQstatus: CONNECTION_STARTED: Waiting for connection to be made."); break; @@ -943,7 +937,7 @@ class SQLConn : public EventHandler Instance->Log(DEBUG,"SQLConn::Close"); Instance->Log(DEBUG, "FD IS: %d", this->fd); - if (!this->Instance->SE->DelFd(this)) + if (!this->Instance->SE->DelFd(this, true)) { Instance->Log(DEBUG, "PQsocket cant be removed from the socket engine!"); } -- cgit v1.2.3