本文整理汇总了C++中OutputBuffer::setup方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputBuffer::setup方法的具体用法?C++ OutputBuffer::setup怎么用?C++ OutputBuffer::setup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputBuffer
的用法示例。
在下文中一共展示了OutputBuffer::setup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
// Check for correct number of arguments
if(argc != 3)
{
cerr << "Invalid number of arguments"<<std::endl;
return 1;
}
// set up UDP socket, including BINDING hints, IP, and port number
int sockfd;
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("Can't create socket");
exit(-1);
}
int maxSockfd = sockfd;
char serverIP[20];
struct addrinfo hints;
struct addrinfo* res;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET; // IPv4
hints.ai_socktype = SOCK_DGRAM;
int portno = atoi(argv[1]);
cout << "port number is " << portno<<endl;
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(portno); // short, network byte order
addr.sin_addr.s_addr = inet_addr("10.0.0.1");
memset(addr.sin_zero, '\0', sizeof(addr.sin_zero));
if (bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
perror("bind");
return 2;
}
HeaderPacket req_pkt_syn;
struct sockaddr_in clientAddr;
socklen_t clilen = sizeof(clientAddr);
OutputBuffer mybuffer;
mybuffer.setup();
uint16_t state = NO_CONNECTION;
if(recvfrom(sockfd, &req_pkt_syn, sizeof(req_pkt_syn), 0, (struct sockaddr*) &clientAddr, (socklen_t*) &clilen) < 0)
{
cerr << "recvfrom failed" << endl;
return 1;
}
else
{
if(ntohs(req_pkt_syn.m_flags) != SYN)
{
cerr << "Received a packet that's not SYN, cannot set up connection" <<endl;
return 1;
}
uint16_t initseq = genRandom();
// sending out SYNACK packet
HeaderPacket resp_pkt_synack;
resp_pkt_synack.m_seq = htons(initseq);
resp_pkt_synack.m_ack = htons(0); //server does not need to ack with anything
resp_pkt_synack.m_flags = htons(SYNACK); //SYNACK flag
//resp_pkt_synack.m_window = htons(RECV_WINDOW);
if(sendto(sockfd, &resp_pkt_synack, sizeof(resp_pkt_synack), 0, (struct sockaddr*) &clientAddr, clilen)<0)
{
cerr << "Sendto fails" << endl;
return 1;
}
state = SYNACK_SENT;
}
fd_set readFds;
fd_set writeFds;
fd_set errFds;
fd_set watchFds;
FD_ZERO(&readFds);
FD_ZERO(&writeFds);
FD_ZERO(&errFds);
FD_ZERO(&watchFds);
FileReader myreader;
myreader.openfile(argv[2]);
bool finish = false;
double sRTT = 3;
double devRtt = 3;
struct timeval tv;
if(!FD_ISSET(sockfd, &readFds))
FD_SET(sockfd, &readFds);
//.........这里部分代码省略.........