Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement nn_symbol_info function

This is useful for two reasons:

* For language bindings to provide correct namespacing and type
  conversions of socket options
* To turn integer value into name (it's impossible without namespacing,
  because many symbols have same integer value)
  • Loading branch information...
commit 56c7e271d7dee2ff823f04f65aae09ffa1db5cc0 1 parent cb94553
@tailhook tailhook authored
View
3  doc/nn_symbol.txt
@@ -20,7 +20,7 @@ has no significance to its associated symbol; the mappings may change between
library versions.
Typically a client will iterate through the symbols until nn_symbol returns
-NULL in order to collect all the symbols.
+NULL in order to collect all the symbols.
All symbols exposed by 'nn_symbol' are available directly in the C API,
generally as preprocessor macros. Thus, this function is useful mostly for
@@ -63,6 +63,7 @@ for (i = 0; ; ++i) {
SEE ALSO
--------
+linknanomsg:nn_symbol_info[3]
linknanomsg:nn_errno[3]
linknanomsg:nn_strerror[3]
linknanomsg:nanomsg[7]
View
151 doc/nn_symbol_info.txt
@@ -0,0 +1,151 @@
+nn_symbol_info(3)
+=================
+
+NAME
+----
+nn_symbol_info - query the names and properties of nanomsg symbols
+
+
+SYNOPSIS
+--------
+*#include <nanomsg/nn.h>*
+
+*int nn_symbol_info (int 'i', struct nn_symbol_properties '*buf', int 'buflen');*
+
+
+DESCRIPTION
+-----------
+Retrieves the symbol name and value at index 'i'. Indices start at 0. An index
+has no significance to its associated symbol; the mappings may change between
+library versions.
+
+The nn_symbol_properties has the following definition:
+
+----
+struct nn_symbol_properties {
+
+ /* The constant value */
+ int value;
+
+ /* The contant name */
+ const char* name;
+
+ /* The constant namespace, or zero for namespaces themselves */
+ int ns;
+
+ /* The option type for socket option constants */
+ int type;
+
+ /* The unit for the option value for socket option constants */
+ int unit;
+};
+----
+
+More structure members may be added in future, but input pointer will be
+written only up to 'buflen' so ABI is forward-compatible.
+
+Typically a client will iterate through the symbols until nn_symbol_info
+returns NULL in order to collect all the symbols.
+
+All symbols exposed by 'nn_symbol_info' are available directly in the C API,
+generally as preprocessor macros. Thus, this function is useful mostly for
+language bindings that can't parse the header file and rely on retrieving the
+symbols in the runtime.
+
+Note that the NN_MSG symbol is not exported by the _nn_symbol_ function. First,
+it is a pointer rather than an integer; second, the symbol is not supposed to
+be exported from language bindings to the user. Instead, language bindings
+should provide the zero-copy functionality in a language-specific way, if at
+all (zero-copy functionality may not make sense for some languages/bindings).
+
+AVAILABLE NAMESPACES
+--------------------
+*NN_NS_NAMESPACE*::
+Equals to zero and denotes the NN_NS_* constants themselves
+*NN_NS_VERSION*::
+Nanomsg version constants
+*NN_NS_DOMAIN*::
+Socket domain (or address family) constants AF_SP, AF_SP_RAW
+*NN_NS_TRANSPORT*::
+Transport name constants (used for socket options mainly)
+*NN_NS_PROTOCOL*::
+Socket protocol constants
+*NN_NS_OPTION_LEVEL*::
+Socket option level constants (NN_SOL_SOCKET)
+*NN_NS_SOCKET_OPTION*::
+Socket options for NN_SOL_SOCKET level
+*NN_NS_TRANSPORT_OPTION*::
+Socket options for transport level (used with transport constants)
+*NN_NS_OPTION_TYPE*::
+The option types (described below)
+*NN_NS_FLAG*::
+The nn_send/nn_recv flags (only NN_DONTWAIT for now)
+*NN_NS_ERROR*::
+The errno values
+*NN_NS_LIMIT*::
+Various nanomsg limits (only NN_SOCKADDR_MAX for now)
+
+AVAILABLE OPTION TYPES
+----------------------
+*NN_TYPE_NONE*::
+No type, is returned for constants that are not socket options
+*NN_TYPE_INT*::
+The integer type
+*NN_TYPE_STR*::
+String (char *) type
+
+More types may be added in future nanomsg. You may enumerate all of them using
+the 'nn_symbol_info' itself by checking 'NN_NS_OPTION_TYPE' namespace.
+
+AVAILABLE OPTION UNITS
+----------------------
+*NN_UNIT_NONE*::
+No unit, is returned for constants that are not socket options, or do not have
+any meaningful unit (strings, integer values)
+*NN_UNIT_BYTES*::
+The option value is expressed in bytes
+*NN_UNIT_MILLISECONDS*::
+The option value is expressed in milliseconds
+*NN_UNIT_PRIORITY*::
+The option value is a priority, an integer from 1 to 16
+*NN_UNIT_BOOLEAN*::
+The option value is boolean, an integer 0 or 1
+
+More types may be added in future nanomsg. You may enumerate all of them using
+the 'nn_symbol_info' itself by checking 'NN_NS_OPTION_TYPE' namespace.
+
+
+RETURN VALUE
+------------
+If 'i' is valid, returns the number of bytes stored at the structure. The
+maximum value that can be returned is 'buflen'.
+
+If 'i' is out-of-range, nn_symbol_info returns zero.
+
+
+EXAMPLE
+-------
+
+----
+int i;
+for (i = 0; ; ++i) {
+ struct nn_symbol_properties sym;
+ int rc = nn_symbol_info (i, &sym, sizeof (sym));
+ if(rc == 0)
+ break;
+ assert (rc == sizeof (sym));
+ printf ("'%s' = %d\n", sym->name, sym->value);
+}
+----
+
+SEE ALSO
+--------
+linknanomsg:nn_symbol[3]
+linknanomsg:nn_errno[3]
+linknanomsg:nn_strerror[3]
+linknanomsg:nanomsg[7]
+
+
+AUTHORS
+-------
+Evan Wies <evan@neomantra.net>
View
270 src/core/symbol.c
@@ -34,102 +34,182 @@
#include "../survey.h"
#include "../bus.h"
-struct sym_value_name {
- int value;
- const char* name;
-};
-
-static const struct sym_value_name sym_value_names [] = {
-
- {NN_VERSION_CURRENT, "NN_VERSION_CURRENT"},
- {NN_VERSION_REVISION, "NN_VERSION_REVISION"},
- {NN_VERSION_AGE, "NN_VERSION_AGE"},
-
- {AF_SP, "AF_SP"},
- {AF_SP_RAW, "AF_SP_RAW"},
-
- {NN_INPROC, "NN_INPROC"},
- {NN_IPC, "NN_IPC"},
- {NN_TCP, "NN_TCP"},
-
- {NN_PAIR, "NN_PAIR"},
- {NN_PUB, "NN_PUB"},
- {NN_SUB, "NN_SUB"},
- {NN_REP, "NN_REP"},
- {NN_REQ, "NN_REQ"},
- {NN_PUSH, "NN_PUSH"},
- {NN_PULL, "NN_PULL"},
- {NN_SURVEYOR, "NN_SURVEYOR"},
- {NN_RESPONDENT, "NN_RESPONDENT"},
- {NN_BUS, "NN_BUS"},
-
- {NN_SOCKADDR_MAX, "NN_SOCKADDR_MAX"},
-
- {NN_SOL_SOCKET, "NN_SOL_SOCKET"},
-
- {NN_LINGER, "NN_LINGER"},
- {NN_SNDBUF, "NN_SNDBUF"},
- {NN_RCVBUF, "NN_RCVBUF"},
- {NN_SNDTIMEO, "NN_SNDTIMEO"},
- {NN_RCVTIMEO, "NN_RCVTIMEO"},
- {NN_RECONNECT_IVL, "NN_RECONNECT_IVL"},
- {NN_RECONNECT_IVL_MAX, "NN_RECONNECT_IVL_MAX"},
- {NN_SNDPRIO, "NN_SNDPRIO"},
- {NN_SNDFD, "NN_SNDFD"},
- {NN_RCVFD, "NN_RCVFD"},
- {NN_DOMAIN, "NN_DOMAIN"},
- {NN_PROTOCOL, "NN_PROTOCOL"},
- {NN_IPV4ONLY, "NN_IPV4ONLY"},
- {NN_SOCKET_NAME, "NN_SOCKET_NAME"},
-
- {NN_SUB_SUBSCRIBE, "NN_SUB_SUBSCRIBE"},
- {NN_SUB_UNSUBSCRIBE, "NN_SUB_UNSUBSCRIBE"},
- {NN_REQ_RESEND_IVL, "NN_REQ_RESEND_IVL"},
- {NN_SURVEYOR_DEADLINE, "NN_SURVEYOR_DEADLINE"},
- {NN_TCP_NODELAY, "NN_TCP_NODELAY"},
-
- {NN_DONTWAIT, "NN_DONTWAIT"},
-
- {EADDRINUSE, "EADDRINUSE"},
- {EADDRNOTAVAIL, "EADDRNOTAVAIL"},
- {EAFNOSUPPORT, "EAFNOSUPPORT"},
- {EAGAIN, "EAGAIN"},
- {EBADF, "EBADF"},
- {ECONNREFUSED, "ECONNREFUSED"},
- {EFAULT, "EFAULT"},
- {EFSM, "EFSM"},
- {EINPROGRESS, "EINPROGRESS"},
- {EINTR, "EINTR"},
- {EINVAL, "EINVAL"},
- {EMFILE, "EMFILE"},
- {ENAMETOOLONG, "ENAMETOOLONG"},
- {ENETDOWN, "ENETDOWN"},
- {ENOBUFS, "ENOBUFS"},
- {ENODEV, "ENODEV"},
- {ENOMEM, "ENOMEM"},
- {ENOPROTOOPT, "ENOPROTOOPT"},
- {ENOTSOCK, "ENOTSOCK"},
- {ENOTSUP, "ENOTSUP"},
- {EPROTO, "EPROTO"},
- { EPROTONOSUPPORT, "EPROTONOSUPPORT"},
- {ETERM, "ETERM"},
- {ETIMEDOUT, "ETIMEDOUT"},
- {EACCES, "EACCES" },
- {ECONNABORTED, "ECONNABORTED"},
- {ECONNRESET, "ECONNRESET"},
- {EHOSTUNREACH, "EHOSTUNREACH"},
- {EMSGSIZE, "EMSGSIZE"},
- {ENETRESET, "ENETRESET"},
- {ENETUNREACH, "ENETUNREACH"},
- {ENOTCONN, "ENOTCONN"},
+#include <string.h>
+
+static const struct nn_symbol_properties sym_value_names [] = {
+ {NN_NS_NAMESPACE, "NN_NS_NAMESPACE", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_VERSION, "NN_NS_VERSION", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_DOMAIN, "NN_NS_DOMAIN", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_TRANSPORT, "NN_NS_TRANSPORT", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_PROTOCOL, "NN_NS_PROTOCOL", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_OPTION_LEVEL, "NN_NS_OPTION_LEVEL", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_SOCKET_OPTION, "NN_NS_SOCKET_OPTION", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_TRANSPORT_OPTION, "NN_NS_TRANSPORT_OPTION", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_OPTION_TYPE, "NN_NS_OPTION_TYPE", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_FLAG, "NN_NS_FLAG", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_ERROR, "NN_NS_ERROR", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_NS_LIMIT, "NN_NS_LIMIT", NN_NS_NAMESPACE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {NN_TYPE_NONE, "NN_TYPE_NONE", NN_NS_OPTION_TYPE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_TYPE_INT, "NN_TYPE_INT", NN_NS_OPTION_TYPE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_TYPE_STR, "NN_TYPE_STR", NN_NS_OPTION_TYPE,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {NN_UNIT_NONE, "NN_UNIT_NONE", NN_NS_OPTION_UNIT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_UNIT_BYTES, "NN_UNIT_BYTES", NN_NS_OPTION_UNIT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_UNIT_MILLISECONDS, "NN_UNIT_MILLISECONDS", NN_NS_OPTION_UNIT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_UNIT_PRIORITY, "NN_UNIT_PRIORITY", NN_NS_OPTION_UNIT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_UNIT_BOOLEAN, "NN_UNIT_BOOLEAN", NN_NS_OPTION_UNIT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {NN_VERSION_CURRENT, "NN_VERSION_CURRENT", NN_NS_VERSION,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_VERSION_REVISION, "NN_VERSION_REVISION", NN_NS_VERSION,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_VERSION_AGE, "NN_VERSION_AGE", NN_NS_VERSION,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {AF_SP, "AF_SP", NN_NS_DOMAIN,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {AF_SP_RAW, "AF_SP_RAW", NN_NS_DOMAIN,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {NN_INPROC, "NN_INPROC", NN_NS_TRANSPORT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_IPC, "NN_IPC", NN_NS_TRANSPORT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_TCP, "NN_TCP", NN_NS_TRANSPORT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {NN_PAIR, "NN_PAIR", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_PUB, "NN_PUB", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_SUB, "NN_SUB", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_REP, "NN_REP", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_REQ, "NN_REQ", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_PUSH, "NN_PUSH", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_PULL, "NN_PULL", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_SURVEYOR, "NN_SURVEYOR", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_RESPONDENT, "NN_RESPONDENT", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+ {NN_BUS, "NN_BUS", NN_NS_PROTOCOL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {NN_SOCKADDR_MAX, "NN_SOCKADDR_MAX", NN_NS_LIMIT,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {NN_SOL_SOCKET, "NN_SOL_SOCKET", NN_NS_OPTION_LEVEL,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {NN_LINGER, "NN_LINGER", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_MILLISECONDS},
+ {NN_SNDBUF, "NN_SNDBUF", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_BYTES},
+ {NN_RCVBUF, "NN_RCVBUF", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_BYTES},
+ {NN_SNDTIMEO, "NN_SNDTIMEO", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_MILLISECONDS},
+ {NN_RCVTIMEO, "NN_RCVTIMEO", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_MILLISECONDS},
+ {NN_RECONNECT_IVL, "NN_RECONNECT_IVL", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_MILLISECONDS},
+ {NN_RECONNECT_IVL_MAX, "NN_RECONNECT_IVL_MAX", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_MILLISECONDS},
+ {NN_SNDPRIO, "NN_SNDPRIO", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_PRIORITY},
+ {NN_SNDFD, "NN_SNDFD", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_NONE},
+ {NN_RCVFD, "NN_RCVFD", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_NONE},
+ {NN_DOMAIN, "NN_DOMAIN", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_NONE},
+ {NN_PROTOCOL, "NN_PROTOCOL", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_NONE},
+ {NN_IPV4ONLY, "NN_IPV4ONLY", NN_NS_SOCKET_OPTION,
+ NN_TYPE_INT, NN_UNIT_BOOLEAN},
+ {NN_SOCKET_NAME, "NN_SOCKET_NAME", NN_NS_SOCKET_OPTION,
+ NN_TYPE_STR, NN_UNIT_NONE},
+
+ {NN_SUB_SUBSCRIBE, "NN_SUB_SUBSCRIBE", NN_NS_TRANSPORT_OPTION,
+ NN_TYPE_STR, NN_UNIT_NONE},
+ {NN_SUB_UNSUBSCRIBE, "NN_SUB_UNSUBSCRIBE", NN_NS_TRANSPORT_OPTION,
+ NN_TYPE_STR, NN_UNIT_NONE},
+ {NN_REQ_RESEND_IVL, "NN_REQ_RESEND_IVL", NN_NS_TRANSPORT_OPTION,
+ NN_TYPE_INT, NN_UNIT_MILLISECONDS},
+ {NN_SURVEYOR_DEADLINE, "NN_SURVEYOR_DEADLINE", NN_NS_TRANSPORT_OPTION,
+ NN_TYPE_INT, NN_UNIT_MILLISECONDS},
+ {NN_TCP_NODELAY, "NN_TCP_NODELAY", NN_NS_TRANSPORT_OPTION,
+ NN_TYPE_INT, NN_UNIT_BOOLEAN},
+
+ {NN_DONTWAIT, "NN_DONTWAIT", NN_NS_FLAG,
+ NN_TYPE_NONE, NN_UNIT_NONE},
+
+ {EADDRINUSE, "EADDRINUSE", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EADDRNOTAVAIL, "EADDRNOTAVAIL", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EAFNOSUPPORT, "EAFNOSUPPORT", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EAGAIN, "EAGAIN", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EBADF, "EBADF", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ECONNREFUSED, "ECONNREFUSED", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EFAULT, "EFAULT", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EFSM, "EFSM", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EINPROGRESS, "EINPROGRESS", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EINTR, "EINTR", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EINVAL, "EINVAL", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EMFILE, "EMFILE", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENAMETOOLONG, "ENAMETOOLONG", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENETDOWN, "ENETDOWN", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENOBUFS, "ENOBUFS", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENODEV, "ENODEV", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENOMEM, "ENOMEM", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENOPROTOOPT, "ENOPROTOOPT", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENOTSOCK, "ENOTSOCK", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENOTSUP, "ENOTSUP", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EPROTO, "EPROTO", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EPROTONOSUPPORT, "EPROTONOSUPPORT", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ETERM, "ETERM", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ETIMEDOUT, "ETIMEDOUT", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EACCES, "EACCES" , NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ECONNABORTED, "ECONNABORTED", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ECONNRESET, "ECONNRESET", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EHOSTUNREACH, "EHOSTUNREACH", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {EMSGSIZE, "EMSGSIZE", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENETRESET, "ENETRESET", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENETUNREACH, "ENETUNREACH", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
+ {ENOTCONN, "ENOTCONN", NN_NS_ERROR, NN_TYPE_NONE, NN_UNIT_NONE},
};
const int SYM_VALUE_NAMES_LEN = (sizeof (sym_value_names) /
sizeof (sym_value_names [0]));
+
const char *nn_symbol (int i, int *value)
{
- const struct sym_value_name *svn;
+ const struct nn_symbol_properties *svn;
if (i < 0 || i >= SYM_VALUE_NAMES_LEN) {
errno = EINVAL;
return NULL;
@@ -141,3 +221,15 @@ const char *nn_symbol (int i, int *value)
return svn->name;
}
+int nn_symbol_info (int i, struct nn_symbol_properties *buf, int buflen)
+{
+ if (i < 0 || i >= SYM_VALUE_NAMES_LEN) {
+ return 0;
+ }
+ if (buflen > (int)sizeof (struct nn_symbol_properties)) {
+ buflen = (int)sizeof (struct nn_symbol_properties);
+ }
+ memcpy(buf, &sym_value_names [i], buflen);
+ return buflen;
+}
+
View
53 src/nn.h
@@ -184,11 +184,64 @@ NN_EXPORT int nn_errno (void);
/* Resolves system errors and native errors to human-readable string. */
NN_EXPORT const char *nn_strerror (int errnum);
+
/* Returns the symbol name (e.g. "NN_REQ") and value at a specified index. */
/* If the index is out-of-range, returns NULL and sets errno to EINVAL */
/* General usage is to start at i=0 and iterate until NULL is returned. */
NN_EXPORT const char *nn_symbol (int i, int *value);
+/* Constants that are returned in `ns` member of nn_symbol_properties */
+#define NN_NS_NAMESPACE 0
+#define NN_NS_VERSION 1
+#define NN_NS_DOMAIN 2
+#define NN_NS_TRANSPORT 3
+#define NN_NS_PROTOCOL 4
+#define NN_NS_OPTION_LEVEL 5
+#define NN_NS_SOCKET_OPTION 6
+#define NN_NS_TRANSPORT_OPTION 7
+#define NN_NS_OPTION_TYPE 8
+#define NN_NS_OPTION_UNIT 9
+#define NN_NS_FLAG 10
+#define NN_NS_ERROR 11
+#define NN_NS_LIMIT 12
+
+/* Constants that are returned in `type` member of nn_symbol_properties */
+#define NN_TYPE_NONE 0
+#define NN_TYPE_INT 1
+#define NN_TYPE_STR 2
+
+/* Constants that are returned in the `unit` member of nn_symbol_properties */
+#define NN_UNIT_NONE 0
+#define NN_UNIT_BYTES 1
+#define NN_UNIT_MILLISECONDS 2
+#define NN_UNIT_PRIORITY 3
+#define NN_UNIT_BOOLEAN 4
+
+/* Structure that is returned from nn_symbol */
+struct nn_symbol_properties {
+
+ /* The constant value */
+ int value;
+
+ /* The contant name */
+ const char* name;
+
+ /* The constant namespace, or zero for namespaces themselves */
+ int ns;
+
+ /* The option type for socket option constants */
+ int type;
+
+ /* The unit for the option value for socket option constants */
+ int unit;
+};
+
+/* Fills in nn_symbol_properties structure and returns it's length */
+/* If the index is out-of-range, returns 0 */
+/* General usage is to start at i=0 and iterate until zero is returned. */
+NN_EXPORT int nn_symbol_info (int i,
+ struct nn_symbol_properties *buf, int buflen);
+
/******************************************************************************/
/* Helper function for shutting down multi-threaded applications. */
/******************************************************************************/
View
12 tests/symbol.c
@@ -24,16 +24,21 @@
int main ()
{
- int value, i;
+ int i;
+ struct nn_symbol_properties sym;
+ int value;
nn_assert (nn_symbol (-1, NULL) == NULL);
nn_assert (nn_errno () == EINVAL);
+ nn_assert (nn_symbol_info (-1, &sym, (int) sizeof (sym)) == 0);
nn_assert (nn_symbol (2000, NULL) == NULL);
nn_assert (nn_errno () == EINVAL);
+ nn_assert (nn_symbol_info (2000, &sym, (int) sizeof (sym)) == 0);
nn_assert (nn_symbol (6, &value) != NULL);
nn_assert (value != 0);
+ nn_assert (nn_symbol_info (6, &sym, (int) sizeof (sym)) == sizeof (sym));
for (i = 0; ; ++i) {
const char* name = nn_symbol (i, &value);
@@ -43,6 +48,11 @@ int main ()
}
}
+ for (i = 0; ; ++i) {
+ if (nn_symbol_info (i, &sym, sizeof (sym)) == 0)
+ break;
+ }
+
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.