Skip to content

Commit

Permalink
Fix deprecation warnings
Browse files Browse the repository at this point in the history
Change-Id: If0a4a7157c6f9036c2957357c42d0f937f98b8a9
Reviewed-on: http://review.couchbase.org/40024
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information
avsej committed Aug 26, 2014
1 parent b0492f8 commit 16507e6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
35 changes: 20 additions & 15 deletions ext/couchbase_ext/bucket.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ trigger_on_connect_callback(VALUE self)
}

static void
error_callback(lcb_t handle, lcb_error_t error, const char *errinfo)
bootstrap_callback(lcb_t handle, lcb_error_t error)
{
struct cb_bucket_st *bucket = (struct cb_bucket_st *)lcb_get_cookie(handle);

lcb_breakout(handle);
bucket->exception = cb_check_error(error, errinfo, Qnil);
bucket->exception = cb_check_error(error, "bootstrap error", Qnil);
if (bucket->async && !bucket->connected) {
(void)trigger_on_connect_callback(bucket->self);
}
Expand Down Expand Up @@ -407,7 +407,7 @@ do_connect(struct cb_bucket_st *bucket)
rb_exc_raise(cb_check_error(err, "failed to create libcouchbase instance", Qnil));
}
lcb_set_cookie(bucket->handle, bucket);
(void)lcb_set_error_callback(bucket->handle, error_callback);
(void)lcb_set_bootstrap_callback(bucket->handle, bootstrap_callback);
(void)lcb_set_store_callback(bucket->handle, cb_storage_callback);
(void)lcb_set_get_callback(bucket->handle, cb_get_callback);
(void)lcb_set_touch_callback(bucket->handle, cb_touch_callback);
Expand All @@ -421,11 +421,8 @@ do_connect(struct cb_bucket_st *bucket)
(void)lcb_set_unlock_callback(bucket->handle, cb_unlock_callback);
(void)lcb_set_configuration_callback(bucket->handle, configuration_callback);

if (bucket->timeout > 0) {
lcb_set_timeout(bucket->handle, bucket->timeout);
} else {
bucket->timeout = lcb_get_timeout(bucket->handle);
}
lcb_cntl(bucket->handle, (bucket->timeout > 0) ? LCB_CNTL_SET : LCB_CNTL_GET,
LCB_CNTL_OP_TIMEOUT, &bucket->timeout);
err = lcb_connect(bucket->handle);
if (err != LCB_SUCCESS) {
cb_bucket_disconnect(bucket->self);
Expand Down Expand Up @@ -930,7 +927,7 @@ cb_bucket_timeout_set(VALUE self, VALUE val)
VALUE tmval;

bucket->timeout = (uint32_t)NUM2ULONG(val);
lcb_set_timeout(bucket->handle, bucket->timeout);
lcb_cntl(bucket->handle, LCB_CNTL_SET, LCB_CNTL_OP_TIMEOUT, &bucket->timeout);
tmval = ULONG2NUM(bucket->timeout);

return tmval;
Expand Down Expand Up @@ -984,10 +981,15 @@ cb_bucket_key_prefix_set(VALUE self, VALUE val)
cb_bucket_hostname_get(VALUE self)
{
struct cb_bucket_st *bucket = DATA_PTR(self);

if (bucket->handle) {
const char * host = lcb_get_host(bucket->handle);
unsigned long len = RSTRING_LEN(bucket->hostname);
const char *host;
char *colon;
unsigned long len;
host = lcb_get_node(bucket->handle, LCB_NODE_HTCONFIG | LCB_NODE_NEVERNULL, 0);
if (host != NULL && (colon = strstr(host, ":")) != NULL) {
*colon = '\0';
}
len = RSTRING_LEN(bucket->hostname);
if (len != strlen(host) || strncmp(RSTRING_PTR(bucket->hostname), host, len) != 0) {
bucket->hostname = STR_NEW_CSTR(host);
rb_str_freeze(bucket->hostname);
Expand All @@ -1007,7 +1009,12 @@ cb_bucket_port_get(VALUE self)
{
struct cb_bucket_st *bucket = DATA_PTR(self);
if (bucket->handle) {
bucket->port = atoi(lcb_get_port(bucket->handle));
const char *port;
port = lcb_get_node(bucket->handle, LCB_NODE_HTCONFIG | LCB_NODE_NEVERNULL, 0);
if (port && (port = strstr(port, ":"))) {
port++;
}
bucket->port = atoi(port);
}
return UINT2NUM(bucket->port);
}
Expand Down Expand Up @@ -1433,5 +1440,3 @@ cb_bucket_disconnect(VALUE self)
return Qfalse;
}
}


1 change: 0 additions & 1 deletion ext/couchbase_ext/couchbase_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,3 @@ rb_funcall_2(VALUE self, ID method, VALUE arg1, VALUE arg2)
}

#endif

7 changes: 7 additions & 0 deletions ext/couchbase_ext/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ cb_check_error_with_status(lcb_error_t rc, const char *msg, VALUE key,
}

str = rb_str_buf_new2(msg ? msg : "");
if (msg) {
str = rb_str_buf_new2(msg);
rb_str_buf_cat2(str, ", ");
} else {
str = rb_str_buf_new2("");
}
rb_str_buf_cat2(str, lcb_strerror(NULL, rc));
rb_str_buf_cat2(str, " (");
if (key != Qnil) {
snprintf(buf, 300, "key=\"%s\", ", RSTRING_PTR(key));
Expand Down

0 comments on commit 16507e6

Please sign in to comment.