Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructuring the SSL event handling #228

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions examples/libboostasio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <amqpcpp.h>
#include <amqpcpp/libboostasio.h>

#include <openssl/ssl.h>
#include <openssl/opensslv.h>

/**
* Main program
* @return int
Expand All @@ -32,9 +35,16 @@ int main()

// handler for libev
AMQP::LibBoostAsioHandler handler(service);


// init the SSL library
#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSL_library_init();
#else
OPENSSL_init_ssl(0, NULL);
#endif

// make a connection
AMQP::TcpConnection connection(&handler, AMQP::Address("amqp://guest:guest@localhost/"));
AMQP::TcpConnection connection(&handler, AMQP::Address("amqps://guest:guest@localhost/"));

// we need a channel too
AMQP::TcpChannel channel(&connection);
Expand All @@ -44,7 +54,6 @@ int main()

// report the name of the temporary queue
std::cout << "declared queue " << name << std::endl;

// now we can close the connection
connection.close();
});
Expand Down
5 changes: 3 additions & 2 deletions examples/libev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ int main()
#endif

// make a connection
AMQP::Address address("amqp://guest:guest@localhost/");
// AMQP::Address address("amqps://guest:guest@localhost/");
// AMQP::Address address("amqp://guest:guest@localhost/");
AMQP::Address address("amqps://guest:guest@localhost/");
AMQP::TcpConnection connection(&handler, address);


// we need a channel too
AMQP::TcpChannel channel(&connection);

Expand Down
26 changes: 17 additions & 9 deletions include/amqpcpp/libboostasio.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,15 @@ class LibBoostAsioHandler : public virtual TcpHandler
{
connection->process(fd, AMQP::readable);

_read_pending = true;

_socket.async_read_some(
boost::asio::null_buffers(),
get_read_handler(connection, fd));
// Avoid setting up too many read handlers if process already setup a read handler
if (!_read_pending)
{
_read_pending = true;

_socket.async_read_some(
boost::asio::null_buffers(),
get_read_handler(connection, fd));
}
}
}

Expand Down Expand Up @@ -226,11 +230,15 @@ class LibBoostAsioHandler : public virtual TcpHandler
{
connection->process(fd, AMQP::writable);

_write_pending = true;
// Avoid setting up too many write handlers if process() already setup a write handler
if (!_write_pending)
{
_write_pending = true;

_socket.async_write_some(
boost::asio::null_buffers(),
get_write_handler(connection, fd));
_socket.async_write_some(
boost::asio::null_buffers(),
get_write_handler(connection, fd));
}
}
}

Expand Down
Loading