...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
After you close a connection or an error has occurred, and if its underlying
Stream
supports it, you can re-open an existing connection. This is the case for
tcp_connection
and unix_connection
.
![]() |
Warning |
---|---|
Unfortunately, |
If you are using tcp_connection
or unix_connection
,
or any other stream supporting reconnection:
connection::close
,
you can re-open the connection later by calling connection::connect
normally, even if the close operation failed.
connection::connect
operation failed, you can try opening it again by simply calling connection::connect
again.
connection::close
first, and then try opening the connection again by calling connection::connect
.
If your Stream
type doesn't
fulfill the SocketStream
type requirements, then you can't use connection::connect
or connection::close
,
and you are thus responsible for establishing the physical connection and closing
the underlying stream, if necessary. Some guidelines:
connection::quit
,
you should close the underlying stream, if required. You should then re-establish
the physical connection on the stream, and call connection::handshake
afterwards.
connection::handshake
operation failed, you are responsible for closing the underlying stream
if required. You should then establish the physical connection again, and
then call connection::handshake
.
connection::quit
first, then close and re-open the physical connection, and finally call
connection::handshake
.
Note that Boost.MySQL does not perform any built-in retry strategy, as different use cases have different requirements. You can implement it as you best like with these tools. If you implemented your own and you would like to contribute it, please create a PR in the GitHub repository.