C++ make_http_request not functioning
Mon, 01/14/2013 - 21:26
I am using some of the example documents to try and retrieve a view from couchbase. I am using C++ and Couchbase 2.0.
I am using the following:
static void complete_callback(lcb_http_request_t request,lcb_t instance, const void *cookie, lcb_error_t error,const lcb_http_resp_t *resp)
{
const void *buffer3 = resp->v.v0.bytes;
const char *temp3 = (const char *)buffer3;
//At this point I have checked and there is nothing being stored and resp as no data in "bytes"
}
int main()
{
...
(void)lcb_set_http_complete_callback(instance, complete_callback);
lcb_error_t rc;
lcb_http_cmd_t cmd ;
cmd.version = 0;
cmd.v.v0.path = "_design/getKeys/_view/getKeys?limit=10";
cmd.v.v0.npath = strlen(cmd.v.v0.path);
cmd.v.v0.body = NULL;
cmd.v.v0.nbody = 0;
cmd.v.v0.method = LCB_HTTP_METHOD_GET;
cmd.v.v0.chunked = 1;
cmd.v.v0.content_type = "application/json";
rc = lcb_make_http_request(instance, NULL, LCB_HTTP_TYPE_VIEW, &cmd, NULL);
lcb_wait(instance);
...
}I have successfully added and removed documents from the bucket. However when running the code above I receive no data. Even using a debugger I can see that "resp" has nothing in "bytes". In couchbase I have made a view and published it. I am able to view results through a web-browser using the "_design/getKeys/_view/getKeys?limit=10" path. However, I am able to see a read from the server. Any help and definitely advice would be greatly appreciated.
Obviously you have two options:
1) define data_callback in conjunction to complete_callback, then you will receive chunks with data callback and complete callback will be triggered after the end of stream
2) set cmd.v.v0.chunked to zero, this will force libcouchbase to collect all chunks and emit them as a whole in complete_callback
This behaviour is documented here: https://github.com/couchbase/libcouchbase/blob/master/include/libcouchba...
Find me on FreeNode IRC in #libcouchbase channel