]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspsocket.cpp
Cut down on debug on restart
[user/henk/code/inspircd.git] / src / inspsocket.cpp
index 9d2745a2df46496a1097d3fc4dd7cb74c7263ed3..68e2c8f96aea8060ae25df558d4bbdda0a6f281e 100644 (file)
@@ -2,12 +2,9 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  *
@@ -259,15 +256,15 @@ void InspSocket::Close()
 {
        if (this->fd > -1)
        {
-                if (this->IsIOHooked)
+                if (this->IsIOHooked && Instance->Config->GetIOHook(this))
                {
                        try
                        {
                                Instance->Config->GetIOHook(this)->OnRawSocketClose(this->fd);
                        }
-                       catch (ModuleException& modexcept)
+                       catch (CoreException& modexcept)
                        {
-                               Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
+                               Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                        }
                }
                this->OnClose();
@@ -296,9 +293,9 @@ char* InspSocket::Read()
                {
                        MOD_RESULT = Instance->Config->GetIOHook(this)->OnRawSocketRead(this->fd,this->ibuf,sizeof(this->ibuf),result2);
                }
-               catch (ModuleException& modexcept)
+               catch (CoreException& modexcept)
                {
-                       Instance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
+                       Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                }
                if (MOD_RESULT < 0)
                {
@@ -367,11 +364,42 @@ bool InspSocket::FlushWriteBuffer()
                        {
                                try
                                {
-                                       Instance->Config->GetIOHook(this)->OnRawSocketWrite(this->fd, outbuffer[0].c_str(), outbuffer[0].length());
+                                       int result = Instance->Config->GetIOHook(this)->OnRawSocketWrite(this->fd, outbuffer[0].c_str(), outbuffer[0].length());
+                                       if (result > 0)
+                                       {
+                                               if ((unsigned int)result == outbuffer[0].length())
+                                               {
+                                                       outbuffer.pop_front();
+                                               }
+                                               else
+                                               {
+                                                       std::string temp = outbuffer[0].substr(result);
+                                                       outbuffer[0] = temp;
+                                                       errno = EAGAIN;
+                                               }
+                                       }
+                                       else if ((result == -1) && (errno != EAGAIN))
+                                       {
+                                               this->Instance->Log(DEBUG,"Write error on socket: %s",strerror(errno));
+                                               this->OnError(I_ERR_WRITE);
+                                               this->state = I_ERROR;
+                                               this->Instance->SE->DelFd(this);
+                                               this->Close();
+                                               return true;
+                                       }
+                                       else if (result == 0)
+                                       {
+                                               this->Instance->Log(DEBUG,"Write error on socket: EOF");
+                                               this->OnError(I_ERR_WRITE);
+                                               this->state = I_ERROR;
+                                               this->Instance->SE->DelFd(this);
+                                               this->Close();
+                                               return true;
+                                       }
                                }
-                               catch (ModuleException& modexcept)
+                               catch (CoreException& modexcept)
                                {
-                                       Instance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
+                                       Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                                        return true;
                                }
                        }
@@ -483,12 +511,29 @@ bool InspSocket::Poll()
                                if (!this->Instance->SE->AddFd(this))
                                        return false;
                        }
+                       if (Instance->Config->GetIOHook(this))
+                       {
+                               try
+                               {
+                                       Instance->Config->GetIOHook(this)->OnRawSocketConnect(this->fd);
+                               }
+                               catch (CoreException& modexcept)
+                               {
+                                       Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
+                               }
+                       }
                        return this->OnConnected();
                break;
                case I_LISTENING:
                        length = sizeof (client);
                        incoming = accept (this->fd, (sockaddr*)&client,&length);
 
+#ifdef IPV6
+                       this->OnIncomingConnection(incoming, (char*)insp_ntoa(client.sin6_addr));
+#else
+                       this->OnIncomingConnection(incoming, (char*)insp_ntoa(client.sin_addr));
+#endif
+
                        if (this->IsIOHooked)
                        {
                                try
@@ -499,18 +544,13 @@ bool InspSocket::Poll()
                                        Instance->Config->GetIOHook(this)->OnRawSocketAccept(incoming, insp_ntoa(client.sin_addr), this->port);
 #endif
                                }
-                               catch (ModuleException& modexcept)
+                               catch (CoreException& modexcept)
                                {
-                                       Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
+                                       Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
                                }
                        }
 
                        this->SetQueues(incoming);
-#ifdef IPV6
-                       this->OnIncomingConnection(incoming, (char*)insp_ntoa(client.sin6_addr));
-#else
-                       this->OnIncomingConnection(incoming, (char*)insp_ntoa(client.sin_addr));
-#endif
                        return true;
                break;
                case I_CONNECTED:
@@ -597,7 +637,6 @@ void InspSocket::HandleEvent(EventType et, int errornum)
                        }
                        else
                        {
-                               Instance->Log(DEBUG,"State=%d CONNECTED=%d", this->state, I_CONNECTED);
                                if (this->FlushWriteBuffer())
                                {
                                        this->Instance->SE->DelFd(this);