本文整理汇总了C++中ei_x_free函数的典型用法代码示例。如果您正苦于以下问题:C++ ei_x_free函数的具体用法?C++ ei_x_free怎么用?C++ ei_x_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ei_x_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ei_x_encode_list_header
void *erlXML_StartElementHandler(expat_data *d,
const XML_Char *name,
const XML_Char **atts)
{
int i;
ei_x_encode_list_header(&event_buf, 1);
ei_x_encode_tuple_header(&event_buf, 2);
ei_x_encode_long(&event_buf, XML_START);
ei_x_encode_tuple_header(&event_buf, 2);
encode_name(name);
ei_x_append(&event_buf, &xmlns_buf);
ei_x_free(&xmlns_buf);
ei_x_new(&xmlns_buf);
for (i = 0; atts[i]; i += 2) {}
if (i > 0)
{
ei_x_encode_list_header(&event_buf, i/2);
for (i = 0; atts[i]; i += 2)
{
ei_x_encode_tuple_header(&event_buf, 2);
encode_name(atts[i]);
ei_x_encode_binary(&event_buf, atts[i+1], strlen(atts[i+1]));
}
}
ei_x_encode_empty_list(&event_buf);
return NULL;
}
示例2: ei_rpc_to
/*
* Now returns non-negative number for success, negative for failure.
*/
int ei_rpc_to(ei_cnode *ec, int fd, char *mod, char *fun,
const char *buf, int len)
{
ei_x_buff x;
erlang_pid *self = ei_self(ec);
self->num = fd;
/* encode header */
ei_x_new_with_version(&x);
ei_x_encode_tuple_header(&x, 2); /* A */
self->num = fd;
ei_x_encode_pid(&x, self); /* A 1 */
ei_x_encode_tuple_header(&x, 5); /* B A 2 */
ei_x_encode_atom(&x, "call"); /* B 1 */
ei_x_encode_atom(&x, mod); /* B 2 */
ei_x_encode_atom(&x, fun); /* B 3 */
ei_x_append_buf(&x, buf, len); /* B 4 */
ei_x_encode_atom(&x, "user"); /* B 5 */
/* ei_x_encode_atom(&x,"user"); */
ei_send_reg_encoded(fd, self, "rex", x.buff, x.index);
ei_x_free(&x);
return 0;
} /* rpc_to */
示例3: ei_x_new_with_version
bool CCESUT::TradeOrder(PTradeOrderTxnInput pTxnInput,
INT32 iTradeType, bool bExecutorIsAccountOwner) {
ei_x_buff x;
ei_x_new_with_version(&x);
ei_x_encode_tuple_header(&x, 2);
{
ei_x_encode_atom(&x, "ok");
ei_x_encode_tuple_header(&x, 2);
{
ei_x_encode_atom(&x, APP ".BH.TO");
ei_x_encode_tuple_header(&x, 3);
{
m_Encoder.encode(&x, "trade_type", iTradeType);
m_Encoder.encode(&x, "executor_is_account_owner", bExecutorIsAccountOwner);
m_Encoder.encode(&x, *pTxnInput);
}
}
}
int result = driver_output(m_ErlDrvPort, x.buff, x.index);
#ifdef _TRACE
cout << "[TO] ! " << *pTxnInput << ", result=" << result << '\r' << endl;
#endif
ei_x_free(&x);
return result;
}
示例4: json_parse_to_ei
void json_parse_to_ei(ErlDrvData session, const unsigned char* s, int len, int opts) {
int parseValue = opts & EEP0018_PARSE_VALUE;
unsigned char* yajl_msg = 0;
unsigned char* msg = 0;
ErlDrvPort port = (ErlDrvPort) session;
/*
* initialize yajl parser
*/
State state;
init(&state, opts);
yajl_parser_config conf = { YAJL_ALLOW_COMMENTS }; // , YAJL_CHECK_UTF8 };
yajl_handle handle = yajl_alloc(&callbacks, &conf, &state);
/* start parser */
yajl_status stat;
if(parseValue) stat = yajl_parse(handle, (const unsigned char*) "[ ", 2);
stat = yajl_parse(handle, s, len);
if(parseValue) stat = yajl_parse(handle, (const unsigned char*) " ]", 2);
/*
* sometimes the parser is still stuck inside a JSON token. This finishs
* the token no matter what.
*/
if(stat == yajl_status_insufficient_data)
stat = yajl_parse(handle, (const unsigned char*) " ", 1);
/*
* get an error message on errors
*/
switch(stat) {
case yajl_status_ok: break;
case yajl_status_insufficient_data:
msg = (unsigned char*)"Insufficient data";
break;
default:
msg = yajl_msg = yajl_get_error(handle, 0, s, len);
break;
}
/*
* if result is not ok: we write {error, "reason"} instead. This is
* something that will never be encoded from any JSON data.
*/
if(msg) {
ei_x_free(&state.ei_buf);
ei_x_new_with_version(&state.ei_buf);
ei_x_encode_tuple_header(&state.ei_buf, 2);
ei_x_encode_atom_len(&state.ei_buf, "error", 5);
ei_x_encode_string_len(&state.ei_buf, (const char*) msg, strlen((const char*) msg));
if(yajl_msg) yajl_free_error(yajl_msg);
}
send_data(port, EEP0018_EI, state.ei_buf.buff, state.ei_buf.index);
deinit(&state);
}
示例5: reply_avframe
void reply_avframe(AVPacket *pkt, AVCodec *codec) {
ei_x_buff x;
ei_x_new_with_version(&x);
struct video_frame r;
r.content = codec->type == AVMEDIA_TYPE_VIDEO ? frame_content_video :
codec->type == AVMEDIA_TYPE_AUDIO ? frame_content_audio : 0;
r.dts = pkt->dts / 90.0;
r.pts = pkt->pts / 90.0;
r.stream_id = 0;
r.codec = codec->id == AV_CODEC_ID_H264 ? frame_codec_h264 :
codec->id == AV_CODEC_ID_AAC ? frame_codec_aac : 0;
r.flavor = pkt->flags & CODEC_FLAG_GLOBAL_HEADER ? frame_flavor_config :
pkt->flags & AV_PKT_FLAG_KEY ? frame_flavor_keyframe :
frame_flavor_frame;
r.track_id = codec->type == AVMEDIA_TYPE_VIDEO ? 1 : 2;
r.body.data = pkt->data;
r.body.size = pkt->size;
write_video_frame(&x, r);
write_x(&x);
ei_x_free(&x);
}
示例6: 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);
}
}
示例7: reply_atom
void reply_atom(char *a) {
ei_x_buff x;
ei_x_new_with_version(&x);
ei_x_encode_atom(&x, a);
write_x(&x);
ei_x_free(&x);
}
示例8: cmd_ei_send_funs
static void cmd_ei_send_funs(char* buf, int len)
{
int index = 0, n;
long fd;
erlang_pid pid;
ei_x_buff x;
erlang_fun fun1, fun2;
if (ei_decode_long(buf, &index, &fd) < 0)
fail("expected long");
if (ei_decode_pid(buf, &index, &pid) < 0)
fail("expected pid (node)");
if (ei_decode_tuple_header(buf, &index, &n) < 0)
fail("expected tuple");
if (n != 2)
fail("expected tuple");
if (ei_decode_fun(buf, &index, &fun1) < 0)
fail("expected Fun1");
if (ei_decode_fun(buf, &index, &fun2) < 0)
fail("expected Fun2");
if (ei_x_new_with_version(&x) < 0)
fail("ei_x_new_with_version");
if (ei_x_encode_tuple_header(&x, 2) < 0)
fail("encode tuple header");
if (ei_x_encode_fun(&x, &fun1) < 0)
fail("encode fun1");
if (ei_x_encode_fun(&x, &fun2) < 0)
fail("encode fun2");
free_fun(&fun1);
free_fun(&fun2);
send_errno_result(ei_send(fd, &pid, x.buff, x.index));
ei_x_free(&x);
}
示例9: gn_handle_read
/* called from gtk main loop when there's data on the cnode socket */
gboolean gn_handle_read(GIOChannel *source,GIOCondition cond,gpointer data){
erlang_msg msg;
ei_x_buff xbuf;
/* fd = g_io_channel_unix_get_fd(source); */
ei_x_new_with_version(&xbuf);
switch ( ei_xreceive_msg(fd, &msg, &xbuf) ){
case ERL_TICK:
break; /* ignore */
case ERL_MSG:
switch (msg.msgtype) {
case ERL_SEND:
case ERL_REG_SEND:
reply(&msg, &xbuf);
break;
case ERL_LINK:
case ERL_UNLINK:
case ERL_GROUP_LEADER:
break; /* ignore */
case ERL_EXIT:
case ERL_EXIT2:
case ERL_NODE_LINK:
gtk_main_quit(); /* crash and burn */
return FALSE;
}
break;
case ERL_ERROR:
gtk_main_quit(); /* crash and burn */
return FALSE;
}
ei_x_free(&xbuf);
return TRUE;
}
示例10: ei_x_encode_table
int ei_x_encode_table(ei_x_buff* types, ei_x_buff* values, K r, QOpts* opts) {
EI(ei_x_encode_tuple_header(types, 2));
EI(ei_x_encode_atom(types, "table"));
EI(ei_x_encode_tuple_header(values, 2));
ei_x_buff column_types;
ei_x_new_with_version(&column_types);
EIC(ei_x_encode_k_tv(&column_types, values, kK(r->k)[0], opts),
ei_x_free(&column_types));
ei_x_free(&column_types);
EI(ei_x_encode_k_tv(types, values, kK(r->k)[1], opts));
return 0;
}
示例11: send_atom
static void send_atom(ErlDrvPort port, const char *str) {
ei_x_buff x;
ei_x_new_with_version(&x);
ei_x_encode_atom(&x, str);
driver_output(port, x.buff, x.index);
ei_x_free(&x);
}
示例12: gn_start_cnode
int gn_start_cnode(char **argv) {
extern ei_cnode ec;
char rem_node_name[MAXATOMLEN] = ""; /* other node name */
ei_x_buff xbuf;
erlang_pid *self = ei_self(&ec);
strcat(rem_node_name,REMNODE);
strcat(rem_node_name,"@");
strcat(rem_node_name,REMHOST);
rem_regname = g_strdup(REMREG);
g_print("I am %s, you are %s (%d)\n", NODE_NAME, rem_node_name, ERL_DIST_VSN);
ei_set_compat_rel(ERL_DIST_VSN); /* erlnode version of dist. protocol */
if ( ei_connect_init(&ec, NODE_NAME, COOKIE, CREATION) < 0 )
g_critical("ei_connect_init");
if ( (fd = ei_connect(&ec, rem_node_name)) < 0 )
g_critical("ei_connect failed.\nwrong cookie? erl-dist version mismatch?");
self->num = fd; /* bug?? in ei_reg_send_tmo */
ei_x_new_with_version(&xbuf);
gn_wrap_ans("handshake", &xbuf);
ei_x_encode_empty_list(&xbuf);
gn_send(&xbuf);
ei_x_free(&xbuf);
return fd;
}
示例13: erlang_srdb1_insert_update
/**
* Insert a row into a specified table, update on duplicate key.
* \param _h structure representing database connection
* \param _k key names
* \param _v values of the keys
* \param _n number of key=value pairs
*/
int erlang_srdb1_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
const int _n)
{
ei_x_buff argbuf;
int retcode;
if ((!_h) || (!_k) || (!_v) || (!_n)) {
LM_ERR("invalid parameter value\n");
return -1;
}
LM_DBG("erlang_srdb1_insert_update table %.*s\n",CON_TABLE(_h)->len, CON_TABLE(_h)->s);
ei_x_new(&argbuf);
//encode tuple {db_op, table, [cols], [keys], [vals]}
ei_x_encode_tuple_header(&argbuf, 5);
ei_x_encode_atom(&argbuf,"insert_update");
ei_x_encode_atom_len(&argbuf,CON_TABLE(_h)->s,CON_TABLE(_h)->len);
ei_x_encode_list_header(&argbuf, 0); //_c
// ei_x_encode_list_header(&argbuf, 0); //_k
srdb1_encode_k(_k, NULL, _v, _n, &argbuf); //_k
srdb1_encode_v(_k, _v, _n, &argbuf); //_v
retcode=erl_bind.do_erlang_call(&(CON_ERLANG(_h)->con),&(CON_ERLANG(_h)->regname), &argbuf, NULL /*&retbuf*/);
ei_x_free(&argbuf);
if (retcode<0) {
// if(retbuf.buff) shm_free(retbuf.buff);
return retcode;
}
return 0;
}
示例14: send_hash
static void send_hash(ErlDrvPort port, unsigned long hash) {
ei_x_buff x;
ei_x_new_with_version(&x);
ei_x_encode_ulong(&x, hash);
driver_output(port, x.buff, x.index);
// printf("sent hash %d\n", hash);
ei_x_free(&x);
}
示例15: main
/*-----------------------------------------------------------------
* MAIN
*----------------------------------------------------------------*/
int main(int argc, char *argv[])
{
byte* buf;
int size = BUF_SIZE;
if (argc > 1) {
test(argc, argv);
return 0;
}
fprintf(stderr, "gssapi started\r\n");
if ((buf = malloc(size)) == NULL)
return -1;
while ( (buf = read_cmd(buf, &size)) ) {
int res = 0;
int index = 0;
int version, arity;
char command[MAXATOMLEN];
ei_x_buff result;
port_func func;
/* Ensure that we are receiving the binary term by reading and
* stripping the version byte */
EI(ei_decode_version(buf, &index, &version));
/* Our marshalling spec is that we are expecting a tuple {Command, Arg1} */
EI(ei_decode_tuple_header(buf, &index, &arity));
EI(arity != 2);
EI(ei_decode_atom(buf, &index, command));
/* Prepare the output buffer that will hold {ok, Result} or {error, Reason} */
EI(ei_x_new_with_version(&result) || ei_x_encode_tuple_header(&result, 2));
/* fprintf(stderr, "command: %s\r\n", command); */
func = lookup_func(command);
if (func) {
res = func(buf, index, &result);
} else {
EI(ei_x_encode_atom(&result, "error") || ei_x_encode_atom(&result, "unsupported_command"));
}
write_cmd(&result);
ei_x_free(&result);
}
/* error: */
fprintf(stderr, "No more command, exiting\r\n");
return 0;
}