chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.85k stars 1.2k forks source link

Request: Add abort() function to TCP sockets. #516

Open TheStormN opened 4 years ago

TheStormN commented 4 years ago

Hello,

It would be really nice if there is a way to abort a TCP connection(RST). Currently by directly calling close() we get a different behavior on different platforms.

By having abort() functionality we can quickly terminate a connection that appear in a good state but the software detected that it is broken, for example by timeouts or garbage data due to an error in the other party. In such situations aborting the connection is the best thing you can do.

I can also propose a solution(as a workflow). The most cross-platform way to abort a connection is the following:

  1. Set the socket to blocking mode(if not already in that mode).
  2. Enable linger with zero timeout.
  3. Call platform close/closesocket function.

If such functionality is welcome, I can even do the effort to implement it myself and create a PR, so please give your feedback! :)

TheStormN commented 3 years ago

@chriskohlhoff What do you think? If such a functionality would be accepted I will gladly make a PR with the necessary changes.