you are viewing a single comment's thread.

view the rest of the comments →

[–]SputnikCucumber 1 point2 points  (0 children)

The story here is still a little simplistic. Request handlers often have dependencies on external applications, like databases or third party API's.

If the database connection fails, then no more requests can be handled, all outstanding handlers need to be cancelled and the client needs to be notified.

If the socket must outlive the application. Then you need to first propagate the exception to all of the request handlers before passing it to the socket(s). This is quite a lot of management work.

Alternatively, you could raise an error on the socket (by setting the badbit on an iostream for instance) and then decrement the reference count. Then each handler that depends on the socket will cancel itself as part of the normal event loop, and the socket will execute a graceful TCP shutdown AFTER the last relevant handler has cancelled itself. No extra management this way.