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 "socketengine_select.h"
23 #include "helperfuncs.h"
25 SelectEngine::SelectEngine()
27 log(DEBUG,"SelectEngine::SelectEngine()");
32 SelectEngine::~SelectEngine()
34 log(DEBUG,"SelectEngine::~SelectEngine()");
37 bool SelectEngine::AddFd(int fd, bool readable, char type)
39 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
41 log(DEFAULT,"ERROR: FD of %d added above max of %d",fd,MAX_DESCRIPTORS);
44 if (GetRemainingFds() <= 1)
46 log(DEFAULT,"ERROR: System out of file descriptors!");
55 log(DEBUG,"Set readbit");
58 log(DEBUG,"Add socket %d",fd);
64 bool SelectEngine::DelFd(int fd)
66 log(DEBUG,"SelectEngine::DelFd(%d)",fd);
68 if ((fd < 0) || (fd > MAX_DESCRIPTORS))
71 std::map<int,int>::iterator t = fds.find(fd);
75 log(DEBUG,"Deleted fd %d",fd);
83 int SelectEngine::GetMaxFds()
88 int SelectEngine::GetRemainingFds()
90 return FD_SETSIZE - CurrentSetSize;
93 int SelectEngine::Wait(int* fdlist)
101 for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
103 if (ref[a->second] & X_READBIT)
105 FD_SET (a->second, &rfdset);
109 FD_SET (a->second, &wfdset);
115 sresult = select(FD_SETSIZE, &rfdset, &wfdset, NULL, &tval);
118 for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
120 if ((FD_ISSET (a->second, &rfdset)) || (FD_ISSET (a->second, &wfdset)))
121 fdlist[result++] = a->second;
128 std::string SelectEngine::GetName()