diff options
| author | Jake Woltersdorf <jake@playruyi.com> | 2019-03-04 12:35:19 +0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2019-04-07 19:13:44 -0700 |
| commit | c3e062661388f70386d6766e3ce648030af340ee (patch) | |
| tree | a6d247bd24a17e3201a75b1a164e75d16e37196c /src/core/stream.c | |
| parent | 989c5e90d48066b12ad44ed903cfc163d8e89b29 (diff) | |
| download | nng-c3e062661388f70386d6766e3ce648030af340ee.tar.gz nng-c3e062661388f70386d6766e3ce648030af340ee.tar.bz2 nng-c3e062661388f70386d6766e3ce648030af340ee.zip | |
fixes #901 shorter option get/set functions for all types
- Renamed internal nng_*_getx/setx methods with "nni" prefix
- Moved stream get/set option definition macros to options.h and added "NNI_" prefix
- "_PTR" variant of get/set option definition macros is for when first arg is passed as pointer (`nng_stream *s` vs `nng_pipe s`)
- New get/set option functions for `nng_socket` are `nng_socket_get_X` eschewing the previous `nng_getopt` pattern
- Macro-fy legacy getopt/setopt and implement in terms of "new" API
- nng_setopt* use "new" shorter API. Add missing uint64 set functions.
- Shorter get/set option functions get own man page and old getopt/setopt link to them
- Built with -DNNG_ENABLE_DOC=ON and part of central libnng index
- Update copyright
Diffstat (limited to 'src/core/stream.c')
| -rw-r--r-- | src/core/stream.c | 88 |
1 files changed, 6 insertions, 82 deletions
diff --git a/src/core/stream.c b/src/core/stream.c index c0dc38d6..e7ebc4e0 100644 --- a/src/core/stream.c +++ b/src/core/stream.c @@ -282,86 +282,10 @@ nni_stream_checkopt(const char *scheme, const char *name, const void *data, return (NNG_ENOTSUP); } -// -// This next block sets up to define the various typed option functions. -// To make it easier to cover them all at once, we use macros. -// - -#define DEFGET(base) \ - int nng_##base##_get( \ - nng_##base *s, const char *nm, void *vp, size_t *szp) \ - { \ - return (nni_##base##_getx(s, nm, vp, szp, NNI_TYPE_OPAQUE)); \ - } - -#define DEFTYPEDGET(base, suffix, type, nnitype) \ - int nng_##base##_get_##suffix( \ - nng_##base *s, const char *nm, type *vp) \ - { \ - size_t sz = sizeof(*vp); \ - return (nni_##base##_getx(s, nm, vp, &sz, nnitype)); \ - } - -#define DEFGETALL(base) \ - DEFGET(base) \ - DEFTYPEDGET(base, int, int, NNI_TYPE_INT32) \ - DEFTYPEDGET(base, bool, bool, NNI_TYPE_BOOL) \ - DEFTYPEDGET(base, size, size_t, NNI_TYPE_SIZE) \ - DEFTYPEDGET(base, uint64, uint64_t, NNI_TYPE_UINT64) \ - DEFTYPEDGET(base, string, char *, NNI_TYPE_STRING) \ - DEFTYPEDGET(base, ptr, void *, NNI_TYPE_POINTER) \ - DEFTYPEDGET(base, ms, nng_duration, NNI_TYPE_DURATION) \ - DEFTYPEDGET(base, addr, nng_sockaddr, NNI_TYPE_SOCKADDR) - -DEFGETALL(stream) -DEFGETALL(stream_dialer) -DEFGETALL(stream_listener) - -#define DEFSET(base) \ - int nng_##base##_set( \ - nng_##base *s, const char *nm, const void *vp, size_t sz) \ - { \ - return (nni_##base##_setx(s, nm, vp, sz, NNI_TYPE_OPAQUE)); \ - } - -#define DEFTYPEDSETEX(base, suffix, type, len, nnitype) \ - int nng_##base##_set_##suffix(nng_##base *s, const char *nm, type v) \ - { \ - return (nni_##base##_setx(s, nm, &v, len, nnitype)); \ - } - -#define DEFTYPEDSET(base, suffix, type, nnitype) \ - int nng_##base##_set_##suffix(nng_##base *s, const char *nm, type v) \ - { \ - return (nni_##base##_setx(s, nm, &v, sizeof(v), nnitype)); \ - } - -#define DEFSTRINGSET(base) \ - int nng_##base##_set_string( \ - nng_##base *s, const char *nm, const char *v) \ - { \ - return (nni_##base##_setx(s, nm, v, \ - v != NULL ? strlen(v) + 1 : 0, NNI_TYPE_STRING)); \ - } - -#define DEFSOCKADDRSET(base) \ - int nng_##base##_set_adddr( \ - nng_##base *s, const char *nm, const nng_sockaddr *v) \ - { \ - return (nni_##base##_setx( \ - s, nm, v, sizeof(*v), NNI_TYPE_SOCKADDR)); \ - } +NNI_DEFGETALL_PTR(stream) +NNI_DEFGETALL_PTR(stream_dialer) +NNI_DEFGETALL_PTR(stream_listener) -#define DEFSETALL(base) \ - DEFSET(base) \ - DEFTYPEDSET(base, int, int, NNI_TYPE_INT32) \ - DEFTYPEDSET(base, bool, bool, NNI_TYPE_BOOL) \ - DEFTYPEDSET(base, size, size_t, NNI_TYPE_SIZE) \ - DEFTYPEDSET(base, ms, nng_duration, NNI_TYPE_DURATION) \ - DEFTYPEDSET(base, ptr, void *, NNI_TYPE_POINTER) \ - DEFSTRINGSET(base) \ - DEFSOCKADDRSET(base) - -DEFSETALL(stream) -DEFSETALL(stream_dialer) -DEFSETALL(stream_listener)
\ No newline at end of file +NNI_DEFSETALL_PTR(stream) +NNI_DEFSETALL_PTR(stream_dialer) +NNI_DEFSETALL_PTR(stream_listener)
\ No newline at end of file |
