-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
*
- * InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ * Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
*
- * This program is free but copyrighted software; see
- * the file COPYING for details.
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
*
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
+#include "inspircd_config.h"
+
#include "inspircd.h"
+#include "socketengine.h"
+
#ifndef WINDOWS
#include <sys/select.h>
#endif // WINDOWS
-#include "socketengines/socketengine_select.h"
+/** A specialisation of the SocketEngine class, designed to use traditional select().
+ */
+class SelectEngine : public SocketEngine
+{
+public:
+ /** Create a new SelectEngine
+ */
+ SelectEngine();
+ /** Delete a SelectEngine
+ */
+ virtual ~SelectEngine();
+ virtual bool AddFd(EventHandler* eh, int event_mask);
+ virtual void DelFd(EventHandler* eh);
+ void OnSetEvent(EventHandler* eh, int, int);
+ virtual int DispatchEvents();
+ virtual std::string GetName();
+};
SelectEngine::SelectEngine()
{
delete[] ref;
}
-bool SelectEngine::AddFd(EventHandler* eh, int)
+bool SelectEngine::AddFd(EventHandler* eh, int event_mask)
{
int fd = eh->GetFd();
if ((fd < 0) || (fd > GetMaxFds() - 1))
return true;
}
-bool SelectEngine::DelFd(EventHandler* eh, bool force)
+void SelectEngine::DelFd(EventHandler* eh)
{
int fd = eh->GetFd();
if ((fd < 0) || (fd > GetMaxFds() - 1))
- return false;
+ return;
CurrentSetSize--;
ref[fd] = NULL;
ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
- return true;
}
void SelectEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
FD_ZERO(&rfdset);
FD_ZERO(&errfdset);
- /* Populate the select FD sets (this is why select sucks compared to epoll, kqueue, IOCP) */
- for (int i = 0; i < FD_SETSIZE; i++)
+ /* Populate the select FD sets (this is why select sucks compared to epoll, kqueue) */
+ for (unsigned int i = 0; i < FD_SETSIZE; i++)
{
EventHandler* eh = ref[i];
if (!eh)
tval.tv_usec = 0;
sresult = select(FD_SETSIZE, &rfdset, &wfdset, &errfdset, &tval);
+ ServerInstance->UpdateTime();
/* Nothing to process this time around */
if (sresult < 1)
if (FD_ISSET (i, &rfdset))
{
ReadEvents++;
- SetEventMask(eh, eh->GetEventMask() & ~FD_READ_WILL_BLOCK);
+ SetEventMask(ev, ev->GetEventMask() & ~FD_READ_WILL_BLOCK);
ev->HandleEvent(EVENT_READ);
+ if (ev != ref[i])
+ continue;
}
if (FD_ISSET (i, &wfdset))
{
WriteEvents++;
- SetEventMask(eh, eh->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE));
+ SetEventMask(ev, ev->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE));
ev->HandleEvent(EVENT_WRITE);
}
}
{
return "select";
}
+
+SocketEngine* CreateSocketEngine()
+{
+ return new SelectEngine;
+}