… | |
… | |
3 | #include "EXTERN.h" |
3 | #include "EXTERN.h" |
4 | #include "perl.h" |
4 | #include "perl.h" |
5 | #include "XSUB.h" |
5 | #include "XSUB.h" |
6 | |
6 | |
7 | #include <unistd.h> |
7 | #include <unistd.h> |
|
|
8 | #include <fcntl.h> |
8 | |
9 | |
9 | #include "inotify.h" |
10 | #include "inotify.h" |
10 | #include "inotify-syscalls.h" |
11 | #include "inotify-syscalls.h" |
11 | |
12 | |
12 | MODULE = Linux::Inotify2 PACKAGE = Linux::Inotify2 |
13 | MODULE = Linux::Inotify2 PACKAGE = Linux::Inotify2 |
… | |
… | |
51 | inotify_add_watch (int fd, char *name, U32 mask) |
52 | inotify_add_watch (int fd, char *name, U32 mask) |
52 | |
53 | |
53 | int |
54 | int |
54 | inotify_rm_watch (int fd, U32 wd) |
55 | inotify_rm_watch (int fd, U32 wd) |
55 | |
56 | |
|
|
57 | int |
|
|
58 | inotify_blocking (int fd, I32 blocking) |
|
|
59 | CODE: |
|
|
60 | fcntl (fd, F_SETFL, blocking ? 0 : O_NONBLOCK); |
|
|
61 | |
56 | void |
62 | void |
57 | inotify_read (int fd, int size = 8192) |
63 | inotify_read (int fd, int size = 8192) |
58 | PPCODE: |
64 | PPCODE: |
59 | { |
65 | { |
60 | char buf [size], *cur, *end; |
66 | char buf [size], *cur, *end; |
61 | int got = read (fd, buf, size); |
67 | int got = read (fd, buf, size); |
62 | |
68 | |
63 | if (got < 0) |
69 | if (got < 0) |
|
|
70 | if (errno != EAGAIN && errno != EINTR) |
64 | croak ("Linux::Inotify2: read error while reading events"); |
71 | croak ("Linux::Inotify2: read error while reading events"); |
|
|
72 | else |
|
|
73 | XSRETURN_EMPTY; |
65 | |
74 | |
66 | cur = buf; |
75 | cur = buf; |
67 | end = buf + got; |
76 | end = buf + got; |
68 | |
77 | |
69 | while (cur < end) |
78 | while (cur < end) |
… | |
… | |
78 | hv_store (hv, "wd", sizeof ("wd") - 1, newSViv (ev->wd), 0); |
87 | hv_store (hv, "wd", sizeof ("wd") - 1, newSViv (ev->wd), 0); |
79 | hv_store (hv, "mask", sizeof ("mask") - 1, newSViv (ev->mask), 0); |
88 | hv_store (hv, "mask", sizeof ("mask") - 1, newSViv (ev->mask), 0); |
80 | hv_store (hv, "cookie", sizeof ("cookie") - 1, newSViv (ev->cookie), 0); |
89 | hv_store (hv, "cookie", sizeof ("cookie") - 1, newSViv (ev->cookie), 0); |
81 | hv_store (hv, "name", sizeof ("name") - 1, newSVpvn (ev->name, ev->len), 0); |
90 | hv_store (hv, "name", sizeof ("name") - 1, newSVpvn (ev->name, ev->len), 0); |
82 | |
91 | |
83 | XPUSHs (newRV_noinc ((SV *)hv)); |
92 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
84 | } |
93 | } |
85 | } |
94 | } |
86 | |
95 | |
87 | |
96 | |