• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ enif_make_tuple2函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中enif_make_tuple2函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_make_tuple2函数的具体用法?C++ enif_make_tuple2怎么用?C++ enif_make_tuple2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了enif_make_tuple2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:chinnurtb,项目名称:erlang-libvirt,代码行数:27,代码来源:vert_nodedevice.c


示例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
}
开发者ID:amimimor,项目名称:cephelix,代码行数:26,代码来源:rados_pool.cpp


示例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));
}
开发者ID:CODECOMMUNITY,项目名称:geef,代码行数:29,代码来源:index.c


示例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));
}
开发者ID:Vagabond,项目名称:procket,代码行数:30,代码来源:procket.c


示例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);
}
开发者ID:icanhazbroccoli,项目名称:ex_slp,代码行数:32,代码来源:ex_slp.c


示例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);
}
开发者ID:ahf,项目名称:erlang-ucrypto,代码行数:29,代码来源:ucrypto_ec.c


示例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));
}
开发者ID:Vagabond,项目名称:procket,代码行数:36,代码来源:procket.c


示例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);
}
开发者ID:alepharchives,项目名称:erlang-libvirt,代码行数:25,代码来源:vert_secret.c


示例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));
}
开发者ID:RaimoNiskanen,项目名称:otp,代码行数:28,代码来源:prim_file_nif.c


示例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));
}
开发者ID:alepharchives,项目名称:emmap,代码行数:27,代码来源:emmap.cpp


示例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);
    }
}
开发者ID:alepharchives,项目名称:emmap,代码行数:35,代码来源:emmap.cpp


示例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));
}
开发者ID:AdvertiSin,项目名称:cberl,代码行数:35,代码来源:cb.c


示例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));
}
开发者ID:AdvertiSin,项目名称:cberl,代码行数:29,代码来源:cb.c


示例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));   
}
开发者ID:AdvertiSin,项目名称:cberl,代码行数:30,代码来源:cb.c


示例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));
}
开发者ID:amimimor,项目名称:cephelix,代码行数:26,代码来源:rados_cluster.cpp


示例16: open_nif

static ERL_NIF_TERM open_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
    posix_errno_t posix_errno;
    efile_data_t *d;

    ErlNifPid controlling_process;
    enum efile_modes_t modes;
    ERL_NIF_TERM result;
    efile_path_t path;

    ASSERT(argc == 2);
    if(!enif_is_list(env, argv[1])) {
        return enif_make_badarg(env);
    }

    modes = efile_translate_modelist(env, argv[1]);

    if((posix_errno = efile_marshal_path(env, argv[0], &path))) {
        return posix_error_to_tuple(env, posix_errno);
    } else if((posix_errno = efile_open(&path, modes, efile_resource_type, &d))) {
        return posix_error_to_tuple(env, posix_errno);
    }

    result = enif_make_resource(env, d);
    enif_release_resource(d);

    enif_self(env, &controlling_process);

    if(enif_monitor_process(env, d, &controlling_process, &d->monitor)) {
        return posix_error_to_tuple(env, EINVAL);
    }

    return enif_make_tuple2(env, am_ok, result);
}
开发者ID:RaimoNiskanen,项目名称:otp,代码行数:33,代码来源:prim_file_nif.c


示例17: x_create_with_user

ERL_NIF_TERM x_create_with_user(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    const char * func_name = "x_create_with_user()";
    logger.debug(MOD_NAME, func_name, "Entered");

    char name[MAX_NAME_LEN];
    memset(name, 0, MAX_NAME_LEN);
    if (!enif_get_string(env, argv[0], name, MAX_NAME_LEN, ERL_NIF_LATIN1))
    {
        logger.error(MOD_NAME, func_name, "enif get params failed");
        return enif_make_badarg(env);
    }

    rados_t cluster;
    int err = rados_create(&cluster, name);
    if (err < 0) 
    {
        logger.error(MOD_NAME, func_name, "Unable to create cluster handle with name: %s", name);
        return make_error_tuple(env, -err);
    }

    uint64_t id = new_id();
    map_cluster_add(id, cluster);

    logger.debug(MOD_NAME, func_name, "cluster : %ld", id);

    return enif_make_tuple2(env,
                            enif_make_atom(env, "ok"),
                            enif_make_uint64(env, id));
}
开发者ID:amimimor,项目名称:cephelix,代码行数:30,代码来源:rados_cluster.cpp


示例18: seek_nif_impl

static ERL_NIF_TERM seek_nif_impl(efile_data_t *d, ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
    Sint64 new_position, offset;
    enum efile_seek_t seek;

    ASSERT(argc == 2);
    if(!enif_get_int64(env, argv[1], &offset)) {
        return enif_make_badarg(env);
    }

    if(enif_is_identical(argv[0], am_bof)) {
        seek = EFILE_SEEK_BOF;
    } else if(enif_is_identical(argv[0], am_cur)) {
        seek = EFILE_SEEK_CUR;
    } else if(enif_is_identical(argv[0], am_eof)) {
        seek = EFILE_SEEK_EOF;
    } else {
        return enif_make_badarg(env);
    }

    if(!efile_seek(d, seek, offset, &new_position)) {
        return posix_error_to_tuple(env, d->posix_errno);
    }

    return enif_make_tuple2(env, am_ok, enif_make_uint64(env, new_position));
}
开发者ID:RaimoNiskanen,项目名称:otp,代码行数:25,代码来源:prim_file_nif.c


示例19: nif_sendto

/* 0: socket, 1: buffer, 2: flags, 3: struct sockaddr */
    static ERL_NIF_TERM
nif_sendto(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    int sockfd = -1;
    int flags = 0;
    ssize_t n = 0;

    ErlNifBinary buf = {0};
    ErlNifBinary sa = {0};

    if (!enif_get_int(env, argv[0], &sockfd))
        return enif_make_badarg(env);

    if (!enif_inspect_binary(env, argv[1], &buf))
        return enif_make_badarg(env);

    if (!enif_get_int(env, argv[2], &flags))
        return enif_make_badarg(env);

    if (!enif_inspect_binary(env, argv[3], &sa))
        return enif_make_badarg(env);

    n = sendto(sockfd, buf.data, buf.size, flags,
            (sa.size == 0 ? NULL : (struct sockaddr *)sa.data),
            sa.size);

    if (n < 0)
        return error_tuple(env, errno);

    return enif_make_tuple2(env, atom_ok, enif_make_int64(env, n));
}
开发者ID:fhunleth,项目名称:procket,代码行数:32,代码来源:procket.c


示例20: create

static ERL_NIF_TERM
create(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    Example* res;
    ERL_NIF_TERM ret;
    unsigned int id;
    Tracker* tracker;

    if(argc != 1)
    {
        return enif_make_badarg(env);
    }

    if(!enif_get_uint(env, argv[0], &id))
    {
        return enif_make_badarg(env);
    }

    res = enif_alloc_resource(RES_TYPE, sizeof(Example));
    if(res == NULL) return enif_make_badarg(env);

    ret = enif_make_resource(env, res);
    enif_release_resource(res);

    res->id = id;

    tracker = (Tracker*) enif_priv_data(env);
    tracker->count += 1;

    return enif_make_tuple2(env, atom_ok, ret);
}
开发者ID:szpzs,项目名称:nif-examples,代码行数:31,代码来源:resources.c



注:本文中的enif_make_tuple2函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ enif_make_tuple3函数代码示例发布时间:2022-05-30
下一篇:
C++ enif_make_string函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap