bool msgpack_unpack_next(msgpack_unpacked* result, const char* data, size_t len, size_t* off) { msgpack_unpacked_destroy(result); size_t noff = 0; if(off != NULL) { noff = *off; } if(len <= noff) { return false; } msgpack_zone* z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); template_context ctx; template_init(&ctx); ctx.user.z = z; ctx.user.referenced = false; int e = template_execute(&ctx, data, len, &noff); if(e <= 0) { msgpack_zone_free(z); return false; } if(off != NULL) { *off = noff; } result->zone = z; result->data = template_data(&ctx); return true; }
msgpack_unpack_return msgpack_unpack_next(msgpack_unpacked* result, const char* data, size_t len, size_t* off) { size_t noff = 0; msgpack_unpacked_destroy(result); if(off != NULL) { noff = *off; } if(len <= noff) { return MSGPACK_UNPACK_CONTINUE; } if (!result->zone) { result->zone = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); } if (!result->zone) { return MSGPACK_UNPACK_NOMEM_ERROR; } else { int e; template_context ctx; template_init(&ctx); ctx.user.z = result->zone; ctx.user.referenced = false; e = template_execute(&ctx, data, len, &noff); if(e < 0) { msgpack_zone_free(result->zone); result->zone = NULL; return MSGPACK_UNPACK_PARSE_ERROR; } if(e == 0) { return MSGPACK_UNPACK_CONTINUE; } if(off != NULL) { *off = noff; } result->data = template_data(&ctx); return MSGPACK_UNPACK_SUCCESS; } }
static void * recv_from_learner(void *arg) { void *zmq_recv_sock; recv_thd_data *thd = arg; if ((zmq_recv_sock = zmq_socket(thd->zmq_ctx, ZMQ_SUB))) { if (!zmq_connect(zmq_recv_sock, thd->recv_endpoint)) { grn_ctx ctx; if (!grn_ctx_init(&ctx, 0)) { if ((!grn_ctx_use(&ctx, db))) { msgpack_zone *mempool; if ((mempool = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE))) { grn_obj cmd_buf; zmq_pollitem_t items[] = { { zmq_recv_sock, 0, ZMQ_POLLIN, 0} }; GRN_TEXT_INIT(&cmd_buf, 0); zmq_setsockopt(zmq_recv_sock, ZMQ_SUBSCRIBE, "", 0); while (loop) { zmq_poll(items, 1, 10000); if (items[0].revents & ZMQ_POLLIN) { recv_handler(&ctx, zmq_recv_sock, mempool, &cmd_buf); } } grn_obj_unlink(&ctx, &cmd_buf); msgpack_zone_free(mempool); } else { print_error("cannot create msgpack zone."); } /* db_close */ } else { print_error("error in grn_db_open() on recv thread."); } grn_ctx_fin(&ctx); } else { print_error("error in grn_ctx_init() on recv thread."); } } else { print_error("cannot create recv zmq_socket."); } } else { print_error("cannot connect zmq_socket."); } return NULL; }
bool msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* result) { if(result->zone != NULL) { msgpack_zone_free(result->zone); } int ret = msgpack_unpacker_execute(mpac); if(ret <= 0) { result->zone = NULL; memset(&result->data, 0, sizeof(msgpack_object)); return false; } result->zone = msgpack_unpacker_release_zone(mpac); result->data = msgpack_unpacker_data(mpac); msgpack_unpacker_reset(mpac); return true; }
void msgpack_unpacker_destroy(msgpack_unpacker* mpac) { msgpack_zone_free(mpac->z); free(mpac->ctx); decl_count(mpac->buffer); }