How to check the capacity of a TCP send buffer to ensure data delivery

前端 未结 2 773
耶瑟儿~
耶瑟儿~ 2021-01-07 14:48

I would like to add delivery confirmation to my TCP interface. A non-blocking write could populate the send buffer, but the data might never arrive if the connection fails

2条回答
  •  心在旅途
    2021-01-07 15:44

    Actually acking stuff at application level is the only way. Here are a few issues:

    • When you send data, even if it leaves your kernel it's not done until your TCP receives an ACK about it. The API doesn't provide you with this information.

    • The fact that your application received an ACK can mean:

      • The remote kernel (not the application) received the data. There's no telling if the remote process called recv. Maybe it crashes before getting a chance to recv.
      • Some proxy (MANY cheap devices do this) is talking to you and is using a separate connection with the true receiver. You received the ACK but you don't know if the remote system has it. And if the remote system has it, read the bullet above.

    In conclusion:

    • You don't have access to TCP ACKs
    • Even if you would have acess to them, they would be useless

    So you need an application-level ACK, but of course without retransmissions. The ACK should merely tell you "I received and processed your data".

    EDIT

    I see you persevere in your idea. Go look for SIOCOUTQ as described in a few Linux manual pages. Of course it's Linux-onlye, but see if it does what you need.

提交回复
热议问题