/[resiprocate]/main/resip/stack/test/testSelectInterruptor.cxx
ViewVC logotype

Annotation of /main/resip/stack/test/testSelectInterruptor.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5315 - (hide annotations) (download)
Thu Aug 25 22:36:21 2005 UTC (14 years, 5 months ago) by derek
File size: 4312 byte(s)
removed bogus test from testData.cxx
testSelectInterruptor will build on *nix
1 derek 4463 #if defined(HAVE_CONFIG_H)
2 derek 5283 #include "resip/stack/config.hxx"
3 derek 4463 #endif
4    
5     #include <iostream>
6    
7     #if defined (HAVE_POPT_H)
8     #include <popt.h>
9     #else
10     #ifndef WIN32
11     #warning "will not work very well without libpopt"
12     #endif
13     #endif
14    
15 derek 5315 #include "resip/stack/SelectInterruptor.hxx"
16 jason 5276 #include "rutil/Logger.hxx"
17     #include "rutil/DataStream.hxx"
18     #include "rutil/ThreadIf.hxx"
19 derek 4463
20     using namespace resip;
21     using namespace std;
22    
23     #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
24    
25     class FakeApp : public ThreadIf
26     {
27     public:
28     FakeApp(SelectInterruptor& s);
29     ~FakeApp() {};
30    
31     void thread();
32     private:
33     SelectInterruptor& mSi;
34     };
35    
36     FakeApp::FakeApp(SelectInterruptor& s) : mSi(s)
37     {}
38    
39     void FakeApp::thread()
40     {
41     static unsigned wakeups[6] = { 3, 1, 0, 2, 5, 1 };
42    
43     for (unsigned long n = 0; n < sizeof(wakeups)/sizeof(long); n++)
44     {
45     InfoLog( << "Wakeup in: " << wakeups[n] << ", " << n+1 << " of "
46     << sizeof(wakeups)/sizeof(long));
47 derek 4467 #ifdef WIN32
48     Sleep(wakeups[n]*1000);
49     #else
50     sleep(wakeups[n]);
51     #endif
52 derek 4463 InfoLog(<< "Waking up select");
53     mSi.interrupt();
54     }
55     shutdown();
56     }
57    
58    
59     int
60     main(int argc, char* argv[])
61     {
62 derek 4467 #ifdef WIN32
63     initNetwork();
64     #endif
65    
66 derek 4463 Log::initialize(Log::Cout, Log::Debug, argv[0]);
67    
68     SelectInterruptor si;
69     FakeApp app(si);
70    
71     InfoLog(<< "Starting FakeApp");
72     app.run();
73    
74     int numWakeups = 0;
75     while(!app.isShutdown())
76     {
77     FdSet fdset;
78     si.buildFdSet(fdset);
79    
80     int ret = fdset.selectMilliSeconds(10000);
81    
82     if (ret > 0)
83     {
84     InfoLog(<< "Select detected: " << ret << " ready descriptors");
85     si.process(fdset);
86     numWakeups++;
87     }
88     else
89     {
90     InfoLog(<< "Select detected no ready descriptors, test failed");
91     break;
92     }
93     }
94    
95     if (numWakeups == 6)
96     {
97     InfoLog(<< "Finished, test passed");
98     }
99     app.shutdown();
100     app.join();
101     }
102    
103    
104    
105    
106 derek 4602
107     /* ====================================================================
108     * The Vovida Software License, Version 1.0
109     *
110     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
111     *
112     * Redistribution and use in source and binary forms, with or without
113     * modification, are permitted provided that the following conditions
114     * are met:
115     *
116     * 1. Redistributions of source code must retain the above copyright
117     * notice, this list of conditions and the following disclaimer.
118     *
119     * 2. Redistributions in binary form must reproduce the above copyright
120     * notice, this list of conditions and the following disclaimer in
121     * the documentation and/or other materials provided with the
122     * distribution.
123     *
124     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
125     * and "Vovida Open Communication Application Library (VOCAL)" must
126     * not be used to endorse or promote products derived from this
127     * software without prior written permission. For written
128     * permission, please contact vocal@vovida.org.
129     *
130     * 4. Products derived from this software may not be called "VOCAL", nor
131     * may "VOCAL" appear in their name, without prior written
132     * permission of Vovida Networks, Inc.
133     *
134     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
135     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
136     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
137     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
138     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
139     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
140     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
141     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
142     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
143     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
145     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
146     * DAMAGE.
147     *
148     * ====================================================================
149     *
150     * This software consists of voluntary contributions made by Vovida
151     * Networks, Inc. and many individuals on behalf of Vovida Networks,
152     * Inc. For more information on Vovida Networks, Inc., please see
153     * <http://www.vovida.org/>.
154     *
155     */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27