X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Flistensocket.cpp;h=b0fce7b5b4d475cac50b713f269ab7316fae2476;hb=db2a4c2c15bb170464bbff464d7cc79cd098df26;hp=43584eae1d28051432859136bd20206fb9f6905a;hpb=b868bb52c55fc902e0acab3c4a43576826817e85;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/listensocket.cpp b/src/listensocket.cpp index 43584eae1..b0fce7b5b 100644 --- a/src/listensocket.cpp +++ b/src/listensocket.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * InspIRCd: (C) 2002-2010 InspIRCd Development Team * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see @@ -17,39 +17,34 @@ #include "socket.h" #include "socketengine.h" -ListenSocket::ListenSocket(ConfigTag* tag, const std::string& addr, int port) +ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_to) : bind_tag(tag) { - irc::sockets::sockaddrs bind_to; - - // canonicalize address if it is defined - if (!irc::sockets::aptosa(addr, port, bind_to)) - { - fd = -1; - return; - } irc::sockets::satoap(bind_to, bind_addr, bind_port); bind_desc = irc::sockets::satouser(bind_to); - fd = irc::sockets::OpenTCPSocket(bind_addr); + fd = socket(bind_to.sa.sa_family, SOCK_STREAM, 0); - if (this->fd > -1) - { - 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 (this->fd == -1) + return; - if (rv < 0) - { - ServerInstance->SE->Shutdown(this, 2); - ServerInstance->SE->Close(this); - this->fd = -1; - } - else - { - ServerInstance->SE->NonBlocking(this->fd); - ServerInstance->SE->AddFd(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE); - } + ServerInstance->SE->SetReuse(fd); + int rv = ServerInstance->SE->Bind(this->fd, bind_to); + if (rv >= 0) + rv = ServerInstance->SE->Listen(this->fd, ServerInstance->Config->MaxConn); + + if (rv < 0) + { + int errstore = errno; + ServerInstance->SE->Shutdown(this, 2); + ServerInstance->SE->Close(this); + this->fd = -1; + errno = errstore; + } + else + { + ServerInstance->SE->NonBlocking(this->fd); + ServerInstance->SE->AddFd(this, FD_WANT_POLL_READ | FD_WANT_NO_WRITE); } } @@ -83,7 +78,10 @@ void ListenSocket::AcceptInternal() socklen_t sz = sizeof(server); if (getsockname(incomingSockfd, &server.sa, &sz)) + { ServerInstance->Logs->Log("SOCKET", DEBUG, "Can't get peername: %s", strerror(errno)); + irc::sockets::aptosa(bind_addr, bind_port, server); + } /* * XXX -