ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/schmorp.h
(Generate patch)

Comparing EV/schmorp.h (file contents):
Revision 1.4 by root, Wed Jul 15 16:58:53 2009 UTC vs.
Revision 1.8 by root, Wed Apr 14 00:17:22 2010 UTC

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 */ 6 */
7 7
8#include <signal.h> 8#include <signal.h>
9#include <errno.h>
9 10
10#ifndef _WIN32 11#ifndef _WIN32
11# include <poll.h> 12# include <poll.h>
12#endif 13#endif
13 14
19 (PERL_REVISION > (a) \ 20 (PERL_REVISION > (a) \
20 || (PERL_REVISION == (a) \ 21 || (PERL_REVISION == (a) \
21 && (PERL_VERSION > (b) \ 22 && (PERL_VERSION > (b) \
22 || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) 23 || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c)))))
23 24
25#ifndef PERL_MAGIC_ext
26# define PERL_MAGIC_ext '~'
27#endif
28
24#if !PERL_VERSION_ATLEAST (5,6,0) 29#if !PERL_VERSION_ATLEAST (5,6,0)
25# ifndef PL_ppaddr 30# ifndef PL_ppaddr
26# define PL_ppaddr ppaddr 31# define PL_ppaddr ppaddr
27# endif 32# endif
28# ifndef call_sv 33# ifndef call_sv
208/* taken almost verbatim from libev's ev_win32.c */ 213/* taken almost verbatim from libev's ev_win32.c */
209/* oh, the humanity! */ 214/* oh, the humanity! */
210static int 215static int
211s_pipe (int filedes [2]) 216s_pipe (int filedes [2])
212{ 217{
218 dTHX;
219
213 struct sockaddr_in addr = { 0 }; 220 struct sockaddr_in addr = { 0 };
214 int addr_size = sizeof (addr); 221 int addr_size = sizeof (addr);
215 struct sockaddr_in adr2; 222 struct sockaddr_in adr2;
216 int adr2_size = sizeof (adr2); 223 int adr2_size = sizeof (adr2);
217 SOCKET listener; 224 SOCKET listener;
336#endif 343#endif
337 344
338typedef struct { 345typedef struct {
339 int fd[2]; /* read, write fd, might be equal */ 346 int fd[2]; /* read, write fd, might be equal */
340 int len; /* write length (1 pipe/socket, 8 eventfd) */ 347 int len; /* write length (1 pipe/socket, 8 eventfd) */
341 volatile sig_atomic_t sent;
342} s_epipe; 348} s_epipe;
343 349
344static int 350static int
345s_epipe_new (s_epipe *epp) 351s_epipe_new (s_epipe *epp)
346{ 352{
359 return -1; 365 return -1;
360 366
361 if (s_fd_prepare (ep.fd [0]) 367 if (s_fd_prepare (ep.fd [0])
362 || s_fd_prepare (ep.fd [1])) 368 || s_fd_prepare (ep.fd [1]))
363 { 369 {
370 dTHX;
371
364 close (ep.fd [0]); 372 close (ep.fd [0]);
365 close (ep.fd [1]); 373 close (ep.fd [1]);
366 return -1; 374 return -1;
367 } 375 }
368 376
369 ep.len = 1; 377 ep.len = 1;
370 } 378 }
371 379
372 ep.sent = 0;
373 *epp = ep; 380 *epp = ep;
374 return 0; 381 return 0;
375} 382}
376 383
377static void 384static void
378s_epipe_destroy (s_epipe *epp) 385s_epipe_destroy (s_epipe *epp)
379{ 386{
387 dTHX;
388
380 close (epp->fd [0]); 389 close (epp->fd [0]);
381 390
382 if (epp->fd [1] != epp->fd [0]) 391 if (epp->fd [1] != epp->fd [0])
383 close (epp->fd [1]); 392 close (epp->fd [1]);
384 393
386} 395}
387 396
388static void 397static void
389s_epipe_signal (s_epipe *epp) 398s_epipe_signal (s_epipe *epp)
390{ 399{
391 if (epp->sent)
392 return;
393
394 epp->sent = 1;
395 {
396#ifdef _WIN32 400#ifdef _WIN32
397 /* perl overrides send with a function that crashes in other threads. 401 /* perl overrides send with a function that crashes in other threads.
398 * unfortunately, it overrides it with an argument-less macro, so 402 * unfortunately, it overrides it with an argument-less macro, so
399 * there is no way to force usage of the real send function. 403 * there is no way to force usage of the real send function.
400 * incompetent windows programmers - is this redundant? 404 * incompetent windows programmers - is this redundant?
401 */ 405 */
402 DWORD dummy; 406 DWORD dummy;
403 WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); 407 WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0);
404#else 408#else
405 static uint64_t counter = 1; 409 static uint64_t counter = 1;
410 /* some modules accept fd's from outside, support eventfd here */
411 if (write (epp->fd [1], &counter, epp->len) < 0
412 && errno == EINVAL
413 && epp->len != 8)
406 write (epp->fd [1], &counter, epp->len); 414 write (epp->fd [1], &counter, (epp->len = 8));
407#endif 415#endif
408 }
409} 416}
410 417
411static void 418static void
412s_epipe_drain (s_epipe *epp) 419s_epipe_drain (s_epipe *epp)
413{ 420{
421 dTHX;
414 char buf [9]; 422 char buf [9];
415 423
416#ifdef _WIN32 424#ifdef _WIN32
417 recv (epp->fd [0], buf, sizeof (buf), 0); 425 recv (epp->fd [0], buf, sizeof (buf), 0);
418#else 426#else
419 read (epp->fd [0], buf, sizeof (buf)); 427 read (epp->fd [0], buf, sizeof (buf));
420#endif 428#endif
421
422 epp->sent = 0;
423} 429}
424 430
425/* like new, but dups over old */ 431/* like new, but dups over old */
426static int 432static int
427s_epipe_renew (s_epipe *epp) 433s_epipe_renew (s_epipe *epp)
428{ 434{
435 dTHX;
429 s_epipe epn; 436 s_epipe epn;
430 437
431 if (epp->fd [1] != epp->fd [0]) 438 if (epp->fd [1] != epp->fd [0])
432 close (epp->fd [1]); 439 close (epp->fd [1]);
433 440
437 if (epp->len) 444 if (epp->len)
438 { 445 {
439 if (dup2 (epn.fd [0], epp->fd [0]) < 0) 446 if (dup2 (epn.fd [0], epp->fd [0]) < 0)
440 croak ("unable to dup over old event pipe"); /* should not croak */ 447 croak ("unable to dup over old event pipe"); /* should not croak */
441 448
442 if (epp->fd [1] != epp->fd [0])
443 close (epn.fd [0]); 449 close (epn.fd [0]);
450
451 if (epn.fd [0] == epn.fd [1])
452 epn.fd [1] = epp->fd [0];
444 453
445 epn.fd [0] = epp->fd [0]; 454 epn.fd [0] = epp->fd [0];
446 } 455 }
447 456
448 *epp = epn; 457 *epp = epn;
453#define s_epipe_fd(epp) ((epp)->fd [0]) 462#define s_epipe_fd(epp) ((epp)->fd [0])
454 463
455static int 464static int
456s_epipe_wait (s_epipe *epp) 465s_epipe_wait (s_epipe *epp)
457{ 466{
467 dTHX;
458#ifdef _WIN32 468#ifdef _WIN32
459 fd_set rfd; 469 fd_set rfd;
460 int fd = s_epipe_fd (epp); 470 int fd = s_epipe_fd (epp);
461 471
462 FD_ZERO (&rfd); 472 FD_ZERO (&rfd);
468 struct pollfd pfd; 478 struct pollfd pfd;
469 479
470 pfd.fd = s_epipe_fd (epp); 480 pfd.fd = s_epipe_fd (epp);
471 pfd.events = POLLIN; 481 pfd.events = POLLIN;
472 482
473 return poll (&pfd, 1, 0); 483 return poll (&pfd, 1, -1);
474#endif 484#endif
475} 485}
476 486
477#endif 487#endif
478 488

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines