int ret
=recvfrom(s,BUFF,LEN,MSG_PEEK,(SOCKADDR*)&addr,&addrLen);//这里会触发一个FD_READ事件
ret =recvfrom(s,BUFF,LEN,0,(SOCKADDR*)&addr,&addrLen);
导致2次读取数据
请问如何判断或者进行处理?
...全文
2253打赏收藏
recvfrom函数使用MSG_PEEK参数,导致2次FD_READ事件?
例子: int ret =recvfrom(s,BUFF,LEN,MSG_PEEK,(SOCKADDR*)&addr,&addrLen);//这里会触发一个FD_READ事件 ret =recvfrom(s,BUFF,LEN,0,(SOCKADDR*)&addr,&addrLen); 导致2次读取数据 请问如何判断或者进行处理?
MSG_PEEK Peeks at the incoming data. The data is copied into the buffer but is not removed from the input queue. The function subsequently returns the amount of data that can be read in a single call to the recvfrom (or recv) function, which may not be the same as the total amount of data queued on the socket. The amount of data that can actually be read in a single call to the recvfrom (or recv) function is limited to the data size written in the send or sendto function call.