本文整理汇总了C++中Protocol::_sendData方法的典型用法代码示例。如果您正苦于以下问题:C++ Protocol::_sendData方法的具体用法?C++ Protocol::_sendData怎么用?C++ Protocol::_sendData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Protocol
的用法示例。
在下文中一共展示了Protocol::_sendData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_sendData
int test_sendData(){
Protocol p;
p.state = STATE_CONNECTED;
p.seqnum = 1337;
ASSERT(p.readyForData());
std::vector<uint8_t> emptydata;
std::vector<ProtocolPacket> out = p._sendData(emptydata,5);
ASSERT(out.size() == 1);
ASSERT(out[0].seqnum == 1337);
ASSERT(p.outgoingDataPacket->seqnum == 1337);
ASSERT(p.lastSendAttempt == 5);
return 0;
}
示例2: testDataResending
int testDataResending() {
Protocol p;
p.state = STATE_CONNECTED;
p.seqnum = 1337;
p.pingInterval = 9000; // suppress any pings
ASSERT(p.readyForData() == true);
std::vector<uint8_t> emptydata;
std::vector<ProtocolPacket> out = p._sendData(emptydata,0);
ASSERT(out.size() == 1);
ASSERT(out[0].seqnum == 1337);
ASSERT(p.outgoingDataPacket);
ASSERT(p.outgoingDataPacket->seqnum == 1337);
out = p._timerEvent(p.lastSendAttempt + p.sendAttemptInterval);
ASSERT(out.size() == 0);
out = p._timerEvent(p.lastSendAttempt + p.sendAttemptInterval + 1);
ASSERT(out.size() == 1);
ASSERT(p.outgoingDataPacket->seqnum == 1337);
return 0;
}
示例3: testRecoverLost
int testRecoverLost() {
Protocol a;
Protocol b;
uint64_t t = 0;
a.listen();
std::vector<ProtocolPacket> fora = b._connect(t);
std::vector<ProtocolPacket> forb;
std::vector<ProtocolPacket> out;
std::string arecieved;
std::string brecieved;
int asentCount = 0;
int bsentCount = 0;
int loopCounter = 0;
while (loopCounter < 500000) {
t += 10;
if (asentCount < 500 && a.readyForData()) {
out = a._sendData("foo",t);
forb.insert(forb.end(),out.begin(),out.end());
asentCount += 1;
}
if (bsentCount < 1000 && b.readyForData()) {
out = b._sendData("bar",t);
fora.insert(fora.end(),out.begin(),out.end());
bsentCount += 1;
}
if (loopCounter > 10) { //start dropping packets after _connection is up
if (((loopCounter % 8) == 0) && fora.size() ) {
fora.pop_back();
}
if (((loopCounter % 7) == 0) && forb.size()){
forb.pop_back();
}
}
// drop some more packets by not accepting data arbitrarily
for (std::vector<ProtocolPacket>::iterator it = fora.begin() ; it != fora.end() ; it++ ) {
std::pair<std::vector<ProtocolPacket>,std::vector<uint8_t> > eventResult;
eventResult = a._packetEvent(*it,t,true);
out = eventResult.first;
std::string gotData(eventResult.second.begin(),eventResult.second.end());
arecieved += gotData;
forb.insert(forb.end(),out.begin(),out.end());
}
fora.clear();
for (std::vector<ProtocolPacket>::iterator it = forb.begin() ; it != forb.end() ; it++ ) {
std::pair<std::vector<ProtocolPacket>,std::vector<uint8_t> > eventResult;
eventResult = b._packetEvent(*it,t,true);
out = eventResult.first;
std::string gotData(eventResult.second.begin(),eventResult.second.end());
brecieved += gotData;
fora.insert(fora.end(),out.begin(),out.end());
}
forb.clear();
out = a._timerEvent(t);
forb.insert(forb.end(),out.begin(),out.end());
out = b._timerEvent(t);
fora.insert(fora.end(),out.begin(),out.end());
if (asentCount == 500 && bsentCount == 1000 && !a.outgoingDataPacket && !b.outgoingDataPacket) {
break;
}
loopCounter += 1;
}
ASSERT(a.state == STATE_CONNECTED);
ASSERT(b.state == STATE_CONNECTED);
ASSERT(loopCounter != 500000);
ASSERT(arecieved.size() == 1000*3);
for(int i = 0 ; i < 1000; i++){
ASSERT(arecieved.substr(i*3,3) == std::string("bar"));
}
for(int i = 0 ; i < 500; i++){
ASSERT(brecieved.substr(i*3,3) == std::string("foo"));
}
return 0;
}