summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
5 files changed, 19 insertions, 25 deletions
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
{