本文整理汇总了C++中OutputBuffer::switch_to_read方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputBuffer::switch_to_read方法的具体用法?C++ OutputBuffer::switch_to_read怎么用?C++ OutputBuffer::switch_to_read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputBuffer
的用法示例。
在下文中一共展示了OutputBuffer::switch_to_read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
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
// clock_t t = clock();
///mybuffer.record_start(seq, clock());
cout << "Sending data packet " << seq << endl;
/*
cout << "print out payload" <<endl;
int p_size = strlen(res_pkt.payload);
if(p_size >1024)
p_size = 1024;
for (int i = 0; i<p_size; i++) {
cout << res_pkt.payload[i];
}
cout << endl;
*/
res_pkt.m_flags = htons(0x0);
if(sendto(sockfd, &res_pkt, sizeof(res_pkt), 0, (struct sockaddr*) &clientAddr, clilen)<0)
{
cerr << "Sendto fails" << endl;
return 1;
}
if(mybuffer.switch_to_read())
{
cout << "SWITCH TO READ STATE" <<endl;
FD_CLR(fd, &writeFds);
FD_SET(fd, &readFds);
}
break;
}
case SENT_FIN:
{
uint16_t seq = mybuffer.retcumulative();
res_pkt.m_seq = htons(seq);
//res_pkt.m_window = htons(getWindowSize());
res_pkt.m_ack = htons(0);
res_pkt.m_flags = htons(FIN);
cout << "Sending FIN packet " << seq << endl;
if(sendto(sockfd, &res_pkt, sizeof(res_pkt), 0, (struct sockaddr*) &clientAddr, clilen)<0)
{
cerr << "Sendto fails" << endl;
return 1;
}
FD_CLR(fd, &writeFds);
FD_SET(fd, &readFds);
break;
}
}
}
}
}
}
close(sockfd);
}