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
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Post Increment
24 * Contributor(s): ______________________________________.
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"
39 #include <ptclib/sockagg.h>
41 PCREATE_PROCESS(AggTest
);
44 : PProcess("Post Increment", "AggTest", MAJOR_VERSION
, MINOR_VERSION
, BUILD_TYPE
, BUILD_NUMBER
)
48 class MyUDPSocket
: public PUDPSocket
62 PArgList
& args
= GetArguments();
72 "o-output:" "-no-output."
73 "t-trace." "-no-trace."
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
);
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
]);
98 socketHandler
.RemoveSocket(sockets
[num
]);
104 cout
<< "handler finished with " << socketHandler
.workers
.size() << " threads" << endl
;
108 // End of File ///////////////////////////////////////////////////////////////