]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspsocket.cpp
Make irc::spacify take 'const char*' instead of 'char*'
[user/henk/code/inspircd.git] / src / inspsocket.cpp
index 23d89a71f054164adc48a2701775bc1405ecfbfa..34f4a6201a9e86304f9c9cefa00419b355002022 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,7 +256,7 @@ void InspSocket::Close()
 {
        if (this->fd > -1)
        {
-                if (this->IsIOHooked)
+                if (this->IsIOHooked && Instance->Config->GetIOHook(this))
                {
                        try
                        {
@@ -367,7 +364,38 @@ 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)
                                {
@@ -483,7 +511,7 @@ bool InspSocket::Poll()
                                if (!this->Instance->SE->AddFd(this))
                                        return false;
                        }
-                       if (this->IsIOHooked)
+                       if (Instance->Config->GetIOHook(this))
                        {
                                try
                                {
@@ -500,6 +528,12 @@ bool InspSocket::Poll()
                        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
@@ -517,11 +551,6 @@ bool InspSocket::Poll()
                        }
 
                        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: