Libev, How to pass arguments to relevant callbacks

前端 未结 2 1938
忘掉有多难
忘掉有多难 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:28

    The author answered it himself, but in a comment. Since this shows up as unanswered, I am posting his answer in the "answer" section and closing the loop. Not sure if there is a better way... feel free to fix this.

    Question author says:

    Sorry, I think I got the answer now, and feel deeply ashamed at my carelessness of reading documentation:

    struct my_io{
       ev_io io;
       int otherfd;
       void *somedata;
       struct whatever *mostinteresting;
    };
    // ...
    struct my_io w;
    ev_io_init (&w.io, my_cb, fd, EV_READ);
    

    And then we use the my_io like this:

    static void my_cb (struct ev_loop *loop, ev_io *w_, int revents)
    {
       struct my_io *w = (struct my_io *)w_;
       //...
    }
    

提交回复
热议问题