Couchbase-Client
view release on metacpan or search on metacpan
xs/perl-couchbase-async.h view on Meta::CPAN
#ifndef PERL_COUCHBASE_ASYNC_H_
#define PERL_COUCHBASE_ASYNC_H_
#include "perl-couchbase.h"
#include <perlio.h>
typedef void(*plcba_c_evhandler)(libcouchbase_socket_t, short, void*);
typedef struct libcouchbase_io_opt_st plcba_cbcio;
/*two layered approach:
LAYER ONE:
layer defines event loop functions for libcouchbase.
layer exposes perl-compatible event loop API for event loop implementation
to select() on sockets, and stop selecting on them.
event loop implementation *must* keep track of an opaque object passed to it,
and call into the 'master' XS function with the following:
the opaque object
the event which ocurred.
this opaque object on the C end will contain the private C I/O handlers, and
a void*-typed argument, the internals of which will be known only to libcouchbase
itself.
specifically, Perl will only know about update_event() and delete_event().
update_event will be called with an additional empty RV - which, if needed
can be populated with a dup'd file descriptor, available for perl to select()
on.
The purpose for the dup'd fd is that perl will close() it when its object goes
out of scope. We don't want this to be seen from within libcouchbase.
LAYER TWO:
this layer defines the notification mechanism for operation results.
Operation requests will involve a user-defined 'opaque' data object (SV*),
and is asynchronously batched to libcouchbase_* functions.
The cookies for these functions are special. A cookie will have a hashref
in which it will store a Couchbase::Client::Return object for each key.
(in the case of stat(), which is only a single command, a pseudo-key will be
used TBC..)
Additionally, the cookie will have a counter which will decrement for each
response received. When the counter reaches 0, it means all the responses have
been received.
The cookie will have an SV* which is a function to call once the data has been
collected for an operation. It will be passed the hashref and the user-supplied
data
*/
#define PLCBA_EVENT_CLASS "Couchbase::Client::Async::Event"
/*various fields for helper class*/
typedef enum {
PLCBA_EVIDX_FD,
PLCBA_EVIDX_DUPFH,
PLCBA_EVIDX_WATCHFLAGS,
PLCBA_EVIDX_STATEFLAGS,
PLCBA_EVIDX_OPAQUE,
PLCBA_EVIDX_PLDATA,
} PLCBA_evidx_t;
#define PLCBA_EVIDX_TIMERID PLCBA_EVIDX_FD
/*various types of actions which may be taken by the callback*/
typedef enum {
PLCBA_EVACTION_WATCH,
PLCBA_EVACTION_UNWATCH,
PLCBA_EVACTION_SUSPEND,
PLCBA_EVACTION_RESUME,
} PLCBA_evaction_t;
typedef enum {
PLCBA_EVSTATE_INITIALIZED,
PLCBA_EVSTATE_ACTIVE,
PLCBA_EVSTATE_SUSPENDED
} PLCBA_evstate_t;
typedef enum {
PLCBA_EVTYPE_IO,
PLCBA_EVTYPE_TIMER
} PLCBA_evtype_t;
typedef struct PLCBA_c_event_st PLCBA_c_event;
struct PLCBA_c_event_st {
/*position within linked list*/
PLCBA_c_event *next;
PLCBA_c_event *prev;
/*Couchbase::Client::Async::Event object*/
AV *pl_event;
PLCBA_evtype_t evtype;
struct {
plcba_c_evhandler handler;
void *arg;
} c;
( run in 0.714 second using v1.01-cache-2.11-cpan-fe3c2283af0 )