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.6 by root, Sat Jul 18 00:59:45 2009 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
208/* taken almost verbatim from libev's ev_win32.c */ 209/* taken almost verbatim from libev's ev_win32.c */
209/* oh, the humanity! */ 210/* oh, the humanity! */
210static int 211static int
211s_pipe (int filedes [2]) 212s_pipe (int filedes [2])
212{ 213{
214 dTHX;
215
213 struct sockaddr_in addr = { 0 }; 216 struct sockaddr_in addr = { 0 };
214 int addr_size = sizeof (addr); 217 int addr_size = sizeof (addr);
215 struct sockaddr_in adr2; 218 struct sockaddr_in adr2;
216 int adr2_size = sizeof (adr2); 219 int adr2_size = sizeof (adr2);
217 SOCKET listener; 220 SOCKET listener;
336#endif 339#endif
337 340
338typedef struct { 341typedef struct {
339 int fd[2]; /* read, write fd, might be equal */ 342 int fd[2]; /* read, write fd, might be equal */
340 int len; /* write length (1 pipe/socket, 8 eventfd) */ 343 int len; /* write length (1 pipe/socket, 8 eventfd) */
341 volatile sig_atomic_t sent;
342} s_epipe; 344} s_epipe;
343 345
344static int 346static int
345s_epipe_new (s_epipe *epp) 347s_epipe_new (s_epipe *epp)
346{ 348{
359 return -1; 361 return -1;
360 362
361 if (s_fd_prepare (ep.fd [0]) 363 if (s_fd_prepare (ep.fd [0])
362 || s_fd_prepare (ep.fd [1])) 364 || s_fd_prepare (ep.fd [1]))
363 { 365 {
366 dTHX;
367
364 close (ep.fd [0]); 368 close (ep.fd [0]);
365 close (ep.fd [1]); 369 close (ep.fd [1]);
366 return -1; 370 return -1;
367 } 371 }
368 372
369 ep.len = 1; 373 ep.len = 1;
370 } 374 }
371 375
372 ep.sent = 0;
373 *epp = ep; 376 *epp = ep;
374 return 0; 377 return 0;
375} 378}
376 379
377static void 380static void
378s_epipe_destroy (s_epipe *epp) 381s_epipe_destroy (s_epipe *epp)
379{ 382{
383 dTHX;
384
380 close (epp->fd [0]); 385 close (epp->fd [0]);
381 386
382 if (epp->fd [1] != epp->fd [0]) 387 if (epp->fd [1] != epp->fd [0])
383 close (epp->fd [1]); 388 close (epp->fd [1]);
384 389
386} 391}
387 392
388static void 393static void
389s_epipe_signal (s_epipe *epp) 394s_epipe_signal (s_epipe *epp)
390{ 395{
391 if (epp->sent)
392 return;
393
394 epp->sent = 1;
395 {
396#ifdef _WIN32 396#ifdef _WIN32
397 /* perl overrides send with a function that crashes in other threads. 397 /* perl overrides send with a function that crashes in other threads.
398 * unfortunately, it overrides it with an argument-less macro, so 398 * unfortunately, it overrides it with an argument-less macro, so
399 * there is no way to force usage of the real send function. 399 * there is no way to force usage of the real send function.
400 * incompetent windows programmers - is this redundant? 400 * incompetent windows programmers - is this redundant?
401 */ 401 */
402 DWORD dummy; 402 DWORD dummy;
403 WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); 403 WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0);
404#else 404#else
405 static uint64_t counter = 1; 405 static uint64_t counter = 1;
406 /* some modules accept fd's from outside, support eventfd here */
407 if (write (epp->fd [1], &counter, epp->len) < 0
408 && errno == EINVAL
409 && epp->len != 8)
406 write (epp->fd [1], &counter, epp->len); 410 write (epp->fd [1], &counter, (epp->len = 8));
407#endif 411#endif
408 }
409} 412}
410 413
411static void 414static void
412s_epipe_drain (s_epipe *epp) 415s_epipe_drain (s_epipe *epp)
413{ 416{
417 dTHX;
414 char buf [9]; 418 char buf [9];
415 419
416#ifdef _WIN32 420#ifdef _WIN32
417 recv (epp->fd [0], buf, sizeof (buf), 0); 421 recv (epp->fd [0], buf, sizeof (buf), 0);
418#else 422#else
419 read (epp->fd [0], buf, sizeof (buf)); 423 read (epp->fd [0], buf, sizeof (buf));
420#endif 424#endif
421
422 epp->sent = 0;
423} 425}
424 426
425/* like new, but dups over old */ 427/* like new, but dups over old */
426static int 428static int
427s_epipe_renew (s_epipe *epp) 429s_epipe_renew (s_epipe *epp)
428{ 430{
431 dTHX;
429 s_epipe epn; 432 s_epipe epn;
430 433
431 if (epp->fd [1] != epp->fd [0]) 434 if (epp->fd [1] != epp->fd [0])
432 close (epp->fd [1]); 435 close (epp->fd [1]);
433 436
453#define s_epipe_fd(epp) ((epp)->fd [0]) 456#define s_epipe_fd(epp) ((epp)->fd [0])
454 457
455static int 458static int
456s_epipe_wait (s_epipe *epp) 459s_epipe_wait (s_epipe *epp)
457{ 460{
461 dTHX;
458#ifdef _WIN32 462#ifdef _WIN32
459 fd_set rfd; 463 fd_set rfd;
460 int fd = s_epipe_fd (epp); 464 int fd = s_epipe_fd (epp);
461 465
462 FD_ZERO (&rfd); 466 FD_ZERO (&rfd);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines