本文整理汇总了C++中zframe_size函数的典型用法代码示例。如果您正苦于以下问题:C++ zframe_size函数的具体用法?C++ zframe_size怎么用?C++ zframe_size使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zframe_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unregister
void unregister(std::string const &name) {
directoryd::ServiceRequest request;
request.set_type(directoryd::UNREGISTER);
auto *r = request.mutable_unregister();
r->set_name(name);
zframe_t *sf = zframe_new(NULL, request.ByteSize());
assert (sf != NULL);
request.SerializeToArray(zframe_data(sf),zframe_size(sf));
int retval = zframe_send(&sf,
DDClient::instance().register_socket(), 0);
assert(retval == 0);
zframe_t *rf = zframe_recv (DDClient::instance().register_socket());
directoryd::ServiceReply reply;
reply.ParseFromArray(zframe_data(rf),zframe_size(rf));
zframe_destroy(&rf);
if (reply.type() != directoryd::UNREGISTER) {
throw RegistrationError("Got back incorrect message type when trying to unregister.");
}
if (reply.success() != true) {
throw RegistrationError(reply.result());
}
}
示例2: zhashx_unpack
zhashx_t *
zhashx_unpack (zframe_t *frame)
{
zhashx_t *self = zhashx_new ();
if (!self)
return NULL;
assert (frame);
if (zframe_size (frame) < 4)
return self; // Arguable...
byte *needle = zframe_data (frame);
byte *ceiling = needle + zframe_size (frame);
size_t nbr_items = ntohl (*(uint32_t *) needle);
needle += 4;
while (nbr_items && needle < ceiling) {
// Get key as string
size_t key_size = *needle++;
if (needle + key_size <= ceiling) {
char key [256];
memcpy (key, needle, key_size);
key [key_size] = 0;
needle += key_size;
// Get value as longstr
if (needle + 4 <= ceiling) {
size_t value_size = ntohl (*(uint32_t *) needle);
needle += 4;
// Be wary of malformed frames
if (needle + value_size <= ceiling) {
char *value = (char *) zmalloc (value_size + 1);
if (!value) {
zhashx_destroy (&self);
return NULL;
}
memcpy (value, needle, value_size);
value [value_size] = 0;
needle += value_size;
// Hash takes ownership of value
if (zhashx_insert (self, key, value)) {
zhashx_destroy (&self);
break;
}
}
}
}
}
// Hash will free values in destructor
if (self)
zhashx_autofree (self);
return self;
}
示例3: s_self_handle_pipe
static int
s_self_handle_pipe (self_t *self)
{
// Get just the command off the pipe
char *command = zstr_recv (self->pipe);
if (!command)
return -1; // Interrupted
if (self->verbose)
zsys_info ("zbeacon: API command=%s", command);
if (streq (command, "VERBOSE"))
self->verbose = true;
else
if (streq (command, "CONFIGURE")) {
int port;
int rc = zsock_recv (self->pipe, "i", &port);
assert (rc == 0);
s_self_configure (self, port);
}
else
if (streq (command, "PUBLISH")) {
zframe_destroy (&self->transmit);
zsock_recv (self->pipe, "fi", &self->transmit, &self->interval);
assert (zframe_size (self->transmit) <= UDP_FRAME_MAX);
if (self->interval == 0)
self->interval = INTERVAL_DFLT;
// Start broadcasting immediately
self->ping_at = zclock_mono ();
}
else
if (streq (command, "SILENCE"))
zframe_destroy (&self->transmit);
else
if (streq (command, "SUBSCRIBE")) {
zframe_destroy (&self->filter);
self->filter = zframe_recv (self->pipe);
assert (zframe_size (self->filter) <= UDP_FRAME_MAX);
}
else
if (streq (command, "UNSUBSCRIBE"))
zframe_destroy (&self->filter);
else
if (streq (command, "$TERM"))
self->terminated = true;
else {
zsys_error ("zbeacon: - invalid command: %s", command);
assert (false);
}
zstr_free (&command);
return 0;
}
示例4: interval_minit
void
interval_minit (interval_t ** interval, zmsg_t * msg)
{
*interval = malloc (sizeof (interval_t));
zframe_t *frame = zmsg_first (msg);
memcpy (&((*interval)->start), zframe_data (frame), zframe_size (frame));
frame = zmsg_next (msg);
memcpy (&((*interval)->end), zframe_data (frame), zframe_size (frame));
}
示例5: rb_czmq_frame_cmp
static VALUE rb_czmq_frame_cmp(VALUE obj, VALUE other_frame)
{
long diff;
zframe_t *other = NULL;
if (obj == other_frame) return INT2NUM(0);
ZmqGetFrame(obj);
ZmqAssertFrame(other_frame);
Data_Get_Struct(other_frame, zframe_t, other);
if (!other) rb_raise(rb_eTypeError, "uninitialized ZMQ frame!"); \
if (!(st_lookup(frames_map, (st_data_t)other, 0))) rb_raise(rb_eZmqError, "object %p has been destroyed by the ZMQ framework", (void *)other_frame);
diff = (zframe_size(frame) - zframe_size(other));
if (diff == 0) return INT2NUM(0);
if (diff > 0) return INT2NUM(1);
return INT2NUM(-1);
}
示例6: _thsafe_zmq_client_recv_read
static ssize_t _thsafe_zmq_client_recv_read (smio_t *self, uint8_t *data,
uint32_t size)
{
ssize_t ret_size = -1;
/* Returns NULL if confirmation was not OK or in case of error.
* Returns the original message if the confirmation was OK */
zmsg_t *recv_msg = _thsafe_zmq_client_recv_confirmation (self);
ASSERT_TEST(recv_msg != NULL, "Could not receive confirmation code", err_null_recv_msg);
/* If we are here, confirmation code was OK. Check for second frame */
zframe_t *reply_frame = zmsg_pop (recv_msg);
zframe_destroy (&reply_frame); /* Don't do anything with the reply code */
zframe_t *return_frame = zmsg_pop (recv_msg);
ASSERT_TEST(return_frame != NULL, "Could not receive retrurn code", err_null_ret_code_frame);
if (zframe_size (return_frame) != THSAFE_RETURN_SIZE) {
DBE_DEBUG (DBG_MSG | DBG_LVL_ERR, "[smio_thsafe_client:zmq] Return frame size is wrong\n");
goto err_wrong_size_ret_frame;
}
zframe_t *data_frame = zmsg_pop (recv_msg);
ASSERT_TEST(data_frame != NULL, "Could not receive data", err_recv_data);
/* Check if the frame has the number of bytes requested.
* For now, we consider a success only when the number of
* bytes requested is the same as the actually read*/
if ((ssize_t) zframe_size (data_frame) != *(THSAFE_RETURN_TYPE *) zframe_data (return_frame)) {
DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Data frame size is wrong\n");
goto err_recv_data;
}
uint8_t* raw_data = (uint8_t *) zframe_data (data_frame);
memcpy (data, raw_data, size);
ret_size = size;
DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Received data successfully\n");
zframe_destroy (&data_frame);
err_recv_data:
err_wrong_size_ret_frame:
zframe_destroy (&return_frame);
err_null_ret_code_frame:
zmsg_destroy (&recv_msg);
err_null_recv_msg:
return ret_size;
}
示例7: s_broker_worker_msg
static void s_broker_worker_msg(broker_t *self, zframe_t *sender, zmsg_t *msg)
{
assert (zmsg_size(msg) >= 1); // At least, command
zframe_t *command = zmsg_pop(msg);
char *id_string = zframe_strhex(sender);
int worker_ready = (zhash_lookup(self->workers, id_string) != NULL);
free (id_string);
worker_t *worker = s_worker_require(self, sender);
if (zframe_streq(command, MDPW_READY)) {
if (worker_ready) { // Not first command in session
s_worker_delete(worker, 1);
// Додумать, по идеи синоним сердцебиения
} else {
if (zframe_size(sender) >= 4 && memcmp(zframe_data (sender), "mmi.", 4) == 0) {
s_worker_delete(worker, 1);
// Додумать, по идеи синоним сердцебиения
} else {
// Attach worker to service and mark as idle
zframe_t *service_frame = zmsg_pop(msg);
worker->service = s_service_require(self, service_frame);
worker->service->workers++;
s_worker_waiting(worker);
zframe_destroy(&service_frame);
}
}
} else if (zframe_streq(command, MDPW_REPLY)) {
if (worker_ready) {
// Remove and save client return envelope and insert the
// protocol header and service name, then rewrap envelope.
zframe_t *client = zmsg_unwrap(msg);
zmsg_pushstr(msg, worker->service->name);
zmsg_pushstr(msg, MDPC_CLIENT);
zmsg_wrap(msg, client);
zmsg_send(&msg, self->socket);
s_worker_waiting(worker);
} else {
// Просто обрыв связи между воркером и брокером
// синоним сердцебиения
s_worker_delete(worker, 1);
}
} else if (zframe_streq(command, MDPW_HEARTBEAT)) {
if (worker_ready) {
worker->expiry = zclock_time () + HEARTBEAT_EXPIRY;
} else {
// Просто обрыв связи между воркером и брокером
// синоним сердцебиения
s_worker_delete(worker, 1);
}
} else if (zframe_streq (command, MDPW_DISCONNECT)) {
s_worker_delete(worker, 0);
} else {
zclock_log ("E: invalid input message");
zmsg_dump (msg);
}
free (command);
zmsg_destroy (&msg);
}
示例8: s_recv_from_zyre
static int
s_recv_from_zyre (s_agent_t *self)
{
zyre_event_t *event = zyre_event_new (self->zyre);
if (zyre_event_type (event) == ZYRE_EVENT_SHOUT
&& streq (zyre_event_group (event), "DROPS")) {
zmsg_t *msg = zyre_event_msg (event);
char *operation = zmsg_popstr (msg);
if (streq (operation, "CREATE")) {
char *filename = zmsg_popstr (msg);
zframe_t *frame = zmsg_pop (msg);
zfile_t *file = zfile_new (self->path, filename);
zfile_output (file);
fwrite (zframe_data (frame), 1, zframe_size (frame), zfile_handle (file));
zfile_destroy (&file);
zframe_destroy (&frame);
zstr_send (self->pipe, filename);
free (filename);
}
free (operation);
}
zyre_event_destroy (&event);
return 0;
}
示例9: _devio_do_smio_op
/**************** Helper Functions ***************/
static devio_err_e _devio_do_smio_op (devio_t *self, void *msg)
{
zmq_server_args_t *server_args = (zmq_server_args_t *) msg;
/* Message is:
* frame 0: opcode
* frame 1: payload */
/* Extract the first frame and determine the opcode */
zframe_t *opcode = zmsg_pop (*server_args->msg);
devio_err_e err = (opcode == NULL) ? DEVIO_ERR_BAD_MSG : DEVIO_SUCCESS;
ASSERT_TEST(opcode != NULL, "Could not receive opcode", err_null_opcode);
if (zframe_size (opcode) != THSAFE_OPCODE_SIZE) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_ERR,
"[dev_io_core:poll_all_sm] Invalid opcode size received\n");
err = DEVIO_ERR_BAD_MSG;
goto err_wrong_opcode_size;
}
uint32_t opcode_data = *(uint32_t *) zframe_data (opcode);
if (opcode_data > THSAFE_OPCODE_END-1) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_ERR,
"[dev_io_core:poll_all_sm] Invalid opcode received\n");
err = DEVIO_ERR_BAD_MSG;
goto err_invalid_opcode;
}
/* Do the actual work... */
disp_table_call (self->disp_table_thsafe_ops, opcode_data, self, server_args);
err_invalid_opcode:
err_wrong_opcode_size:
zframe_destroy (&opcode);
err_null_opcode:
return err;
}
示例10: SNetDistribZMQUnpack
void SNetDistribZMQUnpack(zframe_t **srcframe, void *dst, size_t count)
{
if (*srcframe != NULL) {
size_t dst_size = count;
size_t srcframe_size = zframe_size(*srcframe);
byte *srcframe_data = zframe_data(*srcframe);
if(dst_size > srcframe_size) {
dst = NULL;
} else {
memcpy(dst, srcframe_data, dst_size);
if ((srcframe_size - dst_size) != 0) {
byte *newdst = SNetMemAlloc(srcframe_size - dst_size);
memcpy(newdst, srcframe_data + count, srcframe_size - dst_size);
zframe_reset(*srcframe, newdst, srcframe_size - dst_size);
SNetMemFree(newdst);
} else {
zframe_destroy(srcframe);
*srcframe = NULL;
}
}
} else {
dst = NULL;
}
}
示例11: zmsg_remove
void
zmsg_remove (zmsg_t *self, zframe_t *frame)
{
assert (self);
self->content_size -= zframe_size (frame);
zlist_remove (self->frames, frame);
}
示例12: zgossip_msg_decode
zgossip_msg_t *
zgossip_msg_decode (zmsg_t **msg_p)
{
assert (msg_p);
zmsg_t *msg = *msg_p;
if (msg == NULL)
return NULL;
zgossip_msg_t *self = zgossip_msg_new (0);
// Read and parse command in frame
zframe_t *frame = zmsg_pop (msg);
if (!frame)
goto empty; // Malformed or empty
// Get and check protocol signature
self->needle = zframe_data (frame);
self->ceiling = self->needle + zframe_size (frame);
uint16_t signature;
GET_NUMBER2 (signature);
if (signature != (0xAAA0 | 0))
goto empty; // Invalid signature
// Get message id and parse per message type
GET_NUMBER1 (self->id);
switch (self->id) {
case ZGOSSIP_MSG_HELLO:
break;
case ZGOSSIP_MSG_ANNOUNCE:
GET_STRING (self->endpoint);
GET_STRING (self->service);
break;
case ZGOSSIP_MSG_PING:
break;
case ZGOSSIP_MSG_PONG:
break;
case ZGOSSIP_MSG_INVALID:
break;
default:
goto malformed;
}
// Successful return
zframe_destroy (&frame);
zmsg_destroy (msg_p);
return self;
// Error returns
malformed:
printf ("E: malformed message '%d'\n", self->id);
empty:
zframe_destroy (&frame);
zmsg_destroy (msg_p);
zgossip_msg_destroy (&self);
return (NULL);
}
示例13: _thsafe_zmq_client_recv_write
static ssize_t _thsafe_zmq_client_recv_write (smio_t *self)
{
ssize_t ret_size = -1;
/* Returns NULL if confirmation was not OK or in case of error.
* Returns the original message if the confirmation was OK */
zmsg_t *recv_msg = _thsafe_zmq_client_recv_confirmation (self);
ASSERT_TEST(recv_msg != NULL, "Could not receive confirmation code", err_null_recv_msg);
/* If we are here, confirmation code was OK. Check for second frame */
zframe_t *reply_frame = zmsg_pop (recv_msg);
zframe_destroy (&reply_frame); /* Don't do anything with the reply code */
zframe_t *return_frame = zmsg_pop (recv_msg);
ASSERT_TEST(return_frame != NULL, "Could not receive retrurn code", err_null_ret_code_frame);
if (zframe_size (return_frame) != THSAFE_RETURN_SIZE) {
DBE_DEBUG (DBG_MSG | DBG_LVL_ERR, "[smio_thsafe_client:zmq] Return frame size is wrong\n");
goto err_wrong_size_ret_frame;
}
ret_size = *(THSAFE_RETURN_TYPE *) zframe_data (return_frame);
DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Received code: %zd\n", ret_size);
err_wrong_size_ret_frame:
zframe_destroy (&return_frame);
err_null_ret_code_frame:
err_null_recv_msg:
return ret_size;
}
示例14: rb_czmq_frame_size
static VALUE rb_czmq_frame_size(VALUE obj)
{
size_t size;
ZmqGetFrame(obj);
size = zframe_size(frame);
return LONG2FIX(size);
}
示例15: rb_czmq_frame_data
static VALUE rb_czmq_frame_data(VALUE obj)
{
size_t size;
ZmqGetFrame(obj);
size = zframe_size(frame);
return ZmqEncode(rb_str_new((char *)zframe_data(frame), (long)size));
}