summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/socketengine.h4
-rw-r--r--include/socketengine_epoll.h2
-rw-r--r--include/socketengine_kqueue.h2
-rw-r--r--include/socketengine_select.h2
-rw-r--r--src/modules/extra/m_pgsql.cpp26
-rw-r--r--src/socketengine.cpp2
-rw-r--r--src/socketengine_epoll.cpp4
-rw-r--r--src/socketengine_kqueue.cpp8
-rw-r--r--src/socketengine_select.cpp4
9 files changed, 24 insertions, 30 deletions
diff --git a/include/socketengine.h b/include/socketengine.h
index 55f8516f9..557c314c6 100644
--- a/include/socketengine.h
+++ b/include/socketengine.h
@@ -94,7 +94,7 @@ class EventHandler : public Extensible
* is still added to a SocketEngine instance!
* If this function is unimplemented, the base class
* will return true.
- *
+ *
* NOTE: You cannot set both Readable() and
* Writeable() to true. If you wish to receive
* a write event for your object, you must call
@@ -227,7 +227,7 @@ public:
* @param eh The event handler object to remove
* @return True if the event handler was removed
*/
- virtual bool DelFd(EventHandler* eh);
+ virtual bool DelFd(EventHandler* eh, bool force = false);
/** Returns true if a file descriptor exists in
* the socket engine's list.
diff --git a/include/socketengine_epoll.h b/include/socketengine_epoll.h
index ca71fb500..d61e8e865 100644
--- a/include/socketengine_epoll.h
+++ b/include/socketengine_epoll.h
@@ -45,7 +45,7 @@ public:
virtual bool AddFd(EventHandler* eh);
virtual int GetMaxFds();
virtual int GetRemainingFds();
- virtual bool DelFd(EventHandler* eh);
+ virtual bool DelFd(EventHandler* eh, bool force);
virtual int DispatchEvents();
virtual std::string GetName();
virtual void WantWrite(EventHandler* eh);
diff --git a/include/socketengine_kqueue.h b/include/socketengine_kqueue.h
index d1f59c47b..505607dae 100644
--- a/include/socketengine_kqueue.h
+++ b/include/socketengine_kqueue.h
@@ -49,7 +49,7 @@ public:
virtual bool AddFd(EventHandler* eh);
virtual int GetMaxFds();
virtual int GetRemainingFds();
- virtual bool DelFd(EventHandler* eh);
+ virtual bool DelFd(EventHandler* eh, bool force);
virtual int DispatchEvents();
virtual std::string GetName();
virtual void WantWrite(EventHandler* eh);
diff --git a/include/socketengine_select.h b/include/socketengine_select.h
index f1392dda6..ed774f5c1 100644
--- a/include/socketengine_select.h
+++ b/include/socketengine_select.h
@@ -50,7 +50,7 @@ public:
virtual bool AddFd(EventHandler* eh);
virtual int GetMaxFds();
virtual int GetRemainingFds();
- virtual bool DelFd(EventHandler* eh);
+ virtual bool DelFd(EventHandler* eh, bool force);
virtual int DispatchEvents();
virtual std::string GetName();
virtual void WantWrite(EventHandler* eh);
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!");
}
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index 965df906a..668335e6b 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -66,7 +66,7 @@ EventHandler* SocketEngine::GetRef(int fd)
return ref[fd];
}
-bool SocketEngine::DelFd(EventHandler* eh)
+bool SocketEngine::DelFd(EventHandler* eh, bool force)
{
return true;
}
diff --git a/src/socketengine_epoll.cpp b/src/socketengine_epoll.cpp
index 49fd1339a..24ee6c891 100644
--- a/src/socketengine_epoll.cpp
+++ b/src/socketengine_epoll.cpp
@@ -91,7 +91,7 @@ void EPollEngine::WantWrite(EventHandler* eh)
}
}
-bool EPollEngine::DelFd(EventHandler* eh)
+bool EPollEngine::DelFd(EventHandler* eh, bool force)
{
int fd = eh->GetFd();
if ((fd < 0) || (fd > MAX_DESCRIPTORS))
@@ -103,7 +103,7 @@ bool EPollEngine::DelFd(EventHandler* eh)
ev.data.fd = fd;
int i = epoll_ctl(EngineHandle, EPOLL_CTL_DEL, fd, &ev);
- if (i < 0)
+ if (i < 0 && !force)
return false;
CurrentSetSize--;
diff --git a/src/socketengine_kqueue.cpp b/src/socketengine_kqueue.cpp
index b56ca264c..4d0039903 100644
--- a/src/socketengine_kqueue.cpp
+++ b/src/socketengine_kqueue.cpp
@@ -80,7 +80,7 @@ bool KQueueEngine::AddFd(EventHandler* eh)
return true;
}
-bool KQueueEngine::DelFd(EventHandler* eh)
+bool KQueueEngine::DelFd(EventHandler* eh, bool force)
{
int fd = eh->GetFd();
@@ -91,12 +91,12 @@ bool KQueueEngine::DelFd(EventHandler* eh)
EV_SET(&ke, eh->GetFd(), EVFILT_READ, EV_DELETE, 0, 0, NULL);
int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
-
+
EV_SET(&ke, eh->GetFd(), EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
int j = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
- if ((j < 0) && (i < 0))
+ if ((j < 0) && (i < 0) && !force)
return false;
CurrentSetSize--;
@@ -151,7 +151,7 @@ int KQueueEngine::DispatchEvents()
}
if (ke_list[j].flags & EVFILT_WRITE)
{
- /* This looks wrong but its right. As above, theres no modify
+ /* This looks wrong but its right. As above, theres no modify
* call in kqueue. See the manpage.
*/
struct kevent ke;
diff --git a/src/socketengine_select.cpp b/src/socketengine_select.cpp
index 2be16b282..afa42c7bc 100644
--- a/src/socketengine_select.cpp
+++ b/src/socketengine_select.cpp
@@ -60,7 +60,7 @@ void SelectEngine::WantWrite(EventHandler* eh)
writeable[eh->GetFd()] = true;
}
-bool SelectEngine::DelFd(EventHandler* eh)
+bool SelectEngine::DelFd(EventHandler* eh, bool force)
{
int fd = eh->GetFd();
@@ -151,7 +151,7 @@ int SelectEngine::DispatchEvents()
if (ev[i])
ev[i]->HandleEvent(EVENT_WRITE);
writeable[ev[i]->GetFd()] = false;
-
+
}
else
{