⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settings.cpp

📁 在Linux/Unix环境下发包测试性能的工具
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        theVariable = getenv( env_options[i].name );        if ( theVariable != NULL ) {            Settings_Interpret( env_options[i].val, theVariable, mSettings );        }        i++;    }} // end ParseEnvironment/* ------------------------------------------------------------------- * Parse settings from app's command line. * ------------------------------------------------------------------- */void Settings_ParseCommandLine( int argc, char **argv, thread_Settings *mSettings ) {    int option;    while ( (option =             gnu_getopt_long( argc, argv, short_options,                              long_options, NULL )) != EOF ) {        Settings_Interpret( option, gnu_optarg, mSettings );    }    for ( int i = gnu_optind; i < argc; i++ ) {        fprintf( stderr, "%s: ignoring extra argument -- %s\n", argv[0], argv[i] );    }} // end ParseCommandLine/* ------------------------------------------------------------------- * Interpret individual options, either from the command line * or from environment variables. * ------------------------------------------------------------------- */void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtSettings ) {    char outarg[100];    switch ( option ) {        case '1': // Single Client            setSingleClient( mExtSettings );            break;        case 'b': // UDP bandwidth            if ( !isUDP( mExtSettings ) ) {                fprintf( stderr, warn_implied_udp, option );            }            if ( mExtSettings->mThreadMode != kMode_Client ) {                fprintf( stderr, warn_invalid_server_option, option );                break;            }            Settings_GetLowerCaseArg(optarg,outarg);            mExtSettings->mUDPRate = byte_atoi(outarg);            setUDP( mExtSettings );            // if -l has already been processed, mBufLenSet is true            // so don't overwrite that value.            if ( !isBuflenSet( mExtSettings ) ) {                mExtSettings->mBufLen = kDefault_UDPBufLen;            }            break;        case 'c': // client mode w/ server host to connect to            mExtSettings->mHost = new char[ strlen( optarg ) + 1 ];            strcpy( mExtSettings->mHost, optarg );            if ( mExtSettings->mThreadMode == kMode_Unknown ) {                // Test for Multicast                iperf_sockaddr temp;                SockAddr_setHostname( mExtSettings->mHost, &temp,                                      (isIPV6( mExtSettings ) ? 1 : 0 ));                if ( SockAddr_isMulticast( &temp ) ) {                    setMulticast( mExtSettings );                }                mExtSettings->mThreadMode = kMode_Client;                mExtSettings->mThreads = 1;            }            break;        case 'd': // Dual-test Mode            if ( mExtSettings->mThreadMode != kMode_Client ) {                fprintf( stderr, warn_invalid_server_option, option );                break;            }            if ( isCompat( mExtSettings ) ) {                fprintf( stderr, warn_invalid_compatibility_option, option );            }#ifdef HAVE_THREAD            mExtSettings->mMode = kTest_DualTest;#else            fprintf( stderr, warn_invalid_single_threaded, option );            mExtSettings->mMode = kTest_TradeOff;#endif            break;        case 'f': // format to print in            mExtSettings->mFormat = (*optarg);            break;        case 'h': // print help and exit#ifndef WIN32            fprintf( stderr, usage_long );#else            fprintf(stderr, usage_long1);            fprintf(stderr, usage_long2);#endif            exit(1);            break;        case 'i': // specify interval between periodic bw reports            mExtSettings->mInterval = atof( optarg );            if ( mExtSettings->mInterval < 0.5 ) {                fprintf (stderr, report_interval_small, mExtSettings->mInterval);                mExtSettings->mInterval = 0.5;            }            break;        case 'l': // length of each buffer            Settings_GetUpperCaseArg(optarg,outarg);            mExtSettings->mBufLen = byte_atoi( outarg );            setBuflenSet( mExtSettings );            if ( !isUDP( mExtSettings ) ) {                 if ( mExtSettings->mBufLen < (int) sizeof( client_hdr ) &&                      !isCompat( mExtSettings ) ) {                    setCompat( mExtSettings );                    fprintf( stderr, warn_implied_compatibility, option );                 }            } else {                if ( mExtSettings->mBufLen < (int) sizeof( UDP_datagram ) ) {                    mExtSettings->mBufLen = sizeof( UDP_datagram );                    fprintf( stderr, warn_buffer_too_small, mExtSettings->mBufLen );                }                if ( !isCompat( mExtSettings ) &&                            mExtSettings->mBufLen < (int) ( sizeof( UDP_datagram )                            + sizeof( client_hdr ) ) ) {                    setCompat( mExtSettings );                    fprintf( stderr, warn_implied_compatibility, option );                }            }            break;        case 'm': // print TCP MSS            setPrintMSS( mExtSettings );            break;        case 'n': // bytes of data            // amount mode (instead of time mode)            unsetModeTime( mExtSettings );            Settings_GetUpperCaseArg(optarg,outarg);            mExtSettings->mAmount = byte_atoi( outarg );            break;        case 'o' : // output the report and other messages into the file            unsetSTDOUT( mExtSettings );            mExtSettings->mOutputFileName = new char[strlen(optarg)+1];            strcpy( mExtSettings->mOutputFileName, optarg);            break;        case 'p': // server port            mExtSettings->mPort = atoi( optarg );            break;        case 'r': // test mode tradeoff            if ( mExtSettings->mThreadMode != kMode_Client ) {                fprintf( stderr, warn_invalid_server_option, option );                break;            }            if ( isCompat( mExtSettings ) ) {                fprintf( stderr, warn_invalid_compatibility_option, option );            }            mExtSettings->mMode = kTest_TradeOff;            break;        case 's': // server mode            if ( mExtSettings->mThreadMode != kMode_Unknown ) {                fprintf( stderr, warn_invalid_client_option, option );                break;            }            mExtSettings->mThreadMode = kMode_Listener;            break;        case 't': // seconds to write for            // time mode (instead of amount mode)            setModeTime( mExtSettings );            mExtSettings->mAmount = (int) (atof( optarg ) * 100.0);            break;        case 'u': // UDP instead of TCP            // if -b has already been processed, UDP rate will            // already be non-zero, so don't overwrite that value            if ( !isUDP( mExtSettings ) ) {                setUDP( mExtSettings );                mExtSettings->mUDPRate = kDefault_UDPRate;            }            // if -l has already been processed, mBufLenSet is true            // so don't overwrite that value.            if ( !isBuflenSet( mExtSettings ) ) {                mExtSettings->mBufLen = kDefault_UDPBufLen;            } else if ( mExtSettings->mBufLen < (int) ( sizeof( UDP_datagram )                         + sizeof( client_hdr ) ) &&                        !isCompat( mExtSettings ) ) {                setCompat( mExtSettings );                fprintf( stderr, warn_implied_compatibility, option );            }            break;        case 'v': // print version and exit            fprintf( stderr, version );            exit(1);            break;        case 'w': // TCP window size (socket buffer size)            Settings_GetUpperCaseArg(optarg,outarg);            mExtSettings->mTCPWin = byte_atoi(outarg);            if ( mExtSettings->mTCPWin < 2048 ) {                fprintf( stderr, warn_window_small, mExtSettings->mTCPWin );            }            break;        case 'x': // Limit Reports            while ( *optarg != '\0' ) {                switch ( *optarg ) {                    case 's':                    case 'S':                        setNoSettReport( mExtSettings );                        break;                    case 'c':                    case 'C':                        setNoConnReport( mExtSettings );                        break;                    case 'd':                    case 'D':                        setNoDataReport( mExtSettings );                        break;                    case 'v':                    case 'V':                        setNoServReport( mExtSettings );                        break;                    case 'm':                    case 'M':                        setNoMultReport( mExtSettings );                        break;                    default:                        fprintf(stderr, warn_invalid_report, *optarg);                }                optarg++;            }            break;        case 'y': // Reporting Style            switch ( *optarg ) {                case 'c':                case 'C':                    mExtSettings->mReportMode = kReport_CSV;                    break;                default:                    fprintf( stderr, warn_invalid_report_style, optarg );            }            break;            // more esoteric options        case 'B': // specify bind address            mExtSettings->mLocalhost = new char[ strlen( optarg ) + 1 ];            strcpy( mExtSettings->mLocalhost, optarg );            // Test for Multicast            iperf_sockaddr temp;            SockAddr_setHostname( mExtSettings->mLocalhost, &temp,                                  (isIPV6( mExtSettings ) ? 1 : 0 ));            if ( SockAddr_isMulticast( &temp ) ) {                setMulticast( mExtSettings );            }            break;        case 'C': // Run in Compatibility Mode            setCompat( mExtSettings );            if ( mExtSettings->mMode != kTest_Normal ) {                fprintf( stderr, warn_invalid_compatibility_option,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -