Kylin/AsioZeroMQ/Options.h
2023-07-21 14:07:27 +08:00

66 lines
1.7 KiB
C++

#ifndef OPTIONS_H
#define OPTIONS_H
#include <zmq.h>
namespace ZeroMQ {
enum class SocketType : int {
Req = ZMQ_REQ,
Rep = ZMQ_REP,
Dealer = ZMQ_DEALER,
Router = ZMQ_ROUTER,
Pub = ZMQ_PUB,
Sub = ZMQ_SUB,
Xpub = ZMQ_XPUB,
Xsub = ZMQ_XSUB,
Push = ZMQ_PUSH,
Pull = ZMQ_PULL,
Stream = ZMQ_STREAM,
Pair = ZMQ_PAIR
};
enum class SendFlags : int {
None = 0,
Dontwait = ZMQ_DONTWAIT,
Sndmore = ZMQ_SNDMORE,
};
enum class RecvFlags : int {
None = 0,
Dontwait = ZMQ_DONTWAIT,
};
// BoolUnit: if true accepts values of type bool (but passed as T into libzmq)
template <int Option, class T, bool BoolUnit = false>
struct IntegralOption {};
// NullTerm:
// 0: binary data
// 1: null-terminated string (`getsockopt` size includes null)
// 2: binary (size 32) or Z85 encoder string of size 41 (null included)
template <int Option, int NullTerm = 1>
struct ArrayOption {};
// ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_LINGER, linger, int);
using LingerType = IntegralOption<ZMQ_LINGER, int, false>;
inline constexpr LingerType Linger;
// ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_RCVHWM, rcvhwm, int);
using ReceiveHighWaterMarkType = IntegralOption<ZMQ_RCVHWM, int, false>;
inline constexpr ReceiveHighWaterMarkType ReceiveHighWaterMark;
// ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_EVENTS, events, int);
using EventsType = IntegralOption<ZMQ_EVENTS, int, false>;
inline constexpr EventsType Events;
// ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_RCVMORE, rcvmore, int);
using ReceiveMoreType = IntegralOption<ZMQ_RCVMORE, int, true>;
inline constexpr ReceiveMoreType ReceiveMore;
// ZMQ_DEFINE_ARRAY_OPT(ZMQ_SUBSCRIBE, subscribe);
using SubscribeType = ArrayOption<ZMQ_SUBSCRIBE>;
inline constexpr SubscribeType Subscribe;
} // namespace ZeroMQ
#endif // OPTIONS_H