User's Guide
Reference Manual
Release Notes
PDF
Top

Erlang Interface
Reference Manual
Version 3.7.5

Expand All
Contract All

Table of Contents

- ei
  - Top of manual page
  - ei_set_compat_rel()
  - ei_encode_version()
  - ei_x_encode_version()
  - ei_encode_long()
  - ei_x_encode_long()
  - ei_encode_ulong()
  - ei_x_encode_ulong()
  - ei_encode_longlong()
  - ei_x_encode_longlong()
  - ei_encode_ulonglong()
  - ei_x_encode_ulonglong()
  - ei_encode_bignum()
  - ei_x_encode_bignum()
  - ei_encode_double()
  - ei_x_encode_double()
  - ei_encode_boolean()
  - ei_x_encode_boolean()
  - ei_encode_char()
  - ei_x_encode_char()
  - ei_encode_string()
  - ei_encode_string_len()
  - ei_x_encode_string()
  - ei_x_encode_string_len()
  - ei_encode_atom()
  - ei_encode_atom_len()
  - ei_x_encode_atom()
  - ei_x_encode_atom_len()
  - ei_encode_binary()
  - ei_x_encode_binary()
  - ei_encode_pid()
  - ei_x_encode_pid()
  - ei_encode_fun()
  - ei_x_encode_fun()
  - ei_encode_port()
  - ei_x_encode_port()
  - ei_encode_ref()
  - ei_x_encode_ref()
  - ei_encode_term()
  - ei_x_encode_term()
  - ei_encode_trace()
  - ei_x_encode_trace()
  - ei_encode_tuple_header()
  - ei_x_encode_tuple_header()
  - ei_encode_list_header()
  - ei_x_encode_list_header()
  - ei_encode_empty_list()
  - ei_x_encode_empty_list()
  - ei_get_type()
  - ei_decode_version()
  - ei_decode_long()
  - ei_decode_ulong()
  - ei_decode_longlong()
  - ei_decode_ulonglong()
  - ei_decode_bignum()
  - ei_decode_double()
  - ei_decode_boolean()
  - ei_decode_char()
  - ei_decode_string()
  - ei_decode_atom()
  - ei_decode_binary()
  - ei_decode_fun()
  - free_fun()
  - ei_decode_pid()
  - ei_decode_port()
  - ei_decode_ref()
  - ei_decode_trace()
  - ei_decode_tuple_header()
  - ei_decode_list_header()
  - ei_decode_ei_term()
  - ei_decode_term()
  - ei_print_term()
  - ei_s_print_term()
  - ei_x_format()
  - ei_x_format_wo_ver()
  - ei_x_new()
  - ei_x_new_with_version()
  - ei_x_free()
  - ei_x_append()
  - ei_x_append_buf()
  - ei_skip_term()
- ei_connect
  - Top of manual page
  - ei_connect_init()
  - ei_connect_xinit()
  - ei_connect()
  - ei_xconnect()
  - ei_connect_tmo()
  - ei_xconnect_tmo()
  - ei_receive()
  - ei_receive_tmo()
  - ei_receive_msg()
  - ei_xreceive_msg()
  - ei_receive_msg_tmo()
  - ei_xreceive_msg_tmo()
  - ei_receive_encoded()
  - ei_receive_encoded_tmo()
  - ei_send()
  - ei_send_tmo()
  - ei_send_encoded()
  - ei_send_encoded_tmo()
  - ei_reg_send()
  - ei_reg_send_tmo()
  - ei_send_reg_encoded()
  - ei_send_reg_encoded_tmo()
  - ei_rpc()
  - ei_rpc_to()
  - ei_rpc_from()
  - ei_publish()
  - ei_publish_tmo()
  - ei_accept()
  - ei_accept_tmo()
  - ei_unpublish()
  - ei_unpublish_tmo()
  - ei_thisnodename()
  - ei_thishostname()
  - ei_thisalivename()
  - ei_self()
  - *ei_gethostbyname()
  - *ei_gethostbyaddr()
  - *ei_gethostbyname_r()
  - *ei_gethostbyaddr_r()
  - ei_get_tracelevel()
  - ei_set_tracelevel()
- registry
  - Top of manual page
  - ei_reg_open()
  - ei_reg_resize()
  - ei_reg_close()
  - ei_reg_setival()
  - ei_reg_setfval()
  - ei_reg_setsval()
  - ei_reg_setpval()
  - ei_reg_setval()
  - ei_reg_getival()
  - ei_reg_getfval()
  - ei_reg_getsval()
  - ei_reg_getpval()
  - ei_reg_getval()
  - ei_reg_markdirty()
  - ei_reg_delete()
  - ei_reg_stat()
  - ei_reg_tabstat()
  - ei_reg_dump()
  - ei_reg_restore()
  - ei_reg_purge()
- erl_connect
  - Top of manual page
  - erl_connect_init()
  - erl_connect_xinit()
  - erl_connect()
  - erl_xconnect()
  - erl_close_connection()
  - erl_receive()
  - erl_receive_msg()
  - erl_xreceive_msg()
  - erl_send()
  - erl_reg_send()
  - erl_rpc()
  - erl_rpc_to()
  - erl_rpc_from()
  - erl_publish()
  - erl_accept()
  - erl_thiscookie()
  - erl_thisnodename()
  - erl_thishostname()
  - erl_thisalivename()
  - erl_thiscreation()
  - erl_unpublish()
  - *erl_gethostbyname()
  - *erl_gethostbyaddr()
  - *erl_gethostbyname_r()
  - *erl_gethostbyaddr_r()
- erl_error
  - Top of manual page
  - erl_err_msg()
  - erl_err_quit()
  - erl_err_ret()
  - erl_err_sys()
  - erl_errno()
- erl_eterm
  - Top of manual page
  - erl_cons()
  - erl_copy_term()
  - erl_element()
  - erl_init()
  - erl_hd()
  - erl_iolist_to_binary()
  - erl_iolist_to_string()
  - erl_iolist_length()
  - erl_length()
  - erl_mk_atom()
  - erl_mk_binary()
  - erl_mk_empty_list()
  - erl_mk_estring()
  - erl_mk_float()
  - erl_mk_int()
  - erl_mk_list()
  - erl_mk_pid()
  - erl_mk_port()
  - erl_mk_ref()
  - erl_mk_long_ref()
  - erl_mk_string()
  - erl_mk_tuple()
  - erl_mk_uint()
  - erl_mk_var()
  - erl_print_term()
  - erl_set_compat_rel()
  - erl_size()
  - erl_tl()
  - erl_var_content()
- erl_format
  - Top of manual page
  - erl_format()
  - erl_match()
- erl_global
  - Top of manual page
  - erl_global_names()
  - erl_global_register()
  - erl_global_unregister()
  - erl_global_whereis()
- erl_malloc
  - Top of manual page
  - erl_alloc_eterm()
  - erl_eterm_release()
  - erl_eterm_statistics()
  - erl_free_array()
  - erl_free_term()
  - erl_free_compound()
  - erl_malloc()
  - erl_free()
- erl_marshal
  - Top of manual page
  - erl_compare_ext()
  - erl_decode()
  - erl_decode_buf()
  - erl_encode()
  - erl_encode_buf()
  - erl_ext_size()
  - erl_ext_type()
  - erl_peek_ext()
  - erl_term_len()
- erl_call

# registry

### C LIBRARY

registry

### LIBRARY SUMMARY

Store and backup key-value pairs

### DESCRIPTION

This module provides support for storing key-value pairs in a table known as a registry, backing up registries to Mnesia in an atomic manner, and later restoring the contents of a registry from Mnesia.

### EXPORTS

ei_reg * ei_reg_open(size)

Types:

int size;

Open (create) a registry. The registry will be initially empty. Use ei_reg_close() to close the registry later.

size is the approximate number of objects you intend to store in the registry. Since the registry uses a hash table with collision chaining, there is no absolute upper limit on the number of objects that can be stored in it. However for reasons of efficiency, it is a good idea to choose a number that is appropriate for your needs. It is possible to use ei_reg_resize() to change the size later. Note that the number you provide will be increased to the nearest larger prime number.

On success, an empty registry will be returned. On failure, NULL will be returned.

int ei_reg_resize(reg,newsize)

Types:

ei_reg *reg;
int newsize;

Change the size of a registry.

newsize is the new size to make the registry. The number will be increased to the nearest larger prime number.

On success, the registry will be resized, all contents rehashed, and the function will return 0. On failure, the registry will be left unchanged and the function will return -1.

int ei_reg_close(reg)

Types:

ei_reg *reg;

A registry that has previously been created with ei_reg_open() is closed, and all the objects it contains are freed.

reg is the registry to close.

The function returns 0.

int ei_reg_setival(reg,key,i)

Types:

ei_reg *reg;
const char *key;
int i;

Create a key-value pair with the specified key and integer value i. If an object already existed with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

reg is the registry where the object should be placed.

key is the name of the object.

i is the integer value to assign.

The function returns 0 on success, or -1 on failure.

int ei_reg_setfval(reg,key,f)

Types:

ei_reg *reg;
const char *key;
double f;

Create a key-value pair with the specified key and floating point value f. If an object already existed with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

reg is the registry where the object should be placed.

key is the name of the object.

f is the floating point value to assign.

The function returns 0 on success, or -1 on failure.

int ei_reg_setsval(reg,key,s)

Types:

ei_reg *reg;
const char *key;
const char *s;

Create a key-value pair with the specified key whose "value" is the specified string s. If an object already existed with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

reg is the registry where the object should be placed.

key is the name of the object.

s is the string to assign. The string itself must have been created through a single call to malloc() or similar function, so that the registry can later delete it if necessary by calling free().

The function returns 0 on success, or -1 on failure.

int ei_reg_setpval(reg,key,p,size)

Types:

ei_reg *reg;
const char *key;
const void *p;
int size;

Create a key-value pair with the specified key whose "value" is the binary object pointed to by p. If an object already existed with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

reg is the registry where the object should be placed.

key is the name of the object.

p is a pointer to the binary object. The object itself must have been created through a single call to malloc() or similar function, so that the registry can later delete it if necessary by calling free().

size is the length in bytes of the binary object.

The function returns 0 on success, or -1 on failure.

int ei_reg_setval(reg,key,flags,v,...)

Types:

ei_reg *reg;
const char *key;
int flags;
v (see below)

Create a key-value pair with the specified key whose value is specified by v. If an object already existed with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().

reg is the registry where the object should be placed.

key is the name of the object.

flags indicates the type of the object specified by v. Flags must be one of EI_INT, EI_FLT, EI_STR and EI_BIN, indicating whether v is int, double, char* or void*. If flags is EI_BIN, then a fifth argument size is required, indicating the size in bytes of the object pointed to by v.

If you wish to store an arbitrary pointer in the registry, specify a size of 0. In this case, the object itself will not be transferred by an ei_reg_dump() operation, just the pointer value.

The function returns 0 on success, or -1 on failure.

int ei_reg_getival(reg,key)

Types:

ei_reg *reg;
const char *key;

Get the value associated with key in the registry. The value must be an integer.

reg is the registry where the object will be looked up.

key is the name of the object to look up.

On success, the function returns the value associated with key. If the object was not found or it was not an integer object, -1 is returned. To avoid problems with in-band error reporting (i.e. if you cannot distinguish between -1 and a valid result) use the more general function ei_reg_getval() instead.

double ei_reg_getfval(reg,key)

Types:

ei_reg *reg;
const char *key;

Get the value associated with key in the registry. The value must be a floating point type.

reg is the registry where the object will be looked up.

key is the name of the object to look up.

On success, the function returns the value associated with key. If the object was not found or it was not a floating point object, -1.0 is returned. To avoid problems with in-band error reporting (i.e. if you cannot distinguish between -1.0 and a valid result) use the more general function ei_reg_getval() instead.

const char * ei_reg_getsval(reg,key)

Types:

ei_reg *reg;
const char *key;

Get the value associated with key in the registry. The value must be a string.

reg is the registry where the object will be looked up.

key is the name of the object to look up.

On success, the function returns the value associated with key. If the object was not found or it was not a string, NULL is returned. To avoid problems with in-band error reporting (i.e. if you cannot distinguish between NULL and a valid result) use the more general function ei_reg_getval() instead.

const void * ei_reg_getpval(reg,key,size)

Types:

ei_reg *reg;
const char *key;
int size;

Get the value associated with key in the registry. The value must be a binary (pointer) type.

reg is the registry where the object will be looked up.

key is the name of the object to look up.

size will be initialized to contain the length in bytes of the object, if it is found.

On success, the function returns the value associated with key and indicates its length in size. If the object was not found or it was not a binary object, NULL is returned. To avoid problems with in-band error reporting (i.e. if you cannot distinguish between NULL and a valid result) use the more general function ei_reg_getval() instead.

int ei_reg_getval(reg,key,flags,v,...)

Types:

ei_reg *reg;
const char *key;
int flags;
void *v (see below)

This is a general function for retrieving any kind of object from the registry.

reg is the registry where the object will be looked up.

key is the name of the object to look up.

flags indicates the type of object that you are looking for. If flags is 0, then any kind of object will be returned. If flags is one of EI_INT, EI_FLT, EI_STR or EI_BIN, then only values of that kind will be returned. The buffer pointed to by v must be large enough to hold the return data, i.e. it must be a pointer to one of int, double, char* or void*, respectively. Also, if flags is EI_BIN, then a fifth argument int *size is required, so that the size of the object can be returned.

If the function succeeds, v (and size if the object is binary) will be initialized with the value associated with key, and the function will return one of EI_INT, EI_FLT, EI_STR or EI_BIN, indicating the type of object. On failure the function will return -1 and the arguments will not be updated.

int ei_reg_markdirty(reg,key)

Types:

ei_reg *reg;
const char *key;

Mark a registry object as dirty. This will ensure that it is included in the next backup to Mnesia. Normally this operation will not be necessary since all of the normal registry 'set' functions do this automatically. However if you have retrieved the value of a string or binary object from the registry and modified the contents, then the change will be invisible to the registry and the object will be assumed to be unmodified. This function allows you to make such modifications and then let the registry know about them.

reg is the registry containing the object.

key is the name of the object to mark.

The function returns 0 on success, or -1 on failure.

int ei_reg_delete(reg,key)

Types:

ei_reg *reg;
const char *key;

Delete an object from the registry. The object is not actually removed from the registry, it is only marked for later removal so that on subsequent backups to Mnesia, the corresponding object can be removed from the Mnesia table as well. If another object is later created with the same key, the object will be reused.

The object will be removed from the registry after a call to ei_reg_dump() or ei_reg_purge().

reg is the registry containing key.

key is the object to remove.

If the object was found, the function returns 0 indicating success. Otherwise the function returns -1.

int ei_reg_stat(reg,key,obuf)

Types:

ei_reg *reg;
const char *key;
struct ei_reg_stat *obuf;

Return information about an object.

reg is the registry containing the object.

key is the name of the object.

obuf is a pointer to an ei_reg_stat structure, defined below:

    struct ei_reg_stat {
      int attr;
      int size;
    };

In attr the object's attributes are stored as the logical OR of its type (one of EI_INT, EI_FLT, EI_BIN and EI_STR), whether it is marked for deletion (EI_DELET) and whether it has been modified since the last backup to Mnesia (EI_DIRTY).

The size field indicates the size in bytes required to store EI_STR (including the terminating 0) and EI_BIN objects, or 0 for EI_INT and EI_FLT.

The function returns 0 and initializes obuf on success, or returns -1 on failure.

int ei_reg_tabstat(reg,obuf)

Types:

ei_reg *reg;
struct ei_reg_tabstat *obuf;

Return information about a registry. Using information returned by this function, you can see whether the size of the registry is suitable for the amount of data it contains.

reg is the registry to return information about.

obuf is a pointer to an ei_reg_tabstat structure, defined below:

    struct ei_reg_tabstat {
      int size;
      int nelem;
      int npos;
      int collisions;
    };

The size field indicates the number of hash positions in the registry. This is the number you provided when you created or last resized the registry, rounded up to the nearest prime.

nelem indicates the number of elements stored in the registry. It includes objects that are deleted but not purged.

npos indicates the number of unique positions that are occupied in the registry.

collisions indicates how many elements are sharing positions in the registry.

On success, the function returns 0 and obuf is initialized to contain table statistics. On failure, the function returns -1.

int ei_reg_dump(fd,reg,mntab,flags)

Types:

int fd;
ei_reg *reg;
const char *mntab;
int flags;

Dump the contents of a registry to a Mnesia table in an atomic manner, i.e. either all data will be updated, or none of it will. If any errors are encountered while backing up the data, the entire operation is aborted.

fd is an open connection to Erlang. Mnesia 3.0 or later must be running on the Erlang node.

reg is the registry to back up.

mntab is the name of the Mnesia table where the backed up data should be placed. If the table does not exist, it will be created automatically using configurable defaults. See your Mnesia documentation for information about configuring this behaviour.

If flags is 0, the backup will include only those objects which have been created, modified or deleted since the last backup or restore (i.e. an incremental backup). After the backup, any objects that were marked dirty are now clean, and any objects that had been marked for deletion are deleted.

Alternatively, setting flags to EI_FORCE will cause a full backup to be done, and EI_NOPURGE will cause the deleted objects to be left in the registry afterwards. These can be bitwise ORed together if both behaviours are desired. If EI_NOPURGE was specified, you can use ei_reg_purge() to explicitly remove the deleted items from the registry later.

The function returns 0 on success, or -1 on failure.

int ei_reg_restore(fd,reg,mntab)

Types:

int fd;
ei_reg *reg;
const char *mntab;

The contents of a Mnesia table are read into the registry.

fd is an open connection to Erlang. Mnesia 3.0 or later must be running on the Erlang node.

reg is the registry where the data should be placed.

mntab is the name of the Mnesia table to read data from.

Note that only tables of a certain format can be restored, i.e. those that have been created and backed up to with ei_reg_dump(). If the registry was not empty before the operation, then the contents of the table are added to the contents of the registry. If the table contains objects with the same keys as those already in the registry, the registry objects will be overwritten with the new values. If the registry contains objects that were not in the table, they will be unchanged by this operation.

After the restore operation, the entire contents of the registry is marked as unmodified. Note that this includes any objects that were modified before the restore and not overwritten by the restore.

The function returns 0 on success, or -1 on failure.

int ei_reg_purge(reg)

Types:

ei_reg *reg;

Remove all objects marked for deletion. When objects are deleted with ei_reg_delete() they are not actually removed from the registry, only marked for later removal. This is so that on a subsequent backup to Mnesia, the objects can also be removed from the Mnesia table. If you are not backing up to Mnesia then you may wish to remove the objects manually with this function.

reg is a registry containing objects marked for deletion.

The function returns 0 on success, or -1 on failure.