fix bug: error about missing openssl was also reported when not even opening a secure connection

This commit is contained in:
Emiel Bruijntjes 2018-03-08 10:44:42 +01:00
parent 9a08c64ff7
commit cea5a54487
3 changed files with 16 additions and 12 deletions

View File

@ -66,20 +66,30 @@ int main()
MyHandler handler(loop);
// init the SSL library
SSL_library_init();
// SSL_library_init();
// make a connection
AMQP::Address address("amqps://guest:guest@localhost/");
AMQP::Address address("amqp://guest:guest@localhost/");
AMQP::TcpConnection connection(&handler, address);
// we need a channel too
AMQP::TcpChannel channel(&connection);
// create a temporary queue
channel.declareQueue(AMQP::exclusive).onSuccess([&connection](const std::string &name, uint32_t messagecount, uint32_t consumercount) {
channel.declareQueue(AMQP::exclusive).onSuccess([&connection, &channel](const std::string &name, uint32_t messagecount, uint32_t consumercount) {
// report the name of the temporary queue
std::cout << "declared queue " << name << std::endl;
// close the channel
channel.close().onSuccess([&connection, &channel]() {
// report that channel was closed
std::cout << "channel closed" << std::endl;
// close the connection
connection.close();
});
});
// run the loop

View File

@ -25,7 +25,7 @@ namespace AMQP {
* @param hostname The address to connect to
*/
TcpConnection::TcpConnection(TcpHandler *handler, const Address &address) :
// _state(new TcpResolver(this, address.hostname(), address.port(), address.secure(), handler)),
_state(new TcpResolver(this, address.hostname(), address.port(), address.secure(), handler)),
_connection(this, address.login(), address.vhost()) {}
/**
@ -133,14 +133,8 @@ void TcpConnection::onHeartbeat(Connection *connection)
*/
void TcpConnection::onError(Connection *connection, const char *message)
{
// current object is going to be removed, but we have to keep it for a while
auto ptr = std::move(_state);
// object is now in a closed state
//_state.reset(new TcpClosed(ptr.get()));
// tell the implementation to report the error
ptr->reportError(message);
_state->reportError(message);
}
/**

View File

@ -93,7 +93,7 @@ private:
try
{
// check if we support openssl in the first place
if (!OpenSSL::valid()) throw std::runtime_error("Secure connection cannot be established: libssl.so cannot be loaded");
if (_secure && !OpenSSL::valid()) throw std::runtime_error("Secure connection cannot be established: libssl.so cannot be loaded");
// get address info
AddressInfo addresses(_hostname.data(), _port);