本文整理汇总了C++中enif_make_tuple2函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_make_tuple2函数的具体用法?C++ enif_make_tuple2怎么用?C++ enif_make_tuple2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enif_make_tuple2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vert_virNodeNumOfDevices
ERL_NIF_TERM
vert_virNodeNumOfDevices(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *vp = NULL;
ErlNifBinary cap = {0};
u_int32_t flags = 0;
int n = 0;
VERT_GET_RESOURCE(0, vp, VERT_RES_CONNECT);
VERT_GET_IOLIST(1, cap);
VERT_GET_UINT(2, flags);
if (cap.size > 0)
VERT_BIN_APPEND_NULL(cap);
n = virNodeNumOfDevices(vp->res,
(cap.size == 0 ? NULL : (char *)cap.data),
flags);
VERTERR(n < 0);
return enif_make_tuple2(env,
atom_ok,
enif_make_int(env, n));
}
示例2: x_pool_lookup
ERL_NIF_TERM x_pool_lookup(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
uint64_t id;
char pool_name[MAX_NAME_LEN];
if (!enif_get_uint64(env, argv[0], &id) ||
!enif_get_string(env, argv[1], pool_name, MAX_NAME_LEN, ERL_NIF_LATIN1))
{
return enif_make_badarg(env);
}
rados_t cluster = map_cluster_get(id);
if (cluster == NULL)
{
return enif_make_badarg(env);
}
int64_t err = rados_pool_lookup(cluster, pool_name);
if (err < 0)
{
return make_error_tuple(env, -err);
}
return enif_make_tuple2(env,
enif_make_atom(env, "ok"),
enif_make_int64(env, err)); // Pool ID
}
示例3: geef_index_write_tree
ERL_NIF_TERM
geef_index_write_tree(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
geef_index *index;
geef_repository *repo;
ErlNifBinary bin;
git_oid id;
int error;
if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index))
return enif_make_badarg(env);
if (argc == 2) {
if (!enif_get_resource(env, argv[1], geef_repository_type, (void **) &repo))
return enif_make_badarg(env);
error = git_index_write_tree_to(&id, index->index, repo->repo);
} else {
error = git_index_write_tree(&id, index->index);
}
if (error < 0)
return geef_error(env);
if (geef_oid_bin(&bin, &id) < 0)
return geef_oom(env);
return enif_make_tuple2(env, atoms.ok, enif_make_binary(env, &bin));
}
示例4: nif_getsockname
// int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
static ERL_NIF_TERM
nif_getsockname(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
int s = -1;
ErlNifBinary addr = {0};
socklen_t addrlen = 0;
if (!enif_get_int(env, argv[0], &s))
return enif_make_badarg(env);
if (!enif_inspect_binary(env, argv[1], &addr))
return enif_make_badarg(env);
/* Make the binary mutable */
if (!enif_realloc_binary(&addr, addr.size))
return error_tuple(env, ENOMEM);
addrlen = addr.size;
if (getsockname(s, (struct sockaddr *)addr.data, (socklen_t *)&addrlen) < 0)
return error_tuple(env, errno);
PROCKET_REALLOC(addr, addrlen);
return enif_make_tuple2(env,
atom_ok,
enif_make_binary(env, &addr));
}
示例5: ex_slp_open
static ERL_NIF_TERM
ex_slp_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
char *lang;
char *ret_code;
int isasync;
unsigned int term_len;
SLPHandle *hslp;
SLPEXP SLPError SLPAPI error;
if (enif_get_atom_length(env, argv[0], &term_len, ERL_NIF_LATIN1) < 0) {
return enif_make_badarg(env);
}
if (enif_get_atom(env, argv[0], lang, term_len, ERL_NIF_LATIN1) < 0) {
return enif_make_badarg(env);
}
if ( ! enif_get_int(env, argv[1], &isasync)) return enif_make_badarg(env);
hslp = enif_alloc_resource(NIF_SLP_HANDLE, sizeof(SLPHandle));
if (hslp == NULL) return enif_make_badarg(env);
//error = SLPOpen(lang, isasync > 0 ? SLP_TRUE : SLP_FALSE, hslp);
error = SLPOpen(lang, isasync > 0 ? SLP_TRUE : SLP_FALSE, hslp);
ERL_NIF_TERM term = enif_make_resource(env, hslp);
enif_release_resource(hslp);
return enif_make_tuple2(env, enif_make_int(env, error), term);
}
示例6: ucrypto_ec_sign_nif
ERL_NIF_TERM ucrypto_ec_sign_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
unsigned int length;
struct ec_key_handle *handle = NULL;
ErlNifBinary data;
ErlNifBinary signature;
if (! enif_get_resource(env, argv[0], ec_key_resource, (void **)&handle))
return enif_make_badarg(env);
if (! enif_inspect_iolist_as_binary(env, argv[1], &data))
return enif_make_badarg(env);
if (! handle->key)
return enif_make_tuple2(env, ATOM_ERROR, ATOM_UNINITIALIZED_KEY);
length = ECDSA_size(handle->key);
if (! enif_alloc_binary(length, &signature))
return ATOM_ERROR;
if (! ECDSA_sign(0, data.data, data.size, signature.data, &length, handle->key))
return ATOM_ERROR;
if (! enif_realloc_binary(&signature, length))
return ATOM_ERROR;
return enif_make_binary(env, &signature);
}
示例7: nif_socket
/* 0: procotol, 1: type, 2: family */
static ERL_NIF_TERM
nif_socket(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
int s = -1;
int family = 0;
int type = 0;
int protocol = 0;
int flags = 0;
if (!enif_get_int(env, argv[0], &family))
return enif_make_badarg(env);
if (!enif_get_int(env, argv[1], &type))
return enif_make_badarg(env);
if (!enif_get_int(env, argv[2], &protocol))
return enif_make_badarg(env);
s = socket(family, type, protocol);
if (s < 0)
return error_tuple(env, errno);
flags = fcntl(s, F_GETFL, 0);
if (flags < 0)
return error_tuple(env, errno);
if (fcntl(s, F_SETFL, flags|O_NONBLOCK) < 0)
return error_tuple(env, errno);
return enif_make_tuple2(env,
atom_ok,
enif_make_int(env, s));
}
示例8: vert_virSecretGetValue
ERL_NIF_TERM
vert_virSecretGetValue(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *sp = NULL;
u_int32_t flags = 0;
size_t value_size = 0;
unsigned char *secret = NULL;
ERL_NIF_TERM buf = {0};
VERT_GET_RESOURCE(0, sp, VERT_RES_SECRET);
VERT_GET_UINT(1, flags);
secret = virSecretGetValue(sp->res, &value_size, flags);
VERTERR(secret == NULL);
BINCOPY(buf, secret, value_size);
free(secret);
return enif_make_tuple2(env,
atom_ok,
buf);
}
示例9: read_file_nif
static ERL_NIF_TERM read_file_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
posix_errno_t posix_errno;
efile_fileinfo_t info = {0};
efile_path_t path;
efile_data_t *d;
ErlNifBinary result;
ASSERT(argc == 1);
if((posix_errno = efile_marshal_path(env, argv[0], &path))) {
return posix_error_to_tuple(env, posix_errno);
} else if((posix_errno = efile_read_info(&path, 1, &info))) {
return posix_error_to_tuple(env, posix_errno);
} else if((posix_errno = efile_open(&path, EFILE_MODE_READ, efile_resource_type, &d))) {
return posix_error_to_tuple(env, posix_errno);
}
posix_errno = read_file(d, info.size, &result);
enif_release_resource(d);
if(posix_errno) {
return posix_error_to_tuple(env, posix_errno);
}
return enif_make_tuple2(env, am_ok, enif_make_binary(env, &result));
}
示例10: describe_error
static ERL_NIF_TERM describe_error(ErlNifEnv* env, int err) {
switch (err) {
case EAGAIN:
return enif_make_atom(env, "eagain");
case EINVAL:
return enif_make_atom(env, "einval");
case ENOSPC:
return enif_make_atom(env, "enospc");
case ENOENT:
return enif_make_atom(env, "enoent");
case ENOMEM:
return enif_make_atom(env, "enomem");
case EACCES:
return enif_make_atom(env, "eacces");
case EBADF:
return enif_make_atom(env, "ebadf");
case ENODEV:
return enif_make_atom(env, "enodev");
case ENXIO:
return enif_make_atom(env, "enxio");
case EOVERFLOW:
return enif_make_atom(env, "eoverflow");
}
return enif_make_tuple2(env,
enif_make_atom(env, "errno"),
enif_make_int(env, err));
}
示例11: emmap_position
static ERL_NIF_TERM emmap_position(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
mhandle *handle;
long position;
long relpos;
if (argc==3
&& enif_get_resource(env, argv[0], MMAP_RESOURCE, (void**)&handle)
&& enif_get_long(env, argv[2], &relpos)
&& (argv[1] == ATOM_CUR || argv[1] == ATOM_BOF || argv[1] == ATOM_EOF))
{
RW_LOCK;
if (argv[1] == ATOM_BOF) {
position = 0L + relpos;
} else if (argv[1] == ATOM_CUR) {
position = handle->position + relpos;
} else if (argv[1] == ATOM_EOF) {
position = handle->len - relpos;
}
if (position < 0L || ((unsigned long)position) > handle->len) {
RW_UNLOCK;
return enif_make_badarg(env);
}
handle->position = position;
RW_UNLOCK;
return enif_make_tuple2(env, ATOM_OK, enif_make_ulong(env, position));
}
else
{
return enif_make_badarg(env);
}
}
示例12: cb_http
ERL_NIF_TERM cb_http(ErlNifEnv* env, handle_t* handle, void* obj)
{
http_args_t* args = (http_args_t*)obj;
struct libcouchbase_callback cb;
lcb_error_t ret;
lcb_http_request_t req;
lcb_http_cmd_t cmd;
cmd.version = 0;
cmd.v.v0.path = args->path;
cmd.v.v0.npath = strlen(args->path);
cmd.v.v0.body = args->body;
cmd.v.v0.nbody = strlen(args->body);
cmd.v.v0.method = args->method;
cmd.v.v0.chunked = 0; // no support for chunking
cmd.v.v0.content_type = args->content_type;
ret = lcb_make_http_request(handle->instance, &cb, args->type, &cmd, &req);
if (ret != LCB_SUCCESS) {
return return_lcb_error(env, ret);
}
lcb_wait(handle->instance);
if(cb.error != LCB_SUCCESS) {
return return_lcb_error(env, cb.error);
}
ErlNifBinary value_binary;
enif_alloc_binary(cb.size, &value_binary);
memcpy(value_binary.data, cb.data, cb.size);
return enif_make_tuple2(env, A_OK(env), enif_make_binary(env, &value_binary));
}
示例13: cb_arithmetic
ERL_NIF_TERM cb_arithmetic(ErlNifEnv* env, handle_t* handle, void* obj)
{
arithmetic_args_t* args = (arithmetic_args_t*)obj;
struct libcouchbase_callback cb;
lcb_error_t ret; //for checking responses
lcb_arithmetic_cmd_t arithmetic;
const lcb_arithmetic_cmd_t* commands[1];
commands[0] = &arithmetic;
memset(&arithmetic, 0, sizeof(arithmetic));
arithmetic.v.v0.key = args->key;
arithmetic.v.v0.nkey = args->nkey;
arithmetic.v.v0.initial = args->initial;
arithmetic.v.v0.create = args->create;
arithmetic.v.v0.delta = args->delta;
ret = lcb_arithmetic(handle->instance, &cb, 1, commands);
free(args->key);
if (ret != LCB_SUCCESS) {
return return_lcb_error(env, ret);
}
lcb_wait(handle->instance);
if(cb.error != LCB_SUCCESS) {
return return_lcb_error(env, cb.error);
}
return enif_make_tuple2(env, A_OK(env), return_value(env, &cb));
}
示例14: cb_getl
ERL_NIF_TERM cb_getl(ErlNifEnv* env, handle_t* handle, void* obj)
{
getl_args_t* args = (getl_args_t*)obj;
struct libcouchbase_callback cb;
lcb_error_t ret;
lcb_get_cmd_t cmd;
const lcb_get_cmd_t *commands[1];
commands[0] = &cmd;
memset(&cmd, 0, sizeof(cmd));
cmd.v.v0.key = args->key;
cmd.v.v0.nkey = args->nkey;
cmd.v.v0.exptime = args->exp;
cmd.v.v0.lock = 1;
ret = lcb_get(handle->instance, &cb, 1, commands);
free(args->key);
if (ret != LCB_SUCCESS) {
return return_lcb_error(env, ret);
}
lcb_wait(handle->instance);
if(cb.error != LCB_SUCCESS) {
return return_lcb_error(env, cb.error);
}
return enif_make_tuple2(env, A_OK(env), return_value(env, &cb));
}
示例15: x_get_instance_id
ERL_NIF_TERM x_get_instance_id(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
const char * func_name = "x_get_instance_id()";
uint64_t id;
if (!enif_get_uint64(env, argv[0], &id))
{
logger.error(MOD_NAME, func_name, "enif get params failed");
return enif_make_badarg(env);
}
logger.debug(MOD_NAME, func_name, "cluster : %ld", id);
rados_t cluster = map_cluster_get(id);
if (cluster == NULL)
{
logger.error(MOD_NAME, func_name, "cluster non-existing : %ld", id);
return enif_make_badarg(env);
}
uint64_t inst_id = rados_get_instance_id(cluster);
return enif_make_tuple2(env,
enif_make_atom(env, "ok"),
enif_make_uint64(env, inst_id));
}