@@ -301,7 +301,14 @@ void server<endpoint>::start_listen(const boost::asio::ip::tcp::endpoint& e,size
301
301
302
302
if (num_threads == 0 )
303
303
{
304
- m_endpoint.run_internal ();
304
+ for (;;) {
305
+ try {
306
+ m_endpoint.run_internal ();
307
+ break ;
308
+ } catch (const std::exception & e) { // Don't let an exception trash the endpoint DJS
309
+ m_endpoint.elog ().at (log::elevel::RERROR) << " run_internal exception: " << e.what () << log::endl;
310
+ }
311
+ }
305
312
m_state = IDLE;
306
313
}
307
314
}
@@ -382,35 +389,43 @@ void server<endpoint>::handle_accept(connection_ptr con,
382
389
const boost::system::error_code& error)
383
390
{
384
391
boost::lock_guard<boost::recursive_mutex> lock (m_endpoint.m_lock );
385
-
386
- if (error) {
387
- con->m_fail_code = fail::status::SYSTEM;
388
- con->m_fail_system = error;
389
-
390
- if (error == boost::system::errc::too_many_files_open) {
391
- con->m_fail_reason = " too many files open" ;
392
-
393
- // TODO: make this configurable
394
- // m_timer.expires_from_now(boost::posix_time::milliseconds(1000));
395
- // m_timer.async_wait(boost::bind(&type::start_accept,this));
396
- } else if (error == boost::asio::error::operation_aborted) {
397
- con->m_fail_reason = " io_service operation canceled" ;
398
-
399
- // the operation was canceled. This was probably due to the
400
- // io_service being stopped.
401
- } else {
402
- con->m_fail_reason = " unknown" ;
403
- }
404
-
405
- m_endpoint.m_elog ->at (log::elevel::RERROR)
406
- << " async_accept returned error: " << error
407
- << " (" << con->m_fail_reason << " )" << log::endl;
408
-
409
- con->terminate (false );
410
- } else {
411
- con->start ();
412
- }
413
-
392
+
393
+ try
394
+ {
395
+ if (error) {
396
+ con->m_fail_code = fail::status::SYSTEM;
397
+ con->m_fail_system = error;
398
+
399
+ if (error == boost::system::errc::too_many_files_open) {
400
+ con->m_fail_reason = " too many files open" ;
401
+
402
+ // TODO: make this configurable
403
+ // m_timer.expires_from_now(boost::posix_time::milliseconds(1000));
404
+ // m_timer.async_wait(boost::bind(&type::start_accept,this));
405
+ } else if (error == boost::asio::error::operation_aborted) {
406
+ con->m_fail_reason = " io_service operation canceled" ;
407
+
408
+ // the operation was canceled. This was probably due to the
409
+ // io_service being stopped.
410
+ } else {
411
+ con->m_fail_reason = " unknown" ;
412
+ }
413
+
414
+ m_endpoint.m_elog ->at (log::elevel::RERROR)
415
+ << " async_accept returned error: " << error
416
+ << " (" << con->m_fail_reason << " )" << log::endl;
417
+
418
+ con->terminate (false );
419
+ } else {
420
+ con->start ();
421
+ }
422
+ }
423
+ catch (const std::exception & e)
424
+ { // We must call start_accept, even if we throw DJS
425
+ m_endpoint.m_elog ->at (log::elevel::RERROR)
426
+ << " handle_accept caught exception: " << e.what () << log::endl;
427
+ }
428
+
414
429
this ->start_accept ();
415
430
}
416
431
0 commit comments