1 | #ifndef SCHMORP_PERL_H_ |
1 | #ifndef SCHMORP_PERL_H_ |
2 | #define SCHMORP_PERL_H_ |
2 | #define SCHMORP_PERL_H_ |
3 | |
3 | |
4 | /* WARNING |
4 | /* WARNING |
5 | * This header file is a shared resource between many modules. |
5 | * This header file is a shared resource between many modules. |
|
|
6 | * perl header files MUST already be included. |
6 | */ |
7 | */ |
7 | |
8 | |
8 | #include <signal.h> |
9 | #include <signal.h> |
9 | #include <errno.h> |
10 | #include <errno.h> |
10 | |
11 | |
11 | #ifndef _WIN32 |
12 | #if defined(WIN32 ) || defined(_MINIX) |
|
|
13 | # define SCHMORP_H_PREFER_SELECT 1 |
|
|
14 | #endif |
|
|
15 | |
|
|
16 | #if !SCHMORP_H_PREFER_SELECT |
12 | # include <poll.h> |
17 | # include <poll.h> |
13 | #endif |
18 | #endif |
14 | |
19 | |
15 | /* useful stuff, used by schmorp mostly */ |
20 | /* useful stuff, used by schmorp mostly */ |
16 | |
21 | |
… | |
… | |
20 | (PERL_REVISION > (a) \ |
25 | (PERL_REVISION > (a) \ |
21 | || (PERL_REVISION == (a) \ |
26 | || (PERL_REVISION == (a) \ |
22 | && (PERL_VERSION > (b) \ |
27 | && (PERL_VERSION > (b) \ |
23 | || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) |
28 | || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) |
24 | |
29 | |
|
|
30 | #ifndef PERL_MAGIC_ext |
|
|
31 | # define PERL_MAGIC_ext '~' |
|
|
32 | #endif |
|
|
33 | |
25 | #if !PERL_VERSION_ATLEAST (5,6,0) |
34 | #if !PERL_VERSION_ATLEAST (5,6,0) |
26 | # ifndef PL_ppaddr |
35 | # ifndef PL_ppaddr |
27 | # define PL_ppaddr ppaddr |
36 | # define PL_ppaddr ppaddr |
28 | # endif |
37 | # endif |
29 | # ifndef call_sv |
38 | # ifndef call_sv |
… | |
… | |
40 | # endif |
49 | # endif |
41 | # ifndef IS_PADCONST |
50 | # ifndef IS_PADCONST |
42 | # define IS_PADCONST(v) 0 |
51 | # define IS_PADCONST(v) 0 |
43 | # endif |
52 | # endif |
44 | #endif |
53 | #endif |
|
|
54 | |
|
|
55 | /* use NV for 32 bit perls as it allows larger offsets */ |
|
|
56 | #if IVSIZE >= 8 |
|
|
57 | typedef IV VAL64; |
|
|
58 | # define SvVAL64(sv) SvIV (sv) |
|
|
59 | # define newSVval64(i64) newSViv (i64) |
|
|
60 | #else |
|
|
61 | typedef NV VAL64; |
|
|
62 | # define SvVAL64(sv) SvNV (sv) |
|
|
63 | # define newSVval64(i64) newSVnv (i64) |
|
|
64 | #endif |
|
|
65 | |
|
|
66 | /* typemap for the above */ |
|
|
67 | /* |
|
|
68 | VAL64 T_VAL64 |
|
|
69 | |
|
|
70 | INPUT |
|
|
71 | |
|
|
72 | T_VAL64 |
|
|
73 | $var = ($type)SvVAL64 ($arg); |
|
|
74 | |
|
|
75 | OUTPUT |
|
|
76 | |
|
|
77 | T_VAL64 |
|
|
78 | $arg = newSVval64 ($var); |
|
|
79 | */ |
45 | |
80 | |
46 | /* 5.11 */ |
81 | /* 5.11 */ |
47 | #ifndef CxHASARGS |
82 | #ifndef CxHASARGS |
48 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
83 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
49 | #endif |
84 | #endif |
… | |
… | |
153 | s_get_cv (SV *cb_sv) |
188 | s_get_cv (SV *cb_sv) |
154 | { |
189 | { |
155 | dTHX; |
190 | dTHX; |
156 | HV *st; |
191 | HV *st; |
157 | GV *gvp; |
192 | GV *gvp; |
158 | |
193 | |
159 | return (SV *)sv_2cv (cb_sv, &st, &gvp, 0); |
194 | return (SV *)sv_2cv (cb_sv, &st, &gvp, 0); |
160 | } |
195 | } |
161 | |
196 | |
162 | static SV * |
197 | static SV * |
163 | s_get_cv_croak (SV *cb_sv) |
198 | s_get_cv_croak (SV *cb_sv) |
… | |
… | |
218 | struct sockaddr_in adr2; |
253 | struct sockaddr_in adr2; |
219 | int adr2_size = sizeof (adr2); |
254 | int adr2_size = sizeof (adr2); |
220 | SOCKET listener; |
255 | SOCKET listener; |
221 | SOCKET sock [2] = { -1, -1 }; |
256 | SOCKET sock [2] = { -1, -1 }; |
222 | |
257 | |
223 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
258 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
224 | return -1; |
259 | return -1; |
225 | |
260 | |
226 | addr.sin_family = AF_INET; |
261 | addr.sin_family = AF_INET; |
227 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
262 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
228 | addr.sin_port = 0; |
263 | addr.sin_port = 0; |
… | |
… | |
234 | goto fail; |
269 | goto fail; |
235 | |
270 | |
236 | if (listen (listener, 1)) |
271 | if (listen (listener, 1)) |
237 | goto fail; |
272 | goto fail; |
238 | |
273 | |
239 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
274 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
240 | goto fail; |
275 | goto fail; |
241 | |
276 | |
242 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) |
277 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) |
243 | goto fail; |
278 | goto fail; |
244 | |
279 | |
… | |
… | |
323 | } |
358 | } |
324 | |
359 | |
325 | #endif |
360 | #endif |
326 | |
361 | |
327 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
362 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
|
|
363 | # define SCHMORP_H_HAVE_EVENTFD 1 |
328 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
364 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
329 | # include <stdint.h> |
365 | # include <stdint.h> |
330 | # ifdef __cplusplus |
366 | # ifdef __cplusplus |
331 | extern "C" { |
367 | extern "C" { |
332 | # endif |
368 | # endif |
… | |
… | |
400 | * incompetent windows programmers - is this redundant? |
436 | * incompetent windows programmers - is this redundant? |
401 | */ |
437 | */ |
402 | DWORD dummy; |
438 | DWORD dummy; |
403 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
439 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
404 | #else |
440 | #else |
|
|
441 | # if SCHMORP_H_HAVE_EVENTFD |
405 | static uint64_t counter = 1; |
442 | static uint64_t counter = 1; |
|
|
443 | # else |
|
|
444 | static char counter [8]; |
|
|
445 | # endif |
406 | /* some modules accept fd's from outside, support eventfd here */ |
446 | /* some modules accept fd's from outside, support eventfd here */ |
407 | if (write (epp->fd [1], &counter, epp->len) < 0 |
447 | if (write (epp->fd [1], &counter, epp->len) < 0 |
408 | && errno == EINVAL |
448 | && errno == EINVAL |
409 | && epp->len != 8) |
449 | && epp->len != 8) |
410 | write (epp->fd [1], &counter, (epp->len = 8)); |
450 | write (epp->fd [1], &counter, (epp->len = 8)); |
… | |
… | |
440 | if (epp->len) |
480 | if (epp->len) |
441 | { |
481 | { |
442 | if (dup2 (epn.fd [0], epp->fd [0]) < 0) |
482 | if (dup2 (epn.fd [0], epp->fd [0]) < 0) |
443 | croak ("unable to dup over old event pipe"); /* should not croak */ |
483 | croak ("unable to dup over old event pipe"); /* should not croak */ |
444 | |
484 | |
445 | if (epp->fd [1] != epp->fd [0]) |
|
|
446 | close (epn.fd [0]); |
485 | close (epn.fd [0]); |
|
|
486 | |
|
|
487 | if (epn.fd [0] == epn.fd [1]) |
|
|
488 | epn.fd [1] = epp->fd [0]; |
447 | |
489 | |
448 | epn.fd [0] = epp->fd [0]; |
490 | epn.fd [0] = epp->fd [0]; |
449 | } |
491 | } |
450 | |
492 | |
451 | *epp = epn; |
493 | *epp = epn; |
… | |
… | |
457 | |
499 | |
458 | static int |
500 | static int |
459 | s_epipe_wait (s_epipe *epp) |
501 | s_epipe_wait (s_epipe *epp) |
460 | { |
502 | { |
461 | dTHX; |
503 | dTHX; |
462 | #ifdef _WIN32 |
504 | #if SCHMORP_H_PREFER_SELECT |
463 | fd_set rfd; |
505 | fd_set rfd; |
464 | int fd = s_epipe_fd (epp); |
506 | int fd = s_epipe_fd (epp); |
465 | |
507 | |
466 | FD_ZERO (&rfd); |
508 | FD_ZERO (&rfd); |
467 | FD_SET (fd, &rfd); |
509 | FD_SET (fd, &rfd); |
… | |
… | |
472 | struct pollfd pfd; |
514 | struct pollfd pfd; |
473 | |
515 | |
474 | pfd.fd = s_epipe_fd (epp); |
516 | pfd.fd = s_epipe_fd (epp); |
475 | pfd.events = POLLIN; |
517 | pfd.events = POLLIN; |
476 | |
518 | |
477 | return poll (&pfd, 1, 0); |
519 | return poll (&pfd, 1, -1); |
478 | #endif |
520 | #endif |
479 | } |
521 | } |
480 | |
522 | |
481 | #endif |
523 | #endif |
482 | |
524 | |