recvfrom函数使用MSG_PEEK参数,导致2次FD_READ事件?

C++实习生 2012-04-17 03:59:53
例子:
int ret 
=recvfrom(s,BUFF,LEN,MSG_PEEK,(SOCKADDR*)&addr,&addrLen);//这里会触发一个FD_READ事件

ret =recvfrom(s,BUFF,LEN,0,(SOCKADDR*)&addr,&addrLen);


导致2次读取数据
请问如何判断或者进行处理?
...全文
225 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2012-04-18
  • 打赏
  • 举报
回复
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.
向立天 2012-04-18
  • 打赏
  • 举报
回复
FD_READ是自动触发
你不需要自行处理
fishion 2012-04-18
  • 打赏
  • 举报
回复
FD_READ应该不是你来触发的,是当套节字可读的时候触发的。触发时你调用两次 recvfrom也没问题,不会触发FD_READ的

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧