* ---------------------------------------------------
*/
+#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 bool DelFd(EventHandler* eh, bool force = false);
+ 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))
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)
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 (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;
+}