… | |
… | |
21 | # define GvCV_set(gv,cv) GvCV (gv) = cv |
21 | # define GvCV_set(gv,cv) GvCV (gv) = cv |
22 | #endif |
22 | #endif |
23 | |
23 | |
24 | #if EV_ENABLE_ASSERTIONS |
24 | #if EV_ENABLE_ASSERTIONS |
25 | # undef NDEBUG |
25 | # undef NDEBUG |
26 | # include <assert.h> |
26 | #else |
|
|
27 | # define NDEBUG 1 |
27 | #endif |
28 | #endif |
|
|
29 | |
|
|
30 | /* make sure we get a real assert, not perl's incompatible version */ |
|
|
31 | #include <assert.h> |
28 | |
32 | |
29 | #define EV_STANDALONE 1 |
33 | #define EV_STANDALONE 1 |
30 | #define EV_PROTOTYPES 1 |
34 | #define EV_PROTOTYPES 1 |
31 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
35 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
32 | #define EV_USE_FLOOR 1 |
36 | #define EV_USE_FLOOR 1 |
33 | #define EV_API_STATIC |
37 | #define EV_API_STATIC |
34 | #define EV_H <ev.h> |
38 | #define EV_H "../libev/ev.h" |
35 | #define EV_CONFIG_H error |
39 | #define EV_CONFIG_H error |
36 | #include "EV/EVAPI.h" |
40 | #include "EV/EVAPI.h" |
37 | |
41 | |
38 | #define EV_SELECT_IS_WINSOCKET 0 |
42 | #define EV_SELECT_IS_WINSOCKET 0 |
39 | #ifdef _WIN32 |
43 | #ifdef _WIN32 |
… | |
… | |
42 | # define fd_mask Perl_fd_mask |
46 | # define fd_mask Perl_fd_mask |
43 | #endif |
47 | #endif |
44 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
48 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
45 | #include "libev/ev.c" |
49 | #include "libev/ev.c" |
46 | |
50 | |
47 | #if !defined _WIN32 && !defined _MINIX && !EV_NO_ATFORK |
51 | #if !defined _WIN32 && !defined __minix && !EV_NO_ATFORK |
48 | # include <pthread.h> |
52 | # include <pthread.h> |
49 | #endif |
53 | #endif |
50 | |
54 | |
51 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
55 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
52 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
56 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
… | |
… | |
82 | do { \ |
86 | do { \ |
83 | REF (w); \ |
87 | REF (w); \ |
84 | ev_ ## type ## _stop (e_loop (w), w); \ |
88 | ev_ ## type ## _stop (e_loop (w), w); \ |
85 | } while (0) |
89 | } while (0) |
86 | |
90 | |
|
|
91 | #define PAUSE(type) \ |
|
|
92 | do { \ |
|
|
93 | int active = ev_is_active (w); \ |
|
|
94 | if (active) STOP (type, w) |
|
|
95 | |
|
|
96 | #define RESUME(type) \ |
|
|
97 | if (active) START (type, w); \ |
|
|
98 | } while (0) |
|
|
99 | |
|
|
100 | |
87 | #define RESET(type,w,seta) \ |
101 | #define RESET(type,w,seta) \ |
88 | do { \ |
102 | PAUSE (type); \ |
89 | int active = ev_is_active (w); \ |
|
|
90 | if (active) STOP (type, w); \ |
|
|
91 | ev_ ## type ## _set seta; \ |
103 | ev_ ## type ## _set seta; \ |
92 | if (active) START (type, w); \ |
104 | RESUME (type) |
93 | } while (0) |
|
|
94 | |
105 | |
95 | typedef int Signal; |
106 | typedef int Signal; |
96 | |
107 | |
97 | /* horrible... */ |
108 | /* horrible... */ |
98 | #define CHECK_SIGNAL_CAN_START(w) \ |
109 | #define CHECK_SIGNAL_CAN_START(w) \ |
… | |
… | |
202 | dSP; |
213 | dSP; |
203 | I32 mark = SP - PL_stack_base; |
214 | I32 mark = SP - PL_stack_base; |
204 | SV *sv_self, *sv_events; |
215 | SV *sv_self, *sv_events; |
205 | |
216 | |
206 | /* libev might have stopped the watcher */ |
217 | /* libev might have stopped the watcher */ |
207 | if (expect_false (w->e_flags & WFLAG_UNREFED) |
218 | if (ecb_expect_false (w->e_flags & WFLAG_UNREFED) |
208 | && !ev_is_active (w)) |
219 | && !ev_is_active (w)) |
209 | REF (w); |
220 | REF (w); |
210 | |
221 | |
211 | if (expect_true (sv_self_cache)) |
222 | if (ecb_expect_true (sv_self_cache)) |
212 | { |
223 | { |
213 | sv_self = sv_self_cache; sv_self_cache = 0; |
224 | sv_self = sv_self_cache; sv_self_cache = 0; |
214 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
225 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
215 | } |
226 | } |
216 | else |
227 | else |
217 | { |
228 | { |
218 | sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ |
229 | sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */ |
219 | SvREADONLY_on (sv_self); |
230 | SvREADONLY_on (sv_self); |
220 | } |
231 | } |
221 | |
232 | |
222 | if (expect_true (sv_events_cache)) |
233 | if (ecb_expect_true (sv_events_cache)) |
223 | { |
234 | { |
224 | sv_events = sv_events_cache; sv_events_cache = 0; |
235 | sv_events = sv_events_cache; sv_events_cache = 0; |
225 | SvIV_set (sv_events, revents); |
236 | SvIV_set (sv_events, revents); |
226 | SvIOK_only (sv_events); |
237 | SvIOK_only (sv_events); |
227 | } |
238 | } |
… | |
… | |
237 | PUSHs (sv_events); |
248 | PUSHs (sv_events); |
238 | |
249 | |
239 | PUTBACK; |
250 | PUTBACK; |
240 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
251 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
241 | |
252 | |
242 | if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
253 | if (ecb_expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache)) |
243 | SvREFCNT_dec (sv_self); |
254 | SvREFCNT_dec (sv_self); |
244 | else |
255 | else |
245 | { |
256 | { |
246 | SvREFCNT_dec (SvRV (sv_self)); |
257 | SvREFCNT_dec (SvRV (sv_self)); |
247 | SvRV_set (sv_self, &PL_sv_undef); |
258 | SvRV_set (sv_self, &PL_sv_undef); |
248 | sv_self_cache = sv_self; |
259 | sv_self_cache = sv_self; |
249 | } |
260 | } |
250 | |
261 | |
251 | if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
262 | if (ecb_expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache)) |
252 | SvREFCNT_dec (sv_events); |
263 | SvREFCNT_dec (sv_events); |
253 | else |
264 | else |
254 | sv_events_cache = sv_events; |
265 | sv_events_cache = sv_events; |
255 | |
266 | |
256 | if (expect_false (SvTRUE (ERRSV))) |
267 | if (ecb_expect_false (SvTRUE (ERRSV))) |
257 | { |
268 | { |
258 | SPAGAIN; |
269 | SPAGAIN; |
259 | PUSHMARK (SP); |
270 | PUSHMARK (SP); |
260 | PUTBACK; |
271 | PUTBACK; |
261 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
272 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
… | |
… | |
862 | C_ARGS: e_loop (w), w |
873 | C_ARGS: e_loop (w), w |
863 | |
874 | |
864 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
875 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
865 | C_ARGS: e_loop (w), w, revents |
876 | C_ARGS: e_loop (w), w, revents |
866 | |
877 | |
867 | int keepalive (ev_watcher *w, int new_value = 0) |
878 | int keepalive (ev_watcher *w, SV *new_value = NO_INIT) |
868 | CODE: |
879 | CODE: |
869 | { |
880 | { |
870 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
881 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
871 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
|
|
872 | |
882 | |
873 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
883 | if (items > 1) |
874 | { |
884 | { |
|
|
885 | int value = SvTRUE (new_value) ? WFLAG_KEEPALIVE : 0; |
|
|
886 | |
|
|
887 | if ((value ^ w->e_flags) & WFLAG_KEEPALIVE) |
|
|
888 | { |
875 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
889 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | value; |
876 | REF (w); |
890 | REF (w); |
877 | UNREF (w); |
891 | UNREF (w); |
|
|
892 | } |
878 | } |
893 | } |
879 | } |
894 | } |
880 | OUTPUT: |
895 | OUTPUT: |
881 | RETVAL |
896 | RETVAL |
882 | |
897 | |
883 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
898 | SV *cb (ev_watcher *w, SV *new_cb = NO_INIT) |
884 | CODE: |
899 | CODE: |
885 | { |
900 | { |
886 | if (items > 1) |
901 | if (items > 1) |
887 | { |
902 | { |
888 | new_cb = s_get_cv_croak (new_cb); |
903 | new_cb = s_get_cv_croak (new_cb); |
… | |
… | |
893 | RETVAL = newRV_inc (w->cb_sv); |
908 | RETVAL = newRV_inc (w->cb_sv); |
894 | } |
909 | } |
895 | OUTPUT: |
910 | OUTPUT: |
896 | RETVAL |
911 | RETVAL |
897 | |
912 | |
898 | SV *data (ev_watcher *w, SV *new_data = 0) |
913 | SV *data (ev_watcher *w, SV *new_data = NO_INIT) |
899 | CODE: |
914 | CODE: |
900 | { |
915 | { |
901 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
916 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
902 | |
917 | |
903 | if (items > 1) |
918 | if (items > 1) |
… | |
… | |
913 | CODE: |
928 | CODE: |
914 | RETVAL = newRV_inc (w->loop); |
929 | RETVAL = newRV_inc (w->loop); |
915 | OUTPUT: |
930 | OUTPUT: |
916 | RETVAL |
931 | RETVAL |
917 | |
932 | |
918 | int priority (ev_watcher *w, int new_priority = 0) |
933 | int priority (ev_watcher *w, SV *new_priority = NO_INIT) |
919 | CODE: |
934 | CODE: |
920 | { |
935 | { |
921 | RETVAL = w->priority; |
936 | RETVAL = w->priority; |
922 | |
937 | |
923 | if (items > 1) |
938 | if (items > 1) |
… | |
… | |
931 | XPUSHs (ST (0)); |
946 | XPUSHs (ST (0)); |
932 | PUTBACK; |
947 | PUTBACK; |
933 | call_method ("stop", G_DISCARD | G_VOID); |
948 | call_method ("stop", G_DISCARD | G_VOID); |
934 | } |
949 | } |
935 | |
950 | |
936 | ev_set_priority (w, new_priority); |
951 | ev_set_priority (w, SvIV (new_priority)); |
937 | |
952 | |
938 | if (active) |
953 | if (active) |
939 | { |
954 | { |
940 | PUSHMARK (SP); |
955 | PUSHMARK (SP); |
941 | XPUSHs (ST (0)); |
956 | XPUSHs (ST (0)); |
… | |
… | |
970 | |
985 | |
971 | sv_setsv (e_fh (w), fh); |
986 | sv_setsv (e_fh (w), fh); |
972 | RESET (io, w, (w, fd, events)); |
987 | RESET (io, w, (w, fd, events)); |
973 | } |
988 | } |
974 | |
989 | |
975 | SV *fh (ev_io *w, SV *new_fh = 0) |
990 | SV *fh (ev_io *w, SV *new_fh = NO_INIT) |
976 | CODE: |
991 | CODE: |
977 | { |
992 | { |
978 | if (items > 1) |
993 | if (items > 1) |
979 | { |
994 | { |
980 | int fd = s_fileno (new_fh, w->events & EV_WRITE); |
995 | int fd = s_fileno (new_fh, w->events & EV_WRITE); |
… | |
… | |
989 | RETVAL = newSVsv (e_fh (w)); |
1004 | RETVAL = newSVsv (e_fh (w)); |
990 | } |
1005 | } |
991 | OUTPUT: |
1006 | OUTPUT: |
992 | RETVAL |
1007 | RETVAL |
993 | |
1008 | |
994 | int events (ev_io *w, int new_events = EV_UNDEF) |
1009 | int events (ev_io *w, int new_events = NO_INIT) |
995 | CODE: |
1010 | CODE: |
996 | { |
1011 | { |
997 | RETVAL = w->events; |
1012 | RETVAL = w->events; |
998 | |
1013 | |
999 | if (items > 1) |
1014 | if (items > 1 && (new_events ^ w->events) & (EV_READ | EV_WRITE)) |
1000 | RESET (io, w, (w, w->fd, new_events)); |
1015 | { |
|
|
1016 | PAUSE (io); |
|
|
1017 | ev_io_modify (w, new_events); |
|
|
1018 | RESUME (io); |
|
|
1019 | } |
1001 | } |
1020 | } |
1002 | OUTPUT: |
1021 | OUTPUT: |
1003 | RETVAL |
1022 | RETVAL |
1004 | |
1023 | |
1005 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
1024 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
… | |
… | |
1024 | CHECK_SIG (signal, signum); |
1043 | CHECK_SIG (signal, signum); |
1025 | |
1044 | |
1026 | RESET_SIGNAL (w, (w, signum)); |
1045 | RESET_SIGNAL (w, (w, signum)); |
1027 | } |
1046 | } |
1028 | |
1047 | |
1029 | int signal (ev_signal *w, SV *new_signal = 0) |
1048 | int signal (ev_signal *w, SV *new_signal = NO_INIT) |
1030 | CODE: |
1049 | CODE: |
1031 | { |
1050 | { |
1032 | RETVAL = w->signum; |
1051 | RETVAL = w->signum; |
1033 | |
1052 | |
1034 | if (items > 1) |
1053 | if (items > 1) |
1035 | { |
1054 | { |
1036 | Signal signum = s_signum (new_signal); |
1055 | Signal signum = s_signum (new_signal); |
1037 | CHECK_SIG (new_signal, signum); |
1056 | CHECK_SIG (new_signal, signum); |
1038 | |
|
|
1039 | RESET_SIGNAL (w, (w, signum)); |
1057 | RESET_SIGNAL (w, (w, signum)); |
1040 | } |
1058 | } |
1041 | } |
1059 | } |
1042 | OUTPUT: |
1060 | OUTPUT: |
1043 | RETVAL |
1061 | RETVAL |
… | |
… | |
1054 | CODE: |
1072 | CODE: |
1055 | STOP (timer, w); |
1073 | STOP (timer, w); |
1056 | |
1074 | |
1057 | void ev_timer_again (ev_timer *w, NV repeat = NO_INIT) |
1075 | void ev_timer_again (ev_timer *w, NV repeat = NO_INIT) |
1058 | CODE: |
1076 | CODE: |
|
|
1077 | { |
1059 | if (items > 1) |
1078 | if (items > 1) |
|
|
1079 | { |
|
|
1080 | CHECK_REPEAT (repeat); |
1060 | w->repeat = repeat; |
1081 | w->repeat = repeat; |
1061 | CHECK_REPEAT (w->repeat); |
1082 | } |
|
|
1083 | |
1062 | ev_timer_again (e_loop (w), w); |
1084 | ev_timer_again (e_loop (w), w); |
1063 | UNREF (w); |
1085 | UNREF (w); |
|
|
1086 | } |
1064 | |
1087 | |
1065 | NV ev_timer_remaining (ev_timer *w) |
1088 | NV ev_timer_remaining (ev_timer *w) |
1066 | C_ARGS: e_loop (w), w |
1089 | C_ARGS: e_loop (w), w |
1067 | |
1090 | |
1068 | void DESTROY (ev_timer *w) |
1091 | void DESTROY (ev_timer *w) |
… | |
… | |
1074 | INIT: |
1097 | INIT: |
1075 | CHECK_REPEAT (repeat); |
1098 | CHECK_REPEAT (repeat); |
1076 | CODE: |
1099 | CODE: |
1077 | RESET (timer, w, (w, after, repeat)); |
1100 | RESET (timer, w, (w, after, repeat)); |
1078 | |
1101 | |
|
|
1102 | NV repeat (ev_timer *w, SV *new_repeat = NO_INIT) |
|
|
1103 | CODE: |
|
|
1104 | RETVAL = w->repeat; |
|
|
1105 | if (items > 1) |
|
|
1106 | { |
|
|
1107 | NV repeat = SvNV (new_repeat); |
|
|
1108 | CHECK_REPEAT (repeat); |
|
|
1109 | w->repeat = repeat; |
|
|
1110 | } |
|
|
1111 | OUTPUT: |
|
|
1112 | RETVAL |
|
|
1113 | |
1079 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
1114 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
1080 | |
1115 | |
1081 | void ev_periodic_start (ev_periodic *w) |
1116 | void ev_periodic_start (ev_periodic *w) |
1082 | INIT: |
1117 | INIT: |
1083 | CHECK_REPEAT (w->interval); |
1118 | CHECK_REPEAT (w->interval); |
… | |
… | |
1113 | CODE: |
1148 | CODE: |
1114 | RETVAL = ev_periodic_at (w); |
1149 | RETVAL = ev_periodic_at (w); |
1115 | OUTPUT: |
1150 | OUTPUT: |
1116 | RETVAL |
1151 | RETVAL |
1117 | |
1152 | |
|
|
1153 | NV offset (ev_periodic *w, SV *new_offset = NO_INIT) |
|
|
1154 | CODE: |
|
|
1155 | RETVAL = w->offset; |
|
|
1156 | if (items > 1) |
|
|
1157 | w->offset = SvNV (new_offset); |
|
|
1158 | OUTPUT: |
|
|
1159 | RETVAL |
|
|
1160 | |
|
|
1161 | NV interval (ev_periodic *w, SV *new_interval = NO_INIT) |
|
|
1162 | CODE: |
|
|
1163 | RETVAL = w->interval; |
|
|
1164 | if (items > 1) |
|
|
1165 | { |
|
|
1166 | NV interval = SvNV (new_interval); |
|
|
1167 | CHECK_REPEAT (interval); |
|
|
1168 | w->interval = interval; |
|
|
1169 | } |
|
|
1170 | OUTPUT: |
|
|
1171 | RETVAL |
|
|
1172 | |
|
|
1173 | SV *reschedule_cb (ev_periodic *w, SV *new_reschedule_cb = NO_INIT) |
|
|
1174 | CODE: |
|
|
1175 | RETVAL = e_fh (w) ? e_fh (w) : &PL_sv_undef; |
|
|
1176 | if (items > 1) |
|
|
1177 | { |
|
|
1178 | sv_2mortal (RETVAL); |
|
|
1179 | e_fh (w) = SvTRUE (new_reschedule_cb) ? newSVsv (new_reschedule_cb) : 0; |
|
|
1180 | } |
|
|
1181 | OUTPUT: |
|
|
1182 | RETVAL |
|
|
1183 | |
1118 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
1184 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
1119 | |
1185 | |
1120 | void ev_idle_start (ev_idle *w) |
1186 | void ev_idle_start (ev_idle *w) |
1121 | CODE: |
1187 | CODE: |
1122 | START (idle, w); |
1188 | START (idle, w); |
… | |
… | |
1255 | { |
1321 | { |
1256 | sv_setsv (e_fh (w), path); |
1322 | sv_setsv (e_fh (w), path); |
1257 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval)); |
1323 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval)); |
1258 | } |
1324 | } |
1259 | |
1325 | |
1260 | SV *path (ev_stat *w, SV *new_path = 0) |
1326 | SV *path (ev_stat *w, SV *new_path = NO_INIT) |
1261 | CODE: |
1327 | CODE: |
1262 | { |
1328 | { |
1263 | RETVAL = SvREFCNT_inc (e_fh (w)); |
1329 | RETVAL = e_fh (w) ? e_fh (w) : &PL_sv_undef; |
1264 | |
1330 | |
1265 | if (items > 1) |
1331 | if (items > 1) |
1266 | { |
1332 | { |
1267 | SvREFCNT_dec (e_fh (w)); |
1333 | sv_2mortal (RETVAL); |
1268 | e_fh (w) = newSVsv (new_path); |
1334 | e_fh (w) = newSVsv (new_path); |
1269 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval)); |
1335 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval)); |
1270 | } |
1336 | } |
1271 | } |
1337 | } |
1272 | OUTPUT: |
1338 | OUTPUT: |
1273 | RETVAL |
1339 | RETVAL |
1274 | |
1340 | |
1275 | NV interval (ev_stat *w, NV new_interval = 0.) |
1341 | NV interval (ev_stat *w, SV *new_interval = NO_INIT) |
1276 | CODE: |
1342 | CODE: |
1277 | { |
|
|
1278 | RETVAL = w->interval; |
1343 | RETVAL = w->interval; |
1279 | |
|
|
1280 | if (items > 1) |
1344 | if (items > 1) |
1281 | RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), new_interval)); |
1345 | { |
1282 | } |
1346 | PAUSE (stat); |
|
|
1347 | w->interval = SvNV (new_interval); |
|
|
1348 | RESUME (stat); |
|
|
1349 | } |
1283 | OUTPUT: |
1350 | OUTPUT: |
1284 | RETVAL |
1351 | RETVAL |
1285 | |
1352 | |
1286 | void prev (ev_stat *w) |
1353 | void prev (ev_stat *w) |
1287 | ALIAS: |
1354 | ALIAS: |