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 | |
… | |
… | |
45 | # ifndef IS_PADCONST |
50 | # ifndef IS_PADCONST |
46 | # define IS_PADCONST(v) 0 |
51 | # define IS_PADCONST(v) 0 |
47 | # endif |
52 | # endif |
48 | #endif |
53 | #endif |
49 | |
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 | # define sv_setval64(sv,i64) sv_setiv ((sv), (i64)) |
|
|
61 | #else |
|
|
62 | typedef NV VAL64; |
|
|
63 | # define SvVAL64(sv) SvNV (sv) |
|
|
64 | # define newSVval64(i64) newSVnv (i64) |
|
|
65 | # define sv_setval64(sv,i64) sv_setnv ((sv), (i64)) |
|
|
66 | #endif |
|
|
67 | |
|
|
68 | /* typemap for the above */ |
|
|
69 | /* |
|
|
70 | VAL64 T_VAL64 |
|
|
71 | |
|
|
72 | INPUT |
|
|
73 | |
|
|
74 | T_VAL64 |
|
|
75 | $var = ($type)SvVAL64 ($arg); |
|
|
76 | |
|
|
77 | OUTPUT |
|
|
78 | |
|
|
79 | T_VAL64 |
|
|
80 | $arg = newSVval64 ($var); |
|
|
81 | */ |
|
|
82 | |
50 | /* 5.11 */ |
83 | /* 5.11 */ |
51 | #ifndef CxHASARGS |
84 | #ifndef CxHASARGS |
52 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
85 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
53 | #endif |
86 | #endif |
54 | |
87 | |
… | |
… | |
157 | s_get_cv (SV *cb_sv) |
190 | s_get_cv (SV *cb_sv) |
158 | { |
191 | { |
159 | dTHX; |
192 | dTHX; |
160 | HV *st; |
193 | HV *st; |
161 | GV *gvp; |
194 | GV *gvp; |
162 | |
195 | |
163 | return (SV *)sv_2cv (cb_sv, &st, &gvp, 0); |
196 | return (SV *)sv_2cv (cb_sv, &st, &gvp, 0); |
164 | } |
197 | } |
165 | |
198 | |
166 | static SV * |
199 | static SV * |
167 | s_get_cv_croak (SV *cb_sv) |
200 | s_get_cv_croak (SV *cb_sv) |
… | |
… | |
201 | } |
234 | } |
202 | |
235 | |
203 | /*****************************************************************************/ |
236 | /*****************************************************************************/ |
204 | /* portable pipe/socketpair */ |
237 | /* portable pipe/socketpair */ |
205 | |
238 | |
206 | #ifdef USE_SOCKETS_AS_HANDLES |
239 | #if defined(USE_SOCKETS_AS_HANDLES) || PERL_VERSION_ATLEAST(5,18,0) |
207 | # define S_TO_HANDLE(x) ((HANDLE)win32_get_osfhandle (x)) |
240 | # define S_TO_HANDLE(x) ((HANDLE)win32_get_osfhandle (x)) |
208 | #else |
241 | #else |
209 | # define S_TO_HANDLE(x) ((HANDLE)x) |
242 | # define S_TO_HANDLE(x) ((HANDLE)x) |
210 | #endif |
243 | #endif |
211 | |
244 | |
… | |
… | |
222 | struct sockaddr_in adr2; |
255 | struct sockaddr_in adr2; |
223 | int adr2_size = sizeof (adr2); |
256 | int adr2_size = sizeof (adr2); |
224 | SOCKET listener; |
257 | SOCKET listener; |
225 | SOCKET sock [2] = { -1, -1 }; |
258 | SOCKET sock [2] = { -1, -1 }; |
226 | |
259 | |
227 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
260 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
228 | return -1; |
261 | return -1; |
229 | |
262 | |
230 | addr.sin_family = AF_INET; |
263 | addr.sin_family = AF_INET; |
231 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
264 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
232 | addr.sin_port = 0; |
265 | addr.sin_port = 0; |
… | |
… | |
238 | goto fail; |
271 | goto fail; |
239 | |
272 | |
240 | if (listen (listener, 1)) |
273 | if (listen (listener, 1)) |
241 | goto fail; |
274 | goto fail; |
242 | |
275 | |
243 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
276 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
244 | goto fail; |
277 | goto fail; |
245 | |
278 | |
246 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) |
279 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) |
247 | goto fail; |
280 | goto fail; |
248 | |
281 | |
… | |
… | |
273 | || addr.sin_port != adr2.sin_port) |
306 | || addr.sin_port != adr2.sin_port) |
274 | goto fail; |
307 | goto fail; |
275 | |
308 | |
276 | closesocket (listener); |
309 | closesocket (listener); |
277 | |
310 | |
278 | #ifdef USE_SOCKETS_AS_HANDLES |
311 | #if defined(USE_SOCKETS_AS_HANDLES) || PERL_VERSION_ATLEAST(5,18,0) |
279 | /* when select isn't winsocket, we also expect socket, connect, accept etc. |
312 | /* when select isn't winsocket, we also expect socket, connect, accept etc. |
280 | * to work on fds */ |
313 | * to work on fds */ |
281 | filedes [0] = sock [0]; |
314 | filedes [0] = sock [0]; |
282 | filedes [1] = sock [1]; |
315 | filedes [1] = sock [1]; |
283 | #else |
316 | #else |
… | |
… | |
326 | || fcntl (fd, F_SETFD, FD_CLOEXEC); |
359 | || fcntl (fd, F_SETFD, FD_CLOEXEC); |
327 | } |
360 | } |
328 | |
361 | |
329 | #endif |
362 | #endif |
330 | |
363 | |
|
|
364 | #if HAVE_EVENTFD |
|
|
365 | # include <sys/eventfd.h> |
|
|
366 | #else |
331 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
367 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
|
|
368 | # define SCHMORP_H_HAVE_EVENTFD 1 |
332 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
369 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
333 | # include <stdint.h> |
370 | # include <stdint.h> |
334 | # ifdef __cplusplus |
371 | # ifdef __cplusplus |
335 | extern "C" { |
372 | extern "C" { |
336 | # endif |
373 | # endif |
337 | int eventfd (unsigned int initval, int flags); |
374 | int eventfd (unsigned int initval, int flags); |
338 | # ifdef __cplusplus |
375 | # ifdef __cplusplus |
339 | } |
376 | } |
340 | # endif |
377 | # endif |
341 | #else |
378 | # else |
342 | # define eventfd(initval,flags) -1 |
379 | # define eventfd(initval,flags) -1 |
|
|
380 | # endif |
343 | #endif |
381 | #endif |
344 | |
382 | |
345 | typedef struct { |
383 | typedef struct { |
346 | int fd[2]; /* read, write fd, might be equal */ |
384 | int fd[2]; /* read, write fd, might be equal */ |
347 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
385 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
… | |
… | |
463 | |
501 | |
464 | static int |
502 | static int |
465 | s_epipe_wait (s_epipe *epp) |
503 | s_epipe_wait (s_epipe *epp) |
466 | { |
504 | { |
467 | dTHX; |
505 | dTHX; |
468 | #ifdef _WIN32 |
506 | #if SCHMORP_H_PREFER_SELECT |
469 | fd_set rfd; |
507 | fd_set rfd; |
470 | int fd = s_epipe_fd (epp); |
508 | int fd = s_epipe_fd (epp); |
471 | |
509 | |
472 | FD_ZERO (&rfd); |
510 | FD_ZERO (&rfd); |
473 | FD_SET (fd, &rfd); |
511 | FD_SET (fd, &rfd); |