samedi 16 mai 2015

Strange symbols when i'm trying to get char array from structure

I'm working with libuv (http://ift.tt/P9uAmu) and nodejs v12. I I write native module, in this module i have struct:

    struct Work_req
    {
        const char *data;
        size_t data_length;
        Isolate* isolate;
        unsigned int callback_id;

        Persistent<Function> callback;
    };

Then i try to pass this structure to work:

     Work_req* request = new Work_req;
     request->data = buf->base;
     request->data_length = (size_t)nread;
     request->isolate = env->isolate();
     request->callback_id = callback_id->ToNumber()->Value();

     uv_work_t *req = new uv_work_t;
     req->data = request;

     uv_queue_work(env->event_loop(), req, findCallback, after_findCallback);

In the end of this code i passed work to loop and all is ok. But when i'm trying to read data from uv_work_t *req in findCallback function, i get strange symbols there:

      Work_req *s = ((struct Work_req*)req->data);
      printf(s>data); //print char array from structure here

I see something like this:

����g�Kack_id":1,"error":null,"response":{"type":"test"}}�����

How i can fix it?

Thanks a lot.

Aucun commentaire:

Enregistrer un commentaire