diff options
author | Michael Steinert <mike.steinert@gmail.com> | 2012-06-08 15:38:22 -0600 |
---|---|---|
committer | Alan Antonuk <alan.antonuk@gmail.com> | 2013-04-09 15:48:03 -0700 |
commit | 0f022fce389543404f86824ed6c5720d2502cd09 (patch) | |
tree | 6e39adb0a9268d32e6873a48723f3d84c1316e87 /examples/amqps_producer.c | |
parent | 7240f48af34aea8412473f29e93f6443f79230db (diff) | |
download | rabbitmq-c-github-ask-0f022fce389543404f86824ed6c5720d2502cd09.tar.gz |
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 <mike.steinert@gmail.com>
Diffstat (limited to 'examples/amqps_producer.c')
-rw-r--r-- | examples/amqps_producer.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/examples/amqps_producer.c b/examples/amqps_producer.c index 6e00f29..43649ad 100644 --- a/examples/amqps_producer.c +++ b/examples/amqps_producer.c @@ -35,7 +35,7 @@ #include <string.h> #include <stdint.h> -#include <amqp-ssl.h> +#include <amqp-ssl-socket.h> #include <amqp_framing.h> #include "utils.h" @@ -106,11 +106,10 @@ static void send_batch(amqp_connection_state_t conn, int main(int argc, char const * const *argv) { char const *hostname; - int port; + int port, status; int rate_limit; int message_count; - - int sockfd; + amqp_socket_t *socket; amqp_connection_state_t conn; if (argc < 5) { @@ -126,11 +125,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 SSL/TLS 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); |