From 5e0153dd0826185575242fe594dac4777874c433 Mon Sep 17 00:00:00 2001
From: James Yonan <james@openvpn.net>
Date: Mon, 27 Feb 2017 13:01:26 -0700
Subject: [PATCH] Added user code hook async_connect_post_open() to be called
 immediately after socket open in async_connect.

---
 asio/include/asio/basic_socket.hpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/asio/include/asio/basic_socket.hpp b/asio/include/asio/basic_socket.hpp
index 29986a02..000e5154 100644
--- a/asio/include/asio/basic_socket.hpp
+++ b/asio/include/asio/basic_socket.hpp
@@ -983,6 +983,8 @@ public:
     {
       const protocol_type protocol = peer_endpoint.protocol();
       impl_.get_service().open(impl_.get_implementation(), protocol, open_ec);
+      if (!open_ec)
+        async_connect_post_open(protocol, open_ec);
     }
 
     return async_initiate<ConnectToken, void (asio::error_code)>(
@@ -1841,7 +1843,7 @@ protected:
    * This function destroys the socket, cancelling any outstanding asynchronous
    * operations associated with the socket as if by calling @c cancel.
    */
-  ~basic_socket()
+  virtual ~basic_socket()
   {
   }
 
@@ -1860,6 +1862,11 @@ protected:
 #endif
 
 private:
+  // optional user code hook immediately after socket open in async_connect
+  virtual void async_connect_post_open(const protocol_type& protocol, asio::error_code& ec)
+  {
+  }
+
   // Disallow copying and assignment.
   basic_socket(const basic_socket&) ASIO_DELETED;
   basic_socket& operator=(const basic_socket&) ASIO_DELETED;
