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


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. ef155de41266092eff980e8ce0593f996a0fc099
Date: Thu, 06 Aug 2009 17:49:17 +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  ef155de41266092eff980e8ce0593f996a0fc099 (commit)
       via  4ab5842ae944798446e4e8d53e9591b28735ff71 (commit)
      from  0ab6af04e95a4f4db41f9bfb5385ccab319307fd (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 ef155de41266092eff980e8ce0593f996a0fc099
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Aug 6 19:49:50 2009 +0200

    Use bool instead of int as type for booleans members.

diff --git a/myserver/include/server/clients_thread.h 
b/myserver/include/server/clients_thread.h
index 0488c2c..39fba2d 100644
--- a/myserver/include/server/clients_thread.h
+++ b/myserver/include/server/clients_thread.h
@@ -59,38 +59,38 @@ public:
     */
     INCOMPLETE_REQUEST_NO_WAIT = 3
   };
-  MemBuf *getBuffer();
-  MemBuf *getSecondaryBuffer();
-  ClientsThread(Server* server);
-  ~ClientsThread();
-  void stop();
-  int getTimeout();
-  void setTimeout(int);
-  int isToDestroy();
-  void setToDestroy(int);
-  int isStatic();
-  int isBusy();
-  void setStatic(int);
-  int run();
-  ThreadID getThreadId(){return tid;}
-  int join();
+  MemBuf *getBuffer ();
+  MemBuf *getSecondaryBuffer ();
+  ClientsThread (Server* server);
+  ~ClientsThread ();
+  void stop ();
+  int getTimeout ();
+  void setTimeout (int);
+  bool isToDestroy ();
+  void setToDestroy (bool);
+  bool isStatic();
+  bool isBusy();
+  void setStatic (bool);
+  int run ();
+  ThreadID getThreadId (){return tid;}
+  int join ();
 
 
 private:
   Server* server;
   ThreadID tid;
-  int toDestroy;
+  bool toDestroy;
   int timeout;
-  int initialized;
+  bool initialized;
   int staticThread;
   u_long id;
-  int busy;
-  int threadIsStopped;
-  int threadIsRunning;
+  bool busy;
+  bool threadIsStopped;
+  bool threadIsRunning;
   u_long buffersize;
   u_long secondaryBufferSize;
-  int isRunning();
-  int isStopped();
+  bool isRunning();
+  bool isStopped();
   FtpProtocol *ftpParser;
   HttpProtocol* httpParser;
   HttpsProtocol* httpsParser;
diff --git a/myserver/src/server/clients_thread.cpp 
b/myserver/src/server/clients_thread.cpp
index ce6c941..e32fb3b 100644
--- a/myserver/src/server/clients_thread.cpp
+++ b/myserver/src/server/clients_thread.cpp
@@ -32,38 +32,37 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef WIN32
 extern "C" 
 {
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <time.h>
-#ifdef HAVE_PTHREAD
-#include <pthread.h>
-#endif
-#include <sys/types.h>
-#include <sys/wait.h>
-
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+# include <string.h>
+# include <signal.h>
+# include <unistd.h>
+# include <time.h>
+# ifdef HAVE_PTHREAD
+#  include <pthread.h>
+# endif
+# include <sys/types.h>
+# include <sys/wait.h>
 }
 #endif
 
 /*!
  *Construct the object.
  */
-ClientsThread::ClientsThread(Server* server)
+ClientsThread::ClientsThread (Server* server)
 {
   this->server = server;
-  busy = 0;
-  initialized = 0;
-  toDestroy = 0;
+  busy = false;
+  initialized = false;
+  toDestroy = false;
   staticThread = 0;
   nBytesToRead = 0;
 
-  httpParser = 0;
-  httpsParser = 0;
-  controlProtocolParser = 0;
-  ftpParser = 0;
+  httpParser = NULL;
+  httpsParser = NULL;
+  controlProtocolParser = NULL;
+  ftpParser = NULL;
 }
 
 /*!
@@ -71,35 +70,31 @@ ClientsThread::ClientsThread(Server* server)
  */
 ClientsThread::~ClientsThread()
 {
-  if(initialized == 0)
+  if (!initialized)
     return;
 
-  threadIsRunning = 0;
+  threadIsRunning = false;
 
-  if(httpParser)
+  if (httpParser)
     delete httpParser;
 
-  if(httpsParser)
+  if (httpsParser)
     delete httpsParser;
 
-  if(controlProtocolParser)
+  if (controlProtocolParser)
     delete controlProtocolParser;
 
-  if ( ftpParser != NULL )
+  if (ftpParser)
     delete ftpParser;
 
-  httpParser = 0;
-  httpsParser = 0;
-  controlProtocolParser = 0;
-
-  buffer.free();
-  secondaryBuffer.free();
+  buffer.free ();
+  secondaryBuffer.free ();
 }
 
 /*!
  *Get the timeout value.
  */
-int ClientsThread::getTimeout()
+int ClientsThread::getTimeout ()
 {
   return timeout;
 }
@@ -108,7 +103,7 @@ int ClientsThread::getTimeout()
  *Set the timeout value for the thread.
  *\param newTimeout The new timeout value.
  */
-void ClientsThread::setTimeout(int newTimeout)
+void ClientsThread::setTimeout (int newTimeout)
 {
   timeout = newTimeout;
 }
@@ -123,16 +118,16 @@ DEFINE_THREAD(clients_thread, pParam)
 #ifndef WIN32
   /* Block SigTerm, SigInt, and SigPipe in threads.  */
   sigset_t sigmask;
-  sigemptyset(&sigmask);
-  sigaddset(&sigmask, SIGPIPE);
-  sigaddset(&sigmask, SIGINT);
-  sigaddset(&sigmask, SIGTERM);
-  sigprocmask(SIG_SETMASK, &sigmask, NULL);
+  sigemptyset (&sigmask);
+  sigaddset (&sigmask, SIGPIPE);
+  sigaddset (&sigmask, SIGINT);
+  sigaddset (&sigmask, SIGTERM);
+  sigprocmask (SIG_SETMASK, &sigmask, NULL);
 #endif
   ClientsThread *ct = (ClientsThread*)pParam;
 
   /* Return an error if the thread is initialized.  */
-  if(ct->initialized)
+  if (ct->initialized)
 #ifdef WIN32
     return 1;
 #endif
@@ -140,34 +135,28 @@ DEFINE_THREAD(clients_thread, pParam)
   return (void*)1;
 #endif
 
-  ct->threadIsRunning = 1;
-  ct->threadIsStopped = 0;
-  ct->buffersize = ct->server->getBuffersize();
-  ct->secondaryBufferSize = ct->server->getBuffersize2();
+  ct->threadIsRunning = true;
+  ct->threadIsStopped = false;
+  ct->buffersize = ct->server->getBuffersize ();
+  ct->secondaryBufferSize = ct->server->getBuffersize2 ();
   
-  ct->buffer.setLength(ct->buffersize);
+  ct->buffer.setLength (ct->buffersize);
   ct->buffer.m_nSizeLimit = ct->buffersize;
-  ct->secondaryBuffer.setLength(ct->secondaryBufferSize);
+  ct->secondaryBuffer.setLength (ct->secondaryBufferSize);
   ct->secondaryBuffer.m_nSizeLimit = ct->secondaryBufferSize;
 
   /* Built-in protocols will be initialized at the first use.  */
-  ct->httpParser = 0;
-  ct->httpsParser = 0;
-  ct->controlProtocolParser = 0;
+  ct->initialized = true;
 
-  ct->initialized = 1;
-
-  ct->server->increaseFreeThread();
+  ct->server->increaseFreeThread ();
 
   /* Wait that the server is ready before go in the running loop.  */
-  while(!ct->server->isServerReady() && ct->threadIsRunning)
-  {
+  while (!ct->server->isServerReady() && ct->threadIsRunning)
     Thread::wait(500);
-  }
 
   /*
-   *This function when is alive only call the controlConnections(...) function
-   *of the ClientsThread class instance used for control the thread.
+   * This function when is alive only call the controlConnections(...) function
+   * of the ClientsThread class instance used for control the thread.
    */
   while (ct->threadIsRunning)
     {
@@ -198,7 +187,7 @@ DEFINE_THREAD(clients_thread, pParam)
           ostringstream s;
           s << "Bad alloc: " << ba.what();
 
-          ct->server->logWriteln (s.str ().c_str (), MYSERVER_LOG_MSG_ERROR);
+          ct->server->logWriteln  (s.str ().c_str (), MYSERVER_LOG_MSG_ERROR);
         }
       catch (exception &e)
         {
@@ -209,9 +198,9 @@ DEFINE_THREAD(clients_thread, pParam)
   }
 
   ct->server->decreaseFreeThread ();
-  ct->threadIsStopped = 1;
+  ct->threadIsStopped = true;
 
-  Thread::terminate();
+  Thread::terminate ();
   return 0;
 }
 
@@ -219,26 +208,26 @@ DEFINE_THREAD(clients_thread, pParam)
  *Join the thread.
  *
  */
-int ClientsThread::join()
+int ClientsThread::join ()
 {
-  return Thread::join(tid);
+  return Thread::join (tid);
 }
 
 
 /*!
  *Create the new thread.
  */
-int ClientsThread::run()
+int ClientsThread::run ()
 {
   tid = 0;
-  return Thread::create(&tid, &::clients_thread,
-                        (void *)this);
+  return Thread::create (&tid, &::clients_thread,
+                         (void *)this);
 }
 
 /*!
  *Returns if the thread can be destroyed.
  */
-int ClientsThread::isToDestroy()
+bool ClientsThread::isToDestroy()
 {
   return toDestroy;
 }
@@ -246,7 +235,7 @@ int ClientsThread::isToDestroy()
 /*!
  *Check if the thread is a static one.
  */
-int ClientsThread::isStatic()
+bool ClientsThread::isStatic()
 {
   return staticThread;
 }
@@ -255,7 +244,7 @@ int ClientsThread::isStatic()
  *Set the thread to be static.
  *\param value The new static value.
  */
-void ClientsThread::setStatic(int value)
+void ClientsThread::setStatic (bool value)
 {
   staticThread = value;
 }
@@ -264,7 +253,7 @@ void ClientsThread::setStatic(int value)
  *Set if the thread can be destroyed.
  *\param value The new destroy value.
  */
-void ClientsThread::setToDestroy(int value)
+void ClientsThread::setToDestroy(bool value)
 {
   toDestroy = value;
 }
@@ -277,7 +266,7 @@ void ClientsThread::setToDestroy(int value)
  *Return 1 if no connections to serve are available.
  *Return 0 in all other cases.
  */
-int ClientsThread::controlConnections()
+int ClientsThread::controlConnections ()
 {
   /*
    *Control the protocol used by the connection.
@@ -288,15 +277,14 @@ int ClientsThread::controlConnections()
   Protocol* protocol = 0;
   u_long dataRead = 0;
 
-  c = server->getConnection(this->id);
-
-  server->decreaseFreeThread();
+  c = server->getConnection (this->id);
 
+  server->decreaseFreeThread ();
 
   /*
    *Check if c is a valid connection structure.
    */
-  if(!c)
+  if (!c)
     return 1;
 
   busy = 1;
@@ -308,34 +296,28 @@ int ClientsThread::controlConnections()
   if(err == -1 && !server->deleteConnection(c))
     return 0;
 
-  buffer.setLength(dataRead + err);    
-
-  c->setForceControl(0);
-
+  buffer.setLength (dataRead + err);
+  c->setForceControl (0);
 
   /* Refresh with the right value.  */
   nBytesToRead = dataRead + err;
 
-  if((dataRead + err) < MYSERVER_KB(8))
-  {
+  if ((dataRead + err) < MYSERVER_KB (8))
     ((char*)buffer.getBuffer())[dataRead + err] = '\0';
-  }
   else
-  {
-    server->deleteConnection(c);
-    return 0;
-  }
-
+    {
+      server->deleteConnection (c);
+      return 0;
+    }
 
-  if(getTicks() - c->getTimeout() > 5000)
-    c->setnTries(0);
+  if (getTicks() - c->getTimeout () > 5000)
+    c->setnTries (0);
 
-  if(dataRead)
-  {
-    memcpy((char*)buffer.getBuffer(), c->getConnectionBuffer ()->getBuffer (), 
dataRead);
-  }
+  if (dataRead)
+    memcpy ((char*)buffer.getBuffer(), c->getConnectionBuffer ()->getBuffer (),
+            dataRead);
 
-  c->setActiveThread(this);
+  c->setActiveThread (this);
   try
   {
     if (c->hasContinuation ())
@@ -352,7 +334,7 @@ int ClientsThread::controlConnections()
         protocol = server->getProtocol (c->host->getProtocolName ());
         if (protocol)
           {
-            retcode = protocol->controlConnection(c, (char*)buffer.getBuffer(),
+            retcode = protocol->controlConnection (c, 
(char*)buffer.getBuffer(),
                                              
(char*)secondaryBuffer.getBuffer(), 
                                               buffer.getRealLength(), 
                                              secondaryBuffer.getRealLength(), 
@@ -371,86 +353,86 @@ int ClientsThread::controlConnections()
 
   /* Delete the connection.  */
   if (retcode == DELETE_CONNECTION)
-  {
-    server->deleteConnection (c);
-    return 0;
-  }
+    {
+      server->deleteConnection (c);
+      return 0;
+    }
   /* Keep the connection.  */
   else if (retcode == KEEP_CONNECTION)
-  {
-    c->getConnectionBuffer ()->setLength (0);
-    server->getConnectionsScheduler ()->addWaitingConnection (c);
-  }
+    {
+      c->getConnectionBuffer ()->setLength (0);
+      server->getConnectionsScheduler ()->addWaitingConnection (c);
+    }
   /* Incomplete request to buffer.  */
   else if (retcode == INCOMPLETE_REQUEST)
-  {
-    /*
-     *If the header is incomplete save the current received
-     *data in the connection buffer.
-     *Save the header in the connection buffer.
-     */
-    c->getConnectionBuffer ()->setBuffer (buffer.getBuffer (), nBytesToRead);
-    server->getConnectionsScheduler ()->addWaitingConnection (c);
-  }
+    {
+      /*
+       *If the header is incomplete save the current received
+       *data in the connection buffer.
+       *Save the header in the connection buffer.
+       */
+      c->getConnectionBuffer ()->setBuffer (buffer.getBuffer (), nBytesToRead);
+      server->getConnectionsScheduler ()->addWaitingConnection (c);
+    }
   /* Incomplete request to check before new data is available.  */
-  else if(retcode == INCOMPLETE_REQUEST_NO_WAIT)
-  {
-    c->setForceControl(1);
-    server->getConnectionsScheduler()->addReadyConnection(c);
-  }    
+  else if (retcode == INCOMPLETE_REQUEST_NO_WAIT)
+    {
+      c->setForceControl (1);
+      server->getConnectionsScheduler ()->addReadyConnection (c);
+    }
 
   return 0;
 }
 
 /*!
- *Stop the thread.
+ * Stop the thread.
  */
 void ClientsThread::stop()
 {
   /*
-   *Set the run flag to False.
-   *When the current thread find the threadIsRunning
-   *flag setted to 0 automatically destroy the
-   *thread.
+   * Set the run flag to False.
+   * When the current thread find the threadIsRunning
+   * flag setted to 0 automatically destroy the
+   * thread.
    */
-  threadIsRunning = 0;
+  threadIsRunning = false;
 }
 
 /*!
- *Returns a non-null value if the thread is active.
+ * Returns a non-null value if the thread is active.
  */
-int ClientsThread::isRunning()
+bool ClientsThread::isRunning ()
 {
   return threadIsRunning;
 }
 
 /*!
- *Returns 1 if the thread is stopped.
+ * Returns if the thread is stopped.
  */
-int ClientsThread::isStopped()
+bool ClientsThread::isStopped ()
 {
   return threadIsStopped;
 }
 
 /*!
- *Get a pointer to the buffer.
+ * Get a pointer to the buffer.
  */
-MemBuf* ClientsThread::getBuffer()
+MemBuf* ClientsThread::getBuffer ()
 {
   return &buffer;
 }
 /*!
- *Get a pointer to the secondaryBuffer.
+ * Get a pointer to the secondary buffer.
  */
-MemBuf *ClientsThread::getSecondaryBuffer()
+MemBuf *ClientsThread::getSecondaryBuffer ()
 {
   return &secondaryBuffer;
 }
 
 /*!
- *Check if the thread is working.
+ * Check if the thread is working.
  */
-int ClientsThread::isBusy()
+bool ClientsThread::isBusy ()
 {
   return busy;
 }



commit 4ab5842ae944798446e4e8d53e9591b28735ff71
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Aug 6 19:39:11 2009 +0200

    Do not access just freed memory.

diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index 74d3435..5922a41 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -747,14 +747,16 @@ void Server::displayBoot()
  *Removed threads that can be destroyed.
  *The function returns the number of threads that were destroyed.
  */
-int Server::purgeThreads()
+int Server::purgeThreads ()
 {
-  u_long ticks = getTicks();
+  u_long ticks = getTicks ();
   u_long destroyed = 0;
 
-  purgeThreadsThreshold = std::min(purgeThreadsThreshold << 1, nMaxThreads);
-  threadsMutex->lock();
-  for(list<ClientsThread*>::iterator it = threads.begin(); it != 
threads.end();)
+  purgeThreadsThreshold = std::min (purgeThreadsThreshold << 1,
+                                    nMaxThreads);
+  threadsMutex->lock ();
+  for (list<ClientsThread*>::iterator it = threads.begin ();
+       it != threads.end ();)
   {
     ClientsThread* thread = *it;
 
@@ -775,7 +777,7 @@ int Server::purgeThreads()
         destroyed++;
         it = next;
       }
-    if (thread->isToDestroy ())
+    else if (thread->isToDestroy ())
       {
         if (destroyed < purgeThreadsThreshold)
           thread->stop ();
@@ -791,9 +793,9 @@ int Server::purgeThreads()
         it++;
       }
   }
-  threadsMutex->unlock();
+  threadsMutex->unlock ();
 
-  return threads.size();
+  return threads.size ();
 }
 
 /*!

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

Summary of changes:
 myserver/include/server/clients_thread.h |   44 +++---
 myserver/src/server/clients_thread.cpp   |  248 ++++++++++++++----------------
 myserver/src/server/server.cpp           |   18 ++-
 3 files changed, 147 insertions(+), 163 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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