… | |
… | |
911 | play around with an Xlib connection), then you have to seperately re-test |
911 | play around with an Xlib connection), then you have to seperately re-test |
912 | whether a file descriptor is really ready with a known-to-be good interface |
912 | whether a file descriptor is really ready with a known-to-be good interface |
913 | such as poll (fortunately in our Xlib example, Xlib already does this on |
913 | such as poll (fortunately in our Xlib example, Xlib already does this on |
914 | its own, so its quite safe to use). |
914 | its own, so its quite safe to use). |
915 | |
915 | |
|
|
916 | =head3 The special problem of disappearing file descriptors |
|
|
917 | |
|
|
918 | Some backends (e.g kqueue, epoll) need to be told about closing a file |
|
|
919 | descriptor (either by calling C<close> explicitly or by any other means, |
|
|
920 | such as C<dup>). The reason is that you register interest in some file |
|
|
921 | descriptor, but when it goes away, the operating system will silently drop |
|
|
922 | this interest. If another file descriptor with the same number then is |
|
|
923 | registered with libev, there is no efficient way to see that this is, in |
|
|
924 | fact, a different file descriptor. |
|
|
925 | |
|
|
926 | To avoid having to explicitly tell libev about such cases, libev follows |
|
|
927 | the following policy: Each time C<ev_io_set> is being called, libev |
|
|
928 | will assume that this is potentially a new file descriptor, otherwise |
|
|
929 | it is assumed that the file descriptor stays the same. That means that |
|
|
930 | you I<have> to call C<ev_io_set> (or C<ev_io_init>) when you change the |
|
|
931 | descriptor even if the file descriptor number itself did not change. |
|
|
932 | |
|
|
933 | This is how one would do it normally anyway, the important point is that |
|
|
934 | the libev application should not optimise around libev but should leave |
|
|
935 | optimisations to libev. |
|
|
936 | |
|
|
937 | |
916 | =over 4 |
938 | =over 4 |
917 | |
939 | |
918 | =item ev_io_init (ev_io *, callback, int fd, int events) |
940 | =item ev_io_init (ev_io *, callback, int fd, int events) |
919 | |
941 | |
920 | =item ev_io_set (ev_io *, int fd, int events) |
942 | =item ev_io_set (ev_io *, int fd, int events) |