polyphony 0.19 → 0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +87 -1
  4. data/CHANGELOG.md +35 -0
  5. data/Gemfile.lock +17 -6
  6. data/README.md +200 -139
  7. data/Rakefile +4 -4
  8. data/TODO.md +35 -7
  9. data/bin/poly +11 -0
  10. data/docs/getting-started/getting-started.md +1 -1
  11. data/docs/summary.md +3 -0
  12. data/docs/technical-overview/exception-handling.md +94 -0
  13. data/docs/technical-overview/fiber-scheduling.md +99 -0
  14. data/examples/core/cancel.rb +8 -4
  15. data/examples/core/channel_echo.rb +18 -17
  16. data/examples/core/defer.rb +12 -0
  17. data/examples/core/enumerator.rb +4 -4
  18. data/examples/core/fiber_error.rb +9 -0
  19. data/examples/core/fiber_error_with_backtrace.rb +73 -0
  20. data/examples/core/fork.rb +6 -6
  21. data/examples/core/genserver.rb +16 -8
  22. data/examples/core/lock.rb +3 -3
  23. data/examples/core/move_on.rb +4 -3
  24. data/examples/core/move_on_twice.rb +5 -5
  25. data/examples/core/move_on_with_ensure.rb +8 -11
  26. data/examples/core/move_on_with_value.rb +14 -0
  27. data/examples/core/{multiple_spawn.rb → multiple_spin.rb} +5 -5
  28. data/examples/core/nested_cancel.rb +5 -5
  29. data/examples/core/{nested_multiple_spawn.rb → nested_multiple_spin.rb} +6 -6
  30. data/examples/core/nested_spin.rb +17 -0
  31. data/examples/core/pingpong.rb +21 -0
  32. data/examples/core/pulse.rb +4 -5
  33. data/examples/core/resource.rb +6 -4
  34. data/examples/core/resource_cancel.rb +6 -9
  35. data/examples/core/resource_delegate.rb +3 -3
  36. data/examples/core/sleep.rb +3 -3
  37. data/examples/core/sleep_spin.rb +19 -0
  38. data/examples/core/snooze.rb +32 -0
  39. data/examples/core/spin.rb +14 -0
  40. data/examples/core/{spawn_cancel.rb → spin_cancel.rb} +6 -7
  41. data/examples/core/spin_error.rb +17 -0
  42. data/examples/core/spin_error_backtrace.rb +30 -0
  43. data/examples/core/spin_uncaught_error.rb +15 -0
  44. data/examples/core/supervisor.rb +8 -8
  45. data/examples/core/supervisor_with_cancel_scope.rb +7 -7
  46. data/examples/core/supervisor_with_error.rb +8 -8
  47. data/examples/core/supervisor_with_manual_move_on.rb +6 -7
  48. data/examples/core/suspend.rb +13 -0
  49. data/examples/core/thread.rb +1 -1
  50. data/examples/core/thread_cancel.rb +9 -11
  51. data/examples/core/thread_pool.rb +18 -14
  52. data/examples/core/throttle.rb +7 -7
  53. data/examples/core/timeout.rb +3 -3
  54. data/examples/fs/read.rb +7 -9
  55. data/examples/http/config.ru +7 -3
  56. data/examples/http/cuba.ru +22 -0
  57. data/examples/http/happy_eyeballs.rb +6 -4
  58. data/examples/http/http_client.rb +1 -1
  59. data/examples/http/http_get.rb +1 -1
  60. data/examples/http/http_parse_experiment.rb +21 -16
  61. data/examples/http/http_proxy.rb +28 -26
  62. data/examples/http/http_server.rb +10 -10
  63. data/examples/http/http_server_forked.rb +6 -5
  64. data/examples/http/http_server_throttled.rb +3 -3
  65. data/examples/http/http_ws_server.rb +11 -11
  66. data/examples/http/https_raw_client.rb +1 -1
  67. data/examples/http/https_server.rb +8 -8
  68. data/examples/http/https_wss_server.rb +13 -11
  69. data/examples/http/rack_server.rb +2 -2
  70. data/examples/http/rack_server_https.rb +4 -4
  71. data/examples/http/rack_server_https_forked.rb +5 -5
  72. data/examples/http/websocket_secure_server.rb +6 -6
  73. data/examples/http/websocket_server.rb +5 -5
  74. data/examples/interfaces/pg_client.rb +4 -4
  75. data/examples/interfaces/pg_pool.rb +13 -6
  76. data/examples/interfaces/pg_transaction.rb +5 -4
  77. data/examples/interfaces/redis_channels.rb +15 -11
  78. data/examples/interfaces/redis_client.rb +2 -2
  79. data/examples/interfaces/redis_pubsub.rb +2 -1
  80. data/examples/interfaces/redis_pubsub_perf.rb +13 -9
  81. data/examples/io/backticks.rb +11 -0
  82. data/examples/io/cat.rb +4 -5
  83. data/examples/io/echo_client.rb +9 -4
  84. data/examples/io/echo_client_from_stdin.rb +20 -0
  85. data/examples/io/echo_pipe.rb +7 -8
  86. data/examples/io/echo_server.rb +8 -6
  87. data/examples/io/echo_server_with_timeout.rb +13 -10
  88. data/examples/io/echo_stdin.rb +3 -3
  89. data/examples/io/httparty.rb +2 -2
  90. data/examples/io/httparty_multi.rb +8 -4
  91. data/examples/io/httparty_threaded.rb +6 -2
  92. data/examples/io/io_read.rb +2 -2
  93. data/examples/io/irb.rb +16 -4
  94. data/examples/io/net-http.rb +3 -3
  95. data/examples/io/open.rb +17 -0
  96. data/examples/io/system.rb +3 -3
  97. data/examples/io/tcpserver.rb +15 -0
  98. data/examples/io/tcpsocket.rb +6 -5
  99. data/examples/performance/multi_snooze.rb +29 -0
  100. data/examples/performance/{perf_snooze.rb → snooze.rb} +7 -5
  101. data/examples/performance/snooze_raw.rb +39 -0
  102. data/ext/gyro/async.c +165 -0
  103. data/ext/gyro/child.c +167 -0
  104. data/ext/{ev → gyro}/extconf.rb +4 -3
  105. data/ext/gyro/gyro.c +316 -0
  106. data/ext/{ev/ev.h → gyro/gyro.h} +12 -7
  107. data/ext/gyro/gyro_ext.c +23 -0
  108. data/ext/{ev → gyro}/io.c +65 -57
  109. data/ext/{ev → gyro}/libev.h +0 -0
  110. data/ext/gyro/signal.c +117 -0
  111. data/ext/{ev → gyro}/socket.c +61 -6
  112. data/ext/gyro/timer.c +199 -0
  113. data/ext/libev/Changes +35 -0
  114. data/ext/libev/README +2 -1
  115. data/ext/libev/ev.c +213 -151
  116. data/ext/libev/ev.h +95 -88
  117. data/ext/libev/ev_epoll.c +26 -15
  118. data/ext/libev/ev_kqueue.c +11 -5
  119. data/ext/libev/ev_linuxaio.c +642 -0
  120. data/ext/libev/ev_poll.c +13 -8
  121. data/ext/libev/ev_port.c +5 -2
  122. data/ext/libev/ev_vars.h +14 -3
  123. data/ext/libev/ev_wrap.h +16 -0
  124. data/lib/ev_ext.bundle +0 -0
  125. data/lib/polyphony.rb +46 -50
  126. data/lib/polyphony/auto_run.rb +12 -0
  127. data/lib/polyphony/core/cancel_scope.rb +11 -7
  128. data/lib/polyphony/core/channel.rb +16 -9
  129. data/lib/polyphony/core/coprocess.rb +101 -51
  130. data/lib/polyphony/core/exceptions.rb +14 -12
  131. data/lib/polyphony/core/resource_pool.rb +21 -8
  132. data/lib/polyphony/core/supervisor.rb +10 -5
  133. data/lib/polyphony/core/sync.rb +7 -6
  134. data/lib/polyphony/core/thread.rb +4 -4
  135. data/lib/polyphony/core/thread_pool.rb +4 -4
  136. data/lib/polyphony/core/throttler.rb +6 -4
  137. data/lib/polyphony/extensions/core.rb +253 -0
  138. data/lib/polyphony/extensions/io.rb +28 -16
  139. data/lib/polyphony/extensions/openssl.rb +2 -1
  140. data/lib/polyphony/extensions/socket.rb +47 -52
  141. data/lib/polyphony/http.rb +4 -3
  142. data/lib/polyphony/http/agent.rb +68 -57
  143. data/lib/polyphony/http/server.rb +5 -5
  144. data/lib/polyphony/http/server/http1.rb +268 -0
  145. data/lib/polyphony/http/server/http2.rb +62 -0
  146. data/lib/polyphony/http/server/http2_stream.rb +104 -0
  147. data/lib/polyphony/http/server/rack.rb +64 -0
  148. data/lib/polyphony/http/server/request.rb +119 -0
  149. data/lib/polyphony/net.rb +26 -15
  150. data/lib/polyphony/postgres.rb +17 -13
  151. data/lib/polyphony/redis.rb +16 -15
  152. data/lib/polyphony/version.rb +1 -1
  153. data/lib/polyphony/websocket.rb +11 -4
  154. data/polyphony.gemspec +13 -9
  155. data/test/eg.rb +27 -0
  156. data/test/helper.rb +25 -0
  157. data/test/run.rb +5 -0
  158. data/test/test_async.rb +33 -0
  159. data/test/test_coprocess.rb +239 -77
  160. data/test/test_core.rb +95 -61
  161. data/test/test_gyro.rb +148 -0
  162. data/test/test_http_server.rb +313 -0
  163. data/test/test_io.rb +79 -27
  164. data/test/test_kernel.rb +22 -12
  165. data/test/test_signal.rb +36 -0
  166. data/test/test_timer.rb +24 -0
  167. metadata +89 -33
  168. data/examples/core/nested_async.rb +0 -17
  169. data/examples/core/next_tick.rb +0 -12
  170. data/examples/core/sleep_spawn.rb +0 -19
  171. data/examples/core/spawn.rb +0 -14
  172. data/examples/core/spawn_error.rb +0 -28
  173. data/examples/performance/perf_multi_snooze.rb +0 -21
  174. data/ext/ev/async.c +0 -168
  175. data/ext/ev/child.c +0 -169
  176. data/ext/ev/ev_ext.c +0 -23
  177. data/ext/ev/ev_module.c +0 -242
  178. data/ext/ev/signal.c +0 -119
  179. data/ext/ev/timer.c +0 -197
  180. data/lib/polyphony/core/fiber_pool.rb +0 -98
  181. data/lib/polyphony/extensions/kernel.rb +0 -169
  182. data/lib/polyphony/http/http1_adapter.rb +0 -254
  183. data/lib/polyphony/http/http2_adapter.rb +0 -157
  184. data/lib/polyphony/http/rack.rb +0 -25
  185. data/lib/polyphony/http/request.rb +0 -66
  186. data/test/test_ev.rb +0 -110
data/ext/libev/ev.h CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libev native API header
3
3
  *
4
- * Copyright (c) 2007,2008,2009,2010,2011,2012,2015 Marc Alexander Lehmann <libev@schmorp.de>
4
+ * Copyright (c) 2007-2019 Marc Alexander Lehmann <libev@schmorp.de>
5
5
  * All rights reserved.
6
6
  *
7
7
  * Redistribution and use in source and binary forms, with or without modifica-
@@ -43,19 +43,25 @@
43
43
  #ifdef __cplusplus
44
44
  # define EV_CPP(x) x
45
45
  # if __cplusplus >= 201103L
46
- # define EV_THROW noexcept
46
+ # define EV_NOEXCEPT noexcept
47
47
  # else
48
- # define EV_THROW throw ()
48
+ # define EV_NOEXCEPT
49
49
  # endif
50
50
  #else
51
51
  # define EV_CPP(x)
52
- # define EV_THROW
52
+ # define EV_NOEXCEPT
53
53
  #endif
54
+ #define EV_THROW EV_NOEXCEPT /* pre-4.25, do not use in new code */
54
55
 
55
56
  EV_CPP(extern "C" {)
56
57
 
57
58
  /*****************************************************************************/
58
59
 
60
+ /* pre-4.0 compatibility */
61
+ #ifndef EV_COMPAT3
62
+ # define EV_COMPAT3 1
63
+ #endif
64
+
59
65
  #ifndef EV_FEATURES
60
66
  # if defined __OPTIMIZE_SIZE__
61
67
  # define EV_FEATURES 0x7c
@@ -206,7 +212,7 @@ struct ev_loop;
206
212
  /*****************************************************************************/
207
213
 
208
214
  #define EV_VERSION_MAJOR 4
209
- #define EV_VERSION_MINOR 24
215
+ #define EV_VERSION_MINOR 27
210
216
 
211
217
  /* eventmask, revents, events... */
212
218
  enum {
@@ -334,7 +340,7 @@ typedef struct ev_periodic
334
340
 
335
341
  ev_tstamp offset; /* rw */
336
342
  ev_tstamp interval; /* rw */
337
- ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) EV_THROW; /* rw */
343
+ ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now) EV_NOEXCEPT; /* rw */
338
344
  } ev_periodic;
339
345
 
340
346
  /* invoked when the given signal has been received */
@@ -510,26 +516,27 @@ enum {
510
516
 
511
517
  /* method bits to be ored together */
512
518
  enum {
513
- EVBACKEND_SELECT = 0x00000001U, /* available just about anywhere */
514
- EVBACKEND_POLL = 0x00000002U, /* !win, !aix, broken on osx */
515
- EVBACKEND_EPOLL = 0x00000004U, /* linux */
516
- EVBACKEND_KQUEUE = 0x00000008U, /* bsd, broken on osx */
517
- EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */
518
- EVBACKEND_PORT = 0x00000020U, /* solaris 10 */
519
- EVBACKEND_ALL = 0x0000003FU, /* all known backends */
520
- EVBACKEND_MASK = 0x0000FFFFU /* all future backends */
519
+ EVBACKEND_SELECT = 0x00000001U, /* available just about anywhere */
520
+ EVBACKEND_POLL = 0x00000002U, /* !win, !aix, broken on osx */
521
+ EVBACKEND_EPOLL = 0x00000004U, /* linux */
522
+ EVBACKEND_KQUEUE = 0x00000008U, /* bsd, broken on osx */
523
+ EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */
524
+ EVBACKEND_PORT = 0x00000020U, /* solaris 10 */
525
+ EVBACKEND_LINUXAIO = 0x00000040U, /* Linuix AIO */
526
+ EVBACKEND_ALL = 0x0000007FU, /* all known backends */
527
+ EVBACKEND_MASK = 0x0000FFFFU /* all future backends */
521
528
  };
522
529
 
523
530
  #if EV_PROTOTYPES
524
- EV_API_DECL int ev_version_major (void) EV_THROW;
525
- EV_API_DECL int ev_version_minor (void) EV_THROW;
531
+ EV_API_DECL int ev_version_major (void) EV_NOEXCEPT;
532
+ EV_API_DECL int ev_version_minor (void) EV_NOEXCEPT;
526
533
 
527
- EV_API_DECL unsigned int ev_supported_backends (void) EV_THROW;
528
- EV_API_DECL unsigned int ev_recommended_backends (void) EV_THROW;
529
- EV_API_DECL unsigned int ev_embeddable_backends (void) EV_THROW;
534
+ EV_API_DECL unsigned int ev_supported_backends (void) EV_NOEXCEPT;
535
+ EV_API_DECL unsigned int ev_recommended_backends (void) EV_NOEXCEPT;
536
+ EV_API_DECL unsigned int ev_embeddable_backends (void) EV_NOEXCEPT;
530
537
 
531
- EV_API_DECL ev_tstamp ev_time (void) EV_THROW;
532
- EV_API_DECL void ev_sleep (ev_tstamp delay) EV_THROW; /* sleep for a while */
538
+ EV_API_DECL ev_tstamp ev_time (void) EV_NOEXCEPT;
539
+ EV_API_DECL void ev_sleep (ev_tstamp delay) EV_NOEXCEPT; /* sleep for a while */
533
540
 
534
541
  /* Sets the allocation function to use, works like realloc.
535
542
  * It is used to allocate and free memory.
@@ -537,26 +544,26 @@ EV_API_DECL void ev_sleep (ev_tstamp delay) EV_THROW; /* sleep for a while */
537
544
  * or take some potentially destructive action.
538
545
  * The default is your system realloc function.
539
546
  */
540
- EV_API_DECL void ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW;
547
+ EV_API_DECL void ev_set_allocator (void *(*cb)(void *ptr, size_t size) EV_NOEXCEPT) EV_NOEXCEPT;
541
548
 
542
549
  /* set the callback function to call on a
543
550
  * retryable syscall error
544
551
  * (such as failed select, poll, epoll_wait)
545
552
  */
546
- EV_API_DECL void ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW;
553
+ EV_API_DECL void ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT;
547
554
 
548
555
  #if EV_MULTIPLICITY
549
556
 
550
557
  /* the default loop is the only one that handles signals and child watchers */
551
558
  /* you can call this as often as you like */
552
- EV_API_DECL struct ev_loop *ev_default_loop (unsigned int flags EV_CPP (= 0)) EV_THROW;
559
+ EV_API_DECL struct ev_loop *ev_default_loop (unsigned int flags EV_CPP (= 0)) EV_NOEXCEPT;
553
560
 
554
561
  #ifdef EV_API_STATIC
555
562
  EV_API_DECL struct ev_loop *ev_default_loop_ptr;
556
563
  #endif
557
564
 
558
565
  EV_INLINE struct ev_loop *
559
- ev_default_loop_uc_ (void) EV_THROW
566
+ ev_default_loop_uc_ (void) EV_NOEXCEPT
560
567
  {
561
568
  extern struct ev_loop *ev_default_loop_ptr;
562
569
 
@@ -564,31 +571,31 @@ ev_default_loop_uc_ (void) EV_THROW
564
571
  }
565
572
 
566
573
  EV_INLINE int
567
- ev_is_default_loop (EV_P) EV_THROW
574
+ ev_is_default_loop (EV_P) EV_NOEXCEPT
568
575
  {
569
576
  return EV_A == EV_DEFAULT_UC;
570
577
  }
571
578
 
572
579
  /* create and destroy alternative loops that don't handle signals */
573
- EV_API_DECL struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)) EV_THROW;
580
+ EV_API_DECL struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)) EV_NOEXCEPT;
574
581
 
575
- EV_API_DECL ev_tstamp ev_now (EV_P) EV_THROW; /* time w.r.t. timers and the eventloop, updated after each poll */
582
+ EV_API_DECL ev_tstamp ev_now (EV_P) EV_NOEXCEPT; /* time w.r.t. timers and the eventloop, updated after each poll */
576
583
 
577
584
  #else
578
585
 
579
- EV_API_DECL int ev_default_loop (unsigned int flags EV_CPP (= 0)) EV_THROW; /* returns true when successful */
586
+ EV_API_DECL int ev_default_loop (unsigned int flags EV_CPP (= 0)) EV_NOEXCEPT; /* returns true when successful */
580
587
 
581
588
  EV_API_DECL ev_tstamp ev_rt_now;
582
589
 
583
590
  EV_INLINE ev_tstamp
584
- ev_now (void) EV_THROW
591
+ ev_now (void) EV_NOEXCEPT
585
592
  {
586
593
  return ev_rt_now;
587
594
  }
588
595
 
589
596
  /* looks weird, but ev_is_default_loop (EV_A) still works if this exists */
590
597
  EV_INLINE int
591
- ev_is_default_loop (void) EV_THROW
598
+ ev_is_default_loop (void) EV_NOEXCEPT
592
599
  {
593
600
  return 1;
594
601
  }
@@ -602,17 +609,17 @@ EV_API_DECL void ev_loop_destroy (EV_P);
602
609
  /* when you want to re-use it in the child */
603
610
  /* you can call it in either the parent or the child */
604
611
  /* you can actually call it at any time, anywhere :) */
605
- EV_API_DECL void ev_loop_fork (EV_P) EV_THROW;
612
+ EV_API_DECL void ev_loop_fork (EV_P) EV_NOEXCEPT;
606
613
 
607
- EV_API_DECL unsigned int ev_backend (EV_P) EV_THROW; /* backend in use by loop */
614
+ EV_API_DECL unsigned int ev_backend (EV_P) EV_NOEXCEPT; /* backend in use by loop */
608
615
 
609
- EV_API_DECL void ev_now_update (EV_P) EV_THROW; /* update event loop time */
616
+ EV_API_DECL void ev_now_update (EV_P) EV_NOEXCEPT; /* update event loop time */
610
617
 
611
618
  #if EV_WALK_ENABLE
612
619
  /* walk (almost) all watchers in the loop of a given type, invoking the */
613
620
  /* callback on every such watcher. The callback might stop the watcher, */
614
621
  /* but do nothing else with the loop */
615
- EV_API_DECL void ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW;
622
+ EV_API_DECL void ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT;
616
623
  #endif
617
624
 
618
625
  #endif /* prototypes */
@@ -632,46 +639,46 @@ enum {
632
639
 
633
640
  #if EV_PROTOTYPES
634
641
  EV_API_DECL int ev_run (EV_P_ int flags EV_CPP (= 0));
635
- EV_API_DECL void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)) EV_THROW; /* break out of the loop */
642
+ EV_API_DECL void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)) EV_NOEXCEPT; /* break out of the loop */
636
643
 
637
644
  /*
638
645
  * ref/unref can be used to add or remove a refcount on the mainloop. every watcher
639
646
  * keeps one reference. if you have a long-running watcher you never unregister that
640
647
  * should not keep ev_loop from running, unref() after starting, and ref() before stopping.
641
648
  */
642
- EV_API_DECL void ev_ref (EV_P) EV_THROW;
643
- EV_API_DECL void ev_unref (EV_P) EV_THROW;
649
+ EV_API_DECL void ev_ref (EV_P) EV_NOEXCEPT;
650
+ EV_API_DECL void ev_unref (EV_P) EV_NOEXCEPT;
644
651
 
645
652
  /*
646
653
  * convenience function, wait for a single event, without registering an event watcher
647
654
  * if timeout is < 0, do wait indefinitely
648
655
  */
649
- EV_API_DECL void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW;
656
+ EV_API_DECL void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT;
650
657
 
651
658
  # if EV_FEATURE_API
652
- EV_API_DECL unsigned int ev_iteration (EV_P) EV_THROW; /* number of loop iterations */
653
- EV_API_DECL unsigned int ev_depth (EV_P) EV_THROW; /* #ev_loop enters - #ev_loop leaves */
654
- EV_API_DECL void ev_verify (EV_P) EV_THROW; /* abort if loop data corrupted */
659
+ EV_API_DECL unsigned int ev_iteration (EV_P) EV_NOEXCEPT; /* number of loop iterations */
660
+ EV_API_DECL unsigned int ev_depth (EV_P) EV_NOEXCEPT; /* #ev_loop enters - #ev_loop leaves */
661
+ EV_API_DECL void ev_verify (EV_P) EV_NOEXCEPT; /* abort if loop data corrupted */
655
662
 
656
- EV_API_DECL void ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW; /* sleep at least this time, default 0 */
657
- EV_API_DECL void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW; /* sleep at least this time, default 0 */
663
+ EV_API_DECL void ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT; /* sleep at least this time, default 0 */
664
+ EV_API_DECL void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT; /* sleep at least this time, default 0 */
658
665
 
659
666
  /* advanced stuff for threading etc. support, see docs */
660
- EV_API_DECL void ev_set_userdata (EV_P_ void *data) EV_THROW;
661
- EV_API_DECL void *ev_userdata (EV_P) EV_THROW;
667
+ EV_API_DECL void ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT;
668
+ EV_API_DECL void *ev_userdata (EV_P) EV_NOEXCEPT;
662
669
  typedef void (*ev_loop_callback)(EV_P);
663
- EV_API_DECL void ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW;
670
+ EV_API_DECL void ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT;
664
671
  /* C++ doesn't allow the use of the ev_loop_callback typedef here, so we need to spell it out */
665
- EV_API_DECL void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW;
672
+ EV_API_DECL void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT;
666
673
 
667
- EV_API_DECL unsigned int ev_pending_count (EV_P) EV_THROW; /* number of pending events, if any */
674
+ EV_API_DECL unsigned int ev_pending_count (EV_P) EV_NOEXCEPT; /* number of pending events, if any */
668
675
  EV_API_DECL void ev_invoke_pending (EV_P); /* invoke all pending watchers */
669
676
 
670
677
  /*
671
678
  * stop/start the timer handling.
672
679
  */
673
- EV_API_DECL void ev_suspend (EV_P) EV_THROW;
674
- EV_API_DECL void ev_resume (EV_P) EV_THROW;
680
+ EV_API_DECL void ev_suspend (EV_P) EV_NOEXCEPT;
681
+ EV_API_DECL void ev_resume (EV_P) EV_NOEXCEPT;
675
682
  #endif
676
683
 
677
684
  #endif
@@ -739,85 +746,85 @@ EV_API_DECL void ev_resume (EV_P) EV_THROW;
739
746
 
740
747
  /* feeds an event into a watcher as if the event actually occurred */
741
748
  /* accepts any ev_watcher type */
742
- EV_API_DECL void ev_feed_event (EV_P_ void *w, int revents) EV_THROW;
743
- EV_API_DECL void ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW;
749
+ EV_API_DECL void ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT;
750
+ EV_API_DECL void ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT;
744
751
  #if EV_SIGNAL_ENABLE
745
- EV_API_DECL void ev_feed_signal (int signum) EV_THROW;
746
- EV_API_DECL void ev_feed_signal_event (EV_P_ int signum) EV_THROW;
752
+ EV_API_DECL void ev_feed_signal (int signum) EV_NOEXCEPT;
753
+ EV_API_DECL void ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT;
747
754
  #endif
748
755
  EV_API_DECL void ev_invoke (EV_P_ void *w, int revents);
749
- EV_API_DECL int ev_clear_pending (EV_P_ void *w) EV_THROW;
756
+ EV_API_DECL int ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT;
750
757
 
751
- EV_API_DECL void ev_io_start (EV_P_ ev_io *w) EV_THROW;
752
- EV_API_DECL void ev_io_stop (EV_P_ ev_io *w) EV_THROW;
758
+ EV_API_DECL void ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT;
759
+ EV_API_DECL void ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT;
753
760
 
754
- EV_API_DECL void ev_timer_start (EV_P_ ev_timer *w) EV_THROW;
755
- EV_API_DECL void ev_timer_stop (EV_P_ ev_timer *w) EV_THROW;
761
+ EV_API_DECL void ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT;
762
+ EV_API_DECL void ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT;
756
763
  /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */
757
- EV_API_DECL void ev_timer_again (EV_P_ ev_timer *w) EV_THROW;
764
+ EV_API_DECL void ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT;
758
765
  /* return remaining time */
759
- EV_API_DECL ev_tstamp ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW;
766
+ EV_API_DECL ev_tstamp ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT;
760
767
 
761
768
  #if EV_PERIODIC_ENABLE
762
- EV_API_DECL void ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW;
763
- EV_API_DECL void ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW;
764
- EV_API_DECL void ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW;
769
+ EV_API_DECL void ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT;
770
+ EV_API_DECL void ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT;
771
+ EV_API_DECL void ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT;
765
772
  #endif
766
773
 
767
774
  /* only supported in the default loop */
768
775
  #if EV_SIGNAL_ENABLE
769
- EV_API_DECL void ev_signal_start (EV_P_ ev_signal *w) EV_THROW;
770
- EV_API_DECL void ev_signal_stop (EV_P_ ev_signal *w) EV_THROW;
776
+ EV_API_DECL void ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT;
777
+ EV_API_DECL void ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT;
771
778
  #endif
772
779
 
773
780
  /* only supported in the default loop */
774
781
  # if EV_CHILD_ENABLE
775
- EV_API_DECL void ev_child_start (EV_P_ ev_child *w) EV_THROW;
776
- EV_API_DECL void ev_child_stop (EV_P_ ev_child *w) EV_THROW;
782
+ EV_API_DECL void ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT;
783
+ EV_API_DECL void ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT;
777
784
  # endif
778
785
 
779
786
  # if EV_STAT_ENABLE
780
- EV_API_DECL void ev_stat_start (EV_P_ ev_stat *w) EV_THROW;
781
- EV_API_DECL void ev_stat_stop (EV_P_ ev_stat *w) EV_THROW;
782
- EV_API_DECL void ev_stat_stat (EV_P_ ev_stat *w) EV_THROW;
787
+ EV_API_DECL void ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT;
788
+ EV_API_DECL void ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT;
789
+ EV_API_DECL void ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT;
783
790
  # endif
784
791
 
785
792
  # if EV_IDLE_ENABLE
786
- EV_API_DECL void ev_idle_start (EV_P_ ev_idle *w) EV_THROW;
787
- EV_API_DECL void ev_idle_stop (EV_P_ ev_idle *w) EV_THROW;
793
+ EV_API_DECL void ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT;
794
+ EV_API_DECL void ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT;
788
795
  # endif
789
796
 
790
797
  #if EV_PREPARE_ENABLE
791
- EV_API_DECL void ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW;
792
- EV_API_DECL void ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW;
798
+ EV_API_DECL void ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT;
799
+ EV_API_DECL void ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT;
793
800
  #endif
794
801
 
795
802
  #if EV_CHECK_ENABLE
796
- EV_API_DECL void ev_check_start (EV_P_ ev_check *w) EV_THROW;
797
- EV_API_DECL void ev_check_stop (EV_P_ ev_check *w) EV_THROW;
803
+ EV_API_DECL void ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT;
804
+ EV_API_DECL void ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT;
798
805
  #endif
799
806
 
800
807
  # if EV_FORK_ENABLE
801
- EV_API_DECL void ev_fork_start (EV_P_ ev_fork *w) EV_THROW;
802
- EV_API_DECL void ev_fork_stop (EV_P_ ev_fork *w) EV_THROW;
808
+ EV_API_DECL void ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT;
809
+ EV_API_DECL void ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT;
803
810
  # endif
804
811
 
805
812
  # if EV_CLEANUP_ENABLE
806
- EV_API_DECL void ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW;
807
- EV_API_DECL void ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW;
813
+ EV_API_DECL void ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT;
814
+ EV_API_DECL void ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT;
808
815
  # endif
809
816
 
810
817
  # if EV_EMBED_ENABLE
811
818
  /* only supported when loop to be embedded is in fact embeddable */
812
- EV_API_DECL void ev_embed_start (EV_P_ ev_embed *w) EV_THROW;
813
- EV_API_DECL void ev_embed_stop (EV_P_ ev_embed *w) EV_THROW;
814
- EV_API_DECL void ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW;
819
+ EV_API_DECL void ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT;
820
+ EV_API_DECL void ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT;
821
+ EV_API_DECL void ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT;
815
822
  # endif
816
823
 
817
824
  # if EV_ASYNC_ENABLE
818
- EV_API_DECL void ev_async_start (EV_P_ ev_async *w) EV_THROW;
819
- EV_API_DECL void ev_async_stop (EV_P_ ev_async *w) EV_THROW;
820
- EV_API_DECL void ev_async_send (EV_P_ ev_async *w) EV_THROW;
825
+ EV_API_DECL void ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT;
826
+ EV_API_DECL void ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT;
827
+ EV_API_DECL void ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT;
821
828
  # endif
822
829
 
823
830
  #if EV_COMPAT3
data/ext/libev/ev_epoll.c CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libev epoll fd activity backend
3
3
  *
4
- * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
4
+ * Copyright (c) 2007,2008,2009,2010,2011,2016,2017,2019 Marc Alexander Lehmann <libev@schmorp.de>
5
5
  * All rights reserved.
6
6
  *
7
7
  * Redistribution and use in source and binary forms, with or without modifica-
@@ -124,12 +124,14 @@ epoll_modify (EV_P_ int fd, int oev, int nev)
124
124
  /* add fd to epoll_eperms, if not already inside */
125
125
  if (!(oldmask & EV_EMASK_EPERM))
126
126
  {
127
- array_needsize (int, epoll_eperms, epoll_epermmax, epoll_epermcnt + 1, EMPTY2);
127
+ array_needsize (int, epoll_eperms, epoll_epermmax, epoll_epermcnt + 1, array_needsize_noinit);
128
128
  epoll_eperms [epoll_epermcnt++] = fd;
129
129
  }
130
130
 
131
131
  return;
132
132
  }
133
+ else
134
+ assert (("libev: I/O watcher with invalid fd found in epoll_ctl", errno != EBADF && errno != ELOOP && errno != EINVAL));
133
135
 
134
136
  fd_kill (EV_A_ fd);
135
137
 
@@ -235,21 +237,32 @@ epoll_poll (EV_P_ ev_tstamp timeout)
235
237
  }
236
238
  }
237
239
 
238
- inline_size
239
- int
240
- epoll_init (EV_P_ int flags)
240
+ static int
241
+ epoll_epoll_create (void)
241
242
  {
242
- #ifdef EPOLL_CLOEXEC
243
- backend_fd = epoll_create1 (EPOLL_CLOEXEC);
243
+ int fd;
244
+
245
+ #if defined EPOLL_CLOEXEC && !defined __ANDROID__
246
+ fd = epoll_create1 (EPOLL_CLOEXEC);
244
247
 
245
- if (backend_fd < 0 && (errno == EINVAL || errno == ENOSYS))
248
+ if (fd < 0 && (errno == EINVAL || errno == ENOSYS))
246
249
  #endif
247
- backend_fd = epoll_create (256);
250
+ {
251
+ fd = epoll_create (256);
248
252
 
249
- if (backend_fd < 0)
250
- return 0;
253
+ if (fd >= 0)
254
+ fcntl (fd, F_SETFD, FD_CLOEXEC);
255
+ }
251
256
 
252
- fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
257
+ return fd;
258
+ }
259
+
260
+ inline_size
261
+ int
262
+ epoll_init (EV_P_ int flags)
263
+ {
264
+ if ((backend_fd = epoll_epoll_create ()) < 0)
265
+ return 0;
253
266
 
254
267
  backend_mintime = 1e-3; /* epoll does sometimes return early, this is just to avoid the worst */
255
268
  backend_modify = epoll_modify;
@@ -275,11 +288,9 @@ epoll_fork (EV_P)
275
288
  {
276
289
  close (backend_fd);
277
290
 
278
- while ((backend_fd = epoll_create (256)) < 0)
291
+ while ((backend_fd = epoll_epoll_create ()) < 0)
279
292
  ev_syserr ("(libev) epoll_create");
280
293
 
281
- fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
282
-
283
294
  fd_rearm_all (EV_A);
284
295
  }
285
296
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libev kqueue backend
3
3
  *
4
- * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de>
4
+ * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016,2019 Marc Alexander Lehmann <libev@schmorp.de>
5
5
  * All rights reserved.
6
6
  *
7
7
  * Redistribution and use in source and binary forms, with or without modifica-
@@ -48,7 +48,7 @@ void
48
48
  kqueue_change (EV_P_ int fd, int filter, int flags, int fflags)
49
49
  {
50
50
  ++kqueue_changecnt;
51
- array_needsize (struct kevent, kqueue_changes, kqueue_changemax, kqueue_changecnt, EMPTY2);
51
+ array_needsize (struct kevent, kqueue_changes, kqueue_changemax, kqueue_changecnt, array_needsize_noinit);
52
52
 
53
53
  EV_SET (&kqueue_changes [kqueue_changecnt - 1], fd, filter, flags, fflags, 0, 0);
54
54
  }
@@ -106,7 +106,7 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
106
106
  if (expect_false (res < 0))
107
107
  {
108
108
  if (errno != EINTR)
109
- ev_syserr ("(libev) kevent");
109
+ ev_syserr ("(libev) kqueue kevent");
110
110
 
111
111
  return;
112
112
  }
@@ -129,10 +129,16 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
129
129
  if (fd_valid (fd))
130
130
  kqueue_modify (EV_A_ fd, 0, anfds [fd].events);
131
131
  else
132
- fd_kill (EV_A_ fd);
132
+ {
133
+ assert (("libev: kqueue found invalid fd", 0));
134
+ fd_kill (EV_A_ fd);
135
+ }
133
136
  }
134
137
  else /* on all other errors, we error out on the fd */
135
- fd_kill (EV_A_ fd);
138
+ {
139
+ assert (("libev: kqueue found invalid fd", 0));
140
+ fd_kill (EV_A_ fd);
141
+ }
136
142
  }
137
143
  }
138
144
  else