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"
24 #include "helperfuncs.h"
26 SelectEngine::SelectEngine()
28 log(DEBUG,"SelectEngine::SelectEngine()");
33 SelectEngine::~SelectEngine()
35 log(DEBUG,"SelectEngine::~SelectEngine()");
38 bool SelectEngine::AddFd(int fd, bool readable, char type)
40 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
42 log(DEFAULT,"ERROR: FD of %d added above max of %d",fd,MAX_DESCRIPTORS);
45 if (GetRemainingFds() <= 1)
47 log(DEFAULT,"ERROR: System out of file descriptors!");
56 log(DEBUG,"Set readbit");
59 log(DEBUG,"Add socket %d",fd);
65 bool SelectEngine::DelFd(int fd)
67 log(DEBUG,"SelectEngine::DelFd(%d)",fd);
69 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
72 std::map<int,int>::iterator t = fds.find(fd);
76 log(DEBUG,"Deleted fd %d",fd);
84 int SelectEngine::GetMaxFds()
89 int SelectEngine::GetRemainingFds()
91 return FD_SETSIZE - CurrentSetSize;
94 int SelectEngine::Wait(int* fdlist)
102 for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
104 if (ref[a->second] & X_READBIT)
106 FD_SET (a->second, &rfdset);
110 FD_SET (a->second, &wfdset);
116 sresult = select(FD_SETSIZE, &rfdset, &wfdset, NULL, &tval);
119 for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
121 if ((FD_ISSET (a->second, &rfdset)) || (FD_ISSET (a->second, &wfdset)))
122 fdlist[result++] = a->second;
129 std::string SelectEngine::GetName()