rawsocket sendto() some of the packet are dropped and not seen in the network

▼魔方 西西 提交于 2019-12-05 19:28:31

You are correct that sendto will just put the txpacket in the queue and not guarantee delivery.

From the iEEE documentation on sendto:

Successful completion of a call to sendto() does not guarantee delivery of the message. A return value of -1 indicates only locally-detected errors.

You have to perform some of your own throttling via ioctl() and getsockopt() as you are almost doing. I don't think you can expect the network stack to do it all for you.

Something like:

sendMsgThrottled( msg Msg ) {
    ioctl(socketFd_, SIOCOUTQ, &outstandingBytes);  
    if ( outStandingBytes < limit )
          sendto(socketFd_, ..)
    else
          queueMsg();  /* Or delay */
}

I would test this with by having the send and receiver on the same machine, packet loss can come from other places besides the network layer of the operating system.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!