Skip to content

Commit 42c9f03

Browse files
committed
Merge pull request #1016 from maolin-cdzl/feature-zmsg_sendm
implement zmsg_sendm
2 parents 9daa765 + db45042 commit 42c9f03

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

include/zmsg.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ CZMQ_EXPORT zmsg_t *
4444
CZMQ_EXPORT int
4545
zmsg_send (zmsg_t **self_p, void *dest);
4646

47+
// Send (More) message to destination socket, and destroy the message after sending
48+
// it successfully. If the message has no frames, sends nothing but destroys
49+
// the message anyhow. Nullifies the caller's reference to the message (as
50+
// it is a destructor).
51+
CZMQ_EXPORT int
52+
zmsg_sendm (zmsg_t **self_p, void *dest);
53+
4754
// Return size of message, i.e. number of frames (0 or more).
4855
CZMQ_EXPORT size_t
4956
zmsg_size (zmsg_t *self);

src/zmsg.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,34 @@ zmsg_send (zmsg_t **self_p, void *dest)
149149
return rc;
150150
}
151151

152+
// --------------------------------------------------------------------------
153+
// Send (More) message to destination socket, and destroy the message after sending
154+
// it successfully. If the message has no frames, sends nothing but destroys
155+
// the message anyhow. Nullifies the caller's reference to the message (as
156+
// it is a destructor).
157+
CZMQ_EXPORT int
158+
zmsg_sendm (zmsg_t **self_p, void *dest)
159+
{
160+
assert (self_p);
161+
assert (dest);
162+
zmsg_t *self = *self_p;
163+
164+
int rc = 0;
165+
void *handle = zsock_resolve (dest);
166+
if (self) {
167+
assert (zmsg_is (self));
168+
zframe_t *frame = (zframe_t *) zlist_pop (self->frames);
169+
while (frame) {
170+
rc = zframe_send (&frame, handle,ZFRAME_MORE);
171+
if (rc != 0)
172+
break;
173+
frame = (zframe_t *) zlist_pop (self->frames);
174+
}
175+
if (rc == 0)
176+
zmsg_destroy (self_p);
177+
}
178+
return rc;
179+
}
152180

153181
// --------------------------------------------------------------------------
154182
// Return size of message, i.e. number of frames (0 or more).

0 commit comments

Comments
 (0)