当前位置: 首页>>代码示例>>C++>>正文


C++ enif_get_int函数代码示例

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


在下文中一共展示了enif_get_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: nif_listen

/* 0: file descriptor, 1: backlog */
    static ERL_NIF_TERM
nif_listen(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    int s = -1;
    int backlog = 5;


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

    if (!enif_get_int(env, argv[1], &backlog))
        return enif_make_badarg(env);

    if (listen(s, backlog) < 0)
        return error_tuple(env, errno);

    return atom_ok;
}
开发者ID:amuessig,项目名称:procket,代码行数:19,代码来源:procket.c

示例2: get_element

static ERL_NIF_TERM get_element(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  State *state;
  int i, j;
  if (!enif_get_int(env, argv[1], &i))return enif_make_badarg(env); 
  if (!enif_get_resource(env, argv[0], my_array_type, (void **)&state))
      return enif_make_badarg(env); 
  j = state->data[i];
  return enif_make_int(env, j);
}
开发者ID:FlowerWrong,项目名称:mblog,代码行数:10,代码来源:darray.c

示例3: gc

static ERL_NIF_TERM gc(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
    int i=0 , timestamp = 0;
    CHECK(enif_get_int(env, argv[0], &timestamp));
    for(i=0; i<BUCKET_SIZE; i++) {
        if(hashmap[i]>0) {
            walk_hash(&hashmap[i],timestamp,NULL, 0);
        }
    }
    return enif_make_atom(env, "ok");
}
开发者ID:flaboy,项目名称:metronome,代码行数:10,代码来源:metronome.c

示例4: set_owner_nif

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

    efile_path_t path;
    Sint32 uid, gid;

    if(argc != 3 || !enif_get_int(env, argv[1], &uid)
                 || !enif_get_int(env, argv[2], &gid)) {
        return enif_make_badarg(env);
    }

    if((posix_errno = efile_marshal_path(env, argv[0], &path))) {
        return posix_error_to_tuple(env, posix_errno);
    } else if((posix_errno = efile_set_owner(&path, uid, gid))) {
        return posix_error_to_tuple(env, posix_errno);
    }

    return am_ok;
}
开发者ID:cypherfox,项目名称:otp,代码行数:19,代码来源:prim_file_nif.c

示例5: get_resource_type

static ERL_NIF_TERM get_resource_type(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    PrivData* data = (PrivData*) enif_priv_data(env);
    int ix;
    
    if (!enif_get_int(env, argv[0], &ix) || ix >= 2) {
	return enif_make_badarg(env);
    }
    return enif_make_long(env, data->rt_arr[ix].l);
}
开发者ID:cristiangreco,项目名称:otp,代码行数:10,代码来源:nif_SUITE.c

示例6: test_int

static int test_int(ErlNifEnv* env, int i1)
{
    int i2 = 0;
    ERL_NIF_TERM int_term = enif_make_int(env, i1);
    if (!enif_get_int(env,int_term, &i2) || i1 != i2) {
	fprintf(stderr, "test_int(%d) ...FAILED i2=%d\r\n", i1, i2);
	return 0;
    }
    return 1;
}
开发者ID:cristiangreco,项目名称:otp,代码行数:10,代码来源:nif_SUITE.c

示例7: match_int

static inline int
match_int(ErlNifEnv* env, ERL_NIF_TERM term, State *st){
  int ip, n;
  if(!enif_get_int(env, term, &ip))
    return 0;
  b_reserve(24, st);
  n = sprintf((char*)(st->cur), "%d", ip);
  b_seek(n, st);
  return 1;  
}
开发者ID:dixel,项目名称:jsonx,代码行数:10,代码来源:encoder.c

示例8: op_alloc

// c_soc:op_alloc(ParentKey, Tuple, Arity) => ok
static ERL_NIF_TERM op_alloc(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  soc::State* st = (soc::State*) enif_priv_data(env);

  int                 parentKey;
  int                 parentKeyInt;
  ERL_NIF_TERM*       tuple;
  ERL_NIF_TERM*       tupleInt;
  int                 tupleArity;
  int                 tupleArityInt;
  int                 arity;
  int                 arityInt;

  if (enif_get_int(env, argv[0], &parentKey) == 0) {
    printf("[op_alloc] error: failed to get parentKey\n");
    return -1;
  }

  parentKeyInt = enif_make_copy(st->GetEnv(), parentKey);
  
  if (enif_get_tuple(env, argv[1], &tupleArity, &tuple) == 0) {
    printf("[op_alloc] error: failed to get tuple\n");
    return -1;
  }

  (*tupleInt) = enif_make_copy(st->GetEnv(), (*tuple));
  tupleArityInt = enif_make_copy(st->GetEnv(), tupleArity);

  if (enif_get_int(env, argv[2], &arity) == 0) {
    printf("[op_alloc] error: failed to initialize arity\n");
    return -1;
  } 

  arityInt = enif_make_copy(st->GetEnv(), arity);

  printf("operation start\n");
  soc::Operation* op = new soc::Operation(parentKeyInt, tupleInt, tupleArityInt, arityInt);
  int currentIndex = st->Insert(op);
  int currentIndexExt = enif_make_copy(env, currentIndex);
  printf("operation index: %d end\n", currentIndexExt);

  return enif_make_int(env, currentIndexExt);
}
开发者ID:et4te,项目名称:paraphrase,代码行数:44,代码来源:c_soc.c

示例9: closesockfd

static ERL_NIF_TERM closesockfd(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int fd;

    enif_get_int(env, argv[0], &fd);

    sock_close(fd);

    return enif_make_int(env, fd);
}
开发者ID:0x00evil,项目名称:otp,代码行数:10,代码来源:gen_tcp_api_SUITE.c

示例10: cb_mget_args

void* cb_mget_args(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    mget_args_t* args = (mget_args_t*)enif_alloc(sizeof(mget_args_t));

    ERL_NIF_TERM* currKey;
    ERL_NIF_TERM tail;
    ErlNifBinary key_binary;

    if (!enif_get_list_length(env, argv[0], &args->numkeys)) goto error0;
    args->keys = malloc(sizeof(char*) * args->numkeys);
    args->nkeys = malloc(sizeof(size_t) * args->numkeys);
    currKey = malloc(sizeof(ERL_NIF_TERM));
    tail = argv[0];
    int i = 0;
    while(0 != enif_get_list_cell(env, tail, currKey, &tail)) {
        if (!enif_inspect_iolist_as_binary(env, *currKey, &key_binary)) goto error1;
        args->keys[i] = malloc(sizeof(char) * key_binary.size);
        memcpy(args->keys[i], key_binary.data, key_binary.size);
        args->nkeys[i] = key_binary.size;
        i++;
    }

    if (!enif_get_int(env, argv[1], &args->exp)) goto error1;
    if (!enif_get_int(env, argv[2], &args->lock)) goto error1;

    free(currKey);

    return (void*)args;

    int f = 0;

    error1:
    for(f = 0; f < i; f++) {
        free(args->keys[f]);
    }
    free(args->keys);
    free(args->nkeys);
    free(currKey);
    error0:
    enif_free(args);

    return NULL;
}
开发者ID:muut,项目名称:cberl,代码行数:43,代码来源:cb.c

示例11: nif_recvfrom

/* 0: socket, 1: length, 2: flags, 3: struct sockaddr length */
    static ERL_NIF_TERM
nif_recvfrom(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    int sockfd = -1;
    unsigned long len = 0;
    unsigned long salen = 0;
    int flags = 0;

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


    if (!enif_get_int(env, argv[0], &sockfd))
        return enif_make_badarg(env);
    if (!enif_get_ulong(env, argv[1], &len))
        return enif_make_badarg(env);
    if (!enif_get_int(env, argv[2], &flags))
        return enif_make_badarg(env);
    if (!enif_get_ulong(env, argv[3], &salen))
        return enif_make_badarg(env);

    if (!enif_alloc_binary(len, &buf))
        return error_tuple(env, ENOMEM);

    if (!enif_alloc_binary(salen, &sa))
        return error_tuple(env, ENOMEM);

    if ( (bufsz = recvfrom(sockfd, buf.data, buf.size, flags,
        (sa.size == 0 ? NULL : (struct sockaddr *)sa.data),
        (socklen_t *)&salen)) == -1) {
        int err = errno;
        enif_release_binary(&buf);
        enif_release_binary(&sa);
        return error_tuple(env, err);
    }

    PROCKET_REALLOC(buf, bufsz);
    PROCKET_REALLOC(sa, salen);

    return enif_make_tuple3(env, atom_ok, enif_make_binary(env, &buf),
             enif_make_binary(env, &sa));
}
开发者ID:alanrevans,项目名称:procket,代码行数:44,代码来源:procket.c

示例12: get_group

/*-----------------------------------------------------------------------------------------------------------------------*/
static ERL_NIF_TERM get_group(ErlNifEnv* env, int32_t argc, ERL_NIF_TERM const argv[])
{
   ERL_NIF_TERM pres;
   ERL_NIF_TERM mres;
   ERL_NIF_TERM gres;
   ParserRes* parser = NULL;
   FIXMsg* msg = NULL;
   FIXGroup* group = NULL;
   ERL_NIF_TERM res = get_parser_msg_group(env, argv[0], &pres, &mres, &gres, &parser, &msg, &group);
   if (res != ok_atom)
   {
      return res;
   }
   int32_t tagNum = 0;
   if (!enif_get_int(env, argv[1], &tagNum))
   {
      return make_error(env, FIX_FAILED, "Wrong tag num.");
   }
   int32_t idx = 0;
   if (!enif_get_int(env, argv[2], &idx))
   {
      return make_error(env, FIX_FAILED, "Wrong idx.");
   }
   FIXError* error = NULL;
   pthread_rwlock_rdlock(&parser->lock);
   FIXGroup* ret_group = fix_msg_get_group(msg, group, tagNum, idx, &error);
   pthread_rwlock_unlock(&parser->lock);
   if (!ret_group)
   {
      ERL_NIF_TERM ret = make_parser_error(env, fix_error_get_code(error), fix_error_get_text(error));
      fix_error_free(error);
      return ret;
   }
   FIXGroup** grp = (FIXGroup**)enif_alloc_resource(group_res, sizeof(FIXGroup*));
   *grp = ret_group;
   ERL_NIF_TERM grp_term = enif_make_resource(env, grp);
   enif_release_resource(grp);
   return enif_make_tuple2(env, ok_atom, enif_make_tuple2(
            env,
            group_atom,
            enif_make_tuple3(env, pres, mres, grp_term)));
}
开发者ID:dmitryme,项目名称:fix_engine,代码行数:43,代码来源:fix_parser_nifs.c

示例13: serial_data_avail_nif

static ERL_NIF_TERM
serial_data_avail_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int handle;
    if (!enif_get_int(env, argv[0], &handle))
    {
        return enif_make_badarg(env);
    }
    int data_avail = serialDataAvail(handle);
    return enif_make_int(env, data_avail);
}
开发者ID:alepharchives,项目名称:wpi,代码行数:11,代码来源:wpi.c

示例14: serial_flush_nif

static ERL_NIF_TERM
serial_flush_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int handle;
    if (!enif_get_int(env, argv[0], &handle))
    {
        return enif_make_badarg(env);
    }
    serialFlush(handle);
    return atom_ok;
}
开发者ID:alepharchives,项目名称:wpi,代码行数:11,代码来源:wpi.c

示例15: lcd_clear_nif

static ERL_NIF_TERM
lcd_clear_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int handle;
    if (!enif_get_int(env, argv[0], &handle))
    {
        return enif_make_badarg(env);
    }
    lcdClear(handle);
    return atom_ok;
}
开发者ID:alepharchives,项目名称:wpi,代码行数:11,代码来源:wpi.c


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