diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 29 | ||||
-rw-r--r-- | examples/amqp_bind.c | 102 | ||||
-rw-r--r-- | examples/amqp_consumer.c | 189 | ||||
-rw-r--r-- | examples/amqp_exchange_declare.c | 97 | ||||
-rw-r--r-- | examples/amqp_listen.c | 189 | ||||
-rw-r--r-- | examples/amqp_listenq.c | 172 | ||||
-rw-r--r-- | examples/amqp_producer.c | 159 | ||||
-rw-r--r-- | examples/amqp_sendstring.c | 111 | ||||
-rw-r--r-- | examples/amqp_unbind.c | 102 | ||||
-rw-r--r-- | examples/unix/platform_utils.c | 69 | ||||
-rw-r--r-- | examples/utils.c | 188 | ||||
-rw-r--r-- | examples/utils.h | 62 | ||||
-rw-r--r-- | examples/windows/platform_utils.c | 66 |
13 files changed, 0 insertions, 1535 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am deleted file mode 100644 index ea10f77..0000000 --- a/examples/Makefile.am +++ /dev/null @@ -1,29 +0,0 @@ -noinst_PROGRAMS = amqp_sendstring amqp_exchange_declare amqp_listen amqp_producer amqp_consumer amqp_unbind amqp_bind amqp_listenq - -AM_CFLAGS = -I$(top_srcdir)/librabbitmq - -if GCC -# Because we want to build under Microsoft's C compiler (for which -# there is apparently no demand for C99 support), it's a good idea -# to have gcc tell us when we stray from the old standard. -AM_CFLAGS += -ansi -pedantic -endif - -if USE_MSINTTYPES -AM_CFLAGS += -I$(top_srcdir)/msinttypes -endif - -AM_LDFLAGS = $(top_builddir)/librabbitmq/librabbitmq.la - -noinst_HEADERS = utils.h - -COMMON_SOURCES = utils.c $(PLATFORM_DIR)/platform_utils.c - -amqp_sendstring_SOURCES = amqp_sendstring.c $(COMMON_SOURCES) -amqp_exchange_declare_SOURCES = amqp_exchange_declare.c $(COMMON_SOURCES) -amqp_listen_SOURCES = amqp_listen.c $(COMMON_SOURCES) -amqp_producer_SOURCES = amqp_producer.c $(COMMON_SOURCES) -amqp_consumer_SOURCES = amqp_consumer.c $(COMMON_SOURCES) -amqp_unbind_SOURCES = amqp_unbind.c $(COMMON_SOURCES) -amqp_bind_SOURCES = amqp_bind.c $(COMMON_SOURCES) -amqp_listenq_SOURCES = amqp_listenq.c $(COMMON_SOURCES) diff --git a/examples/amqp_bind.c b/examples/amqp_bind.c deleted file mode 100644 index 561b84d..0000000 --- a/examples/amqp_bind.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *bindingkey; - char const *queue; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, "Usage: amqp_bind host port exchange bindingkey queue\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - bindingkey = argv[4]; - queue = argv[5]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - amqp_queue_bind(conn, 1, - amqp_cstring_bytes(queue), - amqp_cstring_bytes(exchange), - amqp_cstring_bytes(bindingkey), - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding"); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/amqp_consumer.c b/examples/amqp_consumer.c deleted file mode 100644 index 2710643..0000000 --- a/examples/amqp_consumer.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include <assert.h> - -#include "utils.h" - -#define SUMMARY_EVERY_US 1000000 - -static void run(amqp_connection_state_t conn) -{ - uint64_t start_time = now_microseconds(); - int received = 0; - int previous_received = 0; - uint64_t previous_report_time = start_time; - uint64_t next_summary_time = start_time + SUMMARY_EVERY_US; - - amqp_frame_t frame; - int result; - size_t body_received; - size_t body_target; - - uint64_t now; - - while (1) { - now = now_microseconds(); - if (now > next_summary_time) { - int countOverInterval = received - previous_received; - double intervalRate = countOverInterval / ((now - previous_report_time) / 1000000.0); - printf("%d ms: Received %d - %d since last report (%d Hz)\n", - (int)(now - start_time) / 1000, received, countOverInterval, (int) intervalRate); - - previous_received = received; - previous_report_time = now; - next_summary_time += SUMMARY_EVERY_US; - } - - amqp_maybe_release_buffers(conn); - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - return; - - if (frame.frame_type != AMQP_FRAME_METHOD) - continue; - - if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) - continue; - - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - return; - - if (frame.frame_type != AMQP_FRAME_HEADER) { - fprintf(stderr, "Expected header!"); - abort(); - } - - body_target = frame.payload.properties.body_size; - body_received = 0; - - while (body_received < body_target) { - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - return; - - if (frame.frame_type != AMQP_FRAME_BODY) { - fprintf(stderr, "Expected body!"); - abort(); - } - - body_received += frame.payload.body_fragment.len; - assert(body_received <= body_target); - } - - received++; - } -} - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *bindingkey; - - int sockfd; - amqp_connection_state_t conn; - - amqp_bytes_t queuename; - - if (argc < 3) { - fprintf(stderr, "Usage: amqp_consumer host port\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = "amq.direct"; /* argv[3]; */ - bindingkey = "test queue"; /* argv[4]; */ - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - { - amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, amqp_empty_bytes, 0, 0, 0, 1, - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring queue"); - queuename = amqp_bytes_malloc_dup(r->queue); - if (queuename.bytes == NULL) { - fprintf(stderr, "Out of memory while copying queue name"); - return 1; - } - } - - amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey), - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Binding queue"); - - amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - run(conn); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - - return 0; -} diff --git a/examples/amqp_exchange_declare.c b/examples/amqp_exchange_declare.c deleted file mode 100644 index 9b410ca..0000000 --- a/examples/amqp_exchange_declare.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *exchangetype; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 5) { - fprintf(stderr, "Usage: amqp_exchange_declare host port exchange exchangetype\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - exchangetype = argv[4]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - amqp_exchange_declare(conn, 1, amqp_cstring_bytes(exchange), amqp_cstring_bytes(exchangetype), - 0, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring exchange"); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/amqp_listen.c b/examples/amqp_listen.c deleted file mode 100644 index 86c4555..0000000 --- a/examples/amqp_listen.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include <assert.h> - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *bindingkey; - - int sockfd; - amqp_connection_state_t conn; - - amqp_bytes_t queuename; - - if (argc < 5) { - fprintf(stderr, "Usage: amqp_listen host port exchange bindingkey\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - bindingkey = argv[4]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - { - amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, amqp_empty_bytes, 0, 0, 0, 1, - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring queue"); - queuename = amqp_bytes_malloc_dup(r->queue); - if (queuename.bytes == NULL) { - fprintf(stderr, "Out of memory while copying queue name"); - return 1; - } - } - - amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey), - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Binding queue"); - - amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - { - amqp_frame_t frame; - int result; - - amqp_basic_deliver_t *d; - amqp_basic_properties_t *p; - size_t body_target; - size_t body_received; - - while (1) { - amqp_maybe_release_buffers(conn); - result = amqp_simple_wait_frame(conn, &frame); - printf("Result %d\n", result); - if (result < 0) - break; - - printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel); - if (frame.frame_type != AMQP_FRAME_METHOD) - continue; - - printf("Method %s\n", amqp_method_name(frame.payload.method.id)); - if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) - continue; - - d = (amqp_basic_deliver_t *) frame.payload.method.decoded; - printf("Delivery %u, exchange %.*s routingkey %.*s\n", - (unsigned) d->delivery_tag, - (int) d->exchange.len, (char *) d->exchange.bytes, - (int) d->routing_key.len, (char *) d->routing_key.bytes); - - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - break; - - if (frame.frame_type != AMQP_FRAME_HEADER) { - fprintf(stderr, "Expected header!"); - abort(); - } - p = (amqp_basic_properties_t *) frame.payload.properties.decoded; - if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - printf("Content-type: %.*s\n", - (int) p->content_type.len, (char *) p->content_type.bytes); - } - printf("----\n"); - - body_target = frame.payload.properties.body_size; - body_received = 0; - - while (body_received < body_target) { - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - break; - - if (frame.frame_type != AMQP_FRAME_BODY) { - fprintf(stderr, "Expected body!"); - abort(); - } - - body_received += frame.payload.body_fragment.len; - assert(body_received <= body_target); - - amqp_dump(frame.payload.body_fragment.bytes, - frame.payload.body_fragment.len); - } - - if (body_received != body_target) { - /* Can only happen when amqp_simple_wait_frame returns <= 0 */ - /* We break here to close the connection */ - break; - } - } - } - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - - return 0; -} diff --git a/examples/amqp_listenq.c b/examples/amqp_listenq.c deleted file mode 100644 index c7c2a1e..0000000 --- a/examples/amqp_listenq.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include <assert.h> - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *queuename; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 4) { - fprintf(stderr, "Usage: amqp_listenq host port queuename\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - queuename = argv[3]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - amqp_basic_consume(conn, 1, amqp_cstring_bytes(queuename), amqp_empty_bytes, 0, 0, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - { - amqp_frame_t frame; - int result; - - amqp_basic_deliver_t *d; - amqp_basic_properties_t *p; - size_t body_target; - size_t body_received; - - while (1) { - amqp_maybe_release_buffers(conn); - result = amqp_simple_wait_frame(conn, &frame); - printf("Result %d\n", result); - if (result < 0) - break; - - printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel); - if (frame.frame_type != AMQP_FRAME_METHOD) - continue; - - printf("Method %s\n", amqp_method_name(frame.payload.method.id)); - if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) - continue; - - d = (amqp_basic_deliver_t *) frame.payload.method.decoded; - printf("Delivery %u, exchange %.*s routingkey %.*s\n", - (unsigned) d->delivery_tag, - (int) d->exchange.len, (char *) d->exchange.bytes, - (int) d->routing_key.len, (char *) d->routing_key.bytes); - - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - break; - - if (frame.frame_type != AMQP_FRAME_HEADER) { - fprintf(stderr, "Expected header!"); - abort(); - } - p = (amqp_basic_properties_t *) frame.payload.properties.decoded; - if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - printf("Content-type: %.*s\n", - (int) p->content_type.len, (char *) p->content_type.bytes); - } - printf("----\n"); - - body_target = frame.payload.properties.body_size; - body_received = 0; - - while (body_received < body_target) { - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - break; - - if (frame.frame_type != AMQP_FRAME_BODY) { - fprintf(stderr, "Expected body!"); - abort(); - } - - body_received += frame.payload.body_fragment.len; - assert(body_received <= body_target); - - amqp_dump(frame.payload.body_fragment.bytes, - frame.payload.body_fragment.len); - } - - if (body_received != body_target) { - /* Can only happen when amqp_simple_wait_frame returns <= 0 */ - /* We break here to close the connection */ - break; - } - - amqp_basic_ack(conn, 1, d->delivery_tag, 0); - } - } - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - - return 0; -} diff --git a/examples/amqp_producer.c b/examples/amqp_producer.c deleted file mode 100644 index 77c3e92..0000000 --- a/examples/amqp_producer.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include "utils.h" - -#define SUMMARY_EVERY_US 1000000 - -static void send_batch(amqp_connection_state_t conn, - char const *queue_name, - int rate_limit, - int message_count) -{ - uint64_t start_time = now_microseconds(); - int i; - int sent = 0; - int previous_sent = 0; - uint64_t previous_report_time = start_time; - uint64_t next_summary_time = start_time + SUMMARY_EVERY_US; - - char message[256]; - amqp_bytes_t message_bytes; - - for (i = 0; i < sizeof(message); i++) { - message[i] = i & 0xff; - } - - message_bytes.len = sizeof(message); - message_bytes.bytes = message; - - for (i = 0; i < message_count; i++) { - uint64_t now = now_microseconds(); - - die_on_error(amqp_basic_publish(conn, - 1, - amqp_cstring_bytes("amq.direct"), - amqp_cstring_bytes(queue_name), - 0, - 0, - NULL, - message_bytes), - "Publishing"); - sent++; - if (now > next_summary_time) { - int countOverInterval = sent - previous_sent; - double intervalRate = countOverInterval / ((now - previous_report_time) / 1000000.0); - printf("%d ms: Sent %d - %d since last report (%d Hz)\n", - (int)(now - start_time) / 1000, sent, countOverInterval, (int) intervalRate); - - previous_sent = sent; - previous_report_time = now; - next_summary_time += SUMMARY_EVERY_US; - } - - while (((i * 1000000.0) / (now - start_time)) > rate_limit) { - microsleep(2000); - now = now_microseconds(); - } - } - - { - uint64_t stop_time = now_microseconds(); - int total_delta = stop_time - start_time; - - printf("PRODUCER - Message count: %d\n", message_count); - printf("Total time, milliseconds: %d\n", total_delta / 1000); - printf("Overall messages-per-second: %g\n", (message_count / (total_delta / 1000000.0))); - } -} - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - int rate_limit; - int message_count; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 5) { - fprintf(stderr, "Usage: amqp_producer host port rate_limit message_count\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - rate_limit = atoi(argv[3]); - message_count = atoi(argv[4]); - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - send_batch(conn, "test queue", rate_limit, message_count); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/amqp_sendstring.c b/examples/amqp_sendstring.c deleted file mode 100644 index 3c94e41..0000000 --- a/examples/amqp_sendstring.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *routingkey; - char const *messagebody; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, "Usage: amqp_sendstring host port exchange routingkey messagebody\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - routingkey = argv[4]; - messagebody = argv[5]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - { - amqp_basic_properties_t props; - props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG; - props.content_type = amqp_cstring_bytes("text/plain"); - props.delivery_mode = 2; /* persistent delivery mode */ - die_on_error(amqp_basic_publish(conn, - 1, - amqp_cstring_bytes(exchange), - amqp_cstring_bytes(routingkey), - 0, - 0, - &props, - amqp_cstring_bytes(messagebody)), - "Publishing"); - } - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/amqp_unbind.c b/examples/amqp_unbind.c deleted file mode 100644 index fad3e2b..0000000 --- a/examples/amqp_unbind.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *bindingkey; - char const *queue; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, "Usage: amqp_unbind host port exchange bindingkey queue\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - bindingkey = argv[4]; - queue = argv[5]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - amqp_queue_unbind(conn, 1, - amqp_cstring_bytes(queue), - amqp_cstring_bytes(exchange), - amqp_cstring_bytes(bindingkey), - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding"); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/unix/platform_utils.c b/examples/unix/platform_utils.c deleted file mode 100644 index b039c31..0000000 --- a/examples/unix/platform_utils.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -/* For usleep */ -#define _BSD_SOURCE - -#include <stdint.h> - -#include <sys/time.h> -#include <unistd.h> - -uint64_t now_microseconds(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (uint64_t) tv.tv_sec * 1000000 + (uint64_t) tv.tv_usec; -} - -void microsleep(int usec) -{ - usleep(usec); -} diff --git a/examples/utils.c b/examples/utils.c deleted file mode 100644 index 1837be8..0000000 --- a/examples/utils.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> - -#include <stdint.h> -#include <amqp.h> -#include <amqp_framing.h> - -#include "utils.h" - -void die_on_error(int x, char const *context) { - if (x < 0) { - char *errstr = amqp_error_string(-x); - fprintf(stderr, "%s: %s\n", context, errstr); - free(errstr); - exit(1); - } -} - -void die_on_amqp_error(amqp_rpc_reply_t x, char const *context) { - switch (x.reply_type) { - case AMQP_RESPONSE_NORMAL: - return; - - case AMQP_RESPONSE_NONE: - fprintf(stderr, "%s: missing RPC reply type!\n", context); - break; - - case AMQP_RESPONSE_LIBRARY_EXCEPTION: - fprintf(stderr, "%s: %s\n", context, amqp_error_string(x.library_error)); - break; - - case AMQP_RESPONSE_SERVER_EXCEPTION: - switch (x.reply.id) { - case AMQP_CONNECTION_CLOSE_METHOD: { - amqp_connection_close_t *m = (amqp_connection_close_t *) x.reply.decoded; - fprintf(stderr, "%s: server connection error %d, message: %.*s\n", - context, - m->reply_code, - (int) m->reply_text.len, (char *) m->reply_text.bytes); - break; - } - case AMQP_CHANNEL_CLOSE_METHOD: { - amqp_channel_close_t *m = (amqp_channel_close_t *) x.reply.decoded; - fprintf(stderr, "%s: server channel error %d, message: %.*s\n", - context, - m->reply_code, - (int) m->reply_text.len, (char *) m->reply_text.bytes); - break; - } - default: - fprintf(stderr, "%s: unknown server error, method id 0x%08X\n", context, x.reply.id); - break; - } - break; - } - - exit(1); -} - -static void dump_row(long count, int numinrow, int *chs) { - int i; - - printf("%08lX:", count - numinrow); - - if (numinrow > 0) { - for (i = 0; i < numinrow; i++) { - if (i == 8) - printf(" :"); - printf(" %02X", chs[i]); - } - for (i = numinrow; i < 16; i++) { - if (i == 8) - printf(" :"); - printf(" "); - } - printf(" "); - for (i = 0; i < numinrow; i++) { - if (isprint(chs[i])) - printf("%c", chs[i]); - else - printf("."); - } - } - printf("\n"); -} - -static int rows_eq(int *a, int *b) { - int i; - - for (i=0; i<16; i++) - if (a[i] != b[i]) - return 0; - - return 1; -} - -void amqp_dump(void const *buffer, size_t len) { - unsigned char *buf = (unsigned char *) buffer; - long count = 0; - int numinrow = 0; - int chs[16]; - int oldchs[16]; - int showed_dots = 0; - int i; - - for (i = 0; i < len; i++) { - int ch = buf[i]; - - if (numinrow == 16) { - int i; - - if (rows_eq(oldchs, chs)) { - if (!showed_dots) { - showed_dots = 1; - printf(" .. .. .. .. .. .. .. .. : .. .. .. .. .. .. .. ..\n"); - } - } else { - showed_dots = 0; - dump_row(count, numinrow, chs); - } - - for (i=0; i<16; i++) - oldchs[i] = chs[i]; - - numinrow = 0; - } - - count++; - chs[numinrow++] = ch; - } - - dump_row(count, numinrow, chs); - - if (numinrow != 0) - printf("%08lX:\n", count); -} diff --git a/examples/utils.h b/examples/utils.h deleted file mode 100644 index e5ac9a3..0000000 --- a/examples/utils.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef librabbitmq_examples_utils_h -#define librabbitmq_examples_utils_h - -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -extern void die_on_error(int x, char const *context); -extern void die_on_amqp_error(amqp_rpc_reply_t x, char const *context); - -extern void amqp_dump(void const *buffer, size_t len); - -extern uint64_t now_microseconds(void); -extern void microsleep(int usec); - -#endif diff --git a/examples/windows/platform_utils.c b/examples/windows/platform_utils.c deleted file mode 100644 index 915dd27..0000000 --- a/examples/windows/platform_utils.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdint.h> - -#include <windows.h> - -uint64_t now_microseconds(void) -{ - FILETIME ft; - GetSystemTimeAsFileTime(&ft); - return (((uint64_t)ft.dwHighDateTime << 32) | (uint64_t)ft.dwLowDateTime) - / 10; -} - -void microsleep(int usec) -{ - Sleep(usec / 1000); -} |