* ---------------------------------------------------
*/
-#include "inspircd_config.h"
-#include "globals.h"
#include "inspircd.h"
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
-#include <vector>
-#include <string>
#include "socketengine_kqueue.h"
bool KQueueEngine::AddFd(EventHandler* eh)
{
int fd = eh->GetFd();
+
+ ServerInstance->Log(DEFAULT,"KQueueEngine::AddFd(%d)",fd);
+
if ((fd < 0) || (fd > MAX_DESCRIPTORS))
{
ServerInstance->Log(DEFAULT,"ERROR: FD of %d added above max of %d",fd,MAX_DESCRIPTORS);
}
if (ref[fd])
+ {
+ ServerInstance->Log(DEFAULT,"ERROR: Slot already occupied");
return false;
+ }
ref[fd] = eh;
ServerInstance->Log(DEBUG,"Add socket %d",fd);
return MAX_DESCRIPTORS - CurrentSetSize;
}
-int KQueueEngine::Wait(EventHandler** fdlist)
+int KQueueEngine::DispatchEvents()
{
- int result = 0;
-
ts.tv_nsec = 5000L;
ts.tv_sec = 0;
int i = kevent(EngineHandle, NULL, 0, &ke_list[0], MAX_DESCRIPTORS, &ts);
for (int j = 0; j < i; j++)
- fdlist[result++] = ref[ke_list[j].ident];
+ {
+ ServerInstance->Log(DEBUG,"Handle %s event on fd %d",ref[ke_list[j].ident]->Readable() ? "read" : "write", ref[ke_list[j].ident]->GetFd());
+ ref[ke_list[j].ident]->HandleEvent(ref[ke_list[j].ident]->Readable() ? EVENT_READ : EVENT_WRITE);
+ }
- return result;
+ return i;
}
std::string KQueueEngine::GetName()