… | |
… | |
1040 | it is best to always use non-blocking I/O: An extra \f(CW\*(C`read\*(C'\fR(2) returning |
1040 | it is best to always use non-blocking I/O: An extra \f(CW\*(C`read\*(C'\fR(2) returning |
1041 | \&\f(CW\*(C`EAGAIN\*(C'\fR is far preferable to a program hanging until some data arrives. |
1041 | \&\f(CW\*(C`EAGAIN\*(C'\fR is far preferable to a program hanging until some data arrives. |
1042 | .PP |
1042 | .PP |
1043 | If you cannot run the fd in non-blocking mode (for example you should not |
1043 | If you cannot run the fd in non-blocking mode (for example you should not |
1044 | play around with an Xlib connection), then you have to seperately re-test |
1044 | play around with an Xlib connection), then you have to seperately re-test |
1045 | wether a file descriptor is really ready with a known-to-be good interface |
1045 | whether a file descriptor is really ready with a known-to-be good interface |
1046 | such as poll (fortunately in our Xlib example, Xlib already does this on |
1046 | such as poll (fortunately in our Xlib example, Xlib already does this on |
1047 | its own, so its quite safe to use). |
1047 | its own, so its quite safe to use). |
1048 | .IP "ev_io_init (ev_io *, callback, int fd, int events)" 4 |
1048 | .IP "ev_io_init (ev_io *, callback, int fd, int events)" 4 |
1049 | .IX Item "ev_io_init (ev_io *, callback, int fd, int events)" |
1049 | .IX Item "ev_io_init (ev_io *, callback, int fd, int events)" |
1050 | .PD 0 |
1050 | .PD 0 |
… | |
… | |
1991 | \& } |
1991 | \& } |
1992 | .Ve |
1992 | .Ve |
1993 | .SH "MACRO MAGIC" |
1993 | .SH "MACRO MAGIC" |
1994 | .IX Header "MACRO MAGIC" |
1994 | .IX Header "MACRO MAGIC" |
1995 | Libev can be compiled with a variety of options, the most fundemantal is |
1995 | Libev can be compiled with a variety of options, the most fundemantal is |
1996 | \&\f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. This option determines wether (most) functions and |
1996 | \&\f(CW\*(C`EV_MULTIPLICITY\*(C'\fR. This option determines whether (most) functions and |
1997 | callbacks have an initial \f(CW\*(C`struct ev_loop *\*(C'\fR argument. |
1997 | callbacks have an initial \f(CW\*(C`struct ev_loop *\*(C'\fR argument. |
1998 | .PP |
1998 | .PP |
1999 | To make it easier to write programs that cope with either variant, the |
1999 | To make it easier to write programs that cope with either variant, the |
2000 | following macros are defined: |
2000 | following macros are defined: |
2001 | .ie n .IP """EV_A""\fR, \f(CW""EV_A_""" 4 |
2001 | .ie n .IP """EV_A""\fR, \f(CW""EV_A_""" 4 |
… | |
… | |
2037 | .IX Item "EV_DEFAULT, EV_DEFAULT_" |
2037 | .IX Item "EV_DEFAULT, EV_DEFAULT_" |
2038 | Similar to the other two macros, this gives you the value of the default |
2038 | Similar to the other two macros, this gives you the value of the default |
2039 | loop, if multiple loops are supported (\*(L"ev loop default\*(R"). |
2039 | loop, if multiple loops are supported (\*(L"ev loop default\*(R"). |
2040 | .PP |
2040 | .PP |
2041 | Example: Declare and initialise a check watcher, utilising the above |
2041 | Example: Declare and initialise a check watcher, utilising the above |
2042 | macros so it will work regardless of wether multiple loops are supported |
2042 | macros so it will work regardless of whether multiple loops are supported |
2043 | or not. |
2043 | or not. |
2044 | .PP |
2044 | .PP |
2045 | .Vb 5 |
2045 | .Vb 5 |
2046 | \& static void |
2046 | \& static void |
2047 | \& check_cb (EV_P_ ev_timer *w, int revents) |
2047 | \& check_cb (EV_P_ ev_timer *w, int revents) |