You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/09/12 20:22:43 UTC

[1/2] qpid-proton git commit: PROTON-1512: Expose the "aborted" flag for transferred deliveries

Repository: qpid-proton
Updated Branches:
  refs/heads/master ec3c8f659 -> f719f80da


PROTON-1512: Expose the "aborted" flag for transferred deliveries


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f719f80d
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f719f80d
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f719f80d

Branch: refs/heads/master
Commit: f719f80da8c5a4939654e4efb720a02f470026e2
Parents: d7f6e06
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Sep 12 10:28:34 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Sep 12 16:22:23 2017 -0400

----------------------------------------------------------------------
 examples/c/receive.c                   |   7 +-
 examples/go/electron/receive.go        |   2 +-
 proton-c/include/proton/delivery.h     |  33 ++++++++
 proton-c/include/proton/link.h         |   7 +-
 proton-c/src/core/codec.c              |   2 +
 proton-c/src/core/engine-internal.h    |   1 +
 proton-c/src/core/engine.c             |  13 +++-
 proton-c/src/core/transport.c          |  64 ++++++++++------
 proton-c/src/tests/connection_driver.c | 112 ++++++++++++++++++++++++----
 proton-c/src/tests/test_handler.h      |   8 +-
 proton-c/src/tests/test_tools.h        |   4 +-
 11 files changed, 205 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/examples/c/receive.c
----------------------------------------------------------------------
diff --git a/examples/c/receive.c b/examples/c/receive.c
index 6fd74a5..049f75c 100644
--- a/examples/c/receive.c
+++ b/examples/c/receive.c
@@ -74,6 +74,11 @@ static void decode_message(pn_delivery_t *dlv) {
         pn_free(s);
       }
       pn_message_free(m);
+    } else if (len < 0) {
+      fprintf(stderr, "decode_message: %s\n", pn_code(len));
+      exit_code = 1;
+    } else {
+      fprintf(stderr, "decode_message: no data\n");
     }
   }
 }
@@ -160,7 +165,7 @@ void run(app_data_t *app) {
   do {
     pn_event_batch_t *events = pn_proactor_wait(app->proactor);
     for (pn_event_t *e = pn_event_batch_next(events); e; e = pn_event_batch_next(events)) {
-      if (!handle(app, e)) {
+      if (!handle(app, e) || exit_code != 0) {
         return;
       }
     }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/examples/go/electron/receive.go
----------------------------------------------------------------------
diff --git a/examples/go/electron/receive.go b/examples/go/electron/receive.go
index 7229b07..57ca53e 100644
--- a/examples/go/electron/receive.go
+++ b/examples/go/electron/receive.go
@@ -87,7 +87,7 @@ func main() {
 				} else if err == electron.Closed {
 					return
 				} else {
-					log.Fatal("receive error %v: %v", urlStr, err)
+					log.Fatalf("receive error %v: %v", urlStr, err)
 				}
 			}
 		}(urlStr)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/include/proton/delivery.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/delivery.h b/proton-c/include/proton/delivery.h
index 209bf78..b9f627b 100644
--- a/proton-c/include/proton/delivery.h
+++ b/proton-c/include/proton/delivery.h
@@ -174,12 +174,31 @@ PN_EXTERN size_t pn_delivery_pending(pn_delivery_t *delivery);
 /**
  * Check if a delivery only has partial message data.
  *
+ * Note a partial message may be pn_delivery_aborted() which means the message
+ * is incomplete but the rest of the message will never be delivered.
+ *
  * @param[in] delivery a delivery object
  * @return true if the delivery only contains part of a message, false otherwise
  */
 PN_EXTERN bool pn_delivery_partial(pn_delivery_t *delivery);
 
 /**
+ * On the receiving side, check if the delivery has been aborted.
+ *
+ * Aborting a delivery means the sender cannot complete the message. It  will not
+ * send any more data and the data received so far should be discarded by the receiver.
+ * An aborted deliver is settled by the sender.
+ *
+ * Calling pn_link_recv() when the current delivery on the link is aborted will
+ * return a PN_STATE error code.
+ *
+ * @see pn_delivery_abort()
+ * @param[in] delivery a delivery object
+ * @return true if the delivery has been aborted, false otherwise
+ */
+PN_EXTERN bool pn_delivery_aborted(pn_delivery_t *delivery); /* FIXME aconway 2017-09-11:  */
+
+/**
  * Check if a delivery is writable.
  *
  * A delivery is considered writable if it is the current delivery on
@@ -242,6 +261,20 @@ PN_EXTERN void pn_delivery_clear(pn_delivery_t *delivery);
 PN_EXTERN bool pn_delivery_current(pn_delivery_t *delivery);
 
 /**
+ * On the sending side, abort a delivery.
+ *
+ * Aborting a delivery means the sender cannot complete the message. It  will not
+ * send any more data and the data received so far should be discarded by the receiver.
+ *
+ * The aborted messages is also settled, and can never be used again.
+ *
+ * @see pn_delivery_aborted()
+ *
+ * @param[in] delivery a delivery object
+ */
+PN_EXTERN void pn_delivery_abort(pn_delivery_t *delivery);
+
+/**
  * Settle a delivery.
  *
  * A settled delivery can never be used again.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/include/proton/link.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/link.h b/proton-c/include/proton/link.h
index 792181e..864f8e0 100644
--- a/proton-c/include/proton/link.h
+++ b/proton-c/include/proton/link.h
@@ -586,8 +586,6 @@ PN_EXTERN void pn_link_offered(pn_link_t *sender, int credit);
  */
 PN_EXTERN ssize_t pn_link_send(pn_link_t *sender, const char *bytes, size_t n);
 
-//PN_EXTERN void pn_link_abort(pn_sender_t *sender);
-
 /**
  * Grant credit for incoming deliveries on a receiver.
  *
@@ -625,8 +623,9 @@ PN_EXTERN void pn_link_set_drain(pn_link_t *receiver, bool drain);
  * the network, so just because there is no data to read does not
  * imply the message is complete. To ensure the entirety of the
  * message data has been read, either invoke ::pn_link_recv until
- * PN_EOS is returned, or verify that ::pn_delivery_partial is false,
- * and ::pn_delivery_pending is 0.
+ * PN_EOS is returned, or verify that
+ *
+ *     (!pn_delivery_partial(d) && !pn_delivery_aborted(d) && pn_delivery_pending(d)==0)
  *
  * @param[in] receiver a receiving link object
  * @param[in] bytes a pointer to an empty buffer

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/src/core/codec.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/codec.c b/proton-c/src/core/codec.c
index 3417c94..b088f00 100644
--- a/proton-c/src/core/codec.c
+++ b/proton-c/src/core/codec.c
@@ -567,6 +567,7 @@ int pn_data_vfill(pn_data_t *data, const char *fmt, va_list ap)
       }
       break;
     case 'D':
+      /* The next 2 args are the descriptor, value for a described value. */
       err = pn_data_put_described(data);
       pn_data_enter(data);
       break;
@@ -611,6 +612,7 @@ int pn_data_vfill(pn_data_t *data, const char *fmt, va_list ap)
         return pn_error_format(data->error, PN_ERR, "exit failed");
       break;
     case '?':
+     /* Consumes 2 args: bool, value. Insert null if bool is false else value */
       if (!va_arg(ap, int)) {
         err = pn_data_put_null(data);
         if (err) return err;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/src/core/engine-internal.h
----------------------------------------------------------------------
diff --git a/proton-c/src/core/engine-internal.h b/proton-c/src/core/engine-internal.h
index 1dbe91c..2bfed83 100644
--- a/proton-c/src/core/engine-internal.h
+++ b/proton-c/src/core/engine-internal.h
@@ -338,6 +338,7 @@ struct pn_delivery_t {
   bool tpwork;
   bool done;
   bool referenced;
+  bool aborted;
 };
 
 #define PN_SET_LOCAL(OLD, NEW)                                          \

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/src/core/engine.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/engine.c b/proton-c/src/core/engine.c
index 7af1987..0863caa 100644
--- a/proton-c/src/core/engine.c
+++ b/proton-c/src/core/engine.c
@@ -1904,7 +1904,7 @@ ssize_t pn_link_recv(pn_link_t *receiver, char *bytes, size_t n)
   if (!receiver) return PN_ARG_ERR;
 
   pn_delivery_t *delivery = receiver->current;
-  if (delivery) {
+  if (delivery && !delivery->aborted) {
     size_t size = pn_buffer_get(delivery->bytes, 0, n, bytes);
     pn_buffer_trim(delivery->bytes, size, 0);
     if (size) {
@@ -2054,6 +2054,17 @@ bool pn_delivery_partial(pn_delivery_t *delivery)
   return !delivery->done;
 }
 
+void pn_delivery_abort(pn_delivery_t *delivery) {
+  if (!delivery->aborted) {
+    delivery->aborted = true;
+    pn_delivery_settle(delivery);
+  }
+}
+
+bool pn_delivery_aborted(pn_delivery_t *delivery) {
+  return delivery->aborted;
+}
+
 pn_condition_t *pn_connection_condition(pn_connection_t *connection)
 {
   assert(connection);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/src/core/transport.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/transport.c b/proton-c/src/core/transport.c
index f9eea7b..9d3381a 100644
--- a/proton-c/src/core/transport.c
+++ b/proton-c/src/core/transport.c
@@ -974,7 +974,10 @@ static int pni_post_amqp_transfer_frame(pn_transport_t *transport, uint16_t ch,
                                         bool more,
                                         pn_sequence_t frame_limit,
                                         uint64_t code,
-                                        pn_data_t* state)
+                                        pn_data_t* state,
+                                        bool resume,
+                                        bool aborted,
+                                        bool batchable)
 {
   bool more_flag = more;
   int framecount = 0;
@@ -984,10 +987,11 @@ static int pni_post_amqp_transfer_frame(pn_transport_t *transport, uint16_t ch,
 
  compute_performatives:
   pn_data_clear(transport->output_args);
-  int err = pn_data_fill(transport->output_args, "DL[IIzIoon?DLC]", TRANSFER,
+  int err = pn_data_fill(transport->output_args, "DL[IIzIoon?DLCooo]", TRANSFER,
                          handle, id, tag->size, tag->start,
                          message_format,
-                         settled, more_flag, (bool)code, code, state);
+                         settled, more_flag, (bool)code, code, state,
+                         resume, aborted, batchable);
   if (err) {
     pn_transport_logf(transport,
                       "error posting transfer frame: %s: %s", pn_code(err),
@@ -1481,10 +1485,12 @@ int pn_do_transfer(pn_transport_t *transport, uint8_t frame_type, uint16_t chann
   bool settled;
   bool more;
   bool has_type;
+  bool resume, aborted, batchable;
   uint64_t type;
   pn_data_clear(transport->disp_data);
-  int err = pn_data_scan(args, "D.[I?Iz.oo.D?LC]", &handle, &id_present, &id, &tag,
-                         &settled, &more, &has_type, &type, transport->disp_data);
+  int err = pn_data_scan(args, "D.[I?Iz.oo.D?LCooo]", &handle, &id_present, &id, &tag,
+                         &settled, &more, &has_type, &type, transport->disp_data,
+                         &resume, &aborted, &batchable);
   if (err) return err;
   pn_session_t *ssn = pni_channel_state(transport, channel);
   if (!ssn) {
@@ -1534,19 +1540,26 @@ int pn_do_transfer(pn_transport_t *transport, uint8_t frame_type, uint16_t chann
       pn_work_update(transport->connection, delivery);
     }
   }
+  delivery->aborted = aborted;
+  if (aborted) {
+    delivery->remote.settled = true;
+    delivery->done = true;
+    delivery->updated = true;
+    pn_buffer_clear(delivery->bytes);
+    pn_work_update(transport->connection, delivery);
+  } else {
+    pn_buffer_append(delivery->bytes, payload->start, payload->size);
+    ssn->incoming_bytes += payload->size;
+    delivery->done = !more;
 
-  pn_buffer_append(delivery->bytes, payload->start, payload->size);
-  ssn->incoming_bytes += payload->size;
-  delivery->done = !more;
-
-  ssn->state.incoming_transfer_count++;
-  ssn->state.incoming_window--;
+    ssn->state.incoming_transfer_count++;
+    ssn->state.incoming_window--;
 
-  // XXX: need better policy for when to refresh window
-  if (!ssn->state.incoming_window && (int32_t) link->state.local_handle >= 0) {
-    pni_post_flow(transport, ssn, link);
+    // XXX: need better policy for when to refresh window
+    if (!ssn->state.incoming_window && (int32_t) link->state.local_handle >= 0) {
+      pni_post_flow(transport, ssn, link);
+    }
   }
-
   pn_collector_put(transport->connection->collector, PN_OBJECT, delivery, PN_DELIVERY);
   return 0;
 }
@@ -2168,14 +2181,19 @@ static int pni_process_tpwork_sender(pn_transport_t *transport, pn_delivery_t *d
       pn_data_clear(transport->disp_data);
       PN_RETURN_IF_ERROR(pni_disposition_encode(&delivery->local, transport->disp_data));
       int count = pni_post_amqp_transfer_frame(transport,
-                                              ssn_state->local_channel,
-                                              link_state->local_handle,
-                                              state->id, &bytes, &tag,
-                                              0, // message-format
-                                              delivery->local.settled,
-                                              !delivery->done,
-                                              ssn_state->remote_incoming_window,
-                                              delivery->local.type, transport->disp_data);
+                                               ssn_state->local_channel,
+                                               link_state->local_handle,
+                                               state->id, &bytes, &tag,
+                                               0, // message-format
+                                               delivery->local.settled,
+                                               !delivery->done,
+                                               ssn_state->remote_incoming_window,
+                                               delivery->local.type,
+                                               transport->disp_data,
+                                               false, /* Resume */
+                                               delivery->aborted,
+                                               false /* Batchable */
+      );
       if (count < 0) return count;
       xfr_posted = true;
       ssn_state->outgoing_transfer_count += count;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/src/tests/connection_driver.c
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/connection_driver.c b/proton-c/src/tests/connection_driver.c
index a511284..4db324c 100644
--- a/proton-c/src/tests/connection_driver.c
+++ b/proton-c/src/tests/connection_driver.c
@@ -27,6 +27,7 @@
 #include <proton/session.h>
 #include <proton/link.h>
 
+/* Place for handlers to save link and delivery pointers */
 struct context {
   pn_link_t *link;
   pn_delivery_t *delivery;
@@ -53,6 +54,7 @@ static pn_event_type_t open_handler(test_handler_t *th, pn_event_t *e) {
   return PN_EVENT_NONE;
 }
 
+/* Handler that returns control on PN_DELIVERY */
 static pn_event_type_t delivery_handler(test_handler_t *th, pn_event_t *e) {
   switch (pn_event_type(e)) {
    case PN_DELIVERY: {
@@ -68,10 +70,9 @@ static pn_event_type_t delivery_handler(test_handler_t *th, pn_event_t *e) {
 /* Blow-by-blow event verification of a single message transfer */
 static void test_message_transfer(test_t *t) {
   test_connection_driver_t client, server;
-  test_connection_driver_init(&client, t, open_handler, NULL, NULL);
-  test_connection_driver_init(&server, t, delivery_handler, NULL, NULL);
-  struct context server_ctx;
-  server.handler.context = &server_ctx;
+  struct context server_ctx = {0};
+  test_connection_driver_init(&client, t, open_handler, NULL);
+  test_connection_driver_init(&server, t, delivery_handler, &server_ctx);
   pn_transport_set_server(server.driver.transport);
 
   pn_connection_open(client.driver.connection);
@@ -138,24 +139,40 @@ static void test_message_transfer(test_t *t) {
   test_connection_driver_destroy(&server);
 }
 
+/* Handler that opens a connection and sender link */
+pn_event_type_t send_client_handler(test_handler_t *th, pn_event_t *e) {
+  switch (pn_event_type(e)) {
+   case PN_CONNECTION_LOCAL_OPEN:
+    pn_connection_open(pn_event_connection(e));
+    pn_session_t *ssn = pn_session(pn_event_connection(e));
+    pn_session_open(ssn);
+    pn_link_t *snd = pn_sender(ssn, "x");
+    pn_link_open(snd);
+    break;
+   case PN_LINK_REMOTE_OPEN: {
+    struct context *ctx = (struct context*) th->context;
+    if (ctx) ctx->link = pn_event_link(e);
+    return PN_LINK_REMOTE_OPEN;
+   }
+   default:
+    break;
+  }
+  return PN_EVENT_NONE;
+}
+
 /* Send a message in pieces, ensure each can be received before the next is sent */
 static void test_message_stream(test_t *t) {
   /* Set up the link, give credit, start the delivery */
   test_connection_driver_t client, server;
-  test_connection_driver_init(&client, t, open_handler, NULL, NULL);
-  test_connection_driver_init(&server, t, delivery_handler, NULL, NULL);
-  struct context server_ctx;
-  server.handler.context = &server_ctx;
+  struct context server_ctx = {0}, client_ctx = {0};
+  test_connection_driver_init(&client, t, send_client_handler, &client_ctx);
+  test_connection_driver_init(&server, t, delivery_handler, &server_ctx);
   pn_transport_set_server(server.driver.transport);
 
   pn_connection_open(client.driver.connection);
-  pn_session_t *ssn = pn_session(client.driver.connection);
-  pn_session_open(ssn);
-  pn_link_t *snd = pn_sender(ssn, "x");
-  pn_link_open(snd);
   test_connection_drivers_run(&client, &server);
   pn_link_t *rcv = server_ctx.link;
-  TEST_CHECK(t, rcv);
+  pn_link_t *snd = client_ctx.link;
   pn_link_flow(rcv, 1);
   test_connection_drivers_run(&client, &server);
   test_handler_keep(&client.handler, 1);
@@ -200,9 +217,78 @@ static void test_message_stream(test_t *t) {
   test_connection_driver_destroy(&server);
 }
 
+// Test aborting a message mid stream.
+static void test_message_abort(test_t *t) {
+  /* Set up the link, give credit, start the delivery */
+  test_connection_driver_t client, server;
+  struct context server_ctx = {0}, client_ctx = {0};
+  test_connection_driver_init(&client, t, send_client_handler, &client_ctx);
+  test_connection_driver_init(&server, t, delivery_handler, &server_ctx);
+  pn_transport_set_server(server.driver.transport);
+  pn_connection_open(client.driver.connection);
+
+  test_connection_drivers_run(&client, &server);
+  pn_link_t *rcv = server_ctx.link;
+  pn_link_t *snd = client_ctx.link;
+  pn_link_flow(rcv, 1);
+  test_connection_drivers_run(&client, &server);
+
+  /* Encode a large (not very) message to send in chunks, and abort */
+  pn_message_t *m = pn_message();
+  char body[1024] = { 0 };
+  pn_data_put_binary(pn_message_body(m), pn_bytes(sizeof(body), body));
+  pn_rwbytes_t buf = { 0 };
+  ssize_t size = message_encode(m, &buf);
+  (void)size;
+
+  /* Send 3 chunks, then abort */
+  static const ssize_t CHUNK = 100;
+  pn_delivery(snd, pn_dtag("x", 1));
+  pn_rwbytes_t buf2 = { 0 };
+  ssize_t received = 0;
+  for (ssize_t i = 0; i < CHUNK*3; i += CHUNK) {
+    /* Send a chunk */
+    ssize_t c = (i+CHUNK < size) ? CHUNK : size - i;
+    TEST_CHECK(t, c == pn_link_send(snd, buf.start + i, c));
+    TEST_CHECK(t, &server == test_connection_drivers_run(&client, &server));
+    test_handler_keep(&server.handler, 1);
+    TEST_HANDLER_EXPECT(&server.handler, PN_DELIVERY, 0);
+    /* Receive a chunk */
+    pn_delivery_t *dlv = server_ctx.delivery;
+    pn_link_t *l = pn_delivery_link(dlv);
+    ssize_t dsize = pn_delivery_pending(dlv);
+    rwbytes_ensure(&buf2, received+dsize);
+    TEST_ASSERT(dsize == pn_link_recv(l, buf2.start + received, dsize));
+    received += dsize;
+  }
+  /* Now abort the message on the sender*/
+  pn_delivery_t *d = pn_link_current(snd);
+  pn_delivery_abort(d);
+  TEST_CHECK(t, pn_link_current(snd) != d);
+  TEST_CHECK(t, &server == test_connection_drivers_run(&client, &server));
+  TEST_HANDLER_EXPECT(&server.handler, PN_DELIVERY, 0);
+  /* And verify we see it aborted on the receiver */
+  d = pn_link_current(rcv);
+  TEST_CHECK(t, pn_delivery_aborted(d));
+  /* Aborted implies settled, !partial, pending == 0, pn_link_recv returns error */
+  TEST_CHECK(t, pn_delivery_settled(d));
+  TEST_CHECK(t, !pn_delivery_partial(d));
+  TEST_INT_EQUAL(t, 0, pn_delivery_pending(d));
+  char b[16];
+  TEST_INT_EQUAL(t, PN_STATE_ERR, pn_link_recv(rcv, b, sizeof(b)));
+
+  pn_message_free(m);
+  free(buf.start);
+  free(buf2.start);
+  test_connection_driver_destroy(&client);
+  test_connection_driver_destroy(&server);
+}
+
+
 int main(int argc, char **argv) {
   int failed = 0;
   RUN_ARGV_TEST(failed, t, test_message_transfer(&t));
   RUN_ARGV_TEST(failed, t, test_message_stream(&t));
+  RUN_ARGV_TEST(failed, t, test_message_abort(&t));
   return failed;
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/src/tests/test_handler.h
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/test_handler.h b/proton-c/src/tests/test_handler.h
index 7bdab89..420e910 100644
--- a/proton-c/src/tests/test_handler.h
+++ b/proton-c/src/tests/test_handler.h
@@ -36,7 +36,7 @@ typedef struct test_handler_t {
   test_t *t;
   test_handler_fn f;
   pn_event_type_t log[MAX_EVENT_LOG]; /* Log of event types */
-  size_t log_size;                     /* Number of events in the log */
+  size_t log_size;                    /* Number of events in the log */
   void *context;                      /* Test-specific context */
 } test_handler_t;
 
@@ -101,11 +101,11 @@ typedef struct test_connection_driver_t {
   pn_connection_driver_t driver;
 } test_connection_driver_t;
 
-void test_connection_driver_init(test_connection_driver_t *d, test_t *t, test_handler_fn f,
-                                 pn_connection_t *connection, pn_transport_t *transport)
+void test_connection_driver_init(test_connection_driver_t *d, test_t *t, test_handler_fn f, void* context)
 {
   test_handler_init(&d->handler, t, f);
-  pn_connection_driver_init(&d->driver, connection, transport);
+  d->handler.context = context;
+  pn_connection_driver_init(&d->driver, NULL, NULL);
 }
 
 void test_connection_driver_destroy(test_connection_driver_t *d) {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f719f80d/proton-c/src/tests/test_tools.h
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/test_tools.h b/proton-c/src/tests/test_tools.h
index bd48e60..6b2f91f 100644
--- a/proton-c/src/tests/test_tools.h
+++ b/proton-c/src/tests/test_tools.h
@@ -139,10 +139,12 @@ bool test_etype_equal_(test_t *t, pn_event_type_t want, pn_event_type_t got, con
                      pn_event_type_name(got));
 }
 
+#define TEST_INT_EQUAL(TEST, WANT, GOT)                                 \
+  test_check_((TEST), (int)(WANT) == (int)(GOT), NULL, __FILE__, __LINE__, "want %d, got %d", (int)(WANT), (int)(GOT))
+
 #define TEST_STR_EQUAL(TEST, WANT, GOT)                                 \
   test_check_((TEST), !strcmp((WANT), (GOT)), NULL, __FILE__, __LINE__, "want '%s', got '%s'", (WANT), (GOT))
 
-
 #define TEST_STR_IN(TEST, WANT, GOT)                                    \
   test_check_((TEST), strstr((GOT), (WANT)), NULL, __FILE__, __LINE__, "'%s' not in '%s'", (WANT), (GOT))
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[2/2] qpid-proton git commit: PROTON-1585: Remove un-necessary include/pncompat from C examples.

Posted by ac...@apache.org.
PROTON-1585: Remove un-necessary include/pncompat from C examples.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/d7f6e066
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/d7f6e066
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/d7f6e066

Branch: refs/heads/master
Commit: d7f6e0662980fb8196dfd3b536210e76f851c6cd
Parents: ec3c8f6
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Sep 12 13:56:35 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Sep 12 16:22:23 2017 -0400

----------------------------------------------------------------------
 examples/c/include/pncompat/internal/LICENSE    |  33 ---
 examples/c/include/pncompat/internal/getopt.c   | 250 -------------------
 examples/c/include/pncompat/internal/getopt.h   |  63 -----
 examples/c/include/pncompat/misc_defs.h         |  50 ----
 examples/c/include/pncompat/misc_funcs.inc      |  68 -----
 tests/tools/apps/c/CMakeLists.txt               |   2 +-
 .../apps/c/include/pncompat/internal/LICENSE    |  32 +++
 .../apps/c/include/pncompat/internal/getopt.c   | 250 +++++++++++++++++++
 .../apps/c/include/pncompat/internal/getopt.h   |  63 +++++
 tests/tools/apps/c/include/pncompat/misc_defs.h |  50 ++++
 .../apps/c/include/pncompat/misc_funcs.inc      |  68 +++++
 11 files changed, 464 insertions(+), 465 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/examples/c/include/pncompat/internal/LICENSE
----------------------------------------------------------------------
diff --git a/examples/c/include/pncompat/internal/LICENSE b/examples/c/include/pncompat/internal/LICENSE
deleted file mode 100644
index 99efb42..0000000
--- a/examples/c/include/pncompat/internal/LICENSE
+++ /dev/null
@@ -1,33 +0,0 @@
-Free Getopt
-Copyright (c)2002-2003 Mark K. Kim
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-  * Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
-
-  * Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in
-    the documentation and/or other materials provided with the
-    distribution.
-
-  * Neither the original author of this software nor the names of its
-    contributors may be used to endorse or promote products derived
-    from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGE.
-

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/examples/c/include/pncompat/internal/getopt.c
----------------------------------------------------------------------
diff --git a/examples/c/include/pncompat/internal/getopt.c b/examples/c/include/pncompat/internal/getopt.c
deleted file mode 100644
index 7ef9a68..0000000
--- a/examples/c/include/pncompat/internal/getopt.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*****************************************************************************
-* getopt.c - competent and free getopt library.
-* $Header: /cvsroot/freegetopt/freegetopt/getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $
-*
-* Copyright (c)2002-2003 Mark K. Kim
-* All rights reserved.
-* 
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-*   * Redistributions of source code must retain the above copyright
-*     notice, this list of conditions and the following disclaimer.
-*
-*   * Redistributions in binary form must reproduce the above copyright
-*     notice, this list of conditions and the following disclaimer in
-*     the documentation and/or other materials provided with the
-*     distribution.
-*
-*   * Neither the original author of this software nor the names of its
-*     contributors may be used to endorse or promote products derived
-*     from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-* DAMAGE.
-*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "getopt.h"
-
-
-static const char* ID = "$Id: getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $";
-
-
-char* optarg = NULL;
-int optind = 0;
-int opterr = 1;
-int optopt = '?';
-
-
-static char** prev_argv = NULL;        /* Keep a copy of argv and argc to */
-static int prev_argc = 0;              /*    tell if getopt params change */
-static int argv_index = 0;             /* Option we're checking */
-static int argv_index2 = 0;            /* Option argument we're checking */
-static int opt_offset = 0;             /* Index into compounded "-option" */
-static int dashdash = 0;               /* True if "--" option reached */
-static int nonopt = 0;                 /* How many nonopts we've found */
-
-static void increment_index()
-{
-	/* Move onto the next option */
-	if(argv_index < argv_index2)
-	{
-		while(prev_argv[++argv_index] && prev_argv[argv_index][0] != '-'
-				&& argv_index < argv_index2+1);
-	}
-	else argv_index++;
-	opt_offset = 1;
-}
-
-
-/*
-* Permutes argv[] so that the argument currently being processed is moved
-* to the end.
-*/
-static int permute_argv_once()
-{
-	/* Movability check */
-	if(argv_index + nonopt >= prev_argc) return 1;
-	/* Move the current option to the end, bring the others to front */
-	else
-	{
-		char* tmp = prev_argv[argv_index];
-
-		/* Move the data */
-		memmove(&prev_argv[argv_index], &prev_argv[argv_index+1],
-				sizeof(char**) * (prev_argc - argv_index - 1));
-		prev_argv[prev_argc - 1] = tmp;
-
-		nonopt++;
-		return 0;
-	}
-}
-
-
-int getopt(int argc, char** argv, char* optstr)
-{
-	int c = 0;
-
-	/* If we have new argv, reinitialize */
-	if(prev_argv != argv || prev_argc != argc)
-	{
-		/* Initialize variables */
-		prev_argv = argv;
-		prev_argc = argc;
-		argv_index = 1;
-		argv_index2 = 1;
-		opt_offset = 1;
-		dashdash = 0;
-		nonopt = 0;
-	}
-
-	/* Jump point in case we want to ignore the current argv_index */
-	getopt_top:
-
-	/* Misc. initializations */
-	optarg = NULL;
-
-	/* Dash-dash check */
-	if(argv[argv_index] && !strcmp(argv[argv_index], "--"))
-	{
-		dashdash = 1;
-		increment_index();
-	}
-
-	/* If we're at the end of argv, that's it. */
-	if(argv[argv_index] == NULL)
-	{
-		c = -1;
-	}
-	/* Are we looking at a string? Single dash is also a string */
-	else if(dashdash || argv[argv_index][0] != '-' || !strcmp(argv[argv_index], "-"))
-	{
-		/* If we want a string... */
-		if(optstr[0] == '-')
-		{
-			c = 1;
-			optarg = argv[argv_index];
-			increment_index();
-		}
-		/* If we really don't want it (we're in POSIX mode), we're done */
-		else if(optstr[0] == '+' || getenv("POSIXLY_CORRECT"))
-		{
-			c = -1;
-
-			/* Everything else is a non-opt argument */
-			nonopt = argc - argv_index;
-		}
-		/* If we mildly don't want it, then move it back */
-		else
-		{
-			if(!permute_argv_once()) goto getopt_top;
-			else c = -1;
-		}
-	}
-	/* Otherwise we're looking at an option */
-	else
-	{
-		char* opt_ptr = NULL;
-
-		/* Grab the option */
-		c = argv[argv_index][opt_offset++];
-
-		/* Is the option in the optstr? */
-		if(optstr[0] == '-') opt_ptr = strchr(optstr+1, c);
-		else opt_ptr = strchr(optstr, c);
-		/* Invalid argument */
-		if(!opt_ptr)
-		{
-			if(opterr)
-			{
-				fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
-			}
-
-			optopt = c;
-			c = '?';
-
-			/* Move onto the next option */
-			increment_index();
-		}
-		/* Option takes argument */
-		else if(opt_ptr[1] == ':')
-		{
-			/* ie, -oARGUMENT, -xxxoARGUMENT, etc. */
-			if(argv[argv_index][opt_offset] != '\0')
-			{
-				optarg = &argv[argv_index][opt_offset];
-				increment_index();
-			}
-			/* ie, -o ARGUMENT (only if it's a required argument) */
-			else if(opt_ptr[2] != ':')
-			{
-				/* One of those "you're not expected to understand this" moment */
-				if(argv_index2 < argv_index) argv_index2 = argv_index;
-				while(argv[++argv_index2] && argv[argv_index2][0] == '-');
-				optarg = argv[argv_index2];
-
-				/* Don't cross into the non-option argument list */
-				if(argv_index2 + nonopt >= prev_argc) optarg = NULL;
-
-				/* Move onto the next option */
-				increment_index();
-			}
-			else
-			{
-				/* Move onto the next option */
-				increment_index();
-			}
-
-			/* In case we got no argument for an option with required argument */
-			if(optarg == NULL && opt_ptr[2] != ':')
-			{
-				optopt = c;
-				c = '?';
-
-				if(opterr)
-				{
-					fprintf(stderr,"%s: option requires an argument -- %c\n",
-							argv[0], optopt);
-				}
-			}
-		}
-		/* Option does not take argument */
-		else
-		{
-			/* Next argv_index */
-			if(argv[argv_index][opt_offset] == '\0')
-			{
-				increment_index();
-			}
-		}
-	}
-
-	/* Calculate optind */
-	if(c == -1)
-	{
-		optind = argc - nonopt;
-	}
-	else
-	{
-		optind = argv_index;
-	}
-
-	return c;
-}
-
-
-/* vim:ts=3
-*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/examples/c/include/pncompat/internal/getopt.h
----------------------------------------------------------------------
diff --git a/examples/c/include/pncompat/internal/getopt.h b/examples/c/include/pncompat/internal/getopt.h
deleted file mode 100644
index 0b78650..0000000
--- a/examples/c/include/pncompat/internal/getopt.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*****************************************************************************
-* getopt.h - competent and free getopt library.
-* $Header: /cvsroot/freegetopt/freegetopt/getopt.h,v 1.2 2003/10/26 03:10:20 vindaci Exp $
-*
-* Copyright (c)2002-2003 Mark K. Kim
-* All rights reserved.
-* 
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-*   * Redistributions of source code must retain the above copyright
-*     notice, this list of conditions and the following disclaimer.
-*
-*   * Redistributions in binary form must reproduce the above copyright
-*     notice, this list of conditions and the following disclaimer in
-*     the documentation and/or other materials provided with the
-*     distribution.
-*
-*   * Neither the original author of this software nor the names of its
-*     contributors may be used to endorse or promote products derived
-*     from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-* DAMAGE.
-*/
-#ifndef GETOPT_H_
-#define GETOPT_H_
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-extern char* optarg;
-extern int optind;
-extern int opterr;
-extern int optopt;
-
-int getopt(int argc, char** argv, char* optstr);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* GETOPT_H_ */
-
-
-/* vim:ts=3
-*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/examples/c/include/pncompat/misc_defs.h
----------------------------------------------------------------------
diff --git a/examples/c/include/pncompat/misc_defs.h b/examples/c/include/pncompat/misc_defs.h
deleted file mode 100644
index 90b0d4e..0000000
--- a/examples/c/include/pncompat/misc_defs.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef PNCOMAPT_MISC_DEFS_H
-#define PNCOMAPT_MISC_DEFS_H
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#if defined(qpid_proton_EXPORTS)
-#error This include file is not for use in the main proton library
-#endif
-
-/*
- * Platform neutral definitions. Only intended for use by Proton
- * examples and test/debug programs.
- *
- * This file and any related support files may change or be removed
- * at any time.
- */
-
-// getopt()
-
-#include <proton/types.h>
-
-#if defined(__IBMC__)
-#  include <stdlib.h>
-#elif !defined(_WIN32) || defined (__CYGWIN__)
-#  include <getopt.h>
-#else
-#  include "internal/getopt.h"
-#endif
-
-pn_timestamp_t time_now(void);
-
-#endif /* PNCOMPAT_MISC_DEFS_H */

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/examples/c/include/pncompat/misc_funcs.inc
----------------------------------------------------------------------
diff --git a/examples/c/include/pncompat/misc_funcs.inc b/examples/c/include/pncompat/misc_funcs.inc
deleted file mode 100644
index 821aaf4..0000000
--- a/examples/c/include/pncompat/misc_funcs.inc
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-/*
- * This file provides the functions for "misc_defs.h" in the form of
- * included code, as opposed to a separate library or object
- * dependency.  In the absence of portable "pragma weak" compiler
- * directives, this provides a simple workaround.
- *
- * Usage for a single compilation unit:
- *
- *  #include "pncompat/misc_funcs.inc"
- *
- * Usage for multiple combined compilation units: chose one to include
- * "pncompat/misc_funcs.inc" as above and in each other unit needing the
- * definitions use
- *
- *  #include "pncompat/misc_defs.h"
- *
- */
-
-#include "misc_defs.h"
-
-#if defined(_WIN32) && ! defined(__CYGWIN__)
-#include "pncompat/internal/getopt.c"
-#endif
-
-#if defined(_WIN32) && ! defined(__CYGWIN__)
-#include <windows.h>
-pn_timestamp_t time_now(void)
-{
-  FILETIME now;
-  ULARGE_INTEGER t;
-  GetSystemTimeAsFileTime(&now);
-  t.u.HighPart = now.dwHighDateTime;
-  t.u.LowPart = now.dwLowDateTime;
-  // Convert to milliseconds and adjust base epoch
-  return t.QuadPart / 10000 - 11644473600000;
-}
-#else
-#include <sys/time.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-pn_timestamp_t time_now(void)
-{
-  struct timeval now;
-  if (gettimeofday(&now, NULL)) {fprintf(stderr, "gettimeofday failed\n"); abort();}
-  return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_usec / 1000);
-}
-#endif

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/tests/tools/apps/c/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/tests/tools/apps/c/CMakeLists.txt b/tests/tools/apps/c/CMakeLists.txt
index 2c801c4..7851c7b 100644
--- a/tests/tools/apps/c/CMakeLists.txt
+++ b/tests/tools/apps/c/CMakeLists.txt
@@ -19,7 +19,7 @@
 
 include(CheckIncludeFiles)
 
-include_directories(${CMAKE_SOURCE_DIR}/examples/c/include)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
 CHECK_INCLUDE_FILES("inttypes.h" INTTYPES_AVAILABLE)
 if (INTTYPES_AVAILABLE)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/tests/tools/apps/c/include/pncompat/internal/LICENSE
----------------------------------------------------------------------
diff --git a/tests/tools/apps/c/include/pncompat/internal/LICENSE b/tests/tools/apps/c/include/pncompat/internal/LICENSE
new file mode 100644
index 0000000..2c1799c
--- /dev/null
+++ b/tests/tools/apps/c/include/pncompat/internal/LICENSE
@@ -0,0 +1,32 @@
+Free Getopt
+Copyright (c)2002-2003 Mark K. Kim
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+  * Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in
+    the documentation and/or other materials provided with the
+    distribution.
+
+  * Neither the original author of this software nor the names of its
+    contributors may be used to endorse or promote products derived
+    from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/tests/tools/apps/c/include/pncompat/internal/getopt.c
----------------------------------------------------------------------
diff --git a/tests/tools/apps/c/include/pncompat/internal/getopt.c b/tests/tools/apps/c/include/pncompat/internal/getopt.c
new file mode 100644
index 0000000..5f24dd8
--- /dev/null
+++ b/tests/tools/apps/c/include/pncompat/internal/getopt.c
@@ -0,0 +1,250 @@
+/*****************************************************************************
+* getopt.c - competent and free getopt library.
+* $Header: /cvsroot/freegetopt/freegetopt/getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $
+*
+* Copyright (c)2002-2003 Mark K. Kim
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+*   * Redistributions of source code must retain the above copyright
+*     notice, this list of conditions and the following disclaimer.
+*
+*   * Redistributions in binary form must reproduce the above copyright
+*     notice, this list of conditions and the following disclaimer in
+*     the documentation and/or other materials provided with the
+*     distribution.
+*
+*   * Neither the original author of this software nor the names of its
+*     contributors may be used to endorse or promote products derived
+*     from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+* DAMAGE.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "getopt.h"
+
+
+static const char* ID = "$Id: getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $";
+
+
+char* optarg = NULL;
+int optind = 0;
+int opterr = 1;
+int optopt = '?';
+
+
+static char** prev_argv = NULL;        /* Keep a copy of argv and argc to */
+static int prev_argc = 0;              /*    tell if getopt params change */
+static int argv_index = 0;             /* Option we're checking */
+static int argv_index2 = 0;            /* Option argument we're checking */
+static int opt_offset = 0;             /* Index into compounded "-option" */
+static int dashdash = 0;               /* True if "--" option reached */
+static int nonopt = 0;                 /* How many nonopts we've found */
+
+static void increment_index()
+{
+	/* Move onto the next option */
+	if(argv_index < argv_index2)
+	{
+		while(prev_argv[++argv_index] && prev_argv[argv_index][0] != '-'
+				&& argv_index < argv_index2+1);
+	}
+	else argv_index++;
+	opt_offset = 1;
+}
+
+
+/*
+* Permutes argv[] so that the argument currently being processed is moved
+* to the end.
+*/
+static int permute_argv_once()
+{
+	/* Movability check */
+	if(argv_index + nonopt >= prev_argc) return 1;
+	/* Move the current option to the end, bring the others to front */
+	else
+	{
+		char* tmp = prev_argv[argv_index];
+
+		/* Move the data */
+		memmove(&prev_argv[argv_index], &prev_argv[argv_index+1],
+				sizeof(char**) * (prev_argc - argv_index - 1));
+		prev_argv[prev_argc - 1] = tmp;
+
+		nonopt++;
+		return 0;
+	}
+}
+
+
+int getopt(int argc, char** argv, char* optstr)
+{
+	int c = 0;
+
+	/* If we have new argv, reinitialize */
+	if(prev_argv != argv || prev_argc != argc)
+	{
+		/* Initialize variables */
+		prev_argv = argv;
+		prev_argc = argc;
+		argv_index = 1;
+		argv_index2 = 1;
+		opt_offset = 1;
+		dashdash = 0;
+		nonopt = 0;
+	}
+
+	/* Jump point in case we want to ignore the current argv_index */
+	getopt_top:
+
+	/* Misc. initializations */
+	optarg = NULL;
+
+	/* Dash-dash check */
+	if(argv[argv_index] && !strcmp(argv[argv_index], "--"))
+	{
+		dashdash = 1;
+		increment_index();
+	}
+
+	/* If we're at the end of argv, that's it. */
+	if(argv[argv_index] == NULL)
+	{
+		c = -1;
+	}
+	/* Are we looking at a string? Single dash is also a string */
+	else if(dashdash || argv[argv_index][0] != '-' || !strcmp(argv[argv_index], "-"))
+	{
+		/* If we want a string... */
+		if(optstr[0] == '-')
+		{
+			c = 1;
+			optarg = argv[argv_index];
+			increment_index();
+		}
+		/* If we really don't want it (we're in POSIX mode), we're done */
+		else if(optstr[0] == '+' || getenv("POSIXLY_CORRECT"))
+		{
+			c = -1;
+
+			/* Everything else is a non-opt argument */
+			nonopt = argc - argv_index;
+		}
+		/* If we mildly don't want it, then move it back */
+		else
+		{
+			if(!permute_argv_once()) goto getopt_top;
+			else c = -1;
+		}
+	}
+	/* Otherwise we're looking at an option */
+	else
+	{
+		char* opt_ptr = NULL;
+
+		/* Grab the option */
+		c = argv[argv_index][opt_offset++];
+
+		/* Is the option in the optstr? */
+		if(optstr[0] == '-') opt_ptr = strchr(optstr+1, c);
+		else opt_ptr = strchr(optstr, c);
+		/* Invalid argument */
+		if(!opt_ptr)
+		{
+			if(opterr)
+			{
+				fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
+			}
+
+			optopt = c;
+			c = '?';
+
+			/* Move onto the next option */
+			increment_index();
+		}
+		/* Option takes argument */
+		else if(opt_ptr[1] == ':')
+		{
+			/* ie, -oARGUMENT, -xxxoARGUMENT, etc. */
+			if(argv[argv_index][opt_offset] != '\0')
+			{
+				optarg = &argv[argv_index][opt_offset];
+				increment_index();
+			}
+			/* ie, -o ARGUMENT (only if it's a required argument) */
+			else if(opt_ptr[2] != ':')
+			{
+				/* One of those "you're not expected to understand this" moment */
+				if(argv_index2 < argv_index) argv_index2 = argv_index;
+				while(argv[++argv_index2] && argv[argv_index2][0] == '-');
+				optarg = argv[argv_index2];
+
+				/* Don't cross into the non-option argument list */
+				if(argv_index2 + nonopt >= prev_argc) optarg = NULL;
+
+				/* Move onto the next option */
+				increment_index();
+			}
+			else
+			{
+				/* Move onto the next option */
+				increment_index();
+			}
+
+			/* In case we got no argument for an option with required argument */
+			if(optarg == NULL && opt_ptr[2] != ':')
+			{
+				optopt = c;
+				c = '?';
+
+				if(opterr)
+				{
+					fprintf(stderr,"%s: option requires an argument -- %c\n",
+							argv[0], optopt);
+				}
+			}
+		}
+		/* Option does not take argument */
+		else
+		{
+			/* Next argv_index */
+			if(argv[argv_index][opt_offset] == '\0')
+			{
+				increment_index();
+			}
+		}
+	}
+
+	/* Calculate optind */
+	if(c == -1)
+	{
+		optind = argc - nonopt;
+	}
+	else
+	{
+		optind = argv_index;
+	}
+
+	return c;
+}
+
+
+/* vim:ts=3
+*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/tests/tools/apps/c/include/pncompat/internal/getopt.h
----------------------------------------------------------------------
diff --git a/tests/tools/apps/c/include/pncompat/internal/getopt.h b/tests/tools/apps/c/include/pncompat/internal/getopt.h
new file mode 100644
index 0000000..d4c0932
--- /dev/null
+++ b/tests/tools/apps/c/include/pncompat/internal/getopt.h
@@ -0,0 +1,63 @@
+/*****************************************************************************
+* getopt.h - competent and free getopt library.
+* $Header: /cvsroot/freegetopt/freegetopt/getopt.h,v 1.2 2003/10/26 03:10:20 vindaci Exp $
+*
+* Copyright (c)2002-2003 Mark K. Kim
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+*   * Redistributions of source code must retain the above copyright
+*     notice, this list of conditions and the following disclaimer.
+*
+*   * Redistributions in binary form must reproduce the above copyright
+*     notice, this list of conditions and the following disclaimer in
+*     the documentation and/or other materials provided with the
+*     distribution.
+*
+*   * Neither the original author of this software nor the names of its
+*     contributors may be used to endorse or promote products derived
+*     from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+* DAMAGE.
+*/
+#ifndef GETOPT_H_
+#define GETOPT_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern char* optarg;
+extern int optind;
+extern int opterr;
+extern int optopt;
+
+int getopt(int argc, char** argv, char* optstr);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* GETOPT_H_ */
+
+
+/* vim:ts=3
+*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/tests/tools/apps/c/include/pncompat/misc_defs.h
----------------------------------------------------------------------
diff --git a/tests/tools/apps/c/include/pncompat/misc_defs.h b/tests/tools/apps/c/include/pncompat/misc_defs.h
new file mode 100644
index 0000000..90b0d4e
--- /dev/null
+++ b/tests/tools/apps/c/include/pncompat/misc_defs.h
@@ -0,0 +1,50 @@
+#ifndef PNCOMAPT_MISC_DEFS_H
+#define PNCOMAPT_MISC_DEFS_H
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#if defined(qpid_proton_EXPORTS)
+#error This include file is not for use in the main proton library
+#endif
+
+/*
+ * Platform neutral definitions. Only intended for use by Proton
+ * examples and test/debug programs.
+ *
+ * This file and any related support files may change or be removed
+ * at any time.
+ */
+
+// getopt()
+
+#include <proton/types.h>
+
+#if defined(__IBMC__)
+#  include <stdlib.h>
+#elif !defined(_WIN32) || defined (__CYGWIN__)
+#  include <getopt.h>
+#else
+#  include "internal/getopt.h"
+#endif
+
+pn_timestamp_t time_now(void);
+
+#endif /* PNCOMPAT_MISC_DEFS_H */

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d7f6e066/tests/tools/apps/c/include/pncompat/misc_funcs.inc
----------------------------------------------------------------------
diff --git a/tests/tools/apps/c/include/pncompat/misc_funcs.inc b/tests/tools/apps/c/include/pncompat/misc_funcs.inc
new file mode 100644
index 0000000..821aaf4
--- /dev/null
+++ b/tests/tools/apps/c/include/pncompat/misc_funcs.inc
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * This file provides the functions for "misc_defs.h" in the form of
+ * included code, as opposed to a separate library or object
+ * dependency.  In the absence of portable "pragma weak" compiler
+ * directives, this provides a simple workaround.
+ *
+ * Usage for a single compilation unit:
+ *
+ *  #include "pncompat/misc_funcs.inc"
+ *
+ * Usage for multiple combined compilation units: chose one to include
+ * "pncompat/misc_funcs.inc" as above and in each other unit needing the
+ * definitions use
+ *
+ *  #include "pncompat/misc_defs.h"
+ *
+ */
+
+#include "misc_defs.h"
+
+#if defined(_WIN32) && ! defined(__CYGWIN__)
+#include "pncompat/internal/getopt.c"
+#endif
+
+#if defined(_WIN32) && ! defined(__CYGWIN__)
+#include <windows.h>
+pn_timestamp_t time_now(void)
+{
+  FILETIME now;
+  ULARGE_INTEGER t;
+  GetSystemTimeAsFileTime(&now);
+  t.u.HighPart = now.dwHighDateTime;
+  t.u.LowPart = now.dwLowDateTime;
+  // Convert to milliseconds and adjust base epoch
+  return t.QuadPart / 10000 - 11644473600000;
+}
+#else
+#include <sys/time.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+pn_timestamp_t time_now(void)
+{
+  struct timeval now;
+  if (gettimeofday(&now, NULL)) {fprintf(stderr, "gettimeofday failed\n"); abort();}
+  return ((pn_timestamp_t)now.tv_sec) * 1000 + (now.tv_usec / 1000);
+}
+#endif


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org