@@ -30,8 +30,10 @@ void PerfdataWriterConnection::Send(boost::asio::const_buffer data)
3030
3131 IoEngine::SpawnCoroutine (
3232 m_Strand, [&, keepAlive = PerfdataWriterConnection::Ptr (this )](boost::asio::yield_context yc) {
33+ Log (LogDebug, " PerfdataWriterConnection" ) << " Send()::1" ;
3334 try {
3435 EnsureConnected (yc);
36+ Log (LogDebug, " PerfdataWriterConnection" ) << " Send()::2" ;
3537
3638 std::visit (
3739 [&](auto & stream) {
@@ -40,9 +42,11 @@ void PerfdataWriterConnection::Send(boost::asio::const_buffer data)
4042 },
4143 m_Stream
4244 );
45+ Log (LogDebug, " PerfdataWriterConnection" ) << " Send()::3" ;
4346
4447 promise.set_value ();
4548 } catch (const std::exception&) {
49+ Log (LogDebug, " PerfdataWriterConnection" ) << " Send()::E" ;
4650 promise.set_exception (std::current_exception ());
4751 }
4852 }
@@ -99,6 +103,7 @@ void PerfdataWriterConnection::StartDisconnectTimeout(std::chrono::milliseconds
99103 IoEngine::SpawnCoroutine (
100104 m_Strand, [&, timeout, keepAlive = PerfdataWriterConnection::Ptr (this )](boost::asio::yield_context yc) {
101105 try {
106+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::1" ;
102107 // Is this even needed?
103108 if (m_State == State::stopped) {
104109 return ;
@@ -108,9 +113,11 @@ void PerfdataWriterConnection::StartDisconnectTimeout(std::chrono::milliseconds
108113 m_State = State::stopped;
109114 }
110115
116+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::2" ;
111117 m_DisconnectTimer.expires_after (timeout);
112118 m_DisconnectTimer.async_wait (yc);
113119
120+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::3" ;
114121 /* There may be ongoing connect or disconnect events, in which case
115122 * we will want to wait until those are complete and we're in a defined
116123 * state again.
@@ -119,18 +126,26 @@ void PerfdataWriterConnection::StartDisconnectTimeout(std::chrono::milliseconds
119126 * connection idles after SSL handshake has started (or before).
120127 */
121128 while (m_State == State::connecting || m_State == State::disconnecting) {
129+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::3.1" ;
130+ std::visit ([](auto & stream) { stream->lowest_layer ().cancel (); }, m_Stream);
122131 m_DisconnectTimer.expires_after (10ms);
123132 m_DisconnectTimer.async_wait (yc);
124133 }
125134
135+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::4" ;
136+
126137 m_State = State::stopped;
127138 std::visit ([](auto & stream) { stream->lowest_layer ().cancel (); }, m_Stream);
128139
140+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::5" ;
129141 // Yield to give the other coroutine a chance to throw.
130142 boost::asio::post (yc);
131143
144+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::6" ;
132145 if (m_State == State::connected) {
146+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::6.1" ;
133147 Disconnect (yc);
148+ Log (LogDebug, " PerfdataWriterConnection" ) << " StartDisconnectTimeout()::6.2" ;
134149 }
135150 } catch (const std::exception& ex) {
136151 Log (LogCritical, " PerfdataWriterConnection" ) << " Ex during disconnect timeout: " << ex.what ();
@@ -154,7 +169,9 @@ PerfdataWriterConnection::Stream PerfdataWriterConnection::ResetStream()
154169void PerfdataWriterConnection::EnsureConnected (boost::asio::yield_context yc)
155170{
156171 while (m_State != State::connected) {
172+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::1" ;
157173 if (m_State == State::stopped) {
174+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::1.1" ;
158175 const boost::system::error_code ec{
159176 boost::system::errc::operation_canceled, boost::system::system_category ()
160177 };
@@ -164,26 +181,34 @@ void PerfdataWriterConnection::EnsureConnected(boost::asio::yield_context yc)
164181 m_State = State::connecting;
165182
166183 try {
184+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::2" ;
167185 std::visit (
168186 [&](auto & stream) {
187+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::3" ;
169188 ::Connect (stream->lowest_layer (), m_Host, m_Port, yc);
170-
189+ Log (LogDebug, " PerfdataWriterConnection " ) << "EnsureConnected()::4";
171190 if constexpr (std::is_same_v<std::decay_t <decltype (stream)>, TlsStream>) {
191+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::4.1" ;
172192 using type = boost::asio::ssl::stream_base::handshake_type;
173193
174194 stream->next_layer ().async_handshake (type::client, yc);
195+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::4.2" ;
175196
176197 if (m_VerifySecure && !stream->next_layer ().IsVerifyOK ()) {
177198 BOOST_THROW_EXCEPTION (std::runtime_error{" TLS certificate validation failed" });
199+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::4.2.1" ;
178200 }
179201 }
180202 },
181203 m_Stream
182204 );
183205
184206 m_State = State::connected;
207+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::5" ;
185208 } catch (const std::exception& ex) {
209+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::E: " << ex.what ();
186210 if (m_State == State::connecting) {
211+ Log (LogDebug, " PerfdataWriterConnection" ) << " EnsureConnected()::E.1" ;
187212 if (const auto * se = dynamic_cast <const boost::system::system_error*>(&ex);
188213 se->code () == boost::system::errc::operation_canceled) {
189214
@@ -206,6 +231,7 @@ void PerfdataWriterConnection::EnsureConnected(boost::asio::yield_context yc)
206231void PerfdataWriterConnection::Disconnect (boost::asio::yield_context yc)
207232{
208233 if (m_State == State::connected) {
234+ Log (LogDebug, " PerfdataWriterConnection" ) << " disconnecting" ;
209235 m_State = State::disconnecting;
210236
211237 if (std::holds_alternative<Shared<AsioTlsStream>::Ptr>(m_Stream)) {
0 commit comments