summaryrefslogtreecommitdiff
path: root/examples/c/ex_async.c
diff options
context:
space:
mode:
authorSusan LoVerso <sue@wiredtiger.com>2014-04-02 15:17:09 -0400
committerSusan LoVerso <sue@wiredtiger.com>2014-04-02 15:17:09 -0400
commit6ccaab2fdd1a7afb542b534f855f2a8e238bfba1 (patch)
tree1a4d4eb5d193dd795b3cd2915b5fac436ae1b0ab /examples/c/ex_async.c
parent7aac76761cc7968ec67dd9074f3bd57582ac3e9a (diff)
downloadmongo-6ccaab2fdd1a7afb542b534f855f2a8e238bfba1.tar.gz
Add raw key/value support.
Diffstat (limited to 'examples/c/ex_async.c')
-rw-r--r--examples/c/ex_async.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/examples/c/ex_async.c b/examples/c/ex_async.c
index 9c2dc8592d2..769159db6c1 100644
--- a/examples/c/ex_async.c
+++ b/examples/c/ex_async.c
@@ -36,13 +36,14 @@
const char *home = NULL;
const char *uri = "table:async";
const char *uri2 = "table:async2";
-uint64_t search_id;
+uint64_t search_id = -1;
int global_error = 0;
/*! [example callback implementation] */
static int
cb_asyncop(WT_ASYNC_CALLBACK *cb, WT_ASYNC_OP *op, int ret, uint32_t flags)
{
+ WT_ITEM k, v;
const char *key, *value;
int t_ret;
@@ -61,15 +62,15 @@ cb_asyncop(WT_ASYNC_CALLBACK *cb, WT_ASYNC_OP *op, int ret, uint32_t flags)
fprintf(stderr, "CALLBACK: search %" PRIu64 " error %d\n",
op->get_id(op), ret);
-#if 0
/*! [Get the op's string key] */
- t_ret = op->get_key(op, &key);
+ t_ret = op->get_key(op, &k);
+ key = k.data;
/*! [Get the op's string key] */
/*! [Get the op's string value] */
- t_ret = op->get_value(op, &value);
+ t_ret = op->get_value(op, &v);
+ value = v.data;
/*! [Get the op's string value] */
printf("Got record: %s : %s\n", key, value);
-#endif
}
return (t_ret);
}
@@ -82,6 +83,7 @@ int main(void)
/*! [example connection] */
WT_ASYNC_OP *op, *op2, *opget;
WT_CONNECTION *wt_conn;
+ WT_ITEM key, value;
WT_SESSION *session;
int i, ret;
char k[16], v[16];
@@ -125,12 +127,16 @@ retry2:
snprintf(k, sizeof(k), "key%d", i);
snprintf(v, sizeof(v), "value%d", i);
/*! [Set the op's string key] */
- op->set_key(op, k);
- op2->set_key(op2, k);
+ key.data = k;
+ key.size = sizeof(k);
+ value.data = v;
+ value.size = sizeof(v);
+ op->set_key(op, &key);
+ op2->set_key(op2, &key);
/*! [Set the op's string key] */
/*! [Set the op's string value] */
- op->set_value(op, v);
- op2->set_value(op2, v);
+ op->set_value(op, &value);
+ op2->set_value(op2, &value);
/*! [Set the op's string value] */
/*! [example insert] */
ret = op->insert(op);
@@ -143,10 +149,15 @@ retry2:
/*! [flush] */
ret = wt_conn->async_new_op(wt_conn, uri, NULL, &cb, &opget);
- opget->set_key(opget, "key1");
+ snprintf(k, sizeof(k), "key1");
+ key.data = k;
+ key.size = sizeof(k);
+ opget->set_key(opget, &key);
search_id = opget->get_id(opget);
opget->search(opget);
+ wt_conn->async_flush(wt_conn);
+
/*! [example close] */
ret = wt_conn->close(wt_conn, NULL);
/*! [example close] */