]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/listensocket.cpp
Remove the -Dssize_t declaration now its typedeffed.
[user/henk/code/inspircd.git] / src / listensocket.cpp
index 452925bf3a7af97af02e4f1ccf826c17d0689a39..e0a18a043fab7a86bafe734fa8f463e1c28ccb73 100644 (file)
 irc::sockets::sockaddrs ListenSocketBase::client;
 irc::sockets::sockaddrs ListenSocketBase::server;
 
-ListenSocketBase::ListenSocketBase(InspIRCd* Instance, int port, const std::string &addr) : ServerInstance(Instance), desc("plaintext")
+ListenSocketBase::ListenSocketBase(int port, const std::string &addr, const std::string &Type, const std::string &Hook)
+       : type(Type), hook(Hook), bind_port(port)
 {
        irc::sockets::sockaddrs bind_to;
 
-       bind_addr = addr;
-       bind_port = port;
-
        // canonicalize address if it is defined
-       if (!addr.empty() && irc::sockets::aptosa(addr.c_str(), port, &bind_to))
-               irc::sockets::satoap(&bind_to, bind_addr, bind_port);
+       if (!irc::sockets::aptosa(addr, port, &bind_to))
+       {
+               // malformed address
+               bind_addr = addr;
+               bind_desc = addr + ":" + ConvToStr(port);
+               this->fd = -1;
+       }
+       else
+       {
+               irc::sockets::satoap(&bind_to, bind_addr, port);
+               bind_desc = irc::sockets::satouser(&bind_to);
 
-       this->SetFd(irc::sockets::OpenTCPSocket(bind_addr.c_str()));
-       if (this->GetFd() > -1)
+               this->fd = irc::sockets::OpenTCPSocket(bind_addr);
+       }
+
+       if (this->fd > -1)
        {
-               if (!Instance->BindSocket(this->fd,port,bind_addr.c_str()))
+               int rv = ServerInstance->SE->Bind(this->fd, &bind_to.sa, sizeof(bind_to));
+               if (rv >= 0)
+                       rv = ServerInstance->SE->Listen(this->fd, ServerInstance->Config->MaxConn);
+
+               if (rv < 0)
+               {
+                       ServerInstance->SE->Shutdown(this, 2);
+                       ServerInstance->SE->Close(this);
                        this->fd = -1;
-               Instance->SE->AddFd(this);
+               }
+               else
+               {
+                       ServerInstance->SE->NonBlocking(this->fd);
+                       ServerInstance->SE->AddFd(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE);
+               }
        }
 }
 
@@ -125,15 +146,9 @@ void ListenSocketBase::AcceptInternal()
                }
        }
 
-       std::string server_addr;
-       std::string client_addr;
-       int dummy_port;
-       irc::sockets::satoap(&server, server_addr, dummy_port);
-       irc::sockets::satoap(&client, client_addr, dummy_port);
-
        ServerInstance->SE->NonBlocking(incomingSockfd);
        ServerInstance->stats->statsAccept++;
-       this->OnAcceptReady(server_addr, incomingSockfd, client_addr);
+       this->OnAcceptReady(incomingSockfd);
 }
 
 void ListenSocketBase::HandleEvent(EventType e, int err)
@@ -152,7 +167,7 @@ void ListenSocketBase::HandleEvent(EventType e, int err)
        }
 }
 
-void ClientListenSocket::OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip)
+void ClientListenSocket::OnAcceptReady(int nfd)
 {
-       ServerInstance->Users->AddUser(ServerInstance, nfd, bind_port, false, &client, ipconnectedto);
+       ServerInstance->Users->AddUser(nfd, this, &client, &server);
 }