]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socket.cpp
Allow ulines to still notice the channel regardless of +T
[user/henk/code/inspircd.git] / src / socket.cpp
index 7be61c9d4c0762b39789af3f50869161450b5a32..160f0f652dd04a8c6774a3f13d4546c7ecf6c67a 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -36,13 +36,11 @@ using namespace std;
 #include "helperfuncs.h"
 #include "socketengine.h"
 
-extern SocketEngine* SE;
 
-extern int boundPortCount;
-extern int openSockfd[MAXSOCKS];
+extern InspIRCd* ServerInstance;
 extern time_t TIME;
 
-InspSocket* socket_ref[65535];
+InspSocket* socket_ref[MAX_DESCRIPTORS];
 
 InspSocket::InspSocket()
 {
@@ -54,7 +52,7 @@ InspSocket::InspSocket(int newfd, char* ip)
        this->fd = newfd;
        this->state = I_CONNECTED;
        this->IP = ip;
-       SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+       ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
        socket_ref[this->fd] = this;
 }
 
@@ -83,7 +81,7 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long
                        else
                        {
                                this->state = I_LISTENING;
-                               SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+                               ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
                                socket_ref[this->fd] = this;
                                log(DEBUG,"New socket now in I_LISTENING state");
                                return;
@@ -131,7 +129,7 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long
                         }
                 }
                 this->state = I_CONNECTING;
-               SE->AddFd(this->fd,false,X_ESTAB_MODULE);
+               ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE);
                socket_ref[this->fd] = this;
                 return;
        }
@@ -164,8 +162,15 @@ char* InspSocket::Read()
        }
        else
        {
-               log(DEBUG,"EOF or error on socket");
-               return NULL;
+               if (n == EAGAIN)
+               {
+                       return "";
+               }
+               else
+               {
+                       log(DEBUG,"EOF or error on socket");
+                       return NULL;
+               }
        }
 }
 
@@ -177,6 +182,7 @@ int InspSocket::Write(std::string data)
 {
        this->Buffer = this->Buffer + data;
        this->FlushWriteBuffer();
+       return data.length();
 }
 
 void InspSocket::FlushWriteBuffer()
@@ -184,7 +190,7 @@ void InspSocket::FlushWriteBuffer()
        int result = 0;
        if (this->Buffer.length())
        {
-               result = send(this->fd,this->Buffer,this->Buffer.length(),0);
+               result = send(this->fd,this->Buffer.c_str(),this->Buffer.length(),0);
                if (result > 0)
                {
                        /* If we wrote some, advance the buffer forwards */
@@ -225,8 +231,8 @@ bool InspSocket::Poll()
                        /* Our socket was in write-state, so delete it and re-add it
                         * in read-state.
                         */
-                       SE->DelFd(this->fd);
-                       SE->AddFd(this->fd,true,X_ESTAB_MODULE);
+                       ServerInstance->SE->DelFd(this->fd);
+                       ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE);
                        return this->OnConnected();
                break;
                case I_LISTENING:
@@ -242,6 +248,9 @@ bool InspSocket::Poll()
                break;
        }
 
+       if (this->Buffer.length())
+               this->FlushWriteBuffer();
+
        return true;
 }
 
@@ -274,7 +283,3 @@ InspSocket::~InspSocket()
        this->Close();
 }
 
-/*
-int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr)
-int OpenTCPSocket (void)
-*/