mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-12 03:59:03 -04:00
revert multiaccept for now until we can fix it for win.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7204 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
e430e58c2e
commit
8d7b4f5ead
102
src/socket.cpp
102
src/socket.cpp
@ -47,8 +47,10 @@ ListenSocket::ListenSocket(InspIRCd* Instance, int port, char* addr) : ServerIns
|
||||
if ((!*addr) || (strchr(addr,':')))
|
||||
this->family = AF_INET6;
|
||||
else
|
||||
#endif
|
||||
this->family = AF_INET;
|
||||
#else
|
||||
this->family = AF_INET;
|
||||
#endif
|
||||
Instance->SE->AddFd(this);
|
||||
}
|
||||
}
|
||||
@ -67,9 +69,10 @@ ListenSocket::~ListenSocket()
|
||||
|
||||
void ListenSocket::HandleEvent(EventType et, int errornum)
|
||||
{
|
||||
sockaddr* sock_us = new sockaddr[2]; // our port number
|
||||
sockaddr* client = new sockaddr[2];
|
||||
socklen_t uslen, length; // length of our port number
|
||||
int incomingSockfd, in_port;
|
||||
int clients;
|
||||
|
||||
#ifdef IPV6
|
||||
if (this->family == AF_INET6)
|
||||
@ -78,72 +81,57 @@ void ListenSocket::HandleEvent(EventType et, int errornum)
|
||||
length = sizeof(sockaddr_in6);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
uslen = sizeof(sockaddr_in);
|
||||
length = sizeof(sockaddr_in);
|
||||
}
|
||||
|
||||
/*
|
||||
* This loop may make you wonder 'why' - simple reason. If we just sit here accept()ing until the
|
||||
* metaphorical cows come home, then we could very well end up with unresponsiveness in a ddos style
|
||||
* situation, which is not desirable (to put it mildly!). This will mean we'll stop accepting and get
|
||||
* on with our lives after accepting enough clients to sink a metaphorical battleship. :) -- w00t
|
||||
*/
|
||||
for (clients = 0; clients < ServerInstance->Config->MaxConn; clients++)
|
||||
{
|
||||
sockaddr* sock_us = new sockaddr[2]; // our port number
|
||||
sockaddr* client = new sockaddr[2];
|
||||
|
||||
incomingSockfd = _accept (this->GetFd(), (sockaddr*)client, &length);
|
||||
|
||||
if ((incomingSockfd > -1) && (!_getsockname(incomingSockfd, sock_us, &uslen)))
|
||||
{
|
||||
char buf[MAXBUF];
|
||||
#ifdef IPV6
|
||||
if (this->family == AF_INET6)
|
||||
{
|
||||
inet_ntop(AF_INET6, &((const sockaddr_in6*)client)->sin6_addr, buf, sizeof(buf));
|
||||
in_port = ntohs(((sockaddr_in6*)sock_us)->sin6_port);
|
||||
}
|
||||
else
|
||||
#else
|
||||
uslen = sizeof(sockaddr_in);
|
||||
length = sizeof(sockaddr_in);
|
||||
#endif
|
||||
{
|
||||
inet_ntop(AF_INET, &((const sockaddr_in*)client)->sin_addr, buf, sizeof(buf));
|
||||
in_port = ntohs(((sockaddr_in*)sock_us)->sin_port);
|
||||
}
|
||||
incomingSockfd = _accept (this->GetFd(), (sockaddr*)client, &length);
|
||||
|
||||
NonBlocking(incomingSockfd);
|
||||
if (ServerInstance->Config->GetIOHook(in_port))
|
||||
{
|
||||
try
|
||||
{
|
||||
ServerInstance->Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, buf, in_port);
|
||||
}
|
||||
catch (CoreException& modexcept)
|
||||
{
|
||||
ServerInstance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
|
||||
}
|
||||
}
|
||||
ServerInstance->stats->statsAccept++;
|
||||
userrec::AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
|
||||
if ((incomingSockfd > -1) && (!_getsockname(incomingSockfd, sock_us, &uslen)))
|
||||
{
|
||||
char buf[MAXBUF];
|
||||
#ifdef IPV6
|
||||
if (this->family == AF_INET6)
|
||||
{
|
||||
inet_ntop(AF_INET6, &((const sockaddr_in6*)client)->sin6_addr, buf, sizeof(buf));
|
||||
in_port = ntohs(((sockaddr_in6*)sock_us)->sin6_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* bail, bail, bail! if we get here, accept failed, meaning something is hardcore wrong.
|
||||
* cut our losses and don't try soak up any more clients during this loop iteration. -- w00t
|
||||
*/
|
||||
shutdown(incomingSockfd,2);
|
||||
close(incomingSockfd);
|
||||
ServerInstance->stats->statsRefused++;
|
||||
return;
|
||||
inet_ntop(AF_INET, &((const sockaddr_in*)client)->sin_addr, buf, sizeof(buf));
|
||||
in_port = ntohs(((sockaddr_in*)sock_us)->sin_port);
|
||||
}
|
||||
|
||||
/* Woots metaphorical comments confuse the metaphor out of me. */
|
||||
delete[] client;
|
||||
delete[] sock_us;
|
||||
#else
|
||||
inet_ntop(AF_INET, &((const sockaddr_in*)client)->sin_addr, buf, sizeof(buf));
|
||||
in_port = ntohs(((sockaddr_in*)sock_us)->sin_port);
|
||||
#endif
|
||||
NonBlocking(incomingSockfd);
|
||||
if (ServerInstance->Config->GetIOHook(in_port))
|
||||
{
|
||||
try
|
||||
{
|
||||
ServerInstance->Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, buf, in_port);
|
||||
}
|
||||
catch (CoreException& modexcept)
|
||||
{
|
||||
ServerInstance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
|
||||
}
|
||||
}
|
||||
ServerInstance->stats->statsAccept++;
|
||||
userrec::AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
|
||||
}
|
||||
else
|
||||
{
|
||||
shutdown(incomingSockfd,2);
|
||||
close(incomingSockfd);
|
||||
ServerInstance->stats->statsRefused++;
|
||||
}
|
||||
delete[] client;
|
||||
delete[] sock_us;
|
||||
}
|
||||
|
||||
/* Match raw bytes using CIDR bit matching, used by higher level MatchCIDR() */
|
||||
|
Loading…
x
Reference in New Issue
Block a user