myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. d52a3f3bd2


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. d52a3f3bd2ffe2ad44843d4103ab1c12c14a6485
Date: Wed, 07 Oct 2009 17:02:48 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  d52a3f3bd2ffe2ad44843d4103ab1c12c14a6485 (commit)
       via  4e2c0d4d5fb5e0cfac4fb3814e33adcfd66bb3f4 (commit)
      from  b7d9283c0f31178d76feb16daf8644c3c5f568e6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit d52a3f3bd2ffe2ad44843d4103ab1c12c14a6485
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 7 16:04:41 2009 +0200

    Replace getNonBLocking with getNonBlocking.

diff --git a/myserver/include/base/socket/socket.h 
b/myserver/include/base/socket/socket.h
index a4b8ed2..0675333 100644
--- a/myserver/include/base/socket/socket.h
+++ b/myserver/include/base/socket/socket.h
@@ -107,7 +107,7 @@ public:
   int operator=(Socket*);
   int getsockname (MYSERVER_SOCKADDR*,int*);
   int setNonBlocking (int);
-  bool getNonBLocking () {return isNonBlocking;}
+  bool getNonBlocking () {return isNonBlocking;}
   virtual int dataOnRead (int sec = 0, int usec = 500);
 
   u_long getThrottling ();



commit 4e2c0d4d5fb5e0cfac4fb3814e33adcfd66bb3f4
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 7 10:20:45 2009 +0200

    Now the `Server::addConnection' function doesn't free the socket argument 
on errors.

diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index bd3784d..c2889d2 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -72,7 +72,6 @@ void ConnectionsScheduler::newData (short event, SocketHandle 
handle)
   connection = connections.get (handle);
   connectionsMutex.unlock ();
 
-
   if (connection == NULL || server == NULL)
     return;
 
@@ -94,37 +93,37 @@ static void eventLoopHandler (int fd, short event, void 
*arg)
   ConnectionsScheduler::DispatcherArg *da = 
(ConnectionsScheduler::DispatcherArg*)arg;
   u_long nbr;
   if (event == EV_READ || event == EV_TIMEOUT)
-  {
-    while (da->socketPair.bytesToRead ())
     {
-      char cmd;
-      da->socketPair.read (&cmd, 1, &nbr);
-      if (cmd == 'c')
-      {
-        /*
-         * Schedule a new connection.
-         * The 'c' command is followed by:
-         * SocketHandle  -> Socket to monitor for new data.
-         * ConnectionPtr -> Related Connection.
-         * timeval       -> Timeout.
-         */
-        SocketHandle handle;
-        ConnectionPtr c;
-        timeval tv = {10, 0};
-
-        da->socketPair.read ((char*)&handle, sizeof (SocketHandle), &nbr);
-        da->socketPair.read ((char*)&c, sizeof (ConnectionPtr), &nbr);
-        da->socketPair.read ((char*)&tv, sizeof (timeval), &nbr);
-
-        event_once ((int) handle, EV_READ | EV_TIMEOUT, newDataHandler, da, 
&tv);
-      }
-      if (cmd == 'r')
-        return;
-      /* Handle other cmd without do anything else.  */
+      while (da->socketPair.bytesToRead ())
+       {
+         char cmd;
+         da->socketPair.read (&cmd, 1, &nbr);
+         if (cmd == 'c')
+           {
+             /*
+              * Schedule a new connection.
+              * The 'c' command is followed by:
+              * SocketHandle  -> Socket to monitor for new data.
+              * ConnectionPtr -> Related Connection.
+              * timeval       -> Timeout.
+              */
+             SocketHandle handle;
+             ConnectionPtr c;
+             timeval tv = {10, 0};
+
+             da->socketPair.read ((char*)&handle, sizeof (SocketHandle), &nbr);
+             da->socketPair.read ((char*)&c, sizeof (ConnectionPtr), &nbr);
+             da->socketPair.read ((char*)&tv, sizeof (timeval), &nbr);
+
+             event_once ((int) handle, EV_READ | EV_TIMEOUT, newDataHandler, 
da, &tv);
+           }
+         if (cmd == 'r')
+           return;
+         /* Handle other cmd without do anything else.  */
+       }
+
+      event_add (&(da->loopEvent), NULL);
     }
-
-    event_add (&(da->loopEvent), NULL);
-  }
 }
 
 static void listenerHandler (int fd, short event, void *arg)
@@ -137,9 +136,15 @@ static void listenerHandler (int fd, short event, void 
*arg)
       MYSERVER_SOCKADDRIN asockIn;
       socklen_t asockInLen = sizeof (asockIn);
       Socket *clientSock = s->serverSocket->accept (&asockIn, &asockInLen);
-
       if (s->server && clientSock)
-        s->server->addConnection (clientSock, &asockIn);
+       {
+         if (s->server->addConnection (clientSock, &asockIn))
+           {
+             clientSock->shutdown (2);
+             clientSock->close ();
+             delete clientSock;
+           }
+       }
     }
  
   event_add (&(s->ev), &tv);
@@ -211,7 +216,6 @@ u_long ConnectionsScheduler::getNumTotalConnections ()
   return nTotalConnections;
 }
 
-
 /*!
  * Register the connection with a new ID.
  * \param connection The connection to register.
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index ac54c39..7b01035 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -954,11 +954,12 @@ u_long Server::getTimeout ()
 
 /*!
  * This function add a new connection to the list.
+ * On a failure, it is responsibility of the caller to
+ * free S.
+ * \return 0 on success.
  */
 int Server::addConnection (Socket *s, MYSERVER_SOCKADDRIN *asockIn)
 {
-
-  int ret = 0;
   char ip[MAX_IP_STRING_LEN];
   char localIp[MAX_IP_STRING_LEN];
   u_short port;
@@ -977,19 +978,13 @@ int Server::addConnection (Socket *s, MYSERVER_SOCKADDRIN 
*asockIn)
    */
   if ( asockIn == NULL ||
        (asockIn->ss_family != AF_INET && asockIn->ss_family != AF_INET6))
-    {
-      delete s;
-      return 0;
-    }
+    return -1;
 
   memset (ip, 0, MAX_IP_STRING_LEN);
   memset (localIp, 0, MAX_IP_STRING_LEN);
 
   if (s->getHandle () < 0)
-    {
-      delete s;
-      return 0;
-    }
+    return -1;
 
   /*
    * Do not accept this connection if a MAX_CONNECTIONS_TO_ACCEPT limit is
@@ -998,10 +993,7 @@ int Server::addConnection (Socket *s, MYSERVER_SOCKADDRIN 
*asockIn)
   if (maxConnectionsToAccept
       && ((u_long)connectionsScheduler.getConnectionsNumber ()
           >= maxConnectionsToAccept))
-    {
-      delete s;
-      return 0;
-    }
+    return -1;
 
 #if ( HAVE_IPV6 )
   if ( asockIn->ss_family == AF_INET )
@@ -1013,10 +1005,7 @@ int Server::addConnection (Socket *s, 
MYSERVER_SOCKADDRIN *asockIn)
                        sizeof (sockaddr_in6),  ip, MAX_IP_STRING_LEN,
                        NULL, 0, NI_NUMERICHOST);
   if (ret)
-    {
-      delete s;
-      return 0;
-    }
+    return -1;
 
   if ( asockIn->ss_family == AF_INET )
     dim = sizeof (sockaddr_in);
@@ -1033,13 +1022,13 @@ int Server::addConnection (Socket *s, 
MYSERVER_SOCKADDRIN *asockIn)
                        sizeof (sockaddr_in6), localIp, MAX_IP_STRING_LEN,
                        NULL, 0, NI_NUMERICHOST);
   if (ret)
-    return 0;
+    return -1;
 #else// !HAVE_IPV6
   dim = sizeof (localSockIn);
   s->getsockname ((MYSERVER_SOCKADDR*)&localSockIn, &dim);
   strncpy (ip,  inet_ntoa (((sockaddr_in *)asockIn)->sin_addr),
            MAX_IP_STRING_LEN);
-  strncpy (localIp,  inet_ntoa (((sockaddr_in *)&localSockIn)->sin_addr),
+  strncpy (localIp, inet_ntoa (((sockaddr_in *)&localSockIn)->sin_addr),
            MAX_IP_STRING_LEN);
 #endif//HAVE_IPV6
 
@@ -1059,20 +1048,7 @@ int Server::addConnection (Socket *s, 
MYSERVER_SOCKADDRIN *asockIn)
     myPort = ntohs (((sockaddr_in6 *)(&localSockIn))->sin6_port);
 #endif
 
-  if (!addConnectionToList (s, asockIn, &ip[0], &localIp[0], port, myPort, 1))
-    {
-      /* If we report error to add the connection to the thread.  */
-      ret = 0;
-
-      /* Shutdown the socket both on receive that on send.  */
-      s->shutdown (2);
-
-      /* Then close it.  */
-      s->close ();
-
-      delete s;
-    }
-  return ret;
+  return addConnectionToList (s, asockIn, &ip[0], &localIp[0], port, myPort, 
1) ? 0 : -1;
 }
 
 /*!

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/base/socket/socket.h              |    2 +-
 .../connections_scheduler.cpp                      |   70 ++++++++++---------
 myserver/src/server/server.cpp                     |   44 +++----------
 3 files changed, 48 insertions(+), 68 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]