Skip to content

Commit fdd9d2d

Browse files
committed
New fill constructor for message_t
New fill constructor: message_t(const void *data, size_t size). Constructs a new message of the given size and copies the data to the message body. In addition a new rebuild() function that does the same for an already constructed object
1 parent 18b5870 commit fdd9d2d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

zmq.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ namespace zmq
227227
}
228228
}
229229

230+
inline message_t (const void *data_, size_t size_)
231+
{
232+
int rc = zmq_msg_init_size (&msg, size_);
233+
if (rc != 0)
234+
throw error_t ();
235+
memcpy(data(), data_, size_);
236+
}
237+
230238
inline message_t (void *data_, size_t size_, free_fn *ffn_,
231239
void *hint_ = NULL)
232240
{
@@ -276,6 +284,17 @@ namespace zmq
276284
throw error_t ();
277285
}
278286

287+
inline void rebuild (const void *data_, size_t size_)
288+
{
289+
int rc = zmq_msg_close (&msg);
290+
if (rc != 0)
291+
throw error_t ();
292+
rc = zmq_msg_init_size (&msg, size_);
293+
if (rc != 0)
294+
throw error_t ();
295+
memcpy(data(), data_, size_);
296+
}
297+
279298
inline void rebuild (void *data_, size_t size_, free_fn *ffn_,
280299
void *hint_ = NULL)
281300
{

0 commit comments

Comments
 (0)