本文整理汇总了C++中OutputBuffer::switch_to_write方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputBuffer::switch_to_write方法的具体用法?C++ OutputBuffer::switch_to_write怎么用?C++ OutputBuffer::switch_to_write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputBuffer
的用法示例。
在下文中一共展示了OutputBuffer::switch_to_write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
{
cout << "Receiving ACK packet "<< ntohs(req_pkt.m_ack)<<endl;
mybuffer.ack(ntohs(req_pkt.m_ack));
/*
clock_t end = clock();
//reset the timeout
double sampleRTT = mybuffer.get_duration(ntohs(req_pkt.m_ack), end);
//now update the waiting time
double difference = sampleRTT - sRTT;
sRTT = sRTT + 0.125 * (difference);
devRtt = devRtt + 0.25 * (abs(difference) - devRtt);
double ret_to = sRTT + 4* devRtt;
double intpart, fracpart;
fracpart = modf(ret_to, &intpart);
tv.tv_sec = (time_t) intpart;
tv.tv_usec = (time_t) 1000000*fracpart;
*/
while(myreader.hasMore() && mybuffer.hasSpace(strlen(myreader.top().payload)))
{
cout << "let's do some insert" <<endl;
mybuffer.insert(myreader.top());
myreader.pop();
}
if(!mybuffer.hasNext())
{
cout <<"change state to finish"<<endl;
state = SENT_FIN;
}
//don't do write until you ack all the packets you just sent out
if(mybuffer.switch_to_write())
{
cout << "SWITCH TO WRITE STATE " <<endl;
FD_CLR(fd, &readFds);
FD_SET(fd, &writeFds);
}
break;
}
case FINACK:
{
cout << "Receiving FINACK packet "<< ntohs(req_pkt.m_ack)<<endl;
finish = true;
FD_CLR(fd, &readFds);
break;
}
default:
break;
}
}
}
else if(FD_ISSET(fd, &writeFds)) // writing, sendto cases
{
cout <<"Do some write" <<endl;
HeaderPacket res_pkt;
switch(state)
{
case CONNECTED:
{
uint16_t seq = mybuffer.getNextSeqNo();
res_pkt = mybuffer.getPkt(seq); // initial sequence number