Is there a way to flush a POSIX socket?

后端 未结 8 1210
误落风尘
误落风尘 2020-11-30 04:20

Is there a standard call for flushing the transmit side of a POSIX socket all the way through to the remote end or does this need to be implemented as part of the user level

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 05:10

    You could set the tcp option SO_LINGER to set a certain timeout and then close the socket in order to make sure all data has been sent (or detect failure to do so) upon the closeing of a connection. Other than that, TCP is a "best effort" protocol, and it doesn't provide any real guarantees that data will ever actually reach the destination (in contrast to what some seems to believe), it just tries it best to get it delivered in correct order and as soon as possible.

提交回复
热议问题