|
reSIProcate/stack
9694
|
00001 00002 #include <cassert> 00003 #include <iostream> 00004 00005 #include "rutil/DnsUtil.hxx" 00006 #include "rutil/Socket.hxx" 00007 #include "resip/stack/UdpTransport.hxx" 00008 00009 #include "rutil/Timer.hxx" 00010 00011 00012 using namespace resip; 00013 using namespace std; 00014 00015 00016 int 00017 main(int argc, char* argv[]) 00018 { 00019 if ( argc != 4 ) 00020 { 00021 cerr << "Usage: testSelect startPort endPort rate\n"; 00022 exit(1); 00023 } 00024 00025 int startPort = atoi( argv[1] ); 00026 int endPort = atoi( argv[2] ); 00027 00028 cout << "Doing port " << startPort << " to " << endPort << endl; 00029 00030 int fd[0xFFFF]; 00031 00032 // open the fd 00033 for( int port=startPort; port<endPort; port++) 00034 { 00035 fd[port] = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 00036 if( fd[port] == INVALID_SOCKET ) 00037 { 00038 cerr << "Fail on creating socket for port " << port << endl; 00039 assert(0); 00040 } 00041 00042 sockaddr_in addr4; 00043 sockaddr* saddr=0; 00044 int saddrLen = 0; 00045 00046 memset(&addr4, 0, sizeof(addr4)); 00047 addr4.sin_family = AF_INET; 00048 addr4.sin_port = htons(port); 00049 addr4.sin_addr.s_addr = htonl(INADDR_ANY); 00050 00051 saddr = reinterpret_cast<sockaddr*>(&addr4); 00052 saddrLen = sizeof(addr4); 00053 00054 if ( bind( fd[port], saddr, saddrLen) == SOCKET_ERROR ) 00055 { 00056 assert(0); 00057 } 00058 00059 bool ok = makeSocketNonBlocking( fd[port] ); 00060 assert(ok); 00061 } 00062 00063 00064 while (1) 00065 { 00066 FdSet fdset; 00067 00068 UInt64 t = Timer::getTimeMicroSec(); 00069 00070 for( int port=startPort; port<endPort; port++) 00071 { 00072 if (fdset.readyToRead(fd[port])) 00073 { 00074 struct sockaddr from; 00075 00076 int MaxBufferSize=1024*4; 00077 00078 char buffer[MaxBufferSize]; 00079 socklen_t fromLen = sizeof(from); 00080 00081 sockaddr_in addrin; 00082 addrin.sin_addr = sendData->destination.ipv4; 00083 addrin.sin_port = htons(port); 00084 addrin.sin_family = AF_INET; 00085 00086 int len = sendto( fd[port], 00087 buffer, 00088 MaxBufferSize, 00089 0, // flags 00090 (const sockaddr*)&addrin, sizeof(sockaddr_in) ); 00091 00092 if ( len == SOCKET_ERROR ) 00093 { 00094 assert(0); 00095 } 00096 if ( len != MaxBufferSize ) 00097 int err = errno; 00098 switch (err) 00099 { 00100 case WSANOTINITIALISED: 00101 assert(0); 00102 break; 00103 00104 case EWOULDBLOCK: 00105 //cerr << " UdpTransport recvfrom got EWOULDBLOCK"; 00106 break; 00107 00108 case 0: 00109 cerr << " UdpTransport recvfrom got error 0 "; 00110 break; 00111 00112 default: 00113 cerr <<"Error receiving, errno="<<err << " " << strerror(err); 00114 break; 00115 } 00116 } 00117 } 00118 00119 } 00120 } 00121 00122 return 0; 00123 } 00124 /* ==================================================================== 00125 * The Vovida Software License, Version 1.0 00126 * 00127 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00128 * 00129 * Redistribution and use in source and binary forms, with or without 00130 * modification, are permitted provided that the following conditions 00131 * are met: 00132 * 00133 * 1. Redistributions of source code must retain the above copyright 00134 * notice, this list of conditions and the following disclaimer. 00135 * 00136 * 2. Redistributions in binary form must reproduce the above copyright 00137 * notice, this list of conditions and the following disclaimer in 00138 * the documentation and/or other materials provided with the 00139 * distribution. 00140 * 00141 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00142 * and "Vovida Open Communication Application Library (VOCAL)" must 00143 * not be used to endorse or promote products derived from this 00144 * software without prior written permission. For written 00145 * permission, please contact vocal@vovida.org. 00146 * 00147 * 4. Products derived from this software may not be called "VOCAL", nor 00148 * may "VOCAL" appear in their name, without prior written 00149 * permission of Vovida Networks, Inc. 00150 * 00151 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00152 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00153 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00154 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00155 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00156 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00157 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00158 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00159 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00160 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00161 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00162 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00163 * DAMAGE. 00164 * 00165 * ==================================================================== 00166 * 00167 * This software consists of voluntary contributions made by Vovida 00168 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00169 * Inc. For more information on Vovida Networks, Inc., please see 00170 * <http://www.vovida.org/>. 00171 * 00172 */
1.7.5.1