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. v0.9.2-289


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-289-g61ba823
Date: Sun, 08 Aug 2010 16:54:01 +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  61ba823d81d5b1e050f8065f54680644801f27ec (commit)
       via  ab1c4a2f031eac035ce506b6cc971fd7f4f2977b (commit)
       via  3a5fc2150c67c9e3f5c6a3e96b88888b73ce42ee (commit)
      from  3e96839388a2dffa1a06b6ed64d801361050d2f0 (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 61ba823d81d5b1e050f8065f54680644801f27ec
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Aug 8 18:53:46 2010 +0200

    Proxy: delay the connection cleanup after the scheduler releases it.

diff --git a/myserver/include/http_handler/proxy/proxy.h 
b/myserver/include/http_handler/proxy/proxy.h
index a3a3d54..de7943e 100644
--- a/myserver/include/http_handler/proxy/proxy.h
+++ b/myserver/include/http_handler/proxy/proxy.h
@@ -39,6 +39,7 @@ public:
                     const char* exec = 0, bool execute = false,
                     bool onlyHeader = false);
   virtual int load ();
+  virtual int unLoad ();
 
 protected:
   struct ConnectionRecord
@@ -65,7 +66,8 @@ protected:
   void removeConnection (Connection *c);
 
   ConnectionPtr getConnection (const char *host, u_short port);
-  void addConnection (ConnectionPtr con, const char *host, u_short port);
+  void addConnection (ConnectionPtr con, const char *host, u_short port,
+                      bool keepalive);
   Mutex connectionsLock;
   vector<ConnectionRecord> connections;
   size_t maxKeepAliveConnections;
diff --git a/myserver/src/connection/connection.cpp 
b/myserver/src/connection/connection.cpp
index 1c80b14..17f331f 100644
--- a/myserver/src/connection/connection.cpp
+++ b/myserver/src/connection/connection.cpp
@@ -118,7 +118,7 @@ int Connection::isScheduled ()
 /*!
   Return if the connection may be deleted by the server.
  */
-int Connection::allowDelete (bool bWait/*= false*/)
+int Connection::allowDelete (bool bWait)
 {
   if (isScheduled ())
      return 0;
diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index c471ffc..e8dfbdd 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -349,7 +349,8 @@ void ConnectionsScheduler::initialize ()
   if (err == -1)
     {
       if (server)
-        server->log (MYSERVER_LOG_MSG_ERROR, _("Error initializing socket 
pair"));
+        server->log (MYSERVER_LOG_MSG_ERROR,
+                     _("Error initializing socket pair"));
       return;
     }
 
@@ -369,7 +370,7 @@ void ConnectionsScheduler::initialize ()
     {
       if (server)
         server->log (MYSERVER_LOG_MSG_ERROR,
-                            _("Error while initializing the dispatcher 
thread"));
+                     _("Error while initializing the dispatcher thread"));
 
       dispatchedThreadId = 0;
     }
@@ -692,6 +693,10 @@ void ConnectionsScheduler::terminateConnections ()
       for (; it != connections.end (); it++)
         {
           ConnectionPtr c = *it;
+
+          if (c->notifySchedulerHandler (-1))
+            continue;
+
           if (c->allowDelete (true) && c->socket)
             c->socket->close ();
         }
diff --git a/myserver/src/http_handler/proxy/proxy.cpp 
b/myserver/src/http_handler/proxy/proxy.cpp
index 41fde71..4163a66 100644
--- a/myserver/src/http_handler/proxy/proxy.cpp
+++ b/myserver/src/http_handler/proxy/proxy.cpp
@@ -126,17 +126,16 @@ int Proxy::send (HttpThreadContext *td, const char* 
scriptpath,
 
       chain.clearAllFilters ();
 
-      if (keepalive)
-        addConnection (con, destUrl.getHost ().c_str (), destUrl.getPort ());
-      else
-        delete con;
+      addConnection (con, destUrl.getHost ().c_str (), destUrl.getPort (),
+                     keepalive);
 
       req.free ();
     }
   catch (exception & e)
     {
       if (con)
-        delete con;
+        addConnection (con, destUrl.getHost ().c_str (), destUrl.getPort (),
+                       false);
       chain.clearAllFilters ();
       return td->http->raiseHTTPError (500);
     }
@@ -345,6 +344,8 @@ int Proxy::load ()
     = Server::getInstance ()->getData ("http.proxy.connections.keepalive",
                                        "64");
   maxKeepAliveConnections = atoi (data);
+
+  return 0;
 }
 
 ConnectionPtr Proxy::getConnection (const char *host, u_short port)
@@ -398,6 +399,12 @@ void Proxy::proxySchedulerHandler (void *p, Connection *c, 
int event)
 
 void Proxy::removeConnection (Connection *c)
 {
+  if (c->getToRemove ())
+    {
+      delete c;
+      return;
+    }
+
   connectionsLock.lock ();
   try
     {
@@ -422,17 +429,23 @@ void Proxy::removeConnection (Connection *c)
     }
 }
 
-void Proxy::addConnection (ConnectionPtr con, const char *host, u_short port)
+void Proxy::addConnection (ConnectionPtr con, const char *host, u_short port,
+                           bool keepalive)
 {
-  if (connections.size () >= maxKeepAliveConnections)
+  ConnectionsScheduler *cs  = Server::getInstance ()->getConnectionsScheduler 
();
+
+  if (!keepalive || connections.size () >= maxKeepAliveConnections)
     {
-      delete con;
+      /* Do not destroy the connection immediately, it can be used by the
+         scheduler, so delay its destruction until we are sure it is not used
+         by the scheduler anymore.  */
+      con->setToRemove (1);
+      cs->addNewWaitingConnection (con);
       return;
     }
 
   con->setSchedulerHandler (Proxy::proxySchedulerHandler, this);
 
-  ConnectionsScheduler *cs  = Server::getInstance ()->getConnectionsScheduler 
();
   cs->addNewWaitingConnection (con);
 
   ConnectionRecord cr;
@@ -442,3 +455,29 @@ void Proxy::addConnection (ConnectionPtr con, const char 
*host, u_short port)
 
   connections.push_back (cr);
 }
+
+int Proxy::unLoad ()
+{
+  ConnectionsScheduler *cs  = Server::getInstance ()->getConnectionsScheduler 
();
+
+  connectionsLock.lock ();
+  try
+    {
+      vector<ConnectionRecord>::iterator it = connections.begin ();
+      for (; it != connections.end (); it++)
+        {
+          (*it).connection->setToRemove (1);
+          cs->addNewWaitingConnection ((*it).connection);
+        }
+
+      connections.clear ();
+      connectionsLock.unlock ();
+    }
+  catch (...)
+    {
+      connectionsLock.unlock ();
+      throw;
+    }
+
+  return 0;
+}



commit ab1c4a2f031eac035ce506b6cc971fd7f4f2977b
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Aug 8 16:16:23 2010 +0200

    Proxy: ensure the connection is still open, otherwise raise an error.

diff --git a/myserver/src/http_handler/proxy/proxy.cpp 
b/myserver/src/http_handler/proxy/proxy.cpp
index c45517a..41fde71 100644
--- a/myserver/src/http_handler/proxy/proxy.cpp
+++ b/myserver/src/http_handler/proxy/proxy.cpp
@@ -172,6 +172,9 @@ int Proxy::flushToClient (HttpThreadContext* td, Socket& 
client,
     }
   while (ret);
 
+  if (read == 0)
+    return td->http->raiseHTTPError (500);
+
   checkDataChunks (td, &keepalive, &useChunks);
 
   string *tmp = td->request.getValue ("Host", NULL);



commit 3a5fc2150c67c9e3f5c6a3e96b88888b73ce42ee
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Aug 8 15:49:39 2010 +0200

    Proxy: do not keep dead connections for reuse.

diff --git a/myserver/include/http_handler/proxy/proxy.h 
b/myserver/include/http_handler/proxy/proxy.h
index c28687a..a3a3d54 100644
--- a/myserver/include/http_handler/proxy/proxy.h
+++ b/myserver/include/http_handler/proxy/proxy.h
@@ -49,7 +49,7 @@ protected:
   };
 
   int flushToClient (HttpThreadContext* td, Socket& client,
-                     FiltersChain &out, bool onlyHeader);
+                     FiltersChain &out, bool onlyHeader, bool *kaClient);
   int readPayLoad (HttpThreadContext* td,
                    HttpResponseHeader* res,
                    FiltersChain *out,
diff --git a/myserver/src/http_handler/proxy/proxy.cpp 
b/myserver/src/http_handler/proxy/proxy.cpp
index 21deeed..c45517a 100644
--- a/myserver/src/http_handler/proxy/proxy.cpp
+++ b/myserver/src/http_handler/proxy/proxy.cpp
@@ -49,6 +49,7 @@ int Proxy::send (HttpThreadContext *td, const char* 
scriptpath,
   FiltersChain chain;
   HttpRequestHeader req;
   u_long nbw;
+  bool keepalive = false;
 
   for (HashMap<string, HttpRequestHeader::Entry*>::Iterator it =
          td->request.begin (); it != td->request.end (); it++)
@@ -121,10 +122,15 @@ int Proxy::send (HttpThreadContext *td, const char* 
scriptpath,
                                                              1);
 
 
-      flushToClient (td, *sock, chain, onlyHeader);
+      flushToClient (td, *sock, chain, onlyHeader, &keepalive);
 
       chain.clearAllFilters ();
-      addConnection (con, destUrl.getHost ().c_str (), destUrl.getPort ());
+
+      if (keepalive)
+        addConnection (con, destUrl.getHost ().c_str (), destUrl.getPort ());
+      else
+        delete con;
+
       req.free ();
     }
   catch (exception & e)
@@ -142,7 +148,7 @@ int Proxy::send (HttpThreadContext *td, const char* 
scriptpath,
   Flush the server reply to the client.
  */
 int Proxy::flushToClient (HttpThreadContext* td, Socket& client,
-                          FiltersChain &out, bool onlyHeader)
+                          FiltersChain &out, bool onlyHeader, bool *kaClient)
 {
   u_long read = 0;
   u_long headerLength;
@@ -181,6 +187,9 @@ int Proxy::flushToClient (HttpThreadContext* td, Socket& 
client,
   else
     td->response.setValue ("Via", via);
 
+  tmp = td->response.getValue ("Connection", NULL);
+  *kaClient = tmp && !strcasecmp (tmp->c_str (), "keep-alive");
+
   string transferEncoding;
   bool hasTransferEncoding = false;
   tmp = td->response.getValue ("Transfer-encoding", NULL);

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

Summary of changes:
 myserver/include/http_handler/proxy/proxy.h        |    6 +-
 myserver/src/connection/connection.cpp             |    2 +-
 .../connections_scheduler.cpp                      |    9 ++-
 myserver/src/http_handler/proxy/proxy.cpp          |   67 +++++++++++++++++---
 4 files changed, 71 insertions(+), 13 deletions(-)


hooks/post-receive
-- 
GNU MyServer



reply via email to

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