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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4467 - (show annotations) (download)
Wed Apr 27 18:32:51 2005 UTC (14 years, 8 months ago) by derek
Original Path: main/sip/resiprocate/test/testSelectInterruptor.cxx
File size: 1968 byte(s)
fixed for windows
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #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 #include "resiprocate/os/SelectInterruptor.hxx"
16 #include "resiprocate/os/Logger.hxx"
17 #include "resiprocate/os/DataStream.hxx"
18 #include "resiprocate/os/ThreadIf.hxx"
19
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 #ifdef WIN32
48 Sleep(wakeups[n]*1000);
49 #else
50 sleep(wakeups[n]);
51 #endif
52 InfoLog(<< "Waking up select");
53 mSi.interrupt();
54 }
55 shutdown();
56 }
57
58
59 int
60 main(int argc, char* argv[])
61 {
62 #ifdef WIN32
63 initNetwork();
64 #endif
65
66 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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27