Permalink
Browse files

Async client - got basic operations working

  • Loading branch information...
1 parent cb7ebbb commit 15f6c4434e2136141a38ac55666b20f1cdc772d1 @mnunberg mnunberg committed Jan 26, 2012
View
@@ -1,3 +1,5 @@
+#include "perl-couchbase-async.h"
+
MODULE = Couchbase::Client PACKAGE = Couchbase::Client::Async PREFIX = PLCBA_
SV *
@@ -11,7 +13,7 @@ PLCBA_connect(self)
void
PLCBA_HaveEvent(pkg, flags, opaque)
- const char pkg
+ const char *pkg
short flags
SV *opaque
View
@@ -1,6 +1,12 @@
#include "perl-couchbase.h"
#include "plcb-util.h"
+
+//#define libcouchbase_wait(x) \
+// libcouchbase_flush_buffers(x, NULL);
+
+#define libcouchbase_behavior_set_syncmode(x, y)
+
static void PLCB_cleanup(PLCB_t *object)
{
if(object->instance) {
@@ -46,9 +52,11 @@ SV *PLCB_construct(const char *pkg, AV *options)
plcb_ctor_init_common(object, instance);
libcouchbase_set_cookie(instance, object);
+ libcouchbase_behavior_set_syncmode(instance, LIBCOUCHBASE_SYNCHRONOUS);
if(libcouchbase_connect(instance) == LIBCOUCHBASE_SUCCESS) {
libcouchbase_wait(instance);
+ warn("Connected!");
}
plcb_setup_callbacks(object);
@@ -65,9 +73,7 @@ SV *PLCB_construct(const char *pkg, AV *options)
inst_name = obj_name->instance;
#define bless_return(object, rv, av) \
- rv = newRV_noinc((SV*)av); \
- sv_bless(rv, object->ret_stash); \
- return rv;
+ return plcb_ret_blessed_rv(object, av);
static SV *PLCB_set_common(SV *self,
@@ -107,10 +113,12 @@ static SV *PLCB_set_common(SV *self,
plcb_convert_storage_free(object, value, store_flags);
if(err != LIBCOUCHBASE_SUCCESS) {
- plcb_ret_set_err(object, ret_av, err);
+ plcb_ret_set_err(object, ret_av, err);
} else {
+ warn("Waiting..");
libcouchbase_wait(instance);
- plcb_ret_set_err(object, ret_av, syncp->err);
+ warn("Done!");
+ plcb_ret_set_err(object, ret_av, syncp->err);
}
bless_return(object, ret_rv, ret_av);
}
@@ -149,11 +157,13 @@ static SV *PLCB_arithmetic_common(SV *self,
if(err != LIBCOUCHBASE_SUCCESS) {
plcb_ret_set_err(object, ret_av, err);
} else {
- libcouchbase_wait(instance);
- plcb_ret_set_err(object, ret_av, syncp->err);
+ if(!syncp->received) {
+ libcouchbase_wait(instance);
+ }
+ plcb_ret_set_err(object, ret_av, syncp->err);
if(syncp->err == LIBCOUCHBASE_SUCCESS) {
- plcb_ret_set_numval(object, ret_av, syncp->arithmetic, syncp->cas);
+ plcb_ret_set_numval(object, ret_av, syncp->arithmetic, syncp->cas);
}
}
bless_return(object, ret_rv, ret_av);
@@ -197,10 +207,10 @@ static SV *PLCB_get_common(SV *self, SV *key, int exp_offset)
libcouchbase_wait(instance);
plcb_ret_set_err(object, ret_av, syncp->err);
if(syncp->err == LIBCOUCHBASE_SUCCESS) {
- plcb_ret_set_strval(
- object, ret_av, syncp->value, syncp->nvalue,
- syncp->store_flags, syncp->cas);
- }
+ plcb_ret_set_strval(
+ object, ret_av, syncp->value, syncp->nvalue,
+ syncp->store_flags, syncp->cas);
+ }
}
bless_return(object, ret_rv, ret_av);
}
View
@@ -12,6 +12,10 @@ lib/Couchbase/Client/Errors_const.pm
lib/Couchbase/Client/IDXConst_const.pm
lib/Couchbase/Client/Compat.pm
+lib/Couchbase/Client/Async.pm
+lib/Couchbase/Client/Async/Event.pm
+lib/Couchbase/Client/Async/Request.pm
+
Client.xs
Async.xs
@@ -25,10 +29,10 @@ convert.c
ctor.c
async.c
async_callbacks.c
+async_events.c
idx_constants.pl
error_constants.pl
print_constants.pl
-async_constants.pl
t/00-load.t
View
@@ -11,7 +11,7 @@ WriteMakefile(
VERSION_FROM => 'lib/Couchbase/Client.pm',
ABSTRACT_FROM => 'lib/Couchbase/Client.pm',
OBJECT => 'callbacks.o convert.o ctor.o Client.o ' .
- 'async.o async_callbacks.o',
+ 'async.o async_callbacks.o async_events.o',
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
Oops, something went wrong.

0 comments on commit 15f6c44

Please sign in to comment.