Beispiel #1
0
void monitor_close(void)
{
  shutdown(sock, SHUT_RDWR);
  shutdown(sock_listen, SHUT_RDWR);

  close(sock);
  close(sock_listen);

  msgpack_sbuffer_free(sbuf);
  msgpack_sbuffer_free(draw_sbuf);
  msgpack_unpacker_free(up);
}
Beispiel #2
0
void unpack(receiver* r) {
    /* buf is allocated by unpacker. */
    msgpack_unpacker* unp = msgpack_unpacker_new(100);
    msgpack_unpacked result;
    msgpack_unpack_return ret;
    size_t recv_len;
    int recv_count = 0;
    int i = 0;

    msgpack_unpacked_init(&result);
    while (true) {
        recv_len = receiver_to_unpacker(r, EACH_RECV_SIZE, unp);
        if (recv_len == 0) break; // (reached end of input)
        printf("receive count: %d %zd bytes received.\n", recv_count++, recv_len);
        ret = msgpack_unpacker_next(unp, &result);
        while (ret == MSGPACK_UNPACK_SUCCESS) {
            msgpack_object obj = result.data;

            /* Use obj. */
            printf("Object no %d:\n", ++i);
            msgpack_object_print(stdout, obj);
            printf("\n");
            /* If you want to allocate something on the zone, you can use zone. */
            /* msgpack_zone* zone = result.zone; */
            /* The lifetime of the obj and the zone,  */

            ret = msgpack_unpacker_next(unp, &result);
        }
        if (ret == MSGPACK_UNPACK_PARSE_ERROR) {
            printf("The data in the buf is invalid format.\n");
            msgpack_unpacked_destroy(&result);
            return;
        }
    }
    msgpack_unpacked_destroy(&result);
    msgpack_unpacker_free(unp);
}