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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5948 - (show annotations) (download)
Fri Feb 17 15:30:16 2006 UTC (13 years, 9 months ago) by dworley
File MIME type: text/plain
File size: 5400 byte(s)
Setting more svn: properties, and adding EOLs to the ends of files
that need it.

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

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