Skip to content

anonymous /gist:349316
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.