summaryrefslogtreecommitdiff
path: root/src/wire.hpp
diff options
context:
space:
mode:
authorMartin Lucina <martin@lucina.net>2012-05-20 07:40:11 +0200
committerMartin Lucina <martin@lucina.net>2012-05-20 07:40:11 +0200
commit1d76284dee8e9b0735a26ee98a3edcd9f5208f09 (patch)
treee6ac09d125e5353a3cfb4fbfd25b76f6dc7c308a /src/wire.hpp
parent8c23de9f2abc2ec21d4b74785fd175050909176e (diff)
Implement SP wire protocolsp
Implements the SP wire protocol, and infrastructure for legacy wire protocol support. Also added an XS_SERVICE_ID socket option to set the service id and renamed the XS_PROTOCOL option to XS_PATTERN_VERSION. The following pattern versions are supported: PAIR: v3 PUBSUB: v1 (legacy), v4 REQREP: v2 PIPELINE: v3 SURVEY: v2 Note that all existing pattern versions have been bumped by 1 to allow for use of legacy protocols (otherwise there would be no way to distinguish between e.g. PUBSUB v3 and PUBSUB v3 using SP). Signed-off-by: Martin Lucina <martin@lucina.net>
Diffstat (limited to 'src/wire.hpp')
-rw-r--r--src/wire.hpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/wire.hpp b/src/wire.hpp
index f840fce..014021b 100644
--- a/src/wire.hpp
+++ b/src/wire.hpp
@@ -24,11 +24,52 @@
#include "stdint.hpp"
// Protocol-related constants.
-#define XS_CMD_SUBSCRIBE 1
-#define XS_CMD_UNSUBSCRIBE 2
+
+// Protocol header.
+#define SP_HEADER_LENGTH 8
+
+// Patterns.
+#define SP_PAIR 1
+#define SP_PUBSUB 2
+#define SP_REQREP 3
+#define SP_PIPELINE 4
+#define SP_SURVEY 5
+
+// Roles.
+#define SP_PAIR_PAIR 1
+#define SP_PUBSUB_PUB 1
+#define SP_PUBSUB_SUB 2
+#define SP_REQREP_REQ 1
+#define SP_REQREP_REP 2
+#define SP_PIPELINE_PUSH 1
+#define SP_PIPELINE_PULL 2
+#define SP_SURVEY_SURVEYOR 1
+#define SP_SURVEY_RESPONDENT 2
+
+// PUBSUB pattern commands.
+#define SP_PUBSUB_CMD_SUBSCRIBE 1
+#define SP_PUBSUB_CMD_UNSUBSCRIBE 2
namespace xs
{
+ // Protocol header type.
+ typedef unsigned char sp_header_t [SP_HEADER_LENGTH];
+
+ // Get the SP protocol header for the specified service, pattern, version
+ // and role.
+ inline void sp_get_header (sp_header_t header_, int service_, int pattern_,
+ int version_, int role_)
+ {
+ header_ [0] = 0; // Protocol identifier
+ header_ [1] = 'S'; // "
+ header_ [2] = 'P'; // "
+ header_ [3] = 0; // Reserved, must be zero.
+ header_ [4] = (service_ >> 8) & 0xff; // Service id high byte
+ header_ [5] = service_ & 0xff; // Service id low byte
+ header_ [6] = pattern_ & 0xff; // Pattern
+ header_ [7] = (version_ & 0xf) << 4; // Pattern version
+ header_ [7] |= role_ & 0xf; // Pattern role
+ }
// Helper functions to convert different integer types to/from network
// byte order.