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

Comparing EV/schmorp.h (file contents):
Revision 1.5 by root, Fri Jul 17 14:49:33 2009 UTC vs.
Revision 1.8 by root, Wed Apr 14 00:17:22 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines