summaryrefslogtreecommitdiff
path: root/src/listensocket.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:46:33 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-21 23:46:33 +0000
commitd221de88276b9e33a108281a9cd0a58875032fc6 (patch)
tree3032609bd5ef7f4a6a4bad5c0b2a4100432ea2df /src/listensocket.cpp
parentdcbb0ae938711cd49df73dc2ff6cd6289aeefb44 (diff)
Kill ListenSocketBase, use OnAcceptConnection for all new connections
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11950 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/listensocket.cpp')
-rw-r--r--src/listensocket.cpp52
1 files changed, 27 insertions, 25 deletions
diff --git a/src/listensocket.cpp b/src/listensocket.cpp
index e0a18a043..8b7053d8f 100644
--- a/src/listensocket.cpp
+++ b/src/listensocket.cpp
@@ -17,30 +17,21 @@
#include "socket.h"
#include "socketengine.h"
-/* Private static member data must be declared in this manner */
-irc::sockets::sockaddrs ListenSocketBase::client;
-irc::sockets::sockaddrs ListenSocketBase::server;
-
-ListenSocketBase::ListenSocketBase(int port, const std::string &addr, const std::string &Type, const std::string &Hook)
- : type(Type), hook(Hook), bind_port(port)
+ListenSocket::ListenSocket(ConfigTag* tag, const std::string& addr, int port)
+ : bind_tag(tag)
{
irc::sockets::sockaddrs bind_to;
// canonicalize address if it is defined
if (!irc::sockets::aptosa(addr, port, &bind_to))
{
- // malformed address
- bind_addr = addr;
- bind_desc = addr + ":" + ConvToStr(port);
- this->fd = -1;
+ fd = -1;
+ return;
}
- else
- {
- irc::sockets::satoap(&bind_to, bind_addr, port);
- bind_desc = irc::sockets::satouser(&bind_to);
+ irc::sockets::satoap(&bind_to, bind_addr, bind_port);
+ bind_desc = irc::sockets::satouser(&bind_to);
- this->fd = irc::sockets::OpenTCPSocket(bind_addr);
- }
+ fd = irc::sockets::OpenTCPSocket(bind_addr);
if (this->fd > -1)
{
@@ -62,7 +53,7 @@ ListenSocketBase::ListenSocketBase(int port, const std::string &addr, const std:
}
}
-ListenSocketBase::~ListenSocketBase()
+ListenSocket::~ListenSocket()
{
if (this->GetFd() > -1)
{
@@ -75,8 +66,11 @@ ListenSocketBase::~ListenSocketBase()
}
/* Just seperated into another func for tidiness really.. */
-void ListenSocketBase::AcceptInternal()
+void ListenSocket::AcceptInternal()
{
+ irc::sockets::sockaddrs client;
+ irc::sockets::sockaddrs server;
+
ServerInstance->Logs->Log("SOCKET",DEBUG,"HandleEvent for Listensoket");
int incomingSockfd;
@@ -148,10 +142,23 @@ void ListenSocketBase::AcceptInternal()
ServerInstance->SE->NonBlocking(incomingSockfd);
ServerInstance->stats->statsAccept++;
- this->OnAcceptReady(incomingSockfd);
+
+ ModResult res;
+ FIRST_MOD_RESULT(OnAcceptConnection, res, (incomingSockfd, this, &client, &server));
+ if (res == MOD_RES_PASSTHRU)
+ {
+ std::string type = bind_tag->getString("type", "clients");
+ if (type == "clients")
+ {
+ ServerInstance->Users->AddUser(incomingSockfd, this, &client, &server);
+ res = MOD_RES_ALLOW;
+ }
+ }
+ if (res != MOD_RES_ALLOW)
+ ServerInstance->SE->Close(incomingSockfd);
}
-void ListenSocketBase::HandleEvent(EventType e, int err)
+void ListenSocket::HandleEvent(EventType e, int err)
{
switch (e)
{
@@ -166,8 +173,3 @@ void ListenSocketBase::HandleEvent(EventType e, int err)
break;
}
}
-
-void ClientListenSocket::OnAcceptReady(int nfd)
-{
- ServerInstance->Users->AddUser(nfd, this, &client, &server);
-}