I am trying to implement an HTTP client using asio
(the standalone version of boost::asio
) for educational purposes. My problem is with keep-alives (at the HTTP level). If the server still has the socket open, I want to just send data over it. If the server already closed it's end, I need to first call connect()
. I tried just writing to the socket and if it comes back with an error then reconnecting, but even if the server already closed it's end, the write still comes back fine (i.e. no error), effectively losing data. How can I determine if the connection is still open on the server, or at least if the write really succeeded?
Asked
Active
Viewed 455 times
0

Baruch
- 20,590
- 28
- 126
- 201
-
Possibly duplicate of http://stackoverflow.com/questions/9920370/how-to-check-if-a-socket-connection-is-live-in-boostasio – roalz Feb 16 '17 at 16:04
-
Off-topic: is your HTTP client project available somewhere? Is it closed or open source? – roalz Feb 16 '17 at 16:16
-
I'm not sure I would recommend `asio` for this. I find that it creates more problems than it solves. – MSalters Feb 16 '17 at 16:48
-
@MSalters why do you say so? – Abhinav Gauniyal Feb 16 '17 at 18:18
-
@AbhinavGauniyal: Because I'm maintaining such a HTTP client, and it has multiple comments about workarounds and hacks needed. And I have multiple bugs in the backlog that will require even more hacks. – MSalters Feb 17 '17 at 10:49
-
@roalz It is here: https://bitbucket.org/BMB/mini-server I am happy to share it, but I don't know how much use it will be. – Baruch Feb 23 '17 at 15:36