MongoDB-Async
view release on metacpan or search on metacpan
mongo_link.h view on Meta::CPAN
#define PREP 1
#define NO_PREP 0
#define CREATE_MSG_HEADER(rid, rto, opcode) \
header.length = 0; \
header.request_id = rid; \
header.response_to = rto; \
header.op = opcode;
#define CREATE_RESPONSE_HEADER(buf, ns, rto, opcode) \
sv_setiv(request_id, SvIV(request_id)+1); \
CREATE_MSG_HEADER(SvIV(request_id), rto, opcode); \
APPEND_HEADER_NS(buf, ns, 0);
#define CREATE_HEADER_WITH_OPTS(buf, ns, opcode, opts) \
sv_setiv(request_id, SvIV(request_id)+1); \
CREATE_MSG_HEADER(SvIV(request_id), 0, opcode); \
APPEND_HEADER_NS(buf, ns, opts);
#define CREATE_HEADER(buf, ns, opcode) \
CREATE_RESPONSE_HEADER(buf, ns, 0, opcode);
#define APPEND_HEADER(buf, opts) buf.pos += INT_32; \
perl_mongo_serialize_int(&buf, header.request_id); \
perl_mongo_serialize_int(&buf, header.response_to); \
perl_mongo_serialize_int(&buf, header.op); \
perl_mongo_serialize_int(&buf, opts);
#define APPEND_HEADER_NS(buf, ns, opts) \
APPEND_HEADER(buf, opts); \
perl_mongo_serialize_string(&buf, ns, strlen(ns));
#define CREATE_BUF(size) \
Newx(buf.start, size, char); \
buf.pos = buf.start; \
buf.end = buf.start + size;
typedef struct {
int length;
int request_id;
int response_to;
int op;
} mongo_msg_header;
/*
* a connection to the database
*
* host is hostname
* port is port number
* socket is the actual socket the connection is using
* connected is a boolean indicating if the socket is connected or not
*/
typedef struct {
ev_io w;
char *buffer;
int len;
int read;
SV *coro;
} mongo_async_sock_reader_state;
typedef struct {
ev_io w;
char *buffer;
int len;
int done;
SV *coro;
} mongo_async_sockwatcher_state;
typedef struct _mongo_server {
char *host;
int port;
int socket;
int connected;
mongo_async_sockwatcher_state sockwatcher;
} mongo_server;
/*
* auto_reconnect is whether to reconnect on disconnect
* timeout is how long to try to connect before failing
* num is the number of servers in this set
* master is the index of the master server, if there is more than 1 server
* server is an array of pointers to connections
*/
typedef struct {
int auto_reconnect;
int timeout;
int num;
mongo_server *master;
int copy;
bool ssl;
#ifdef MONGO_SSL
SSL *ssl_handle;
SSL_CTX *ssl_context;
#endif
int (*sender)(void* link, const char* buffer, size_t len);
int (*receiver)(void* link, const char* buffer, size_t len);
} mongo_link;
typedef struct {
// response header
mongo_msg_header header;
// response fields
int flag;
int64_t cursor_id;
int start;
// number of results used
int at;
// number results returned
int num;
// results
buffer buf;
( run in 1.998 second using v1.01-cache-2.11-cpan-39bf76dae61 )