本文整理汇总了C++中OutputBuffer::getPkt方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputBuffer::getPkt方法的具体用法?C++ OutputBuffer::getPkt怎么用?C++ OutputBuffer::getPkt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputBuffer
的用法示例。
在下文中一共展示了OutputBuffer::getPkt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
return 1;
}
FD_SET(sockfd, &readFds);
}
else if (state == SENT_FIN)
{
HeaderPacket resp_pkt_fin;
resp_pkt_fin.m_seq = htons(mybuffer.getNextSeqNo());
resp_pkt_fin.m_flags = htons(FIN); //FIN flag
resp_pkt_fin.m_ack = htons(0);
//resp_pkt_fin.m_window = htons(mybuffer.getWindowSize());
if(sendto(sockfd, &resp_pkt_fin, sizeof(resp_pkt_fin), 0, (struct sockaddr*) &clientAddr, clilen)<0)
{
cerr << "Sendto fails" << endl;
return 1;
}
FD_SET(sockfd, &readFds);
}
else if (state == CONNECTED)
{
if(mybuffer.timeout())
{
FD_CLR(sockfd, &readFds);
//close after several retrials
close(sockfd);
break;
}
else
{
myreader.truncate(mybuffer.window_size());
uint16_t seq = mybuffer.retcumulative();
HeaderPacket res_pkt = mybuffer.getPkt(seq);
res_pkt.m_seq = htons(seq);
res_pkt.m_flags = htons(0x0);
cout << "Sending data packet " << seq << " retransmit " <<endl;
if(sendto(sockfd, &res_pkt, sizeof(res_pkt), 0, (struct sockaddr*) &clientAddr, clilen)<0)
{
cerr << "Sendto fails" << endl;
return 1;
}
FD_SET(sockfd, &readFds);
}
}
}
else
{
for(int fd = 0; fd <= maxSockfd; fd++){
if (FD_ISSET(fd, &readFds)) // reading, recvfrom cases
{
HeaderPacket req_pkt;
if(recvfrom(fd, &req_pkt, sizeof(req_pkt), 0, (struct sockaddr*) &clientAddr, (socklen_t*) &clilen) < 0)
{
cerr << "recvfrom failed" << endl;
return 1;
}
else
{
switch(ntohs(req_pkt.m_flags))
{
case SYNACK:
{
cout << "Receiveing SYNACK packet "<< ntohs(req_pkt.m_ack)<<endl;
mybuffer.setInitSeq(ntohs(req_pkt.m_ack));
if(myreader.hasMore())