* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ * InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
*
* This program is free but copyrighted software; see
* the file COPYING for details.
EngineHandle = 0;
CurrentSetSize = 0;
- writeable = new bool [GetMaxFds()];
- memset(writeable, 0, sizeof(writeable));
+ writeable.assign(GetMaxFds(), false);
ref = new EventHandler* [GetMaxFds()];
memset(ref, 0, GetMaxFds() * sizeof(EventHandler*));
- ev = new EventHandler* [GetMaxFds()];
}
SelectEngine::~SelectEngine()
{
delete[] ref;
- delete[] ev;
}
bool SelectEngine::AddFd(EventHandler* eh)
if (ref[fd])
return false;
- fds[fd] = fd;
+ fds.insert(fd);
ref[fd] = eh;
CurrentSetSize++;
if ((fd < 0) || (fd > GetMaxFds() - 1))
return false;
- std::map<int,int>::iterator t = fds.find(fd);
+ std::set<int>::iterator t = fds.find(fd);
if (t != fds.end())
fds.erase(t);
{
timeval tval;
int sresult = 0;
- socklen_t codesize;
+ socklen_t codesize = sizeof(int);
int errcode = 0;
FD_ZERO(&wfdset);
FD_ZERO(&errfdset);
/* Populate the select FD set (this is why select sucks compared to epoll, kqueue, IOCP) */
- for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
+ for (std::set<int>::iterator a = fds.begin(); a != fds.end(); a++)
{
- if (ref[a->second]->Readable())
+ if (ref[*a]->Readable())
/* Read notifications */
- FD_SET (a->second, &rfdset);
+ FD_SET (*a, &rfdset);
else
/* Write notifications */
- FD_SET (a->second, &wfdset);
+ FD_SET (*a, &wfdset);
/* Explicitly one-time writeable */
- if (writeable[a->second])
- FD_SET (a->second, &wfdset);
+ if (writeable[*a])
+ FD_SET (*a, &wfdset);
/* All sockets must receive error notifications regardless */
- FD_SET (a->second, &errfdset);
+ FD_SET (*a, &errfdset);
}
/* One second waits */
if (sresult < 1)
return 0;
- /* Safe assumption (as of 1.1 anyway) that a socket can't remove itself from the list in the middle of the loop */
- for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
+ std::vector<int> copy(fds.begin(), fds.end());
+ for (std::vector<int>::iterator a = copy.begin(); a != copy.end(); a++)
{
- EventHandler* ev = ref[a->second];
+ EventHandler* ev = ref[*a];
if (ev)
{
if (FD_ISSET (ev->GetFd(), &errfdset))
}
}
- return result;
+ return sresult;
}
std::string SelectEngine::GetName()