mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-30 13:47:13 +01:00
Problem: code duplication in getsockopt/setsockopt
Solution: extracted common code into do_getsockopt/do_setsockopt functions
This commit is contained in:
@@ -46,6 +46,10 @@
|
||||
#include <sys/ucred.h>
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
// Normal base 256 key is 32 bytes
|
||||
#define CURVE_KEYSIZE 32
|
||||
// Key encoded using Z85 is 40 bytes
|
||||
@@ -255,6 +259,33 @@ struct options_t
|
||||
// Use zero copy strategy for storing message content when decoding.
|
||||
bool zero_copy;
|
||||
};
|
||||
|
||||
int do_getsockopt (void *const optval_,
|
||||
size_t *const optvallen_,
|
||||
const void *value_,
|
||||
const size_t value_len_);
|
||||
|
||||
template <typename T>
|
||||
int do_getsockopt (void *const optval_, size_t *const optvallen_, T value_)
|
||||
{
|
||||
#if __cplusplus >= 201103L && (!defined(__GNUC__) || __GNUC__ > 5)
|
||||
static_assert (std::is_trivially_copyable<T>::value,
|
||||
"invalid use of do_getsockopt");
|
||||
#endif
|
||||
return do_getsockopt (optval_, optvallen_, &value_, sizeof (T));
|
||||
}
|
||||
|
||||
int do_getsockopt (void *const optval_,
|
||||
size_t *const optvallen_,
|
||||
const std::string &value_);
|
||||
|
||||
int do_setsockopt_int_as_bool_strict (const void *const optval_,
|
||||
const size_t optvallen_,
|
||||
bool *out_value_);
|
||||
|
||||
int do_setsockopt_int_as_bool_relaxed (const void *const optval_,
|
||||
const size_t optvallen_,
|
||||
bool *out_value_);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user