From 0f022fce389543404f86824ed6c5720d2502cd09 Mon Sep 17 00:00:00 2001 From: Michael Steinert Date: Fri, 8 Jun 2012 15:38:22 -0600 Subject: Propose new socket API The general idea is to have a non-instantiable socket base class. Connection-specific sub-classes provide a constructor and methods for modifying connection parameters. `amqp_socket_close()` is the destructor. Signed-off-by: Michael Steinert --- examples/amqps_listen.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'examples/amqps_listen.c') diff --git a/examples/amqps_listen.c b/examples/amqps_listen.c index 306bbaa..c6344bd 100644 --- a/examples/amqps_listen.c +++ b/examples/amqps_listen.c @@ -35,7 +35,7 @@ #include #include -#include +#include #include #include @@ -44,11 +44,10 @@ int main(int argc, char const * const *argv) { char const *hostname; - int port; + int port, status; char const *exchange; char const *bindingkey; - - int sockfd; + amqp_socket_t *socket; amqp_connection_state_t conn; amqp_bytes_t queuename; @@ -66,11 +65,31 @@ int main(int argc, char const * const *argv) { conn = amqp_new_connection(); - die_on_error(sockfd = amqp_open_ssl_socket(conn, hostname, port, - argc > 5 ? argv[5] : NULL, - argc > 7 ? argv[6] : NULL, - argc > 7 ? argv[7] : NULL), - "Opening socket"); + socket = amqp_ssl_socket_new(); + if (!socket) { + die("creating SSL/TLS socket"); + } + + if (argc > 5) { + status = amqp_ssl_socket_set_cacert(socket, argv[5]); + if (status) { + die("setting CA certificate"); + } + } + + if (argc > 7) { + status = amqp_ssl_socket_set_key(socket, argv[6], argv[7]); + if (status) { + die("setting client key/cert"); + } + } + + status = amqp_socket_open(socket, hostname, port); + if (status) { + die("opening SSL/TLS connection"); + } + + amqp_set_socket(conn, socket); die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), "Logging in"); amqp_channel_open(conn, 1); -- cgit v1.2.1