summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wragg <david@rabbitmq.com>2010-10-21 17:49:04 +0100
committerDavid Wragg <david@rabbitmq.com>2010-10-21 17:49:04 +0100
commitc72bba9de479902e864e3a6802c934cf7fb45e39 (patch)
tree175f75a729d02b9f5c1b48c17951395cdd7f2531
parent51345a3ded6ecd073921b7e83ec06bbd8988c345 (diff)
downloadrabbitmq-c-github-ask-c72bba9de479902e864e3a6802c934cf7fb45e39.tar.gz
Make the examples compile and work under Windows
-rw-r--r--examples/Makefile.am23
-rw-r--r--examples/amqp_bind.c4
-rw-r--r--examples/amqp_consumer.c11
-rw-r--r--examples/amqp_exchange_declare.c4
-rw-r--r--examples/amqp_listen.c6
-rw-r--r--examples/amqp_listenq.c6
-rw-r--r--examples/amqp_producer.c23
-rw-r--r--examples/amqp_sendstring.c4
-rw-r--r--examples/amqp_unbind.c4
-rw-r--r--examples/unix/platform_utils.c (renamed from librabbitmq/amqp_debug.c)90
-rw-r--r--examples/utils.c (renamed from examples/example_utils.c)84
-rw-r--r--examples/utils.h (renamed from examples/example_utils.h)9
-rw-r--r--examples/windows/platform_utils.c66
-rw-r--r--librabbitmq/Makefile.am2
-rw-r--r--librabbitmq/amqp_private.h6
-rw-r--r--librabbitmq/codegen.py2
16 files changed, 201 insertions, 143 deletions
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 <amqp.h>
#include <amqp_framing.h>
-#include <unistd.h>
-
-#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 <amqp.h>
#include <amqp_framing.h>
-#include <unistd.h>
#include <assert.h>
-#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 <amqp.h>
#include <amqp_framing.h>
-#include <unistd.h>
-
-#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 <amqp.h>
#include <amqp_framing.h>
-#include <unistd.h>
#include <assert.h>
-#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 <amqp.h>
#include <amqp_framing.h>
-#include <unistd.h>
#include <assert.h>
-#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 <amqp.h>
#include <amqp_framing.h>
-#include <unistd.h>
-
-#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 <amqp.h>
#include <amqp_framing.h>
-#include <unistd.h>
-
-#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 <amqp.h>
#include <amqp_framing.h>
-#include <unistd.h>
-
-#include "example_utils.h"
+#include "utils.h"
int main(int argc, char const * const *argv) {
char const *hostname;
diff --git a/librabbitmq/amqp_debug.c b/examples/unix/platform_utils.c
index 7258696..b039c31 100644
--- a/librabbitmq/amqp_debug.c
+++ b/examples/unix/platform_utils.c
@@ -48,86 +48,22 @@
* ***** END LICENSE BLOCK *****
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+/* For usleep */
+#define _BSD_SOURCE
-#include <ctype.h>
+#include <stdint.h>
-static void dump_row(long count, int numinrow, int *chs) {
- int i;
+#include <sys/time.h>
+#include <unistd.h>
- 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");
+uint64_t now_microseconds(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (uint64_t) tv.tv_sec * 1000000 + (uint64_t) tv.tv_usec;
}
-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);
+void microsleep(int usec)
+{
+ usleep(usec);
}
diff --git a/examples/example_utils.c b/examples/utils.c
index 48f21f9..fcd349a 100644
--- a/examples/example_utils.c
+++ b/examples/utils.c
@@ -51,13 +51,13 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include <stdint.h>
#include <amqp.h>
#include <amqp_framing.h>
-#include <sys/time.h>
-#include <unistd.h>
+#include "utils.h"
void die_on_error(int x, char const *context) {
if (x < 0) {
@@ -109,8 +109,80 @@ void die_on_amqp_error(amqp_rpc_reply_t x, char const *context) {
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;
+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/example_utils.h b/examples/utils.h
index 3dd8ec1..e5ac9a3 100644
--- a/examples/example_utils.h
+++ b/examples/utils.h
@@ -1,5 +1,5 @@
-#ifndef librabbitmq_examples_example_utils_h
-#define librabbitmq_examples_example_utils_h
+#ifndef librabbitmq_examples_utils_h
+#define librabbitmq_examples_utils_h
/*
* ***** BEGIN LICENSE BLOCK *****
@@ -54,6 +54,9 @@
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);
+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 <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);
+}
diff --git a/librabbitmq/Makefile.am b/librabbitmq/Makefile.am
index 238c781..a0f8987 100644
--- a/librabbitmq/Makefile.am
+++ b/librabbitmq/Makefile.am
@@ -13,7 +13,7 @@ if USE_MSINTTYPES
AM_CFLAGS += -I$(top_srcdir)/msinttypes
endif
-librabbitmq_la_SOURCES = amqp_mem.c amqp_table.c amqp_connection.c amqp_socket.c amqp_debug.c amqp_api.c $(PLATFORM_DIR)/socket.c
+librabbitmq_la_SOURCES = amqp_mem.c amqp_table.c amqp_connection.c amqp_socket.c amqp_api.c $(PLATFORM_DIR)/socket.c
librabbitmq_la_LDFLAGS = -no-undefined
librabbitmq_la_LIBADD = $(EXTRA_LIBS)
nodist_librabbitmq_la_SOURCES = amqp_framing.c
diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h
index 2e2a7a2..eaf6b2c 100644
--- a/librabbitmq/amqp_private.h
+++ b/librabbitmq/amqp_private.h
@@ -248,10 +248,4 @@ static inline int amqp_decode_bytes(amqp_bytes_t encoded, size_t *offset,
extern void amqp_abort(const char *fmt, ...);
-#ifndef NDEBUG
-extern void amqp_dump(void const *buffer, size_t len);
-#else
-#define amqp_dump(buffer, len) ((void) 0)
-#endif
-
#endif
diff --git a/librabbitmq/codegen.py b/librabbitmq/codegen.py
index a496b9f..6fd149e 100644
--- a/librabbitmq/codegen.py
+++ b/librabbitmq/codegen.py
@@ -467,7 +467,7 @@ extern "C" {
print """/* Function prototypes. */
extern char const *amqp_constant_name(int constantNumber);
extern amqp_boolean_t amqp_constant_is_hard_error(int constantNumber);
-extern char const *amqp_method_name(amqp_method_number_t methodNumber);
+RABBITMQ_EXPORT char const *amqp_method_name(amqp_method_number_t methodNumber);
extern amqp_boolean_t amqp_method_has_content(amqp_method_number_t methodNumber);
extern int amqp_decode_method(amqp_method_number_t methodNumber,
amqp_pool_t *pool,