1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "inspircd_config.h"
22 #include <sys/select.h>
23 #include "socketengine_select.h"
26 SelectEngine::SelectEngine(InspIRCd* Instance) : SocketEngine(Instance)
28 ServerInstance->Log(DEBUG,"SelectEngine::SelectEngine()");
33 SelectEngine::~SelectEngine()
35 ServerInstance->Log(DEBUG,"SelectEngine::~SelectEngine()");
38 bool SelectEngine::AddFd(int fd, bool readable, char type)
40 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
42 ServerInstance->Log(DEFAULT,"ERROR: FD of %d added above max of %d",fd,MAX_DESCRIPTORS);
45 if (GetRemainingFds() <= 1)
47 ServerInstance->Log(DEFAULT,"ERROR: System out of file descriptors!");
59 ServerInstance->Log(DEBUG,"Set readbit");
62 ServerInstance->Log(DEBUG,"Add socket %d",fd);
68 bool SelectEngine::DelFd(int fd)
70 ServerInstance->Log(DEBUG,"SelectEngine::DelFd(%d)",fd);
72 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
75 std::map<int,int>::iterator t = fds.find(fd);
79 ServerInstance->Log(DEBUG,"Deleted fd %d",fd);
87 int SelectEngine::GetMaxFds()
92 int SelectEngine::GetRemainingFds()
94 return FD_SETSIZE - CurrentSetSize;
97 int SelectEngine::Wait(int* fdlist)
105 for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
107 if (ref[a->second] & X_READBIT)
109 FD_SET (a->second, &rfdset);
113 FD_SET (a->second, &wfdset);
119 sresult = select(FD_SETSIZE, &rfdset, &wfdset, NULL, &tval);
122 for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
124 if ((FD_ISSET (a->second, &rfdset)) || (FD_ISSET (a->second, &wfdset)))
125 fdlist[result++] = a->second;
132 std::string SelectEngine::GetName()