public
anonymous / gist:349316
Created

  • Download Gist
gistfile1.h
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include "erl_nif.h"
 
typedef struct {
ErlNifBinary calls;
} PrivData;
 
static int load(ErlNifEnv* env, void** priv_data) {
PrivData* data = enif_alloc(env, sizeof(PrivData));
if (data == NULL) return -1;
*priv_data = data;
return 0;
}
 
static int reload(ErlNifEnv* env, void** priv_data) {
return 0;
}
static void unload(ErlNifEnv* env, void* priv_data) {
enif_free(env, priv_data);
}
 
static ERL_NIF_TERM get(ErlNifEnv* env)
{
PrivData* data = (PrivData*) enif_get_data(env);
enif_release_binary(env, &data->calls);
return enif_make_binary(env, &data->calls);
}
 
static ERL_NIF_TERM put(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
PrivData* data = (PrivData*) enif_get_data(env);
enif_inspect_binary(env, argv[0], &data->calls);
enif_release_binary(env, &data->calls);
return enif_make_atom(env, "ok");
}
 
static ErlNifFunc nif_funcs[] =
{
{"put", 1, put},
{"get", 0, get}
};
 
ERL_NIF_INIT(niftest,nif_funcs,load,reload,NULL,unload);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.