|
reSIProcate/stack
9694
|
00001 #if defined(HAVE_CONFIG_H) 00002 #include "config.h" 00003 #endif 00004 00005 #include <iostream> 00006 00007 #if defined (HAVE_POPT_H) 00008 #include <popt.h> 00009 #else 00010 #ifndef WIN32 00011 #warning "will not work very well without libpopt" 00012 #endif 00013 #endif 00014 00015 #include "rutil/SelectInterruptor.hxx" 00016 #include "rutil/Logger.hxx" 00017 #include "rutil/DataStream.hxx" 00018 #include "rutil/ThreadIf.hxx" 00019 00020 using namespace resip; 00021 using namespace std; 00022 00023 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00024 00025 class FakeApp : public ThreadIf 00026 { 00027 public: 00028 FakeApp(SelectInterruptor& s); 00029 ~FakeApp() {}; 00030 00031 void thread(); 00032 private: 00033 SelectInterruptor& mSi; 00034 }; 00035 00036 FakeApp::FakeApp(SelectInterruptor& s) : mSi(s) 00037 {} 00038 00039 void FakeApp::thread() 00040 { 00041 static unsigned wakeups[6] = { 3, 1, 0, 2, 5, 1 }; 00042 00043 for (unsigned long n = 0; n < sizeof(wakeups)/sizeof(long); n++) 00044 { 00045 InfoLog( << "Wakeup in: " << wakeups[n] << ", " << n+1 << " of " 00046 << sizeof(wakeups)/sizeof(long)); 00047 #ifdef WIN32 00048 Sleep(wakeups[n]*1000); 00049 #else 00050 sleep(wakeups[n]); 00051 #endif 00052 InfoLog(<< "Waking up select"); 00053 mSi.interrupt(); 00054 } 00055 shutdown(); 00056 } 00057 00058 00059 int 00060 main(int argc, char* argv[]) 00061 { 00062 #ifdef WIN32 00063 initNetwork(); 00064 #endif 00065 00066 Log::initialize(Log::Cout, Log::Debug, argv[0]); 00067 00068 SelectInterruptor si; 00069 FakeApp app(si); 00070 00071 InfoLog(<< "Starting FakeApp"); 00072 app.run(); 00073 00074 int numWakeups = 0; 00075 while(!app.isShutdown()) 00076 { 00077 FdSet fdset; 00078 si.buildFdSet(fdset); 00079 00080 int ret = fdset.selectMilliSeconds(10000); 00081 00082 if (ret > 0) 00083 { 00084 InfoLog(<< "Select detected: " << ret << " ready descriptors"); 00085 si.process(fdset); 00086 numWakeups++; 00087 } 00088 else 00089 { 00090 InfoLog(<< "Select detected no ready descriptors, test failed"); 00091 break; 00092 } 00093 } 00094 00095 if (numWakeups == 6) 00096 { 00097 InfoLog(<< "Finished, test passed"); 00098 } 00099 app.shutdown(); 00100 app.join(); 00101 } 00102 00103 00104 00105 00106 00107 /* ==================================================================== 00108 * The Vovida Software License, Version 1.0 00109 * 00110 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00111 * 00112 * Redistribution and use in source and binary forms, with or without 00113 * modification, are permitted provided that the following conditions 00114 * are met: 00115 * 00116 * 1. Redistributions of source code must retain the above copyright 00117 * notice, this list of conditions and the following disclaimer. 00118 * 00119 * 2. Redistributions in binary form must reproduce the above copyright 00120 * notice, this list of conditions and the following disclaimer in 00121 * the documentation and/or other materials provided with the 00122 * distribution. 00123 * 00124 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00125 * and "Vovida Open Communication Application Library (VOCAL)" must 00126 * not be used to endorse or promote products derived from this 00127 * software without prior written permission. For written 00128 * permission, please contact vocal@vovida.org. 00129 * 00130 * 4. Products derived from this software may not be called "VOCAL", nor 00131 * may "VOCAL" appear in their name, without prior written 00132 * permission of Vovida Networks, Inc. 00133 * 00134 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00135 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00136 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00137 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00138 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00139 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00140 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00141 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00142 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00143 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00144 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00145 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00146 * DAMAGE. 00147 * 00148 * ==================================================================== 00149 * 00150 * This software consists of voluntary contributions made by Vovida 00151 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00152 * Inc. For more information on Vovida Networks, Inc., please see 00153 * <http://www.vovida.org/>. 00154 * 00155 */
1.7.5.1