void doPerformance(const string &arg){ if(arg == ARG_CLIENT){ bool bRet = net_connect(g_IP, TEST_CONNECT_PORT); if(!bRet){ DEBUG_E("client 连接失败。"); } PackerPtr pPacker(new Packer(NULL)); pPacker->setBuffer(g_TestContext_1.c_str(), g_TestContext_1.size()); long times(PERFROMANCE_TIMES); while(times--){ net_sendAll_C(pPacker); usleep(1); } sleep(100); } if(arg == ARG_SERVER){ TimeCounter timeCount; bool bRet = net_listen(g_IP, TEST_LISTEN_PORT); if(!bRet){ DEBUG_E("server 监听失败。"); } PackerPtr pPacker; long times(PERFROMANCE_TIMES); bool bNotFull(true); timeCount.start(); while(bRet && times>0){ if(net_recv_S(pPacker)){ if(g_TestContext_1 == string((char*)pPacker->getBuffer(), pPacker->getBufferSize())){ cout << --times << endl; } else{ bNotFull = false; DEBUG_E("接收数据出错。" << string((char*)pPacker->getBuffer(), pPacker->getBufferSize())); break; } if(!bNotFull){ cout << "有数据丢失" << endl; } } } timeCount.stop(); cout << "发送[" << PERFROMANCE_TIMES << "] use time [" << timeCount.getSecTimeD() << "]s" << endl; } }