Libev, How to pass arguments to relevant callbacks

前端 未结 2 1935
忘掉有多难
忘掉有多难 2021-02-18 13:31

I\'m trapped in a situation of argument passing in libev.

Usually, libev receives packages in a function like *receive_callback*, that\'s OK, but in pra

2条回答
  •  面向向阳花
    2021-02-18 14:32

    Yes it's explained in libev document, and there is another way. Each watcher has a void *data member that you can read or modify, and libev will completely ignore it, so you can pass the argument like this:

    w->data = (void *)recv_buff;
    ...
    static void my_cb (struct ev_loop *loop, ev_io *w_, int revents)
    {
        S_RECV_MSG *recv_buff = (S_RECV_MSG*)w_->data;
        ...
    }
    

    see libev document.

提交回复
热议问题