Konstantin Olkhovskiy lupus at oxnull.net
Tue Jul 2 22:59:59 CEST 2013

Hey Jafar,

The "data" member is used to pass additional information around with a watcher, it's typed void * and you ought to cast your int to intptr_t, but it does not sound like a good solution to me.

I would create a struct, allocate it in the appropriate place and point data member to this struct. Other choice is to embed the watcher into another structure (which would contain your int and whatever else you would need) and use container_of magic (refer to Linux kernel source for implementation or rock your own using offsetof) to retrieve a pointer to your structure. The latter is more preferable as it enables you to allocate your watcher and auxiliary data in one go. Also this approach is type-safe (at least better than casting void * to something or interpreting it as an integer).

Konstantin Olkhovskiy

02.07.2013, в 19:35, Jafar habibi livar <iceberg.90427 at gmail.com> написал(а):

> hello
> first of I should thanks for developers of libev.
> heres my question
> what is data member in struct ev_timer?
> can we use it to pass some data to ev_timer callback function?
> I tried but I couldnt save a int variable in data member and get it back in callback function
> I would be very grateful if someone answer me.
> thanks
> _______________________________________________
> libev mailing list
> libev at lists.schmorp.de
> http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

More information about the libev mailing list