]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add HasFd to EventHandler and switch code to use it.
authorSadie Powell <sadie@witchery.services>
Sat, 15 Feb 2020 05:58:19 +0000 (05:58 +0000)
committerSadie Powell <sadie@witchery.services>
Sat, 15 Feb 2020 06:25:12 +0000 (06:25 +0000)
include/socketengine.h
src/coremods/core_dns.cpp
src/listensocket.cpp
src/modules/m_ident.cpp
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/resolvers.cpp
src/socket.cpp
src/socketengine.cpp

index e54dfca976fa30f45814274a1f4c9dfbba0b0237..2b759dad84ef541818296ce0439b8086c7be4a8d 100644 (file)
@@ -182,6 +182,9 @@ class CoreExport EventHandler : public classbase
         */
        inline int GetFd() const { return fd; }
 
+       /** Checks if this event handler has a fd associated with it. */
+       inline bool HasFd() const { return fd >= 0; }
+
        inline int GetEventMask() const { return event_mask; }
 
        /** Set a new file desciptor
index 5dcc994cea048f770c94eb3ff6c1e7856a93c1b5..32613546597af81c9570dd13439b8ceab35f9a2e 100644 (file)
@@ -703,7 +703,7 @@ class MyManager : public Manager, public Timer, public EventHandler
 
        void Rehash(const std::string& dnsserver, std::string sourceaddr, unsigned int sourceport)
        {
-               if (this->GetFd() > -1)
+               if (this->HasFd())
                {
                        SocketEngine::Shutdown(this, 2);
                        SocketEngine::Close(this);
index 40639ba15f0d4f3c1107d049b062fa47dbc90f89..cb1c5c73fcdcc9f219c340862626850044eba9f5 100644 (file)
@@ -130,7 +130,7 @@ ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_t
 
 ListenSocket::~ListenSocket()
 {
-       if (this->GetFd() > -1)
+       if (this->HasFd())
        {
                ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Shut down listener on fd %d", this->fd);
                SocketEngine::Shutdown(this, 2);
index 5994caee57bde54ca4db5b0d77bdab6c3e83075e..dea411cea609da56f2fce1ee6a97c01e885f6bdb 100644 (file)
@@ -187,7 +187,7 @@ class IdentRequestSocket : public EventHandler
                /* Remove ident socket from engine, and close it, but dont detatch it
                 * from its parent user class, or attempt to delete its memory.
                 */
-               if (GetFd() > -1)
+               if (HasFd())
                {
                        ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Close ident socket %d", GetFd());
                        SocketEngine::Close(this);
index 1aab60edaac41b9e2bfdb6a4e4a744c9e4abc6ab..5e6e9b0369b7a8733972dbf79e7cc18240f42f83 100644 (file)
@@ -221,11 +221,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
        {
                // Create a TreeServer object that will start connecting immediately in the background
                TreeSocket* newsocket = new TreeSocket(x, y, sa);
-               if (newsocket->GetFd() > -1)
-               {
-                       /* Handled automatically on success */
-               }
-               else
+               if (!newsocket->HasFd())
                {
                        ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",
                                x->Name.c_str(), newsocket->getError().c_str());
index f048283cfe0dbbca112404653b0048cacf7b1151..14a96933d97e524cf84468361a6dc5d07b563cfe 100644 (file)
@@ -71,11 +71,7 @@ void ServernameResolver::OnLookupComplete(const DNS::Query *r)
        if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
        {
                TreeSocket* newsocket = new TreeSocket(MyLink, myautoconnect, sa);
-               if (newsocket->GetFd() > -1)
-               {
-                       /* We're all OK */
-               }
-               else
+               if (!newsocket->HasFd())
                {
                        /* Something barfed, show the opers */
                        ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",
index e070b68c3464999f882fe70a1e9add7d5a35a023..d2cc2af9a480bcc0bdf313e3b0cd7cc4b2c4e0c7 100644 (file)
@@ -47,7 +47,7 @@ bool InspIRCd::BindPort(ConfigTag* tag, const irc::sockets::sockaddrs& sa, std::
        }
 
        ListenSocket* ll = new ListenSocket(tag, sa);
-       if (ll->GetFd() < 0)
+       if (!ll->HasFd())
        {
                ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to listen on %s from tag at %s: %s",
                        sa.str().c_str(), tag->getTagLocation().c_str(), strerror(errno));
index 61655732e2ff77837ea926192eecf81fe565fba2..e1aef6439fe697476ce5001a4bd0abeee2835d31 100644 (file)
@@ -180,11 +180,7 @@ EventHandler* SocketEngine::GetRef(int fd)
 
 bool SocketEngine::BoundsCheckFd(EventHandler* eh)
 {
-       if (!eh)
-               return false;
-       if (eh->GetFd() < 0)
-               return false;
-       return true;
+       return eh && eh->HasFd();
 }