* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ * InspIRCd: (C) 2002-2009 InspIRCd Development Team
* See: http://www.inspircd.org/wiki/index.php/Credits
*
* This program is free but copyrighted software; see
IOCPEngine::IOCPEngine(InspIRCd * Instance) : SocketEngine(Instance)
{
+ MAX_DESCRIPTORS = 10240;
+
/* Create completion port */
m_completionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)0, 0);
- if (!m_completionPort)
+ if (!m_completionPort)
{
- ServerInstance->Log(SPARSE,"ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
- ServerInstance->Log(SPARSE,"ERROR: this is a fatal error, exiting now.");
- printf("ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
- printf("ERROR: this is a fatal error, exiting now.");
+ ServerInstance->Logs->Log("SOCKET",DEFAULT, "ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.");
+ ServerInstance->Logs->Log("SOCKET",DEFAULT, "ERROR: this is a fatal error, exiting now.");
+ printf("ERROR: Could not initialize socket engine. Your kernel probably does not have the proper features.\n");
+ printf("ERROR: this is a fatal error, exiting now.\n");
ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE);
}
/* Null variables out. */
CurrentSetSize = 0;
EngineHandle = 0;
+ MAX_DESCRIPTORS = 10240;
+ ref = new EventHandler* [10240];
memset(ref, 0, sizeof(EventHandler*) * MAX_DESCRIPTORS);
}
/* Clean up winsock and close completion port */
CloseHandle(m_completionPort);
WSACleanup();
+ delete[] ref;
}
bool IOCPEngine::AddFd(EventHandler* eh)
PostReadEvent(eh);
/* log message */
- ServerInstance->Log(DEBUG, "New fake fd: %u, real fd: %u, address 0x%p", *fake_fd, eh->GetFd(), eh);
+ ServerInstance->Logs->Log("SOCKET",DEBUG, "New fake fd: %u, real fd: %u, address 0x%p", *fake_fd, eh->GetFd(), eh);
/* post a write event if there is data to be written */
if(eh->Writeable())
/* we're all good =) */
try
{
- m_binding.insert( map<int, EventHandler*>::value_type( eh->GetFd(), eh ) );
+ m_binding.insert( std::map<int, EventHandler*>::value_type( eh->GetFd(), eh ) );
}
catch (...)
{
void* m_writeEvent = NULL;
void* m_acceptEvent = NULL;
- ServerInstance->Log(DEBUG, "Removing fake fd %u, real fd %u, address 0x%p", *fake_fd, eh->GetFd(), eh);
+ ServerInstance->Logs->Log("SOCKET",DEBUG, "Removing fake fd %u, real fd %u, address 0x%p", *fake_fd, eh->GetFd(), eh);
/* Cancel pending i/o operations. */
if (CancelIo((HANDLE)fd) == FALSE)
while (GetQueuedCompletionStatus(m_completionPort, &len, &intfd, &overlap, 1000))
{
- if (intfd < 0 || intfd > MAX_DESCRIPTORS)
+ if (intfd > (unsigned long)MAX_DESCRIPTORS)
continue;
// woot, we got an event on a socket :P
eh->GetExt("windows_readevent", m_readEvent);
eh->GetExt("windows_writeevent", m_writeEvent);
+ TotalEvents++;
+
switch(ov->m_event)
{
case SOCKET_IO_EVENT_WRITE_READY:
{
+ WriteEvents++;
eh->Shrink("windows_writeevent");
eh->HandleEvent(EVENT_WRITE, 0);
}
case SOCKET_IO_EVENT_READ_READY:
{
+ ReadEvents++;
if(ov->m_params)
{
// if we had params, it means we are a udp socket with a udp_overlap pointer in this long.
case SOCKET_IO_EVENT_ACCEPT:
{
/* this is kinda messy.. :/ */
+ ReadEvents++;
eh->HandleEvent(EVENT_READ, ov->m_params);
delete ((accept_overlap*)ov->m_params);
eh->Shrink("windows_acceptevent");
case SOCKET_IO_EVENT_ERROR:
{
+ ErrorEvents++;
eh->HandleEvent(EVENT_ERROR, ov->m_params);
}
break;
EventHandler * IOCPEngine::GetRef(int fd)
{
- map<int, EventHandler*>::iterator itr = m_binding.find(fd);
+ std::map<int, EventHandler*>::iterator itr = m_binding.find(fd);
return (itr == m_binding.end()) ? 0 : itr->second;
}
int IOCPEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen)
{
- SOCKET s = fd->GetFd();
+ //SOCKET s = fd->GetFd();
Overlapped* acceptevent = NULL;
if (!fd->GetExt("windows_acceptevent", acceptevent))
Overlapped* ovl = acceptevent;
accept_overlap* ov = (accept_overlap*)ovl->m_params;
- sockaddr_in* server_address = (sockaddr_in*)&ov->buf[10];
+ //sockaddr_in* server_address = (sockaddr_in*)&ov->buf[10];
sockaddr_in* client_address = (sockaddr_in*)&ov->buf[38];
memcpy(addr, client_address, sizeof(sockaddr_in));
accept_overlap* ov = (accept_overlap*)ovl->m_params;
sockaddr_in* server_address = (sockaddr_in*)&ov->buf[10];
- sockaddr_in* client_address = (sockaddr_in*)&ov->buf[38];
+ //sockaddr_in* client_address = (sockaddr_in*)&ov->buf[38];
memcpy(name, server_address, sizeof(sockaddr_in));
*namelen = sizeof(sockaddr_in);
int IOCPEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
{
+ this->UpdateStats(len, 0);
udp_overlap * ov = NULL;
if (!fd->GetExt("windows_readevent", ov))
return -1;
return this->Close(fd->GetFd());
}
+