myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [2747] Added continuations mechanism for scheduled con


From: Giuseppe Scrivano
Subject: [myserver-commit] [2747] Added continuations mechanism for scheduled connections
Date: Wed, 13 Aug 2008 19:37:06 +0000

Revision: 2747
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2747
Author:   gscrivano
Date:     2008-08-13 19:37:05 +0000 (Wed, 13 Aug 2008)

Log Message:
-----------
Added continuations mechanism for scheduled connections

Modified Paths:
--------------
    trunk/myserver/include/connection.h
    trunk/myserver/src/clients_thread.cpp
    trunk/myserver/src/connection.cpp
    trunk/myserver/tests/test_connection.cpp

Modified: trunk/myserver/include/connection.h
===================================================================
--- trunk/myserver/include/connection.h 2008-08-13 19:29:50 UTC (rev 2746)
+++ trunk/myserver/include/connection.h 2008-08-13 19:37:05 UTC (rev 2747)
@@ -42,6 +42,15 @@
 /*! Remove the connection if the administrator decided this.  */
 #define CONNECTION_USER_KILL        2
 
+
+class Connection;
+                                   
+typedef  Connection* ConnectionPtr;
+
+typedef int (*continuationPROC)(ConnectionPtr a, char *b1, char *b2,
+                                int bs1, int bs2, u_long nbtr, u_long id);
+
+
 class Connection
 {
 public:
@@ -107,9 +116,20 @@
   Connection();
   virtual ~Connection();
 
+  /*! Get the continuation function.  */
+  continuationPROC getContinuation(){return continuation;}
+
+  /*! Set a new continuation function.  */
+  void setContinuation(continuationPROC newContinuation){continuation = 
newContinuation;}
+
+  /*! Check if the connection has a continuation.  */
+  bool hasContinuation(){return continuation ? true : false;}
 protected:
        ClientsThread *thread;
 
+  /*! Continuation function.  */
+  continuationPROC continuation;
+
   /*! Identifier for the connection.  */
   u_long ID;
 
@@ -155,7 +175,5 @@
        int priority;
 
 };
-                                   
-typedef  Connection* ConnectionPtr;
 
 #endif

Modified: trunk/myserver/src/clients_thread.cpp
===================================================================
--- trunk/myserver/src/clients_thread.cpp       2008-08-13 19:29:50 UTC (rev 
2746)
+++ trunk/myserver/src/clients_thread.cpp       2008-08-13 19:37:05 UTC (rev 
2747)
@@ -350,18 +350,33 @@
   c->setActiveThread(this);
   try
   {
-    protocol = Server::getInstance()->getProtocol(c->host->getProtocolName());
-    if(protocol)
+    if (c->hasContinuation())
     {
-      retcode = protocol->controlConnection(c, (char*)buffer.getBuffer(), 
-                                            (char*)buffer2.getBuffer(), 
buffer.getRealLength(), 
-                                            buffer2.getRealLength(), 
nBytesToRead, id);
+      retcode = c->getContinuation()(c, 
+                                     (char*)buffer.getBuffer(), 
+                                     (char*)buffer2.getBuffer(), 
+                                     buffer.getRealLength(), 
+                                     buffer2.getRealLength(), 
+                                     nBytesToRead, 
+                                     id);
+      c->setContinuation(NULL);
     }
     else
     {
-      retcode = DELETE_CONNECTION;
+      protocol = 
Server::getInstance()->getProtocol(c->host->getProtocolName());
+      if(protocol)
+      {
+        retcode = protocol->controlConnection(c, 
+                                              (char*)buffer.getBuffer(), 
+                                              (char*)buffer2.getBuffer(), 
+                                              buffer.getRealLength(), 
+                                              buffer2.getRealLength(), 
+                                              nBytesToRead, 
+                                              id);
+      }
+      else
+        retcode = DELETE_CONNECTION;
     }
-
   }
   catch(...)
   {

Modified: trunk/myserver/src/connection.cpp
===================================================================
--- trunk/myserver/src/connection.cpp   2008-08-13 19:29:50 UTC (rev 2746)
+++ trunk/myserver/src/connection.cpp   2008-08-13 19:37:05 UTC (rev 2747)
@@ -39,6 +39,7 @@
   protocolBuffer = NULL;
   socket = 0;
   priority = -1;
+  continuation = NULL;
 }
 
 /*!

Modified: trunk/myserver/tests/test_connection.cpp
===================================================================
--- trunk/myserver/tests/test_connection.cpp    2008-08-13 19:29:50 UTC (rev 
2746)
+++ trunk/myserver/tests/test_connection.cpp    2008-08-13 19:37:05 UTC (rev 
2747)
@@ -172,6 +172,7 @@
     CPPUNIT_ASSERT_EQUAL(connection->isScheduled(), 1);
   }
 
+
   void testPriority()
   {
     for(int i = 0; i < 100; i += 10)
@@ -181,8 +182,18 @@
     }
   }
 
+  void testContinuation()
+  {
+    continuationPROC continuation = (continuationPROC) 100;
 
+    CPPUNIT_ASSERT(connection->getContinuation() == NULL);
+    connection->setContinuation(continuation);
 
+    CPPUNIT_ASSERT(connection->getContinuation() == continuation);
+  }
+
+
+
 };
 
 






reply via email to

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