Added fail safe delay as some camera drivers ignore the frame rate
[pwlib.git] / samples / aggtest / main.cxx
blobd9a88630cdc87879d50aad3e63197be87396f536
1 /*
2 * main.cxx
4 * PWLib application source file for aggtest
6 * Main program entry point.
8 * Copyright (C) 2004 Post Increment
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Post Increment
24 * Contributor(s): ______________________________________.
26 * $Log$
27 * Revision 1.2 2006/01/18 07:16:56 csoutheren
28 * Latest version of socket aggregation code
30 * Revision 1.1 2005/12/22 03:55:52 csoutheren
31 * Added initial version of socket aggregation classes
35 #include "precompile.h"
36 #include "main.h"
37 #include "version.h"
39 #include <ptclib/sockagg.h>
41 PCREATE_PROCESS(AggTest);
43 AggTest::AggTest()
44 : PProcess("Post Increment", "AggTest", MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER)
48 class MyUDPSocket : public PUDPSocket
50 public:
51 BOOL OnRead()
53 BYTE buffer[1024];
54 Read(buffer, 1024);
55 return TRUE;
60 void AggTest::Main()
62 PArgList & args = GetArguments();
64 args.Parse(
65 "-server:"
66 "-to:"
67 "-from:"
68 "-re:"
69 "-attachment:"
71 #if PTRACING
72 "o-output:" "-no-output."
73 "t-trace." "-no-trace."
74 #endif
77 #if PTRACING
78 PTrace::Initialise(args.GetOptionCount('t'),
79 args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL,
80 PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);
81 #endif
83 PSocketAggregator<MyUDPSocket> socketHandler;
85 MyUDPSocket * sockets[100];
86 memset(sockets, 0, sizeof(sockets));
87 const unsigned count = sizeof(sockets) / sizeof(sockets[0]);
89 for (PINDEX i = 0; i < 1000000; ++i) {
90 int num = rand() % count;
91 if (sockets[num] == NULL) {
92 sockets[num] = new MyUDPSocket();
93 sockets[num]->Listen();
94 socketHandler.AddSocket(sockets[num]);
96 else
98 socketHandler.RemoveSocket(sockets[num]);
99 delete sockets[num];
100 sockets[num] = NULL;
104 cout << "handler finished with " << socketHandler.workers.size() << " threads" << endl;
108 // End of File ///////////////////////////////////////////////////////////////