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 | |
… | |
… | |
49 | # ifndef IS_PADCONST |
50 | # ifndef IS_PADCONST |
50 | # define IS_PADCONST(v) 0 |
51 | # define IS_PADCONST(v) 0 |
51 | # endif |
52 | # endif |
52 | #endif |
53 | #endif |
53 | |
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 | */ |
|
|
80 | |
54 | /* 5.11 */ |
81 | /* 5.11 */ |
55 | #ifndef CxHASARGS |
82 | #ifndef CxHASARGS |
56 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
83 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
57 | #endif |
84 | #endif |
58 | |
85 | |
… | |
… | |
161 | s_get_cv (SV *cb_sv) |
188 | s_get_cv (SV *cb_sv) |
162 | { |
189 | { |
163 | dTHX; |
190 | dTHX; |
164 | HV *st; |
191 | HV *st; |
165 | GV *gvp; |
192 | GV *gvp; |
166 | |
193 | |
167 | return (SV *)sv_2cv (cb_sv, &st, &gvp, 0); |
194 | return (SV *)sv_2cv (cb_sv, &st, &gvp, 0); |
168 | } |
195 | } |
169 | |
196 | |
170 | static SV * |
197 | static SV * |
171 | s_get_cv_croak (SV *cb_sv) |
198 | s_get_cv_croak (SV *cb_sv) |
… | |
… | |
205 | } |
232 | } |
206 | |
233 | |
207 | /*****************************************************************************/ |
234 | /*****************************************************************************/ |
208 | /* portable pipe/socketpair */ |
235 | /* portable pipe/socketpair */ |
209 | |
236 | |
210 | #ifdef USE_SOCKETS_AS_HANDLES |
237 | #if defined(USE_SOCKETS_AS_HANDLES) || PERL_VERSION_ATLEAST(5,18,0) |
211 | # define S_TO_HANDLE(x) ((HANDLE)win32_get_osfhandle (x)) |
238 | # define S_TO_HANDLE(x) ((HANDLE)win32_get_osfhandle (x)) |
212 | #else |
239 | #else |
213 | # define S_TO_HANDLE(x) ((HANDLE)x) |
240 | # define S_TO_HANDLE(x) ((HANDLE)x) |
214 | #endif |
241 | #endif |
215 | |
242 | |
… | |
… | |
226 | struct sockaddr_in adr2; |
253 | struct sockaddr_in adr2; |
227 | int adr2_size = sizeof (adr2); |
254 | int adr2_size = sizeof (adr2); |
228 | SOCKET listener; |
255 | SOCKET listener; |
229 | SOCKET sock [2] = { -1, -1 }; |
256 | SOCKET sock [2] = { -1, -1 }; |
230 | |
257 | |
231 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
258 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
232 | return -1; |
259 | return -1; |
233 | |
260 | |
234 | addr.sin_family = AF_INET; |
261 | addr.sin_family = AF_INET; |
235 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
262 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
236 | addr.sin_port = 0; |
263 | addr.sin_port = 0; |
… | |
… | |
242 | goto fail; |
269 | goto fail; |
243 | |
270 | |
244 | if (listen (listener, 1)) |
271 | if (listen (listener, 1)) |
245 | goto fail; |
272 | goto fail; |
246 | |
273 | |
247 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
274 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
248 | goto fail; |
275 | goto fail; |
249 | |
276 | |
250 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) |
277 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) |
251 | goto fail; |
278 | goto fail; |
252 | |
279 | |
… | |
… | |
277 | || addr.sin_port != adr2.sin_port) |
304 | || addr.sin_port != adr2.sin_port) |
278 | goto fail; |
305 | goto fail; |
279 | |
306 | |
280 | closesocket (listener); |
307 | closesocket (listener); |
281 | |
308 | |
282 | #ifdef USE_SOCKETS_AS_HANDLES |
309 | #if defined(USE_SOCKETS_AS_HANDLES) || PERL_VERSION_ATLEAST(5,18,0) |
283 | /* when select isn't winsocket, we also expect socket, connect, accept etc. |
310 | /* when select isn't winsocket, we also expect socket, connect, accept etc. |
284 | * to work on fds */ |
311 | * to work on fds */ |
285 | filedes [0] = sock [0]; |
312 | filedes [0] = sock [0]; |
286 | filedes [1] = sock [1]; |
313 | filedes [1] = sock [1]; |
287 | #else |
314 | #else |
… | |
… | |
330 | || fcntl (fd, F_SETFD, FD_CLOEXEC); |
357 | || fcntl (fd, F_SETFD, FD_CLOEXEC); |
331 | } |
358 | } |
332 | |
359 | |
333 | #endif |
360 | #endif |
334 | |
361 | |
|
|
362 | #if HAVE_EVENTFD |
|
|
363 | # include <sys/eventfd.h> |
|
|
364 | #else |
335 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
365 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
336 | # define SCHMORP_H_HAVE_EVENTFD 1 |
366 | # define SCHMORP_H_HAVE_EVENTFD 1 |
337 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
367 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
338 | # include <stdint.h> |
368 | # include <stdint.h> |
339 | # ifdef __cplusplus |
369 | # ifdef __cplusplus |
340 | extern "C" { |
370 | extern "C" { |
341 | # endif |
371 | # endif |
342 | int eventfd (unsigned int initval, int flags); |
372 | int eventfd (unsigned int initval, int flags); |
343 | # ifdef __cplusplus |
373 | # ifdef __cplusplus |
344 | } |
374 | } |
345 | # endif |
375 | # endif |
346 | #else |
376 | # else |
347 | # define eventfd(initval,flags) -1 |
377 | # define eventfd(initval,flags) -1 |
|
|
378 | # endif |
348 | #endif |
379 | #endif |
349 | |
380 | |
350 | typedef struct { |
381 | typedef struct { |
351 | int fd[2]; /* read, write fd, might be equal */ |
382 | int fd[2]; /* read, write fd, might be equal */ |
352 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
383 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
… | |
… | |
409 | * incompetent windows programmers - is this redundant? |
440 | * incompetent windows programmers - is this redundant? |
410 | */ |
441 | */ |
411 | DWORD dummy; |
442 | DWORD dummy; |
412 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
443 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
413 | #else |
444 | #else |
414 | # if SCHMORP_H_HAVE_EVENTFD |
|
|
415 | static uint64_t counter = 1; |
445 | static uint64_t counter = 1; |
416 | # else |
|
|
417 | static char counter [8]; |
|
|
418 | # endif |
|
|
419 | /* some modules accept fd's from outside, support eventfd here */ |
446 | /* some modules accept fd's from outside, support eventfd here */ |
420 | if (write (epp->fd [1], &counter, epp->len) < 0 |
447 | if (write (epp->fd [1], &counter, epp->len) < 0 |
421 | && errno == EINVAL |
448 | && errno == EINVAL |
422 | && epp->len != 8) |
449 | && epp->len != 8) |
423 | write (epp->fd [1], &counter, (epp->len = 8)); |
450 | write (epp->fd [1], &counter, (epp->len = 8)); |