/*--------------------------------------------------------------- * Copyright (c) 1999,2000,2001,2002,2003 * The Board of Trustees of the University of Illinois * All Rights Reserved. *--------------------------------------------------------------- * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software (Iperf) and associated * documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do * so, subject to the following conditions: * * * Redistributions of source code must retain the above * copyright notice, this list of conditions and * the following disclaimers. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimers in the documentation and/or other materials * provided with the distribution. * * * Neither the names of the University of Illinois, NCSA, * nor the names of its contributors may be used to endorse * or promote products derived from this Software without * specific prior written permission. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ________________________________________________________________ * National Laboratory for Applied Network Research * National Center for Supercomputing Applications * University of Illinois at Urbana-Champaign * http://www.ncsa.uiuc.edu * ________________________________________________________________ * * Client.cpp * by Mark Gates <mgates@nlanr.net> * ------------------------------------------------------------------- * A client thread initiates a connect to the server and handles * sending and receiving data, then closes the socket.
* ------------------------------------------------------------------- */
/* ------------------------------------------------------------------- * Store server hostname, optionally local hostname, and socket info.
* ------------------------------------------------------------------- */
// if we're not doing interval reporting, report the entire transfer as one big packet if(0.0 == mSettings->mInterval) {
reportstruct->packetLen = totLen;
ReportPacket( mSettings->reporthdr, reportstruct );
}
CloseReport( mSettings->reporthdr, reportstruct );
/* ------------------------------------------------------------------- * Send data using the connected UDP/TCP socket, * until a termination flag is reached. * Does not close the socket.
* ------------------------------------------------------------------- */
// InitReport handles Barrier for multiple Streams
mSettings->reporthdr = InitReport( mSettings );
reportstruct = new ReportStruct;
reportstruct->packetID = 0;
lastPacketTime.setnow();
do {
// Test case: drop 17 packets and send 2 out-of-order: // sequence 51, 52, 70, 53, 54, 71, 72 //switch( datagramID ) { // case 53: datagramID = 70; break; // case 71: datagramID = 53; break; // case 55: datagramID = 71; break; // default: break; //}
gettimeofday( &(reportstruct->packetTime), NULL );
if ( isUDP( mSettings ) ) { // store datagram ID into buffer
mBuf_UDP->id = htonl( (reportstruct->packetID)++ );
mBuf_UDP->tv_sec = htonl( reportstruct->packetTime.tv_sec );
mBuf_UDP->tv_usec = htonl( reportstruct->packetTime.tv_usec );
// delay between writes // make an adjustment for how long the last loop iteration took // TODO this doesn't work well in certain cases, like 2 parallel streams
adjust = delay_target + lastPacketTime.subUsec( reportstruct->packetTime );
lastPacketTime.set( reportstruct->packetTime.tv_sec,
reportstruct->packetTime.tv_usec );
if ( isUDP( mSettings ) ) { // send a final terminating datagram // Don't count in the mTotalLen. The server counts this one, // but didn't count our first datagram, so we're even now. // The negative datagram ID signifies termination to the server.
// store datagram ID into buffer
mBuf_UDP->id = htonl( -(reportstruct->packetID) );
mBuf_UDP->tv_sec = htonl( reportstruct->packetTime.tv_sec );
mBuf_UDP->tv_usec = htonl( reportstruct->packetTime.tv_usec );
if ( isMulticast( mSettings ) ) {
write( mSettings->mSock, mBuf, mSettings->mBufLen );
} else {
write_UDP_FIN( );
}
}
DELETE_PTR( reportstruct );
EndReport( mSettings->reporthdr );
} // end Run
/* ------------------------------------------------------------------- * Setup a socket connected to a server. * If inLocalhost is not null, bind to that address, specifying * which outgoing interface to use.
* ------------------------------------------------------------------- */
void Client::Connect( ) { int rc;
SockAddr_remoteAddr( mSettings );
assert( mSettings->inHostname != NULL );
// create an internet socket int type = ( isUDP( mSettings ) ? SOCK_DGRAM : SOCK_STREAM);
/* ------------------------------------------------------------------- * Send a datagram on the socket. The datagram's contents should signify * a FIN to the application. Keep re-transmitting until an * acknowledgement datagram is received.
* ------------------------------------------------------------------- */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.