[asio-users] asio and good error handling
Brought to you by:
chris_kohlhoff
From: Jeff A. <je...@p2...> - 2018-12-27 20:59:34
|
I've used asio to implement some simple tcp and udp messaging. All's well until there's an error. The asio example code mostly just quits on error, which simplifies examples but isn't great for real life: a single service bounces and everything else decides to bounce, too, as they see a broken connection. I've not found any good examples or guidelines for how to handle different errors, perhaps along the lines of "if you get the this error while reading data, then this is a good action to take". I know this isn't one size fits all, but I also know that I don't want to wait around for less common errors just to figure out what triggered them and how to handle them. Even relatively straight-forward things like connection_refused (ECONNREFUSED) can be a bit sticky: do I always want to close and shutdown the socket or are their cases where that's excessive? Maybe if I'm the client, but if I'm the server I can't reconnect, I'm accepting and talking to an ephemeral port on the client. Thanks for any pointers. ps: After getting over some initial hurdles, I've been quite impressed with asio. Many thanks to the developers. -- Jeff Abrahamson +33 6 24 40 01 57 +44 7920 594 255 https://www.p27.eu/jeff/ https://www.transport-nantes.com/ |