From c72bba9de479902e864e3a6802c934cf7fb45e39 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Thu, 21 Oct 2010 17:49:04 +0100 Subject: Make the examples compile and work under Windows --- examples/Makefile.am | 23 ++--- examples/amqp_bind.c | 4 +- examples/amqp_consumer.c | 11 +-- examples/amqp_exchange_declare.c | 4 +- examples/amqp_listen.c | 6 +- examples/amqp_listenq.c | 6 +- examples/amqp_producer.c | 23 +++-- examples/amqp_sendstring.c | 4 +- examples/amqp_unbind.c | 4 +- examples/example_utils.c | 116 ----------------------- examples/example_utils.h | 59 ------------ examples/unix/platform_utils.c | 69 ++++++++++++++ examples/utils.c | 188 ++++++++++++++++++++++++++++++++++++++ examples/utils.h | 62 +++++++++++++ examples/windows/platform_utils.c | 66 +++++++++++++ 15 files changed, 421 insertions(+), 224 deletions(-) delete mode 100644 examples/example_utils.c delete mode 100644 examples/example_utils.h create mode 100644 examples/unix/platform_utils.c create mode 100644 examples/utils.c create mode 100644 examples/utils.h create mode 100644 examples/windows/platform_utils.c (limited to 'examples') diff --git a/examples/Makefile.am b/examples/Makefile.am index e567969..ea10f77 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,5 +1,4 @@ -noinst_PROGRAMS = amqp_sendstring amqp_exchange_declare amqp_listen amqp_producer amqp_consumer \ - amqp_unbind amqp_bind amqp_listenq +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 @@ -16,13 +15,15 @@ endif AM_LDFLAGS = $(top_builddir)/librabbitmq/librabbitmq.la -noinst_HEADERS = example_utils.h +noinst_HEADERS = utils.h -amqp_sendstring_SOURCES = amqp_sendstring.c example_utils.c -amqp_exchange_declare_SOURCES = amqp_exchange_declare.c example_utils.c -amqp_listen_SOURCES = amqp_listen.c example_utils.c -amqp_producer_SOURCES = amqp_producer.c example_utils.c -amqp_consumer_SOURCES = amqp_consumer.c example_utils.c -amqp_unbind_SOURCES = amqp_unbind.c example_utils.c -amqp_bind_SOURCES = amqp_bind.c example_utils.c -amqp_listenq_SOURCES = amqp_listenq.c example_utils.c +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 index 8ffda3f..561b84d 100644 --- a/examples/amqp_bind.c +++ b/examples/amqp_bind.c @@ -56,9 +56,7 @@ #include #include -#include - -#include "example_utils.h" +#include "utils.h" int main(int argc, char const * const *argv) { char const *hostname; diff --git a/examples/amqp_consumer.c b/examples/amqp_consumer.c index 2a0d9b9..2710643 100644 --- a/examples/amqp_consumer.c +++ b/examples/amqp_consumer.c @@ -56,27 +56,26 @@ #include #include -#include #include -#include "example_utils.h" +#include "utils.h" #define SUMMARY_EVERY_US 1000000 static void run(amqp_connection_state_t conn) { - long long start_time = now_microseconds(); + uint64_t start_time = now_microseconds(); int received = 0; int previous_received = 0; - long long previous_report_time = start_time; - long long next_summary_time = start_time + SUMMARY_EVERY_US; + 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; - long long now; + uint64_t now; while (1) { now = now_microseconds(); diff --git a/examples/amqp_exchange_declare.c b/examples/amqp_exchange_declare.c index b4b28ad..9b410ca 100644 --- a/examples/amqp_exchange_declare.c +++ b/examples/amqp_exchange_declare.c @@ -56,9 +56,7 @@ #include #include -#include - -#include "example_utils.h" +#include "utils.h" int main(int argc, char const * const *argv) { char const *hostname; diff --git a/examples/amqp_listen.c b/examples/amqp_listen.c index 7fd5af2..86c4555 100644 --- a/examples/amqp_listen.c +++ b/examples/amqp_listen.c @@ -56,13 +56,9 @@ #include #include -#include #include -#include "example_utils.h" - -/* Private: compiled out in NDEBUG mode */ -extern void amqp_dump(void const *buffer, size_t len); +#include "utils.h" int main(int argc, char const * const *argv) { char const *hostname; diff --git a/examples/amqp_listenq.c b/examples/amqp_listenq.c index 18489da..c7c2a1e 100644 --- a/examples/amqp_listenq.c +++ b/examples/amqp_listenq.c @@ -56,13 +56,9 @@ #include #include -#include #include -#include "example_utils.h" - -/* Private: compiled out in NDEBUG mode */ -extern void amqp_dump(void const *buffer, size_t len); +#include "utils.h" int main(int argc, char const * const *argv) { char const *hostname; diff --git a/examples/amqp_producer.c b/examples/amqp_producer.c index b83e030..77c3e92 100644 --- a/examples/amqp_producer.c +++ b/examples/amqp_producer.c @@ -56,9 +56,7 @@ #include #include -#include - -#include "example_utils.h" +#include "utils.h" #define SUMMARY_EVERY_US 1000000 @@ -67,21 +65,26 @@ static void send_batch(amqp_connection_state_t conn, int rate_limit, int message_count) { - long long start_time = now_microseconds(); + uint64_t start_time = now_microseconds(); int i; int sent = 0; int previous_sent = 0; - long long previous_report_time = start_time; - long long next_summary_time = start_time + SUMMARY_EVERY_US; + 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++) { - long long now = now_microseconds(); + uint64_t now = now_microseconds(); + die_on_error(amqp_basic_publish(conn, 1, amqp_cstring_bytes("amq.direct"), @@ -89,7 +92,7 @@ static void send_batch(amqp_connection_state_t conn, 0, 0, NULL, - (amqp_bytes_t) {.len = sizeof(message), .bytes = message}), + message_bytes), "Publishing"); sent++; if (now > next_summary_time) { @@ -104,13 +107,13 @@ static void send_batch(amqp_connection_state_t conn, } while (((i * 1000000.0) / (now - start_time)) > rate_limit) { - usleep(2000); + microsleep(2000); now = now_microseconds(); } } { - long long stop_time = now_microseconds(); + uint64_t stop_time = now_microseconds(); int total_delta = stop_time - start_time; printf("PRODUCER - Message count: %d\n", message_count); diff --git a/examples/amqp_sendstring.c b/examples/amqp_sendstring.c index 9808251..3c94e41 100644 --- a/examples/amqp_sendstring.c +++ b/examples/amqp_sendstring.c @@ -56,9 +56,7 @@ #include #include -#include - -#include "example_utils.h" +#include "utils.h" int main(int argc, char const * const *argv) { char const *hostname; diff --git a/examples/amqp_unbind.c b/examples/amqp_unbind.c index b014067..fad3e2b 100644 --- a/examples/amqp_unbind.c +++ b/examples/amqp_unbind.c @@ -56,9 +56,7 @@ #include #include -#include - -#include "example_utils.h" +#include "utils.h" int main(int argc, char const * const *argv) { char const *hostname; diff --git a/examples/example_utils.c b/examples/example_utils.c deleted file mode 100644 index 48f21f9..0000000 --- a/examples/example_utils.c +++ /dev/null @@ -1,116 +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 -#include -#include - -#include -#include -#include - -#include -#include - -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!", 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", - 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", - 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", context, x.reply.id); - break; - } - break; - } - - exit(1); -} - -long long now_microseconds(void) { - struct timeval tv; - gettimeofday(&tv, NULL); - return (long long) tv.tv_sec * 1000000 + (long long) tv.tv_usec; -} diff --git a/examples/example_utils.h b/examples/example_utils.h deleted file mode 100644 index 3dd8ec1..0000000 --- a/examples/example_utils.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef librabbitmq_examples_example_utils_h -#define librabbitmq_examples_example_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 long long now_microseconds(void); - -#endif diff --git a/examples/unix/platform_utils.c b/examples/unix/platform_utils.c new file mode 100644 index 0000000..b039c31 --- /dev/null +++ b/examples/unix/platform_utils.c @@ -0,0 +1,69 @@ +/* + * ***** 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 + +#include +#include + +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 new file mode 100644 index 0000000..fcd349a --- /dev/null +++ b/examples/utils.c @@ -0,0 +1,188 @@ +/* + * ***** 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 +#include +#include +#include + +#include +#include +#include + +#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!", 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", + 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", + 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", 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 new file mode 100644 index 0000000..e5ac9a3 --- /dev/null +++ b/examples/utils.h @@ -0,0 +1,62 @@ +#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 new file mode 100644 index 0000000..915dd27 --- /dev/null +++ b/examples/windows/platform_utils.c @@ -0,0 +1,66 @@ +/* + * ***** 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 + +#include + +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); +} -- cgit v1.2.1