44
55#include < boost/asio/post.hpp>
66
7- #include < iostream>
8-
97namespace launchdarkly ::network {
108std::shared_ptr<CurlMultiManager> CurlMultiManager::create (
119 boost::asio::any_io_executor executor) {
@@ -49,7 +47,8 @@ CurlMultiManager::~CurlMultiManager() {
4947void CurlMultiManager::add_handle (const std::shared_ptr<CURL>& easy,
5048 curl_slist* headers,
5149 CompletionCallback callback,
52- std::optional<std::chrono::milliseconds> read_timeout) {
50+ std::optional<std::chrono::milliseconds>
51+ read_timeout) {
5352 if (const CURLMcode rc = curl_multi_add_handle (
5453 multi_handle_.get (), easy.get ());
5554 rc != CURLM_OK) {
@@ -58,8 +57,6 @@ void CurlMultiManager::add_handle(const std::shared_ptr<CURL>& easy,
5857 curl_slist_free_all (headers);
5958 }
6059
61- std::cerr << " Failed to add handle to multi: "
62- << curl_multi_strerror (rc) << std::endl;
6360 return ;
6461 }
6562
@@ -72,19 +69,21 @@ void CurlMultiManager::add_handle(const std::shared_ptr<CURL>& easy,
7269 // Setup read timeout timer if specified
7370 if (read_timeout) {
7471 auto timer = std::make_shared<boost::asio::steady_timer>(executor_);
75- handle_timeouts_[easy.get ()] = HandleTimeoutInfo{read_timeout, timer};
72+ handle_timeouts_[easy.get ()] = HandleTimeoutInfo{
73+ read_timeout, timer};
7674
7775 // Start the timeout timer
7876 timer->expires_after (*read_timeout);
7977 auto weak_self = weak_from_this ();
8078 CURL* easy_ptr = easy.get ();
81- timer->async_wait ([weak_self, easy_ptr](const boost::system::error_code& ec) {
82- if (!ec) {
83- if (auto self = weak_self.lock ()) {
84- self->handle_read_timeout (easy_ptr);
79+ timer->async_wait (
80+ [weak_self, easy_ptr](const boost::system::error_code& ec) {
81+ if (!ec) {
82+ if (auto self = weak_self.lock ()) {
83+ self->handle_read_timeout (easy_ptr);
84+ }
8585 }
86- }
87- });
86+ });
8887 }
8988 }
9089}
@@ -153,14 +152,11 @@ int CurlMultiManager::timer_callback(CURLM* multi,
153152void CurlMultiManager::handle_socket_action (curl_socket_t s,
154153 const int event_bitmask) {
155154 int running_handles = 0 ;
156- const CURLMcode rc = curl_multi_socket_action (multi_handle_.get (), s,
157- event_bitmask,
158- &running_handles);
159-
160- if (rc != CURLM_OK) {
161- std::cerr << " curl_multi_socket_action failed: "
162- << curl_multi_strerror (rc) << std::endl;
163- }
155+ // This can return an error code, but checking the multi_info will be
156+ // sufficient without additional handling for this error code.
157+ curl_multi_socket_action (multi_handle_.get (), s,
158+ event_bitmask,
159+ &running_handles);
164160
165161 check_multi_info ();
166162
@@ -191,7 +187,6 @@ void CurlMultiManager::check_multi_info() {
191187 callback = std::move (it->second );
192188 callbacks_.erase (it);
193189 }
194- callbacks_.erase (easy);
195190
196191 // Get and remove headers
197192 if (auto header_it = headers_.find (easy);
@@ -226,7 +221,8 @@ void CurlMultiManager::check_multi_info() {
226221 if (callback) {
227222 boost::asio::post (executor_, [callback = std::move (callback),
228223 result, handle]() {
229- callback (handle, Result::FromCurlCode (result));
224+ callback (
225+ handle, Result::FromCurlCode (result));
230226 });
231227 }
232228 }
@@ -247,8 +243,6 @@ void CurlMultiManager::start_socket_monitor(SocketInfo* socket_info,
247243 socket_info->sockfd , ec);
248244
249245 if (ec) {
250- std::cerr << " Failed to assign socket: " << ec.message () <<
251- std::endl;
252246 socket_info->handle .reset ();
253247 return ;
254248 }
@@ -368,13 +362,14 @@ void CurlMultiManager::reset_read_timeout(CURL* easy) {
368362
369363 auto weak_self = weak_from_this ();
370364 CURL* easy_ptr = easy;
371- timeout_info.timer ->async_wait ([weak_self, easy_ptr](const boost::system::error_code& ec) {
372- if (!ec) {
373- if (auto self = weak_self.lock ()) {
374- self->handle_read_timeout (easy_ptr);
365+ timeout_info.timer ->async_wait (
366+ [weak_self, easy_ptr](const boost::system::error_code& ec) {
367+ if (!ec) {
368+ if (auto self = weak_self.lock ()) {
369+ self->handle_read_timeout (easy_ptr);
370+ }
375371 }
376- }
377- });
372+ });
378373 }
379374}
380375
@@ -389,7 +384,7 @@ void CurlMultiManager::handle_read_timeout(CURL* easy) {
389384 // Check if handle still exists
390385 auto it = callbacks_.find (easy);
391386 if (it == callbacks_.end ()) {
392- return ; // Handle already completed
387+ return ; // Handle already completed
393388 }
394389
395390 // Get and remove callback
@@ -429,9 +424,9 @@ void CurlMultiManager::handle_read_timeout(CURL* easy) {
429424 // Invoke completion callback with read timeout result
430425 if (callback) {
431426 boost::asio::post (executor_, [callback = std::move (callback),
432- handle]() {
433- callback (handle, Result::FromReadTimeout ());
434- });
427+ handle]() {
428+ callback (handle, Result::FromReadTimeout ());
429+ });
435430 }
436431}
437432} // namespace launchdarkly::network
0 commit comments