本文整理汇总了C++中ei_decode_version函数的典型用法代码示例。如果您正苦于以下问题:C++ ei_decode_version函数的具体用法?C++ ei_decode_version怎么用?C++ ei_decode_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ei_decode_version函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ei_rpc
/*
* A true RPC. It return a NULL pointer
* in case of failure, otherwise a valid
* (ETERM *) pointer containing the reply
*/
int ei_rpc(ei_cnode* ec, int fd, char *mod, char *fun,
const char* inbuf, int inbuflen, ei_x_buff* x)
{
int i, index;
ei_term t;
erlang_msg msg;
char rex[MAXATOMLEN];
if (ei_rpc_to(ec, fd, mod, fun, inbuf, inbuflen) < 0) {
return -1;
}
/* FIXME are we not to reply to the tick? */
while ((i = ei_rpc_from(ec, fd, ERL_NO_TIMEOUT, &msg, x)) == ERL_TICK)
;
if (i == ERL_ERROR) return -1;
/*ep = 'erl'_element(2,emsg.msg);*/ /* {RPC_Tag, RPC_Reply} */
index = 0;
if (ei_decode_version(x->buff, &index, &i) < 0
|| ei_decode_ei_term(x->buff, &index, &t) < 0)
return -1; /* FIXME ei_decode_version don't set erl_errno as before */
/* FIXME this is strange, we don't check correct "rex" atom
and we let it pass if not ERL_SMALL_TUPLE_EXT and arity == 2 */
if (t.ei_type == ERL_SMALL_TUPLE_EXT && t.arity == 2)
if (ei_decode_atom(x->buff, &index, rex) < 0)
return -1;
/* remove header */
x->index -= index;
memmove(x->buff, &x->buff[index], x->index);
return 0;
}
示例2: outputv
static void outputv(ErlDrvData handle, ErlIOVec *ev) {
ErlDrvPort port = (ErlDrvPort) handle;
SysIOVec *bin;
int i, n, index = 0;
unsigned long hash;
unsigned long seed;
//first piece of the iovec is the seed
// printf("ev->size %d\n", ev->size);
// printf("ev-vsize %d\n", ev->vsize);
//apparently we start counting at 1 round here?
bin = &ev->iov[1];
// printf("bin->orig_size %d\n", bin->iov_len);
// printf("bin->iov_base %s\n", bin->iov_base);
ei_decode_version(bin->iov_base, &index, NULL);
ei_decode_ulong(bin->iov_base, &index, &seed);
hash = (unsigned int) seed;
if (index < bin->iov_len) {
hash = MurmurHash2(&bin->iov_base[index], bin->iov_len - index, hash);
}
// printf("hash %d\n", hash);
for (i=2; i<ev->vsize; i++) {
bin = &ev->iov[i];
// printf("bin->orig_size %d\n", bin->iov_len);
hash = MurmurHash2(bin->iov_base, bin->iov_len, hash);
// printf("hashed %d\n", i);
}
send_hash(port, hash);
}
示例3: output
static void output(ErlDrvData drv_data, char *buf, ErlDrvSizeT) {
driver_data_t *data = (driver_data_t *)drv_data;
int result = 0;
int index = 0, version, arity;
ei_decode_version(buf, &index, &version);
ei_decode_tuple_header(buf, &index, &arity);
if (2 == arity) {
result = ergen_driver_do_txn(data->driver, buf, &index);
if(result) {
ergen_drv_output_bool(data->port, result);
} else {
ergen_drv_output_error1(data->port, "badmatch", "cmd");
}
return;
}
ergen_drv_output_error0(data->port, "badarg");
}
示例4: get_bin_term
/*
* Reads an Erlang term.
*
* Only accepts 't' (term) or 'e' (end of test),
* exits program on error
* returns 1 on 'e', 0 on 't'
*/
int get_bin_term(ei_x_buff* x, ei_term* term)
{
int len, version;
ei_x_free(x);
x->buff = read_packet(&len);
x->buffsz = len;
x->index = 0;
switch (x->buff[x->index++]) {
case 'e':
return 1;
case 't':
if (ei_decode_version(x->buff, &x->index, &version) < 0
|| ei_decode_ei_term(x->buff, &x->index, term) < 0) {
fail("Failed to decode term");
exit(0);
}
return 0;
default:
fprintf(stderr, "Garbage received: ");
dump(x->buff, len, 16);
putc('\n', stderr);
fail("C program received garbage");
exit(1);
}
}
示例5: prepared_clear_bindings
static int prepared_clear_bindings(sqlite3_drv_t *drv, char *buffer, int buffer_size) {
unsigned int prepared_index;
long long_prepared_index;
int index = 0;
sqlite3_stmt *statement;
ei_decode_version(buffer, &index, NULL);
ei_decode_long(buffer, &index, &long_prepared_index);
prepared_index = (unsigned int) long_prepared_index;
if (prepared_index >= drv->prepared_count) {
#ifdef DEBUG
fprintf(drv->log, "Tried to clear bindings of prepared statement #%d, but maximum possible is #%d\n", prepared_index, drv->prepared_count - 1);
fflush(drv->log);
#endif
return output_error(drv, SQLITE_MISUSE,
"Trying to clear bindings of non-existent prepared statement");
}
#ifdef DEBUG
fprintf(drv->log, "Clearing bindings of prepared statement #%d\n", prepared_index);
fflush(drv->log);
#endif
statement = drv->prepared_stmts[prepared_index];
sqlite3_clear_bindings(statement);
return output_ok(drv);
}
示例6: prepared_finalize
static int prepared_finalize(sqlite3_drv_t *drv, char *buffer, int buffer_size) {
unsigned int prepared_index;
long long_prepared_index;
int index = 0;
ei_decode_version(buffer, &index, NULL);
ei_decode_long(buffer, &index, &long_prepared_index);
prepared_index = (unsigned int) long_prepared_index;
if (prepared_index >= drv->prepared_count) {
#ifdef DEBUG
fprintf(drv->log, "Tried to finalize prepared statement #%d, but maximum possible is #%d\n", prepared_index, drv->prepared_count - 1);
fflush(drv->log);
#endif
return output_error(drv, SQLITE_MISUSE,
"Trying to finalize non-existent prepared statement");
}
#ifdef DEBUG
fprintf(drv->log, "Finalizing prepared statement #%d\n", prepared_index);
fflush(drv->log);
#endif
// finalize the statement and make sure it isn't accidentally executed again
sqlite3_finalize(drv->prepared_stmts[prepared_index]);
drv->prepared_stmts[prepared_index] = NULL;
// if the statement is at the end of the array, space can be reused;
// otherwise don't bother
if (prepared_index == drv->prepared_count - 1) {
drv->prepared_count--;
}
return output_ok(drv);
}
示例7: handle_elixir_request
/**
* @brief Decode and forward requests from Elixir to the appropriate handlers
* @param req the undecoded request
* @param cookie
*/
static void handle_elixir_request(const char *req, void *cookie)
{
(void) cookie;
// Commands are of the form {Command, Arguments}:
// { atom(), term() }
int req_index = sizeof(uint16_t);
if (ei_decode_version(req, &req_index, NULL) < 0)
errx(EXIT_FAILURE, "Message version issue?");
int arity;
if (ei_decode_tuple_header(req, &req_index, &arity) < 0 ||
arity != 2)
errx(EXIT_FAILURE, "expecting {cmd, args} tuple");
char cmd[MAXATOMLEN];
if (ei_decode_atom(req, &req_index, cmd) < 0)
errx(EXIT_FAILURE, "expecting command atom");
for (struct request_handler *rh = request_handlers; rh->name != NULL; rh++) {
if (strcmp(cmd, rh->name) == 0) {
rh->handler(req, &req_index);
return;
}
}
errx(EXIT_FAILURE, "unknown command: %s", cmd);
}
示例8: prepared_reset
static int prepared_reset(sqlite3_drv_t *drv, char *buffer, int buffer_size) {
unsigned int prepared_index;
long long_prepared_index;
int index = 0;
sqlite3_stmt *statement;
ei_decode_version(buffer, &index, NULL);
ei_decode_long(buffer, &index, &long_prepared_index);
prepared_index = (unsigned int) long_prepared_index;
if (prepared_index >= drv->prepared_count) {
#ifdef DEBUG
fprintf(drv->log, "Tried to reset prepared statement #%d, but maximum possible is #%d\n", prepared_index, drv->prepared_count - 1);
fflush(drv->log);
#endif
return output_error(drv, SQLITE_MISUSE,
"Trying to reset non-existent prepared statement");
}
#ifdef DEBUG
fprintf(drv->log, "Resetting prepared statement #%d\n", prepared_index);
fflush(drv->log);
#endif
// don't bother about error code, any errors should already be shown by step
statement = drv->prepared_stmts[prepared_index];
sqlite3_reset(statement);
return output_ok(drv);
}
示例9: prepared_bind
static int prepared_bind(sqlite3_drv_t *drv, char *buffer, int buffer_size) {
int result;
unsigned int prepared_index;
long long_prepared_index;
int index = 0, type, size;
sqlite3_stmt *statement;
#ifdef DEBUG
fprintf(drv->log, "Finalizing prepared statement: %.*s\n", buffer_size, buffer);
fflush(drv->log);
#endif
ei_decode_version(buffer, &index, NULL);
ei_decode_tuple_header(buffer, &index, &size);
// assert(size == 2);
ei_decode_long(buffer, &index, &long_prepared_index);
prepared_index = (unsigned int) long_prepared_index;
if (prepared_index >= drv->prepared_count) {
return output_error(drv, SQLITE_MISUSE,
"Trying to bind non-existent prepared statement");
}
statement = drv->prepared_stmts[prepared_index];
result =
bind_parameters(drv, buffer, buffer_size, &index, statement, &type, &size);
if (result == SQLITE_OK) {
return output_ok(drv);
} else {
return result; // error has already been output
}
}
示例10: process_data
decode_result process_data(ErlDrvData handle,unsigned char* buf, ErlDrvSizeT* sz,char*& html_content,char*& url_address){
int index = 0,size=0,type=0,ver=0;
if (ei_decode_version((char*)buf, &index,&ver)){
//data encoding version mismatch
return decode_result{false,std::pair<std::string,std::string>("",""),
"data encoding version mismatch"};
}
else if (ei_get_type((char*)buf,&index,&type,&size)){
//must be a binary
return decode_result{false,std::pair<std::string,std::string>("",""),
"must be a binary"};
} else{
int tuple_arity;
ei_decode_tuple_header((char*)buf,&index,&tuple_arity);
ei_get_type((char*)buf,&index,&type,&size);
url_address = (char*)driver_alloc((size+2)*sizeof(char));
ei_decode_string((char*)buf,&index,url_address);
ei_get_type((char*)buf,&index,&type,&size);
//cout << "Html Content Size " << size << endl;
html_content = (char*)driver_alloc((size+2)*sizeof(char));
ei_decode_string((char*)buf,&index,html_content);
*sz = size;
std::string url_address_str(url_address);
std::string html_content_str(html_content);
return decode_result{true,std::pair<std::string,std::string>(url_address_str,html_content_str),NULL};
}
}
示例11: crop
static void crop(Cmd *cmd) {
char *buff = cmd->data;
int len = cmd->size;
Gd *gd = cmd->gd;
int index = 0;
long width, height;
int srcW, srcH, srcX, srcY, destX, destY, playX, playY;
gdImagePtr destination = NULL;
ei_decode_version(buff, &index, NULL);
ei_decode_tuple_header(buff, &index, NULL);
ei_decode_long(buff, &index, &width);
ei_decode_long(buff, &index, &height);
if (NULL == gd->image) {
driver_failure_atom(gd->port, "null_image");
return;
}
srcW = gdImageSX(gd->image);
srcH = gdImageSY(gd->image);
destination = gdImageCreateTrueColor(width, height);
if (NULL == destination) {
driver_failure_posix(gd->port, ENOMEM);
return;
}
gdImageFilledRectangle(destination, 0, 0, width, height, gdImageColorAllocate(destination, 255, 255, 255));
destX = (width - srcW) / 2;
destY = (height - srcH) / 2;
gdImageCopy(destination, gd->image, destX, destY, 0, 0, srcW, srcH);
gdImageDestroy(gd->image);
gd->image = destination;
send_atom(gd->port, "ok");
}
示例12: reply
static void reply(erlang_msg *msg, ei_x_buff *recv_x_buf) {
int index = 0;
int version;
ei_decode_version(recv_x_buf->buff, &index, &version);
send_replies(recv_x_buf->buff, &index);
}
示例13: resize
static void resize(Cmd *cmd) {
char *buff = cmd->data;
int len = cmd->size;
Gd *gd = cmd->gd;
int index = 0;
unsigned long width, height, srcW, srcH;
gdImagePtr destination = NULL;
ei_decode_version(buff, &index, NULL);
ei_decode_tuple_header(buff, &index, NULL);
ei_decode_ulong(buff, &index, &width);
ei_decode_ulong(buff, &index, &height);
if (NULL == gd->image) {
driver_failure_atom(gd->port, "null_image");
return;
}
srcW = gdImageSX(gd->image);
srcH = gdImageSY(gd->image);
destination = gdImageCreateTrueColor(width, height);
if (NULL == destination) {
driver_failure_posix(gd->port, ENOMEM);
return;
}
gdImageCopyResampled(destination, gd->image, 0, 0, 0, 0, width, height, srcW, srcH);
gdImageDestroy(gd->image);
gd->image = destination;
send_atom(gd->port, "ok");
}
示例14: iconv_erl_control
static int iconv_erl_control(ErlDrvData drv_data,
unsigned int command,
char *buf, int len,
char **rbuf, int rlen)
{
int i;
int size;
int index = 0;
int avail;
size_t inleft, outleft;
ErlDrvBinary *b;
char *from, *to, *string, *stmp, *rstring, *rtmp;
iconv_t cd;
ei_decode_version(buf, &index, &i);
ei_decode_tuple_header(buf, &index, &i);
ei_get_type(buf, &index, &i, &size);
from = malloc(size + 1);
ei_decode_string(buf, &index, from);
ei_get_type(buf, &index, &i, &size);
to = malloc(size + 1);
ei_decode_string(buf, &index, to);
ei_get_type(buf, &index, &i, &size);
stmp = string = malloc(size + 1);
ei_decode_string(buf, &index, string);
cd = iconv_open(to, from);
if(cd == (iconv_t) -1)
{
cd = iconv_open("ascii", "ascii");
if(cd == (iconv_t) -1)
{
cd = iconv_open("ascii", "ascii");
}
}
outleft = avail = 4*size;
inleft = size;
rtmp = rstring = malloc(avail);
iconv(cd, &stmp, &inleft, &rtmp, &outleft);
size = rtmp - rstring;
//printf("size=%d, res=%s\r\n", size, rstring);
*rbuf = (char*)(b = driver_alloc_binary(size));
memcpy(b->orig_bytes, rstring, size);
free(from);
free(to);
free(string);
free(rstring);
iconv_close(cd);
return size;
}
示例15: erl_self
ETERM *erl_global_whereis(int fd, const char *name, char *node)
{
char buf[EISMALLBUF];
char *bufp=buf;
char tmpbuf[64];
int index = 0;
erlang_pid *self = erl_self();
erlang_pid epid;
ETERM *opid;
erlang_msg msg;
int i;
int version,arity,msglen;
self->num = fd; /* FIXME looks strange to change something?! */
ei_encode_version(buf,&index);
ei_encode_tuple_header(buf,&index,2);
ei_encode_pid(buf,&index,self); /* PidFrom */
ei_encode_tuple_header(buf,&index,5);
ei_encode_atom(buf,&index,"call"); /* call */
ei_encode_atom(buf,&index,"global"); /* Mod */
ei_encode_atom(buf,&index,"whereis_name"); /* Fun */
ei_encode_list_header(buf,&index,1); /* Args: [ name ] */
ei_encode_atom(buf,&index,name);
ei_encode_empty_list(buf,&index);
ei_encode_atom(buf,&index,"user"); /* user */
/* make the rpc call */
if (ei_send_reg_encoded(fd,self,"rex",buf,index)) return NULL;
while (1) {
index = EISMALLBUF;
if (!(i = ei_recv_internal(fd,&bufp,&index,&msg,&msglen,1,0))) continue;
else break;
}
if (i != ERL_SEND) return NULL;
/* expecting { rex, pid } */
index = 0;
if (ei_decode_version(buf,&index,&version)
|| ei_decode_tuple_header(buf,&index,&arity)
|| (arity != 2)
|| ei_decode_atom(buf,&index,tmpbuf)
|| strcmp(tmpbuf,"rex")
|| ei_decode_pid(buf,&index,&epid))
return NULL; /* bad response from other side */
/* put the pid into a format for the caller */
index = 0;
ei_encode_pid(buf,&index,&epid);
opid = erl_decode((unsigned char*)buf);
/* extract the nodename for the caller */
if (node) strcpy(node,epid.node);
return opid;
}