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. f75a73dfa9


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. f75a73dfa95dd372204bd440b75f74af0143bbd1
Date: Wed, 07 Oct 2009 21:34:40 +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  f75a73dfa95dd372204bd440b75f74af0143bbd1 (commit)
       via  30deb58d51106a59721d31b8e5823c4f8fb7758b (commit)
       via  0706aacbd7c50d14229e3545c2a57a5ed20857a1 (commit)
       via  cc6fac6f99825fbdbfc21b459ac8c61ffd5e94b8 (commit)
       via  3b3fe798b2eb5ee7b466ee924a0f3fdce8f5f4df (commit)
      from  d52a3f3bd2ffe2ad44843d4103ab1c12c14a6485 (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 f75a73dfa95dd372204bd440b75f74af0143bbd1
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 7 23:33:46 2009 +0200

    Various small fixes.

diff --git a/myserver/include/connections_scheduler/connections_scheduler.h 
b/myserver/include/connections_scheduler/connections_scheduler.h
index c2d9d9c..64ebf90 100644
--- a/myserver/include/connections_scheduler/connections_scheduler.h
+++ b/myserver/include/connections_scheduler/connections_scheduler.h
@@ -38,7 +38,6 @@ using namespace std;
 
 # define PRIORITY_CLASSES 3
 
-
 class Server;
 
 class ConnectionsSchedulerVisitor
@@ -59,10 +58,13 @@ public:
     Mutex* eventsMutex;
     ConnectionsScheduler *scheduler;
     Server* server;
-    void reset (Socket* sock, u_short p, Server* ser){serverSocket = sock; 
port = p; server = ser;}
-    ListenerArg (Socket* sock, u_short p, Server* server){reset (sock, p, 
server);}
+    void reset (Socket* sock, u_short p, Server* ser){serverSocket = sock;
+      port = p; server = ser;}
+    ListenerArg (Socket* sock, u_short p, Server* server){reset (sock, p,
+                                                                 server);}
     ListenerArg (){reset (NULL, 0, NULL);}
-    ListenerArg (ListenerArg* l){serverSocket = l->serverSocket; port = 
l->port; server = l->server;}
+    ListenerArg (ListenerArg* l){serverSocket = l->serverSocket; port = 
l->port;
+      server = l->server;}
   };
 
   struct DispatcherArg
@@ -125,5 +127,4 @@ private:
   bool releasing;
 };
 
-
 #endif
diff --git a/myserver/include/protocol/http/http_thread_context.h 
b/myserver/include/protocol/http/http_thread_context.h
index 5b6e49c..824e419 100644
--- a/myserver/include/protocol/http/http_thread_context.h
+++ b/myserver/include/protocol/http/http_thread_context.h
@@ -29,7 +29,8 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 # include <include/conf/mime/mime_manager.h>
 # include <include/conf/security/security_token.h>
 
-extern "C" {
+extern "C"
+{
 # ifdef WIN32
 #  include <direct.h>
 #  include <errno.h>
@@ -52,7 +53,7 @@ struct HttpThreadContext
 {
        int appendOutputs;
 
-  /*! Used by SSI and set by raiseHTTPError.  */
+  /*! Set by raiseHTTPError.  */
   int lastError;
 
   /*! Is the client asking only for the header?  */
diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index 9cdb157..9ab5de7 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -114,7 +114,7 @@ int File::writeToFile (const char* buffer, u_long 
buffersize, u_long* nbw)
  *\param opt Specify how open the file.
  */
 File::File (char *nfilename, int opt)
-  : handle (0)
+  : handle (-1)
 {
   openFile (nfilename, opt);
 }
@@ -306,11 +306,11 @@ int File::createTemporaryFile (const char* filename)
   if (FilesUtility::fileExists (filename))
     FilesUtility::deleteFile (filename);
 
-  return openFile (filename, File::READ |
-                  File::WRITE|
-                  File::FILE_CREATE_ALWAYS |
-                  File::TEMPORARY |
-                  File::NO_INHERIT);
+  return openFile (filename, File::READ
+                  | File::WRITE
+                  | File::FILE_CREATE_ALWAYS
+                  | File::TEMPORARY
+                  | File::NO_INHERIT);
 }
 
 /*!
diff --git a/myserver/src/base/socket/socket.cpp 
b/myserver/src/base/socket/socket.cpp
index 67299b2..6281af4 100644
--- a/myserver/src/base/socket/socket.cpp
+++ b/myserver/src/base/socket/socket.cpp
@@ -97,14 +97,13 @@ int Socket::operator=(Socket* s)
 }
 /*!
  *Create the socket.
- *\return 0 on error.
  */
 int Socket::socket (int af, int type, int protocol)
 {
 #ifdef WIN32
   socketHandle = ::socket (af, type, protocol);
 #else
-  socketHandle = (FileHandle)::socket (af, type, protocol);
+  socketHandle = ::socket (af, type, protocol);
 #endif
   return (int)socketHandle;
 }
@@ -203,14 +202,11 @@ int Socket::listen (int max)
  */
 Socket* Socket::accept (MYSERVER_SOCKADDR* sa, socklen_t* sockaddrlen)
 {
-  socklen_t connectSize;
-  connectSize = (socklen_t) *sockaddrlen;
-
-  SocketHandle acceptedHandle = ::accept (socketHandle, (struct sockaddr *)sa,
-                                          (socklen_t*)&connectSize);
+  int acceptedHandle = ::accept (socketHandle, (struct sockaddr *)sa,
+                                          sockaddrlen);
 
   if (acceptedHandle >= 0)
-    return new Socket (acceptedHandle);
+    return new Socket ((SocketHandle)acceptedHandle);
   else
     return NULL;
 }
@@ -276,7 +272,7 @@ int  Socket::setsockopt (int level, int optname,
 }
 
 /*!
- *Fill the out string with a list of the local IPs. Returns 0 on success.
+ * Fill the out string with a list of the local IPs. Returns 0 on success.
  */
 int Socket::getLocalIPsList (string &out)
 {
@@ -290,32 +286,32 @@ int Socket::getLocalIPsList (string &out)
   aiHints.ai_socktype = SOCK_STREAM;
   if ( getaddrinfo (serverName, NULL, &aiHints, &pHostInfo) == 0 &&
        pHostInfo != NULL )
-  {
-    sockaddr_storage *pCurrentSockAddr = NULL;
-    char straddr[NI_MAXHOST] = "";
-    memset (straddr, 0, NI_MAXHOST);
-    ostringstream stream;
-    for ( pCrtHostInfo = pHostInfo; pCrtHostInfo != NULL;
-          pCrtHostInfo = pCrtHostInfo->ai_next )
     {
-      pCurrentSockAddr =
-        reinterpret_cast<sockaddr_storage *>(pCrtHostInfo->ai_addr);
-      if ( pCurrentSockAddr == NULL )
-        continue;
-
-            if ( !getnameinfo (reinterpret_cast<sockaddr *>(pCurrentSockAddr),
-                              sizeof (sockaddr_storage), straddr, NI_MAXHOST,
-                              NULL, 0, NI_NUMERICHOST) )
+      sockaddr_storage *pCurrentSockAddr = NULL;
+      char straddr[NI_MAXHOST] = "";
+      memset (straddr, 0, NI_MAXHOST);
+      ostringstream stream;
+      for ( pCrtHostInfo = pHostInfo; pCrtHostInfo != NULL;
+            pCrtHostInfo = pCrtHostInfo->ai_next )
+        {
+          pCurrentSockAddr =
+            reinterpret_cast<sockaddr_storage *>(pCrtHostInfo->ai_addr);
+          if ( pCurrentSockAddr == NULL )
+            continue;
+
+          if ( !getnameinfo (reinterpret_cast<sockaddr *>(pCurrentSockAddr),
+                             sizeof (sockaddr_storage), straddr, NI_MAXHOST,
+                             NULL, 0, NI_NUMERICHOST) )
             {
               stream << ( !stream.str ().empty () ? ", " : "" ) << straddr;
             }
-            else
-        return -1;
+          else
+            return -1;
         }
-        out.assign (stream.str ());
-        freeaddrinfo (pHostInfo);
+      out.assign (stream.str ());
+      freeaddrinfo (pHostInfo);
     }
-    return 0;
+  return 0;
 #else// !HAVE_IPV6
 
   MYSERVER_HOSTENT *localhe;
@@ -323,28 +319,28 @@ int Socket::getLocalIPsList (string &out)
   localhe = Socket::gethostbyname (serverName);
 
   if (localhe)
-  {
-    ostringstream stream;
-    int i;
-    /*! Print all the interfaces IPs. */
-    for (i= 0; (localhe->h_addr_list[i]); i++)
     {
+      ostringstream stream;
+      int i;
+      /*! Print all the interfaces IPs. */
+      for (i = 0; (localhe->h_addr_list[i]); i++)
+        {
 # ifdef WIN32
-      ia.S_un.S_addr = *((u_long FAR*) (localhe->h_addr_list[i]));
+          ia.S_un.S_addr = *((u_long FAR*) (localhe->h_addr_list[i]));
 # else
-      ia.s_addr = *((u_long *) (localhe->h_addr_list[i]));
+          ia.s_addr = *((u_long *) (localhe->h_addr_list[i]));
 # endif
-      stream << ( (i != 0) ? ", " : "") << inet_ntoa (ia);
-    }
+          stream << ( (i != 0) ? ", " : "") << inet_ntoa (ia);
+        }
 
-    out.assign (stream.str ());
-    return 0;
-  }
+      out.assign (stream.str ());
+      return 0;
+    }
   else
-  {
-    out.assign ("127.0.0.1");
-    return 0;
-  }
+    {
+      out.assign ("127.0.0.1");
+      return 0;
+    }
 #endif//HAVE_IPV6
   return -1;
 }
@@ -419,10 +415,7 @@ int Socket::ioctlsocket (long cmd,unsigned long* argp)
 #ifdef WIN32
   return ::ioctlsocket (socketHandle, cmd, argp);
 #else
-  int int_argp = 0;
-  int ret = ::ioctl (socketHandle, cmd, &int_argp);
-  *argp = int_argp;
-  return ret;
+  return ::ioctl (socketHandle, cmd, argp);
 #endif
 }
 
@@ -452,12 +445,11 @@ int Socket::connect (const char* host, u_short port)
    *have this host, than create socket.
    */
 
-  //getsockname (&thisSock, &nLength);
   if ( getsockname (&thisSock, &nLength) == 0 )
-  {
-    aiHints.ai_family = thisSock.ss_family;
-    aiHints.ai_socktype = SOCK_STREAM;
-  }
+    {
+      aiHints.ai_family = thisSock.ss_family;
+      aiHints.ai_socktype = SOCK_STREAM;
+    }
 
   memset (szPort, 0, sizeof (char)*10);
   snprintf (szPort, 10, "%d", port);
@@ -471,68 +463,65 @@ int Socket::connect (const char* host, u_short port)
 
   for ( pCrtHostInfo = pHostInfo; pCrtHostInfo != NULL;
         pCrtHostInfo = pCrtHostInfo->ai_next )
-  {
-    pCurrentSockAddr = reinterpret_cast<sockaddr_storage *>
-      (pCrtHostInfo->ai_addr);
-    if ( pCurrentSockAddr == NULL ||
-        (thisSock.ss_family != 0 &&
-         pCurrentSockAddr->ss_family != thisSock.ss_family) )
-      continue;
-
-    if ( thisSock.ss_family == 0 )// socket not created yet
     {
-      //so try to create one now based on 'pCurrentSockAddr'
-      if ( pCurrentSockAddr->ss_family == AF_INET )
-      {
-        if (Socket::socket (AF_INET, SOCK_STREAM, 0) == -1)
-          continue;
-      }
-      else if ( pCurrentSockAddr->ss_family == AF_INET6 )
-      {
-        if (Socket::socket (AF_INET6, SOCK_STREAM, 0) == -1)
-          continue;
-      }
-      if ( getsockname (&thisSock, &nLength) != 0 )
-        return -1;
-    }
+      pCurrentSockAddr = reinterpret_cast<sockaddr_storage *>
+        (pCrtHostInfo->ai_addr);
+      if ( pCurrentSockAddr == NULL ||
+           (thisSock.ss_family != 0 &&
+            pCurrentSockAddr->ss_family != thisSock.ss_family) )
+        continue;
 
-    memset (&connectionSockAddrIn, 0, sizeof (connectionSockAddrIn));
-    connectionSockAddrIn.ss_family = pCurrentSockAddr->ss_family;
+      if ( thisSock.ss_family == 0 )
+        {
+          if ( pCurrentSockAddr->ss_family == AF_INET )
+            {
+              if (Socket::socket (AF_INET, SOCK_STREAM, 0) == -1)
+                continue;
+            }
+          else if ( pCurrentSockAddr->ss_family == AF_INET6 )
+            {
+              if (Socket::socket (AF_INET6, SOCK_STREAM, 0) == -1)
+                continue;
+            }
+          if ( getsockname (&thisSock, &nLength) != 0 )
+            return -1;
+        }
 
-     if ( connectionSockAddrIn.ss_family != AF_INET &&
-         connectionSockAddrIn.ss_family != AF_INET6 )
-         continue;
+      memset (&connectionSockAddrIn, 0, sizeof (connectionSockAddrIn));
+      connectionSockAddrIn.ss_family = pCurrentSockAddr->ss_family;
 
-    if ( connectionSockAddrIn.ss_family == AF_INET )
-    {
-      nSockLen = sizeof (sockaddr_in);
-      memcpy ((sockaddr_in *)&connectionSockAddrIn,
-             (sockaddr_in *)pCurrentSockAddr, nSockLen);
-      ((sockaddr_in *)(&connectionSockAddrIn))->sin_port = htons (port);
+      if ( connectionSockAddrIn.ss_family != AF_INET &&
+           connectionSockAddrIn.ss_family != AF_INET6 )
+        continue;
 
-    }
-    else// if ( connectionSockAddrIn.ss_family == AF_INET6 )
-    {
-      nSockLen = sizeof (sockaddr_in6);
-      memcpy ((sockaddr_in6 *)&connectionSockAddrIn,
-             (sockaddr_in6 *)pCurrentSockAddr, nSockLen);
-      ((sockaddr_in6 *)&connectionSockAddrIn)->sin6_port = htons (port);
-    }
+      if ( connectionSockAddrIn.ss_family == AF_INET )
+        {
+          nSockLen = sizeof (sockaddr_in);
+          memcpy ((sockaddr_in *)&connectionSockAddrIn,
+                  (sockaddr_in *)pCurrentSockAddr, nSockLen);
+          ((sockaddr_in *)(&connectionSockAddrIn))->sin_port = htons (port);
 
-    if (Socket::connect ((MYSERVER_SOCKADDR*)(&connectionSockAddrIn),
-                       nSockLen) == -1)
-    {
-      Socket::close ();
-    }
-    else
-    {
-       bSocketConnected = true;
-       break;
+        }
+      else// if ( connectionSockAddrIn.ss_family == AF_INET6 )
+        {
+          nSockLen = sizeof (sockaddr_in6);
+          memcpy ((sockaddr_in6 *)&connectionSockAddrIn,
+                  (sockaddr_in6 *)pCurrentSockAddr, nSockLen);
+          ((sockaddr_in6 *)&connectionSockAddrIn)->sin6_port = htons (port);
+        }
+
+      if (Socket::connect ((MYSERVER_SOCKADDR*)(&connectionSockAddrIn),
+                           nSockLen) == -1)
+        Socket::close ();
+      else
+        {
+          bSocketConnected = true;
+          break;
+        }
     }
-  }
   freeaddrinfo (pHostInfo);
   if ( !bSocketConnected )
-     return -1;
+    return -1;
 #else
   MYSERVER_HOSTENT *hp = Socket::gethostbyname (host);
   struct sockaddr_in sockAddr;
@@ -541,23 +530,20 @@ int Socket::connect (const char* host, u_short port)
     return -1;
 
   /*! If the socket is not created, create it before use. */
-  if (socketHandle == 0)
-  {
-    if (Socket::socket (AF_INET, SOCK_STREAM, 0) == -1)
-    {
-      return -1;
-    }
-  }
+  if (socketHandle == -1 &&
+      Socket::socket (AF_INET, SOCK_STREAM, 0) == -1)
+    return -1;
+
   sockLen = sizeof (sockAddr);
   memset (&sockAddr, 0, sizeof (sockAddr));
   sockAddr.sin_family = AF_INET;
   memcpy (&sockAddr.sin_addr, hp->h_addr, hp->h_length);
   sockAddr.sin_port = htons (port);
   if (Socket::connect ((MYSERVER_SOCKADDR*)&sockAddr, sockLen) == -1)
-  {
-    Socket::close ();
-    return -1;
-  }
+    {
+      Socket::close ();
+      return -1;
+    }
 #endif
 
   return 0;
@@ -737,7 +723,7 @@ int Socket::dataOnRead (int sec, int usec)
 #endif
   ret = ::select (socketHandle + 1, &readfds, NULL, NULL, &tv);
 
-  if (ret == -1 || ret == 0)
+  if (ret <= 0)
     return 0;
 
   if (FD_ISSET (socketHandle, &readfds))
@@ -753,7 +739,6 @@ int Socket::dataOnRead (int sec, int usec)
 int Socket::read (char* buffer, u_long len, u_long *nbr)
 {
   *nbr = static_cast<u_long>(recv (buffer, len, 0));
-
   if (*nbr == static_cast<u_long>(-1))
     return -1;
 
@@ -767,7 +752,6 @@ int Socket::read (char* buffer, u_long len, u_long *nbr)
 int Socket::write (const char* buffer, u_long len, u_long *nbw)
 {
   *nbw = static_cast<u_long>(send (buffer, len, 0));
-
   if ( *nbw == static_cast<u_long>(-1) )
     return -1;
 
diff --git a/myserver/src/protocol/http/http.cpp 
b/myserver/src/protocol/http/http.cpp
index 94c3e05..20a4eb2 100644
--- a/myserver/src/protocol/http/http.cpp
+++ b/myserver/src/protocol/http/http.cpp
@@ -797,11 +797,9 @@ int Http::controlConnection (ConnectionPtr a, char* 
/*b1*/, char* /*b2*/,
       td->sentData = 0;
       td->vhostDir.assign ("");
       td->vhostSys.assign ("");
-      {
-        HashMap<string, string*>::Iterator it = td->other.begin ();
-        while (it != td->other.end ())
-          delete (*it);
-      }
+      HashMap<string, string*>::Iterator it = td->other.begin ();
+      while (it != td->other.end ())
+        delete (*it);
       td->other.clear ();
 
       /*
@@ -913,7 +911,6 @@ int Http::controlConnection (ConnectionPtr a, char* /*b1*/, 
char* /*b2*/,
           if (ret == -1)
             {
               logHTTPaccess ();
-
               return ClientsThread::DELETE_CONNECTION;
             }
           else if (ret)



commit 30deb58d51106a59721d31b8e5823c4f8fb7758b
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 7 23:30:55 2009 +0200

    Use a switch instead of several if's in the eventLoopHandler body.

diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index cf638e3..585bdba 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -100,8 +100,9 @@ static void eventLoopHandler (int fd, short event, void 
*arg)
         {
           char cmd;
           da->socketPair.read (&cmd, 1, &nbr);
-          if (cmd == 'c')
+          switch (cmd)
             {
+            case 'c':
               /*
                * Schedule a new connection.
                * The 'c' command is followed by:
@@ -115,22 +116,25 @@ static void eventLoopHandler (int fd, short event, void 
*arg)
               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 (handle, EV_READ | EV_TIMEOUT, newDataHandler, da, 
&tv);
-            }
-          if (cmd == 'l')
-            {
+              break;
+
+            case 'l':
               ConnectionsScheduler::ListenerArg *arg;
               da->socketPair.read ((char*)&arg, sizeof (arg), &nbr);
               event_add (&(arg->ev), &tv);
+              break;
+
+            case 'r':
+              return;
+
+            default:
+              /* Handle other cmd with a nop.  */
+              continue;
             }
-          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)



commit 0706aacbd7c50d14229e3545c2a57a5ed20857a1
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 7 23:28:14 2009 +0200

    Delegate `eventLoopHandler' to register a watch for events on the listener 
socket.

diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index c2889d2..cf638e3 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -92,35 +92,42 @@ static void eventLoopHandler (int fd, short event, void 
*arg)
 {
   ConnectionsScheduler::DispatcherArg *da = 
(ConnectionsScheduler::DispatcherArg*)arg;
   u_long nbr;
+  timeval tv = {10, 0};
+
   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.  */
-       }
+        {
+          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;
+
+              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 (handle, EV_READ | EV_TIMEOUT, newDataHandler, da, 
&tv);
+            }
+          if (cmd == 'l')
+            {
+              ConnectionsScheduler::ListenerArg *arg;
+              da->socketPair.read ((char*)&arg, sizeof (arg), &nbr);
+              event_add (&(arg->ev), &tv);
+            }
+          if (cmd == 'r')
+            return;
+          /* Handle other cmd without do anything else.  */
+        }
 
       event_add (&(da->loopEvent), NULL);
     }
@@ -135,18 +142,21 @@ 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)
-       {
-         if (s->server->addConnection (clientSock, &asockIn))
-           {
-             clientSock->shutdown (2);
-             clientSock->close ();
-             delete clientSock;
-           }
-       }
+      Socket *clientSock;
+      do
+        {
+          clientSock = s->serverSocket->accept (&asockIn, &asockInLen);
+          if (s->server && clientSock
+              && s->server->addConnection (clientSock, &asockIn))
+            {
+              clientSock->shutdown (2);
+              clientSock->close ();
+              delete clientSock;
+            }
+        }
+      while (clientSock);
     }
- 
+
   event_add (&(s->ev), &tv);
 }
 
@@ -159,24 +169,22 @@ static void listenerHandler (int fd, short event, void 
*arg)
 void ConnectionsScheduler::listener (ConnectionsScheduler::ListenerArg *la)
 {
   ConnectionsScheduler::ListenerArg *arg = new 
ConnectionsScheduler::ListenerArg (la);
-  static timeval tv = {3, 0};
 
   event_set (&(arg->ev), (int) la->serverSocket->getHandle (), EV_READ | 
EV_TIMEOUT,
-            listenerHandler, arg);
+             listenerHandler, arg);
 
   arg->terminate = &dispatcherArg.terminate;
   arg->scheduler = this;
   arg->server = server;
   arg->eventsMutex = &eventsMutex;
 
+  la->serverSocket->setNonBlocking (1);
   listeners.push_front (arg);
 
-  event_add (&(arg->ev), &tv);
-
-  u_long nbw;
-
   eventsSocketMutex.lock ();
+  u_long nbw;
   dispatcherArg.socketPairWrite.write ("l", 1, &nbw);
+  dispatcherArg.socketPairWrite.write ((const char*)&arg, sizeof (arg), &nbw);
   eventsSocketMutex.unlock ();
 }
 
@@ -324,7 +332,6 @@ void ConnectionsScheduler::addNewReadyConnection 
(ConnectionPtr c)
   addReadyConnectionImpl (c);
 }
 
-
 /*!
  * Add a connection to ready connections queue.
  */



commit cc6fac6f99825fbdbfc21b459ac8c61ffd5e94b8
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 7 23:25:29 2009 +0200

    The file handle is not set explicitely to 0.  It caused the file descriptor 
0 to be close'd when it should not.

diff --git a/myserver/src/protocol/http/http.cpp 
b/myserver/src/protocol/http/http.cpp
index 78592f1..94c3e05 100644
--- a/myserver/src/protocol/http/http.cpp
+++ b/myserver/src/protocol/http/http.cpp
@@ -199,8 +199,8 @@ bool Http::allowMethod (const char *method)
   char name[64];
   sprintf (name, "http.%s.allow", method);
   const char *allow = td->securityToken.getData (name,
-                                                       MYSERVER_VHOST_CONF |
-                                                       MYSERVER_SERVER_CONF, 
"YES");
+                                                 MYSERVER_VHOST_CONF |
+                                                 MYSERVER_SERVER_CONF, "YES");
 
   if (!strcmpi (allow, "NO"))
     return false;
@@ -790,8 +790,6 @@ int Http::controlConnection (ConnectionPtr a, char* /*b1*/, 
char* /*b2*/,
       td->http = this;
       td->appendOutputs = 0;
       td->onlyHeader = 0;
-      td->inputData.setHandle ((Handle) 0);
-      td->outputData.setHandle ((Handle) 0);
       td->filenamePath.assign ("");
       td->outputDataPath.assign ("");
       td->inputDataPath.assign ("");



commit 3b3fe798b2eb5ee7b466ee924a0f3fdce8f5f4df
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 7 20:11:28 2009 +0200

    Remove the meaning-less `Socket::stopBlockingOperations' operation.

diff --git a/myserver/include/base/socket/socket.h 
b/myserver/include/base/socket/socket.h
index 0675333..70d2af0 100644
--- a/myserver/include/base/socket/socket.h
+++ b/myserver/include/base/socket/socket.h
@@ -77,7 +77,6 @@ public:
   void setServerSocket (Socket*);
   Socket* getServerSocket ();
 
-  static void stopBlockingOperations (bool);
   virtual Handle getHandle ();
   void setHandle (SocketHandle);
   static MYSERVER_HOSTENT *gethostbyaddr (char* addr, int len, int type);
@@ -129,9 +128,6 @@ protected:
   /*! Is the socket non blocking?  */
   bool isNonBlocking;
 
-  /*! Stop the sockets system.  */
-  static bool denyBlockingOperations;
-
   virtual int rawSend (const char* buffer, int len, int flags);
 };
 #endif
diff --git a/myserver/src/base/socket/socket.cpp 
b/myserver/src/base/socket/socket.cpp
index 92d437c..67299b2 100644
--- a/myserver/src/base/socket/socket.cpp
+++ b/myserver/src/base/socket/socket.cpp
@@ -39,8 +39,6 @@ extern "C"
 
 using namespace std;
 
-bool Socket::denyBlockingOperations = false;
-
 /*!
  *Source code to wrap the socket library to MyServer project.
  */
@@ -352,14 +350,6 @@ int Socket::getLocalIPsList (string &out)
 }
 
 /*!
- *Set this to true to stop any operation that can block sockets.
- */
-void Socket::stopBlockingOperations (bool value)
-{
-  denyBlockingOperations = value;
-}
-
-/*!
  *Send data over the socket.
  *Return -1 on error.
  *This routine is accessible only from the Socket class.
@@ -369,18 +359,8 @@ int Socket::rawSend (const char* buffer, int len, int 
flags)
 #ifdef WIN32
   int ret;
   SetLastError (0);
-  while (!denyBlockingOperations)
-  {
-    ret = ::send (socketHandle, buffer, len, flags);
-    if ((ret == SOCKET_ERROR) && (GetLastError () == WSAEWOULDBLOCK))
-    {
-      Thread::wait (10);
-    }
-    else
-      break;
 
-  }
-  return ret;
+  return ::send (socketHandle, buffer, len, flags);
 #else
   return ::send (socketHandle, buffer, len, flags);
 #endif
@@ -404,27 +384,27 @@ int Socket::send (const char* buffer, int len, int flags)
   }
   else
   {
-    while (!denyBlockingOperations)
-    {
-      /*! When we can send data again?  */
-      u_long time = getTicks () + (1000 * 1024 / throttlingRate) ;
-      /*! If a throttling rate is specified, send chunks of 1024 bytes.  */
-      ret = rawSend (buffer + (len - toSend), toSend < 1024 ?
-                    toSend : 1024, flags);
-      /*! On errors returns directly -1.  */
-      if (ret < 0)
-        return -1;
-      toSend -= (u_long)ret;
-      /*!
-       *If there are other bytes to send wait before cycle again.
-       */
-      if (toSend)
+    while (1)
       {
-        Thread::wait (getTicks () - time);
+        /*! When we can send data again?  */
+        u_long time = getTicks () + (1000 * 1024 / throttlingRate) ;
+        /*! If a throttling rate is specified, send chunks of 1024 bytes.  */
+        ret = rawSend (buffer + (len - toSend), toSend < 1024 ?
+                       toSend : 1024, flags);
+        /*! On errors returns directly -1.  */
+        if (ret < 0)
+          return -1;
+        toSend -= (u_long)ret;
+        /*!
+         *If there are other bytes to send wait before cycle again.
+         */
+        if (toSend)
+          {
+            Thread::wait (getTicks () - time);
+          }
+        else
+          break;
       }
-      else
-        break;
-    }
     /*! Return the number of sent bytes. */
     return len - toSend;
   }
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index 7b01035..bd084a4 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -448,8 +448,6 @@ void Server::mainLoop ()
 
                   log (MYSERVER_LOG_MSG_INFO, _("Rebooting..."));
 
-                  Socket::stopBlockingOperations (true);
-
                   connectionsScheduler.release ();
 
                   listenThreads.beginFastReboot ();
@@ -458,8 +456,6 @@ void Server::mainLoop ()
 
                   clearAllConnections ();
 
-                  Socket::stopBlockingOperations (false);
-
                   connectionsScheduler.restart ();
                   listenThreads.initialize ();
 
@@ -669,7 +665,6 @@ int Server::terminate ()
     (*it)->stop ();
 
   threadsMutex->unlock ();
-  Socket::stopBlockingOperations (true);
 
   connectionsScheduler.release ();
 
@@ -691,9 +686,6 @@ int Server::terminate ()
 
   freeHashedData ();
 
-  /* Restore the blocking status in case of a reboot.  */
-  Socket::stopBlockingOperations (false);
-
   ipAddresses = 0;
   vhostList = 0;
 

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

Summary of changes:
 myserver/include/base/socket/socket.h              |    4 -
 .../connections_scheduler/connections_scheduler.h  |   11 +-
 .../include/protocol/http/http_thread_context.h    |    5 +-
 myserver/src/base/file/file.cpp                    |   12 +-
 myserver/src/base/socket/socket.cpp                |  286 +++++++++-----------
 .../connections_scheduler.cpp                      |  103 ++++----
 myserver/src/protocol/http/http.cpp                |   15 +-
 myserver/src/server/server.cpp                     |    8 -
 8 files changed, 202 insertions(+), 242 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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