Skip to content

Commit

Permalink
squashme: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
laanwj committed Apr 19, 2016
1 parent 50a825a commit fb843df
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/zmq/zmqpublishnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static const char *MSG_RAWBLOCK = "rawblock";
static const char *MSG_RAWTX = "rawtx";

// Internal function to send multipart message
static int zmq_send_multipart_keepalive(void *sock, const void* data, size_t size, ...)
static int zmq_send_multipart(void *sock, const void* data, size_t size, ...)
{
va_list args;
va_start(args, size);
Expand All @@ -36,7 +36,7 @@ static int zmq_send_multipart_keepalive(void *sock, const void* data, size_t siz

data = va_arg(args, const void*);

rc = zmq_msg_send(&msg, sock, ZMQ_SNDMORE);
rc = zmq_msg_send(&msg, sock, data ? ZMQ_SNDMORE : 0);
if (rc == -1)
{
zmqError("Unable to send ZMQ msg");
Expand Down Expand Up @@ -127,26 +127,12 @@ bool CZMQAbstractPublishNotifier::SendMessage(const char *command, const void* d
{
assert(psocket);

/* send two parts, command & data */
int rc = zmq_send_multipart_keepalive(psocket, command, strlen(command), data, size, 0);
if (rc == -1)
return false;

/* create a LE 4byte sequence number and append it as last message part */
zmq_msg_t msg;
unsigned char msgseq[sizeof(int32_t)];
/* send three parts, command & data & a LE 4byte sequence number */
unsigned char msgseq[sizeof(uint32_t)];
WriteLE32(&msgseq[0], nSequence);
rc = zmq_msg_init_size(&msg, sizeof(uint32_t));
void *buf = zmq_msg_data(&msg);
memcpy(buf, &msgseq, sizeof(uint32_t));
rc = zmq_msg_send(&msg, psocket, 0);
if (rc != sizeof(uint32_t))
{
zmqError("Unable to send ZMQ msg");
zmq_msg_close(&msg);
int rc = zmq_send_multipart(psocket, command, strlen(command), data, size, msgseq, (size_t)sizeof(uint32_t), (void*)0);
if (rc == -1)
return false;
}
zmq_msg_close(&msg);

/* increment memory only sequence number after sending */
nSequence++;
Expand Down

0 comments on commit fb843df

Please sign in to comment.