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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6069 - (show annotations) (download)
Thu Mar 9 23:06:59 2006 UTC (13 years, 8 months ago) by jason
File MIME type: text/plain
File size: 5792 byte(s)
mods for Solaris - tested for Solaris 10 on x86
fixed numerous compiler errors/warnings


1
2 #include <cassert>
3 #include <iostream>
4
5 #include "rutil/DnsUtil.hxx"
6 #include "rutil/Socket.hxx"
7 #include "rutil/Timer.hxx"
8 #include "resip/stack/UdpTransport.hxx"
9
10 using namespace resip;
11 using namespace std;
12
13
14 int
15 main(int argc, char* argv[])
16 {
17 if ( argc != 3 )
18 {
19 cerr << "Usage: testSelect startPort endPort\n";
20 exit(1);
21 }
22
23 int startPort = atoi( argv[1] );
24 int endPort = atoi( argv[2] );
25
26 cout << "Doing port " << startPort << " to " << endPort << endl;
27
28 int fd[0xFFFF];
29
30 #define NUMCYCLES 50
31
32 UInt64 time1[NUMCYCLES];
33 UInt64 time2[NUMCYCLES];
34 UInt64 time3[NUMCYCLES];
35
36 // open the fd
37 for( int port=startPort; port<endPort; port++)
38 {
39 fd[port] = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
40 if( fd[port] == INVALID_SOCKET )
41 {
42 cerr << "Fail on creating socket for port " << port << endl;
43 assert(0);
44 }
45
46 sockaddr_in addr4;
47 sockaddr* saddr=0;
48 int saddrLen = 0;
49
50 memset(&addr4, 0, sizeof(addr4));
51 addr4.sin_family = AF_INET;
52 addr4.sin_port = htons(port);
53 addr4.sin_addr.s_addr = htonl(INADDR_ANY);
54
55 saddr = reinterpret_cast<sockaddr*>(&addr4);
56 saddrLen = sizeof(addr4);
57
58 if ( bind( fd[port], saddr, saddrLen) == SOCKET_ERROR )
59 {
60 assert(0);
61 }
62
63 bool ok = makeSocketNonBlocking( fd[port] );
64 assert(ok);
65 }
66
67
68 for ( int i=0; i<NUMCYCLES; i++ )
69 {
70 FdSet fdset;
71
72 time1[i] = Timer::getTimeMicroSec();
73 // build the fd
74 for( int port=startPort; port<endPort; port++)
75 {
76 fdset.setRead(fd[port]);
77 }
78
79 time2[i] = Timer::getTimeMicroSec();
80 // select
81 int err = fdset.selectMilliSeconds( 0 );
82 assert( err != -1 );
83
84 time3[i] = Timer::getTimeMicroSec();
85 // do the reads
86 for( int port=startPort; port<endPort; port++)
87 {
88 if (fdset.readyToRead(fd[port]))
89 {
90 struct sockaddr from;
91
92 const int MaxBufferSize=1024*4;
93 char buffer[MaxBufferSize];
94 socklen_t fromLen = sizeof(from);
95
96 int len = recvfrom( fd[port],
97 buffer,
98 MaxBufferSize,
99 0 /*flags */,
100 (struct sockaddr*)&from,
101 &fromLen);
102
103 if ( len == SOCKET_ERROR )
104 {
105 int err = errno;
106 switch (err)
107 {
108 case WSANOTINITIALISED:
109 assert(0);
110 break;
111
112 case EWOULDBLOCK:
113 //cerr << " UdpTransport recvfrom got EWOULDBLOCK";
114 break;
115
116 case 0:
117 cerr << " UdpTransport recvfrom got error 0 ";
118 break;
119
120 default:
121 cerr <<"Error receiving, errno="<<err << " " << strerror(err);
122 break;
123 }
124 }
125 }
126
127 }
128 }
129
130 for ( int i=1; i<NUMCYCLES; i++ )
131 {
132 cout << time2[i] - time1[i] << " ";
133 cout << time1[i] - time1[i-1] << " ";
134
135 cout << endl;
136 }
137
138 return 0;
139 }
140 /* ====================================================================
141 * The Vovida Software License, Version 1.0
142 *
143 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
144 *
145 * Redistribution and use in source and binary forms, with or without
146 * modification, are permitted provided that the following conditions
147 * are met:
148 *
149 * 1. Redistributions of source code must retain the above copyright
150 * notice, this list of conditions and the following disclaimer.
151 *
152 * 2. Redistributions in binary form must reproduce the above copyright
153 * notice, this list of conditions and the following disclaimer in
154 * the documentation and/or other materials provided with the
155 * distribution.
156 *
157 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
158 * and "Vovida Open Communication Application Library (VOCAL)" must
159 * not be used to endorse or promote products derived from this
160 * software without prior written permission. For written
161 * permission, please contact vocal@vovida.org.
162 *
163 * 4. Products derived from this software may not be called "VOCAL", nor
164 * may "VOCAL" appear in their name, without prior written
165 * permission of Vovida Networks, Inc.
166 *
167 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
168 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
169 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
170 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
171 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
172 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
173 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
174 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
175 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
176 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
177 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
178 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
179 * DAMAGE.
180 *
181 * ====================================================================
182 *
183 * This software consists of voluntary contributions made by Vovida
184 * Networks, Inc. and many individuals on behalf of Vovida Networks,
185 * Inc. For more information on Vovida Networks, Inc., please see
186 * <http://www.vovida.org/>.
187 *
188 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27