Created
May 17, 2012 21:58
-
-
Save mnunberg/2721838 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
Handle::cb_get(libcouchbase_t instance, ResultSet* rs, | |
libcouchbase_error_t err, | |
const void *key, libcouchbase_size_t nkey, | |
const void *value, libcouchbase_size_t nvalue, | |
libcouchbase_uint32_t flags, libcouchbase_cas_t cas) | |
{ | |
int myerr = mapError(err, Error::SUBSYSf_MEMD|Error::ERROR_GENERIC); | |
rs->stats[myerr]++; | |
if (rs->options.full) { | |
std::string sk((const char*)key, nkey); | |
std::string sv; | |
if (nvalue) { | |
sv.assign((const char*)value, nvalue); | |
} else { | |
sv = ""; | |
} | |
rs->fullstats[sk] = sv; | |
} | |
rs->remaining--; | |
} | |
bool | |
Handle::connect(Error *errp) | |
{ | |
// Gather parameters | |
libcouchbase_error_t the_error; | |
log_debug("Using %s as hostname", options.hostname.c_str()); | |
instance = libcouchbase_create(cstr_ornull(options.hostname), | |
cstr_ornull(options.username), | |
cstr_ornull(options.password), | |
cstr_ornull(options.bucket), | |
NULL); | |
if (!instance) { | |
errp->setCode(Error::SUBSYSf_CLIENT|Error::ERROR_GENERIC); | |
errp->errstr = "Could not construct handle"; | |
return false; | |
} | |
libcouchbase_set_error_callback(instance, cb_err); | |
libcouchbase_set_touch_callback(instance, | |
(libcouchbase_touch_callback)cb_keyop); | |
libcouchbase_set_remove_callback(instance, | |
(libcouchbase_remove_callback)cb_keyop); | |
libcouchbase_set_storage_callback(instance, | |
(libcouchbase_storage_callback)cb_storage); | |
libcouchbase_set_get_callback(instance, | |
(libcouchbase_get_callback)cb_get); | |
libcouchbase_set_cookie(instance, this); | |
the_error = libcouchbase_connect(instance); | |
if (the_error != LIBCOUCHBASE_SUCCESS) { | |
errp->setCode(mapError(the_error, | |
Error::SUBSYSf_NETWORK|Error::ERROR_GENERIC)); | |
errp->errstr = libcouchbase_strerror(instance, the_error); | |
log_error("libcouchbase_connect failed: %s", | |
errp->prettyPrint().c_str()); | |
return false; | |
} | |
libcouchbase_wait(instance); | |
if (pending_errors.size()) { | |
*errp = pending_errors.back(); | |
pending_errors.clear(); | |
log_error("Got errors during connection"); | |
return false; | |
} | |
return true; | |
} | |
bool | |
Handle::dsGet(Command cmd, Dataset const &ds, ResultSet& out, | |
const ResultOptions& options) | |
{ | |
out.options = options; | |
out.clear(); | |
libcouchbase_time_t exp = out.options.expiry; | |
DatasetIterator* iter = ds.getIter(); | |
for (iter->start(); iter->done() == false; iter->advance()) { | |
std::string k = iter->key(); | |
libcouchbase_size_t sz = k.size(); | |
const char *cstr = k.c_str(); | |
libcouchbase_error_t err = | |
libcouchbase_mget(instance, &out, 1, | |
(const void**)&cstr, &sz, &exp); | |
if (err == LIBCOUCHBASE_SUCCESS) { | |
postsubmit(out); | |
} else { | |
out.setError(instance, err, k); | |
} | |
} | |
delete iter; | |
collect_result(out); | |
return true; | |
} | |
/* ..... */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment