@@ -182,8 +182,7 @@ void tcp_server::end_serving() {
182182 shutdown_ = true ;
183183 // issue closure of the server socket; this will result in a cancellation of the associated IO
184184 // operations
185- auto keepalive (acceptor_);
186- post (*io_, [keepalive]() { keepalive->close (); });
185+ post (*io_, [shared_acceptor = acceptor_]() { shared_acceptor->close (); });
187186 // issue closure of all active client session sockets; cancels the related outstanding IO jobs
188187 close_inflight_sockets ();
189188 // also notify any transfer threads that are blocked waiting for a sample by sending them one (=
@@ -199,9 +198,10 @@ void tcp_server::accept_next_connection() {
199198 std::shared_ptr<client_session> newsession{
200199 std::make_shared<client_session>(shared_from_this ())};
201200 // accept a connection on the session's socket
202- auto keepalive (shared_from_this ());
203- acceptor_->async_accept (*newsession->socket (),
204- [keepalive, newsession, this ](err_t err) { handle_accept_outcome (newsession, err); });
201+ acceptor_->async_accept (
202+ *newsession->socket (), [shared_this = shared_from_this (), newsession, this ](err_t err) {
203+ shared_this->handle_accept_outcome (newsession, err);
204+ });
205205 } catch (std::exception &e) {
206206 LOG_F (ERROR, " Error during tcp_server::accept_next_connection: %s" , e.what ());
207207 }
@@ -267,9 +267,10 @@ void client_session::begin_processing() {
267267 serv_->register_inflight_socket (sock_);
268268 registered_ = true ;
269269 // read the request line
270- auto keepalive (shared_from_this ());
271- async_read_until (*sock_, requestbuf_, " \r\n " ,
272- [keepalive, this ](err_t err, size_t ) { handle_read_command_outcome (err); });
270+ async_read_until (
271+ *sock_, requestbuf_, " \r\n " , [shared_this = shared_from_this ()](err_t err, size_t ) {
272+ shared_this->handle_read_command_outcome (err);
273+ });
273274 } catch (std::exception &e) {
274275 LOG_F (ERROR, " Error during client_session::begin_processing: %s" , e.what ());
275276 }
@@ -282,29 +283,31 @@ void client_session::handle_read_command_outcome(error_code err) {
282283 std::string method;
283284 getline (requeststream_, method);
284285 method = trim (method);
285- auto keepalive (shared_from_this ());
286286 if (method == " LSL:shortinfo" )
287287 // shortinfo request: read the content query string
288288 async_read_until (*sock_, requestbuf_, " \r\n " ,
289- [keepalive, this ](err_t err, std::size_t ) { handle_read_query_outcome (err); });
289+ [shared_this = shared_from_this ()](
290+ err_t err, std::size_t ) { shared_this->handle_read_query_outcome (err); });
290291 if (method == " LSL:fullinfo" )
291292 // fullinfo request: reply right away
292293 async_write (*sock_, lslboost::asio::buffer (serv_->fullinfo_msg_ ),
293- [keepalive, this ](err_t , std::size_t ) { });
294+ [shared_this = shared_from_this () ](err_t , std::size_t ) {});
294295 if (method == " LSL:streamfeed" )
295296 // streamfeed request (1.00): read feed parameters
296- async_read_until (
297- *sock_, requestbuf_, " \r\n " , [keepalive, this ](err_t err, std::size_t ) {
298- handle_read_feedparams (100 , " " , err);
297+ async_read_until (*sock_, requestbuf_, " \r\n " ,
298+ [shared_this = shared_from_this () ](err_t err, std::size_t ) {
299+ shared_this-> handle_read_feedparams (100 , " " , err);
299300 });
300301 if (method.compare (0 , 15 , " LSL:streamfeed/" ) == 0 ) {
301302 // streamfeed request with version: read feed parameters
302303 std::vector<std::string> parts = splitandtrim (method, ' ' , true );
303- int request_protocol_version = std::stoi (parts[0 ].substr (15 ));
304- std::string request_uid = (parts.size () > 1 ) ? parts[1 ] : " " ;
305- async_read_until (*sock_, requestbuf_, " \r\n\r\n " , [=](err_t err, std::size_t ) {
306- keepalive->handle_read_feedparams (request_protocol_version, request_uid, err);
307- });
304+ async_read_until (*sock_, requestbuf_, " \r\n\r\n " ,
305+ [shared_this = shared_from_this (),
306+ request_protocol_version = std::stoi (parts[0 ].substr (15 )),
307+ request_uid = (parts.size () > 1 ) ? parts[1 ] : " " ](err_t err, std::size_t ) {
308+ shared_this->handle_read_feedparams (
309+ request_protocol_version, request_uid, err);
310+ });
308311 }
309312 }
310313 } catch (std::exception &e) {
@@ -321,9 +324,8 @@ void client_session::handle_read_query_outcome(error_code err) {
321324 query = trim (query);
322325 if (serv_->info_ ->matches_query (query)) {
323326 // matches: reply (otherwise just close the stream)
324- auto keepalive (shared_from_this ());
325327 async_write (*sock_, lslboost::asio::buffer (serv_->shortinfo_msg_ ),
326- [keepalive ](err_t , std::size_t ) {
328+ [shared_this = shared_from_this () ](err_t , std::size_t ) {
327329 /* keep the client_session alive until the shortinfo is sent completely*/
328330 });
329331 } else
@@ -336,9 +338,8 @@ void client_session::handle_read_query_outcome(error_code err) {
336338
337339void client_session::send_status_message (const std::string &str) {
338340 auto msg (std::make_shared<std::string>(str));
339- auto keepalive (shared_from_this ());
340341 async_write (*sock_, lslboost::asio::buffer (*msg),
341- [msg, keepalive ](
342+ [msg, shared_this = shared_from_this () ](
342343 err_t , std::size_t ) { /* keep objects alive until the message is sent */ });
343344}
344345
@@ -487,10 +488,10 @@ void client_session::handle_read_feedparams(
487488 else
488489 *outarch_ << *temp;
489490 // send off the newly created feedheader
490- auto keepalive ( shared_from_this ());
491- async_write ( *sock_, feedbuf_.data (), [keepalive, this ](err_t err, size_t len) {
492- handle_send_feedheader_outcome (err, len);
493- });
491+ async_write (
492+ *sock_, feedbuf_.data (), [shared_this = shared_from_this () ](err_t err, size_t len) {
493+ shared_this-> handle_send_feedheader_outcome (err, len);
494+ });
494495 DLOG_F (4 , " %p sent test pattern samples" , this );
495496 }
496497 } catch (std::exception &e) {
@@ -544,10 +545,10 @@ void client_session::transfer_samples_thread(std::shared_ptr<client_session>) {
544545 // send off the chunk that we aggregated so far
545546 lslboost::unique_lock<lslboost::mutex> lock (completion_mut_);
546547 transfer_completed_ = false ;
547- auto keepalive ( shared_from_this ());
548- async_write (*sock_, feedbuf_. data (), [keepalive, this ](err_t err, size_t len) {
549- handle_chunk_transfer_outcome (err, len);
550- });
548+ async_write (*sock_, feedbuf_. data (),
549+ [shared_this = shared_from_this () ](err_t err, size_t len) {
550+ shared_this-> handle_chunk_transfer_outcome (err, len);
551+ });
551552 // wait for the completion condition
552553 completion_cond_.wait (lock, [this ]() { return transfer_completed_; });
553554 // handle transfer outcome
0 commit comments