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-286


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-286-g3e96839
Date: Sun, 08 Aug 2010 01:09:03 +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  3e96839388a2dffa1a06b6ed64d801361050d2f0 (commit)
       via  5d1529b1e9e3ce359dc72ad0a61afdb97f91f215 (commit)
       via  998e03b7fcc6e38247247034477bd0082ce312c2 (commit)
      from  c5e025441689007017bb5f6e0f330d4873c76284 (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 3e96839388a2dffa1a06b6ed64d801361050d2f0
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Aug 8 03:08:48 2010 +0200

    The PROXY handler now maintains a pool of keep-alive connections to reuse.

diff --git a/myserver/NEWS b/myserver/NEWS
index eed9f5b..b899b1e 100644
--- a/myserver/NEWS
+++ b/myserver/NEWS
@@ -18,6 +18,9 @@ GNU myserver NEWS                                    -*- 
outline -*-
 
   The build doesn't fail if zlib is not found.
 
+** New features
+
+   The PROXY handler now maintains a pool of keep-alive connections to reuse.
 
 * Noteworthy changes in release 0.9.2
 
diff --git a/myserver/include/http_handler/proxy/proxy.h 
b/myserver/include/http_handler/proxy/proxy.h
index 0c5e4c2..c28687a 100644
--- a/myserver/include/http_handler/proxy/proxy.h
+++ b/myserver/include/http_handler/proxy/proxy.h
@@ -38,7 +38,16 @@ public:
   virtual int send (HttpThreadContext*, const char* scriptpath,
                     const char* exec = 0, bool execute = false,
                     bool onlyHeader = false);
+  virtual int load ();
+
 protected:
+  struct ConnectionRecord
+  {
+    string host;
+    u_short port;
+    ConnectionPtr connection;
+  };
+
   int flushToClient (HttpThreadContext* td, Socket& client,
                      FiltersChain &out, bool onlyHeader);
   int readPayLoad (HttpThreadContext* td,
@@ -52,6 +61,14 @@ protected:
                    bool keepalive = false,
                    string *serverTransferEncoding = NULL);
 
+  static void proxySchedulerHandler (void *p, Connection *c, int event);
+  void removeConnection (Connection *c);
+
+  ConnectionPtr getConnection (const char *host, u_short port);
+  void addConnection (ConnectionPtr con, const char *host, u_short port);
+  Mutex connectionsLock;
+  vector<ConnectionRecord> connections;
+  size_t maxKeepAliveConnections;
   static int timeout;
 };
 #endif
diff --git a/myserver/src/conf/mime/xml_mime_handler.cpp 
b/myserver/src/conf/mime/xml_mime_handler.cpp
index eb686e3..0921067 100644
--- a/myserver/src/conf/mime/xml_mime_handler.cpp
+++ b/myserver/src/conf/mime/xml_mime_handler.cpp
@@ -320,7 +320,6 @@ void XmlMimeHandler::clearRecords ()
 /*!
   Get the MIME type to use on the specified file.
   \param filename Find the MIME type for this file.
-  \param handler If specified, indicate an external handler to use
   if the mime cannot be found locally.
 */
 MimeRecord *XmlMimeHandler::getMIME (const char *filename)
diff --git a/myserver/src/http_handler/proxy/proxy.cpp 
b/myserver/src/http_handler/proxy/proxy.cpp
index 1dbe690..21deeed 100644
--- a/myserver/src/http_handler/proxy/proxy.cpp
+++ b/myserver/src/http_handler/proxy/proxy.cpp
@@ -44,7 +44,8 @@ int Proxy::send (HttpThreadContext *td, const char* 
scriptpath,
                  const char* exec, bool execute, bool onlyHeader)
 {
   Url destUrl (exec, 80);
-  Socket sock;
+  ConnectionPtr con = NULL;
+  Socket *sock;
   FiltersChain chain;
   HttpRequestHeader req;
   u_long nbw;
@@ -72,7 +73,14 @@ int Proxy::send (HttpThreadContext *td, const char* 
scriptpath,
       req.uri.assign ("/");
       req.uri.append (destUrl.getResource ());
       req.uri.append (td->pathInfo);
-      req.setValue ("Connection", "Close");
+      req.setValue ("Connection", "keep-alive");
+      if (td->request.uriOptsPtr)
+        {
+          char buffer[32];
+          u_long size = td->inputData.getFileSize ();
+          sprintf (buffer, "%u", size);
+          req.setValue ("Content-Length", buffer);
+        }
 
       ostringstream host;
       host << destUrl.getHost ();
@@ -88,17 +96,21 @@ int Proxy::send (HttpThreadContext *td, const char* 
scriptpath,
       xForwardedFor.append (td->connection->getIpAddr ());
       req.setValue ("X-Forwarded-For", xForwardedFor.c_str ());
 
-      sock.connect (destUrl.getHost ().c_str (), destUrl.getPort ());
+      con = getConnection (destUrl.getHost ().c_str (), destUrl.getPort ());
+      if (! con)
+        return td->http->raiseHTTPError (500);
+
+      sock = con->socket;
 
       u_long hdrLen =
         HttpHeaders::buildHTTPRequestHeader (td->auxiliaryBuffer->getBuffer (),
                                              &req);
 
 
-      sock.write (td->auxiliaryBuffer->getBuffer (), hdrLen, &nbw);
+      sock->write (td->auxiliaryBuffer->getBuffer (), hdrLen, &nbw);
 
       if (td->request.uriOptsPtr)
-        td->inputData.fastCopyToSocket (&sock, 0, td->auxiliaryBuffer, &nbw);
+        td->inputData.fastCopyToSocket (sock, 0, td->auxiliaryBuffer, &nbw);
 
       chain.setStream (td->connection->socket);
       if (td->mime)
@@ -109,14 +121,16 @@ int Proxy::send (HttpThreadContext *td, const char* 
scriptpath,
                                                              1);
 
 
-      flushToClient (td, sock, chain, onlyHeader);
+      flushToClient (td, *sock, chain, onlyHeader);
 
       chain.clearAllFilters ();
-      sock.close ();
+      addConnection (con, destUrl.getHost ().c_str (), destUrl.getPort ());
       req.free ();
     }
   catch (exception & e)
     {
+      if (con)
+        delete con;
       chain.clearAllFilters ();
       return td->http->raiseHTTPError (500);
     }
@@ -312,3 +326,107 @@ int Proxy::readPayLoad (HttpThreadContext* td,
 
   return HttpDataHandler::RET_OK;
 }
+
+int Proxy::load ()
+{
+  const char *data
+    = Server::getInstance ()->getData ("http.proxy.connections.keepalive",
+                                       "64");
+  maxKeepAliveConnections = atoi (data);
+}
+
+ConnectionPtr Proxy::getConnection (const char *host, u_short port)
+{
+  ConnectionPtr ret = NULL;
+
+  connectionsLock.lock ();
+  try
+    {
+      vector<ConnectionRecord>::iterator it = connections.begin ();
+      for (; it != connections.end (); it++)
+        {
+          if ((*it).port == port && (*it).host.compare (host) == 0)
+            {
+              ret = (*it).connection;
+              connections.erase (it);
+              break;
+            }
+        }
+      connectionsLock.unlock ();
+      if (ret)
+        return ret;
+    }
+  catch (...)
+    {
+      connectionsLock.unlock ();
+      throw;
+    }
+
+  ret = new Connection ();
+  ret->socket = new Socket ();
+  try
+    {
+      ret->socket->socket (AF_INET, SOCK_STREAM, 0);
+      ret->socket->connect (host, port);
+    }
+  catch (...)
+    {
+      delete ret;
+      throw;
+    }
+
+  return ret;
+}
+
+void Proxy::proxySchedulerHandler (void *p, Connection *c, int event)
+{
+  Proxy *proxy = (Proxy *) p;
+  proxy->removeConnection (c);
+}
+
+void Proxy::removeConnection (Connection *c)
+{
+  connectionsLock.lock ();
+  try
+    {
+      vector<ConnectionRecord>::iterator it = connections.begin ();
+      for (; it != connections.end (); it++)
+        {
+          /* Remove only if it is found in the buffer.  Otherwise it is
+             used at this time and we can't remove it.  */
+          if ((*it).connection == c)
+            {
+              connections.erase (it);
+              delete c;
+              break;
+            }
+        }
+
+      connectionsLock.unlock ();
+    }
+  catch (...)
+    {
+      connectionsLock.unlock ();
+    }
+}
+
+void Proxy::addConnection (ConnectionPtr con, const char *host, u_short port)
+{
+  if (connections.size () >= maxKeepAliveConnections)
+    {
+      delete con;
+      return;
+    }
+
+  con->setSchedulerHandler (Proxy::proxySchedulerHandler, this);
+
+  ConnectionsScheduler *cs  = Server::getInstance ()->getConnectionsScheduler 
();
+  cs->addNewWaitingConnection (con);
+
+  ConnectionRecord cr;
+  cr.host = host;
+  cr.port = port;
+  cr.connection = con;
+
+  connections.push_back (cr);
+}



commit 5d1529b1e9e3ce359dc72ad0a61afdb97f91f215
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Aug 8 02:43:52 2010 +0200

    Allow to define a different event handler for connection.

diff --git a/myserver/include/connection/connection.h 
b/myserver/include/connection/connection.h
index eb7360e..1a15bb1 100644
--- a/myserver/include/connection/connection.h
+++ b/myserver/include/connection/connection.h
@@ -132,8 +132,16 @@ public:
   bool hasContinuation (){return continuation ? true : false;}
 
   MemBuf *getConnectionBuffer (){return &connectionBuffer;}
+  void setSchedulerHandler (void (*schedulerHandler) (void *, Connection *,
+                                                      int),
+                            void *schedulerHandlerArgument);
+
+  int notifySchedulerHandler (int event);
 protected:
 
+  void (*schedulerHandler) (void *, Connection *, int event);
+  void *schedulerHandlerArgument;
+
   /*! This buffer must be used only by the ClientsTHREAD class.  */
   MemBuf connectionBuffer;
 
diff --git a/myserver/src/connection/connection.cpp 
b/myserver/src/connection/connection.cpp
index 859778e..1c80b14 100644
--- a/myserver/src/connection/connection.cpp
+++ b/myserver/src/connection/connection.cpp
@@ -39,6 +39,7 @@ void Connection::init ()
   socket = NULL;
   priority = -1;
   continuation = NULL;
+  setSchedulerHandler (NULL, NULL);
 }
 
 /*!
@@ -320,3 +321,31 @@ void Connection::setPriority (int p)
 {
   priority = p;
 }
+
+/*!
+  Set the handler that the scheduler will call on new data.
+  \param schedulerHandler Handler to call.
+  \param schedulerHandlerArgument Argument for the handler.
+ */
+void
+Connection::setSchedulerHandler (void (*schedulerHandler) (void *,
+                                                           Connection *, int),
+                                 void *schedulerHandlerArgument)
+{
+  this->schedulerHandler = schedulerHandler;
+  this->schedulerHandlerArgument = schedulerHandlerArgument;
+}
+
+/*!
+  If a scheduler handler is configured.  Notify it.
+
+  \return 0 if there is not handler.
+*/
+int Connection::notifySchedulerHandler (int event)
+{
+  if (! schedulerHandler)
+    return 0;
+
+  schedulerHandler (schedulerHandlerArgument, this, event);
+  return 1;
+}
diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index 02a3466..c471ffc 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -91,6 +91,9 @@ void ConnectionsScheduler::newData (short event, SocketHandle 
handle)
   if (connection == NULL || server == NULL)
     return;
 
+  if (connection->notifySchedulerHandler (event))
+    return;
+
   if (event == EV_READ)
     addReadyConnection (connection);
   else if (event == EV_TIMEOUT)



commit 998e03b7fcc6e38247247034477bd0082ce312c2
Author: Giuseppe Scrivano <address@hidden>
Date:   Sat Aug 7 22:40:06 2010 +0200

    Do not undefine remove.

diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index fed80e5..02a3466 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -17,8 +17,6 @@
 
 #include "myserver.h"
 
-#undef remove
-
 #ifdef WIN32
 # include <w32sock.h>
 

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

Summary of changes:
 myserver/NEWS                                      |    3 +
 myserver/include/connection/connection.h           |    8 ++
 myserver/include/http_handler/proxy/proxy.h        |   17 +++
 myserver/src/conf/mime/xml_mime_handler.cpp        |    1 -
 myserver/src/connection/connection.cpp             |   29 +++++
 .../connections_scheduler.cpp                      |    5 +-
 myserver/src/http_handler/proxy/proxy.cpp          |  132 ++++++++++++++++++-
 7 files changed, 185 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
GNU MyServer



reply via email to

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