[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sptk-commits
Subject:    r1035 - in trunk/examples: . net
From:       alexey () mail ! total-knowledge ! com
Date:       2009-10-30 2:37:16
Message-ID: courier.000000004AEA515C.000058F1 () mail ! total-knowledge ! com
[Download RAW message or body]

Author: alexey
Date: 2009-10-29 19:37:16 -0700 (Thu, 29 Oct 2009)
New Revision: 1035

Added:
   trunk/examples/safe_list_test.cpp
Modified:
   trunk/examples/CMakeLists.txt
   trunk/examples/net/async_sockets_test.cpp
Log:
Added safe_list_test example for CSafeList.


Modified: trunk/examples/CMakeLists.txt
===================================================================
--- trunk/examples/CMakeLists.txt	2009-10-28 21:02:49 UTC (rev 1034)
+++ trunk/examples/CMakeLists.txt	2009-10-30 02:37:16 UTC (rev 1035)
@@ -19,6 +19,7 @@
         exceptions
         fragmented_stream
         logfile_test
+        safe_list_test
         safe_queue_test
         safe_queue_test_performance
         syslog_test

Modified: trunk/examples/net/async_sockets_test.cpp
===================================================================
--- trunk/examples/net/async_sockets_test.cpp	2009-10-28 21:02:49 UTC (rev 1034)
+++ trunk/examples/net/async_sockets_test.cpp	2009-10-30 02:37:16 UTC (rev 1035)
@@ -96,7 +96,7 @@
     signal(SIGHUP,signal_handler);  // catch hangup signal
     signal(SIGTERM,signal_handler); // catch kill signal
 
-    httpSocket.open("www.google.com",80);
+    httpSocket.open("www.catchoftheday.com.au",80);
     httpSocket2.open("www.sptk.net",80);
 
     CAsyncSockets   asyncSockets(socketsCallback);

Copied: trunk/examples/safe_list_test.cpp (from rev 1031, trunk/examples/safe_queue_test.cpp)
===================================================================
--- trunk/examples/safe_list_test.cpp	                        (rev 0)
+++ trunk/examples/safe_list_test.cpp	2009-10-30 02:37:16 UTC (rev 1035)
@@ -0,0 +1,92 @@
+/***************************************************************************
+                          safe_list_test.cpp  -  description
+                             -------------------
+    begin                : Mon 20 Jul 2009
+    copyright            : (C) 1999-2009 by Alexey Parshin
+    email                : alexeyp@gmail.com
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifdef __BORLANDC__
+#include <condefs.h>
+#endif
+
+#include <sptk4/cutils>
+
+using namespace std;
+using namespace sptk;
+
+// This is the main object of the test, a shared SafeList:
+CSafeList<string>  safeList;
+
+class CProducerThread: public CThread {
+protected:
+    // The thread function.
+    virtual void threadFunction();
+public:
+    // Constructor
+    CProducerThread() :
+        CThread("Producer thread", true)
+    {
+    }
+};
+
+class CConsumerThread: public CThread {
+protected:
+    // The thread function.
+    virtual void threadFunction();
+public:
+    // Constructor
+    CConsumerThread() :
+        CThread("Consumer thread", true)
+    {
+    }
+};
+
+// The thread function. Puts the file into the list
+void CProducerThread::threadFunction()
+{
+    CStrings testFileData;
+    testFileData.loadFromFile("../examples/safe_list_test.cpp");
+    for (unsigned i = 0; i < testFileData.size(); i++)
+        safeList.push_back(testFileData[i]);
+}
+
+// The thread function. Reads the file from the list
+void CConsumerThread::threadFunction()
+{
+    while (!terminated()) {
+        string st;
+        if ( safeList.pop_back(st, 100) )
+            cout << st << endl;
+        else
+            break;
+    }
+}
+
+int main(int, const char**)
+{
+    CProducerThread* producerThread = new CProducerThread;
+    CConsumerThread* consumerThread = new CConsumerThread;
+
+    consumerThread->run();
+    producerThread->run();
+
+    CThread::msleep(100);
+
+    while (consumerThread->running())
+        CThread::msleep(50);
+
+    delete consumerThread;
+    delete producerThread;
+
+    return 0;
+}

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic