X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Flistensocket.cpp;h=961156ae6f74e4b846397d6ab3ef9d4ea33446d2;hb=ca42e175351b6209a8e9cbd5eb92bba4f38a38ce;hp=7c679c1d3fe9b650dba2e6c6080f693943e35284;hpb=7a30c818ee4a5afb0aaea9adca4f2e3606b20c37;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/listensocket.cpp b/src/listensocket.cpp index 7c679c1d3..961156ae6 100644 --- a/src/listensocket.cpp +++ b/src/listensocket.cpp @@ -19,20 +19,20 @@ /* Private static member data must be initialized in this manner */ -unsigned int ListenSocket::socketcount = 0; -sockaddr* ListenSocket::sock_us = NULL; -sockaddr* ListenSocket::client = NULL; -sockaddr* ListenSocket::raddr = NULL; +unsigned int ListenSocketBase::socketcount = 0; +sockaddr* ListenSocketBase::sock_us = NULL; +sockaddr* ListenSocketBase::client = NULL; +sockaddr* ListenSocketBase::raddr = NULL; -ListenSocket::ListenSocket(InspIRCd* Instance, int port, char* addr) : ServerInstance(Instance), desc("plaintext"), bind_addr(addr), bind_port(port) +ListenSocketBase::ListenSocketBase(InspIRCd* Instance, int port, const std::string &addr) : ServerInstance(Instance), desc("plaintext"), bind_addr(addr), bind_port(port) { - this->SetFd(irc::sockets::OpenTCPSocket(addr)); + this->SetFd(irc::sockets::OpenTCPSocket(addr.c_str())); if (this->GetFd() > -1) { - if (!Instance->BindSocket(this->fd,port,addr)) + if (!Instance->BindSocket(this->fd,port,addr.c_str())) this->fd = -1; #ifdef IPV6 - if ((!*addr) || (strchr(addr,':'))) + if ((!*addr.c_str()) || (strchr(addr.c_str(),':'))) this->family = AF_INET6; else #endif @@ -51,7 +51,7 @@ ListenSocket::ListenSocket(InspIRCd* Instance, int port, char* addr) : ServerIns socketcount++; } -ListenSocket::~ListenSocket() +ListenSocketBase::~ListenSocketBase() { if (this->GetFd() > -1) { @@ -71,7 +71,7 @@ ListenSocket::~ListenSocket() } /* Just seperated into another func for tidiness really.. */ -void ListenSocket::AcceptInternal() +void ListenSocketBase::AcceptInternal() { ServerInstance->Logs->Log("SOCKET",DEBUG,"HandleEvent for Listensoket"); socklen_t uslen, length; // length of our port number @@ -100,6 +100,24 @@ void ListenSocket::AcceptInternal() ServerInstance->stats->statsRefused++; return; } + /* + * XXX - + * this is done as a safety check to keep the file descriptors within range of fd_ref_table. + * its a pretty big but for the moment valid assumption: + * file descriptors are handed out starting at 0, and are recycled as theyre freed. + * therefore if there is ever an fd over 65535, 65536 clients must be connected to the + * irc server at once (or the irc server otherwise initiating this many connections, files etc) + * which for the time being is a physical impossibility (even the largest networks dont have more + * than about 10,000 users on ONE server!) + */ + if (incomingSockfd >= ServerInstance->SE->GetMaxFds()) + { + ServerInstance->Logs->Log("SOCKET", DEBUG, "Server is full"); + ServerInstance->SE->Shutdown(incomingSockfd, 2); + ServerInstance->SE->Close(incomingSockfd); + ServerInstance->stats->statsRefused++; + return; + } static char buf[MAXBUF]; static char target[MAXBUF]; @@ -127,31 +145,12 @@ void ListenSocket::AcceptInternal() ServerInstance->Logs->Log("SOCKET", DEBUG, "Can't get peername: %s", strerror(errno)); } - /* - * XXX - - * this is done as a safety check to keep the file descriptors within range of fd_ref_table. - * its a pretty big but for the moment valid assumption: - * file descriptors are handed out starting at 0, and are recycled as theyre freed. - * therefore if there is ever an fd over 65535, 65536 clients must be connected to the - * irc server at once (or the irc server otherwise initiating this many connections, files etc) - * which for the time being is a physical impossibility (even the largest networks dont have more - * than about 10,000 users on ONE server!) - */ - if (incomingSockfd >= ServerInstance->SE->GetMaxFds()) - { - ServerInstance->Logs->Log("SOCKET", DEBUG, "Server is full"); - ServerInstance->SE->Shutdown(incomingSockfd, 2); - ServerInstance->SE->Close(incomingSockfd); - ServerInstance->stats->statsRefused++; - return; - } - ServerInstance->SE->NonBlocking(incomingSockfd); ServerInstance->stats->statsAccept++; - this->OnAcceptReady(target, incomingSockfd); + this->OnAcceptReady(target, incomingSockfd, buf); } -void ListenSocket::HandleEvent(EventType e, int err) +void ListenSocketBase::HandleEvent(EventType e, int err) { switch (e) { @@ -167,7 +166,7 @@ void ListenSocket::HandleEvent(EventType e, int err) } } -void ListenSocket::OnAcceptReady(const std::string &ipconnectedto, int nfd) +void ClientListenSocket::OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip) { - ServerInstance->Users->AddUser(ServerInstance, nfd, bind_port, false, this->family, client, ipconnectedto); + ServerInstance->Users->AddUser(ServerInstance, nfd, bind_port, false, this->family, client, ipconnectedto); }