trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aku...@apache.org
Subject svn commit: r942234 - in /trafficserver/traffic/branches/UserFiber/samples: ./ echoServer.C
Date Fri, 07 May 2010 21:19:22 GMT
Author: akundu
Date: Fri May  7 21:19:22 2010
New Revision: 942234

URL: http://svn.apache.org/viewvc?rev=942234&view=rev
Log:
sample echoServer code using the server framework

Added:
    trafficserver/traffic/branches/UserFiber/samples/
    trafficserver/traffic/branches/UserFiber/samples/echoServer.C

Added: trafficserver/traffic/branches/UserFiber/samples/echoServer.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/echoServer.C?rev=942234&view=auto
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/echoServer.C (added)
+++ trafficserver/traffic/branches/UserFiber/samples/echoServer.C Fri May  7 21:19:22 2010
@@ -0,0 +1,56 @@
+#include <iostream>
+#include <stdlib.h>
+
+#include "UFIO.H"
+#include "UFServer.H"
+
+using namespace std;
+
+struct EchoServer : public UFServer
+{
+    EchoServer(char* interfaceIP, unsigned int port)
+    {
+        _addressToBindTo = interfaceIP ? interfaceIP : "";
+        _port = port;
+    }
+    void handleNewConnection(UFIO* ufio);
+};
+
+unsigned long long int readTimeout = 0;
+void EchoServer::handleNewConnection(UFIO* ufio)
+{
+    if(!ufio)
+    {
+        cerr<<"couldnt create UFIO object"<<endl;
+        return;
+    }
+
+    char buf[256];
+    while ( ((n = ufio->read(buf, 255, readTimeout)) > 0) && ((n = ufio->write(buf,
255)) > 0) ) {}
+}
+
+
+int main(int argc, char** argv)
+{
+    unsigned int numThreads = 8;
+    unsigned int numProcesses = 1;
+    unsigned short int port = 8080;
+    if(argc > 1)
+        numThreads = atoi(argv[1]);
+    if(argc > 2)
+        port = atoi(argv[2]);
+    if(argc > 3)
+        readTimeout = atoi(argv[3]);
+    if(argc > 4)
+        numProcesses = atoi(argv[4]);
+
+    EchoServer ufecho(0, port);
+    ufecho.MAX_ACCEPT_THREADS_ALLOWED   = 1;
+    ufecho.MAX_THREADS_ALLOWED          = numThreads;
+    ufecho.MAX_PROCESSES_ALLOWED        = numProcesses;
+    ufecho.UF_STACK_SIZE                = 8192;
+
+    ufecho.run();
+
+    return 0;
+}



Mime
View raw message