*/
-#include "inspircd.h"
-#include "exitcodes.h"
-
#ifndef SOCKETENGINE_POLL
#define SOCKETENGINE_POLL
#include <vector>
#include <string>
#include <map>
-#include "inspircd_config.h"
+#include "exitcodes.h"
#include "inspircd.h"
#include "socketengine.h"
#endif
-#include <ulimit.h>
-#ifdef __FreeBSD__
+#ifdef BSD
#include <sys/sysctl.h>
+#else
+ #include <ulimit.h>
#endif
PollEngine::PollEngine()
{
CurrentSetSize = 0;
-#ifndef __FreeBSD__
+#ifdef BSD
+ int mib[2];
+ size_t len;
+
+ mib[0] = CTL_KERN;
+#ifdef KERN_MAXFILESPERPROC
+ mib[1] = KERN_MAXFILESPERPROC;
+#else
+ mib[1] = KERN_MAXFILES;
+#endif
+ len = sizeof(MAX_DESCRIPTORS);
+ sysctl(mib, 2, &MAX_DESCRIPTORS, &len, NULL, 0);
+#else
int max = ulimit(4, 0);
if (max > 0)
{
}
else
{
- ServerInstance->Logs->Log("SOCKET", DEFAULT, "ERROR: Can't determine maximum number of open sockets: %s", strerror(errno));
+ ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Can't determine maximum number of open sockets: %s", strerror(errno));
std::cout << "ERROR: Can't determine maximum number of open sockets: " << strerror(errno) << std::endl;
ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
}
-#else
- int mib[2];
- size_t len;
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_MAXFILES;
- len = sizeof(MAX_DESCRIPTORS);
- sysctl(mib, 2, &MAX_DESCRIPTORS, &len, NULL, 0);
#endif
ref = new EventHandler* [GetMaxFds()];
int fd = eh->GetFd();
if ((fd < 0) || (fd > GetMaxFds() - 1))
{
- ServerInstance->Logs->Log("SOCKET",DEBUG,"AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "AddFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
return false;
}
if (fd_mappings.find(fd) != fd_mappings.end())
{
- ServerInstance->Logs->Log("SOCKET",DEBUG,"Attempt to add duplicate fd: %d", fd);
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Attempt to add duplicate fd: %d", fd);
return false;
}
events[index].fd = fd;
events[index].events = mask_to_poll(event_mask);
- ServerInstance->Logs->Log("SOCKET", DEBUG,"New file descriptor: %d (%d; index %d)", fd, events[fd].events, index);
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d (%d; index %d)", fd, events[fd].events, index);
SocketEngine::SetEventMask(eh, event_mask);
CurrentSetSize++;
return true;
std::map<int, unsigned int>::iterator it = fd_mappings.find(eh->GetFd());
if (it == fd_mappings.end())
{
- ServerInstance->Logs->Log("SOCKET",DEBUG,"SetEvents() on unknown fd: %d", eh->GetFd());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "SetEvents() on unknown fd: %d", eh->GetFd());
return;
}
int fd = eh->GetFd();
if ((fd < 0) || (fd > MAX_DESCRIPTORS))
{
- ServerInstance->Logs->Log("SOCKET", DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
return;
}
std::map<int, unsigned int>::iterator it = fd_mappings.find(fd);
if (it == fd_mappings.end())
{
- ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd() on unknown fd: %d", fd);
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DelFd() on unknown fd: %d", fd);
return;
}
CurrentSetSize--;
- ServerInstance->Logs->Log("SOCKET", DEBUG, "Remove file descriptor: %d (index: %d) "
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d (index: %d) "
"(Filled gap with: %d (index: %d))", fd, index, last_fd, last_index);
}
// whoops, deleted out from under us
continue;
}
-
+
if (events[index].revents & POLLOUT)
{
int mask = eh->GetEventMask();