Skip to content

Commit 1253fc5

Browse files
committed
Create function zsock_sendmem
Helper method to ease sending a chunk of memory with a zsock.
1 parent dd9b4a9 commit 1253fc5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

include/zsock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ CZMQ_EXPORT const char *
163163
CZMQ_EXPORT int
164164
zsock_send (zsock_t *self, zmsg_t **msg_p);
165165

166+
// Send data over a socket as a single message frame.
167+
// Returns -1 on error, 0 on success
168+
CZMQ_EXPORT int
169+
zsock_sendmem (zsock_t *self, const void *data, size_t size);
170+
166171
// Receive a zmsg message from the socket. Returns NULL if the process was
167172
// interrupted before the message could be received, or if a receive timeout
168173
// expired.

src/zsock.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,21 @@ zsock_send (zsock_t *self, zmsg_t **msg_p)
468468
}
469469

470470

471+
// --------------------------------------------------------------------------
472+
// Send data over a socket as a single message frame.
473+
// Returns -1 on error, 0 on success
474+
475+
int
476+
zsock_sendmem (zsock_t *self, const void *data, size_t size)
477+
{
478+
assert (self);
479+
assert (data);
480+
zmsg_t *msg = zmsg_new ();
481+
zmsg_addmem (msg, data, size);
482+
return zmsg_send (&msg, self);
483+
}
484+
485+
471486
// --------------------------------------------------------------------------
472487
// Receive a zmsg message from the socket. Returns NULL if the process was
473488
// interrupted before the message could be received, or if a receive timeout

0 commit comments

Comments
 (0)