ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
upgrade to libev 3.2
ryah (author)
about 1 month ago
commit  1a53c2b86d8cb383167163cff4acc0bfaa344a86
tree    20e0acb30afbae2669fb6803ab762adf4082895c
parent  8f16a4f26257e8063b8aa82e6e2c0a11b7eb3f8a
...
1
2
3
4
 
5
6
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
 
 
 
 
 
 
 
 
 
30
31
32
...
282
283
284
 
285
286
287
 
 
288
289
290
...
443
444
445
446
 
447
448
449
...
592
593
594
595
 
 
 
 
 
596
597
598
...
751
752
753
754
 
755
756
757
758
759
760
761
762
 
763
764
765
...
773
774
775
776
777
 
 
 
 
778
779
780
 
 
 
 
 
 
781
 
782
783
 
 
 
 
 
 
 
784
785
 
 
 
 
 
 
 
 
 
 
 
 
 
786
787
788
789
 
 
 
 
 
790
791
792
793
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
794
795
796
...
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
...
855
856
857
 
 
 
 
858
859
 
860
861
 
862
863
864
865
866
867
868
869
870
 
 
 
 
 
 
 
 
 
 
871
872
873
...
886
887
888
889
 
890
891
892
893
 
894
895
 
896
897
898
...
1020
1021
1022
1023
1024
1025
1026
 
 
 
 
1027
1028
1029
 
 
 
 
 
 
1030
1031
1032
...
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
...
1064
1065
1066
1067
1068
 
 
1069
1070
1071
...
1074
1075
1076
 
 
 
 
 
 
 
 
 
1077
1078
1079
...
1119
1120
1121
 
 
 
1122
1123
1124
...
1141
1142
1143
1144
 
1145
1146
 
 
 
 
 
 
1147
1148
1149
1150
1151
1152
1153
1154
 
 
 
1155
1156
 
 
 
1157
1158
1159
...
1185
1186
1187
1188
 
1189
1190
1191
...
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
...
1214
1215
1216
1217
1218
1219
1220
1221
...
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
...
1259
1260
1261
1262
 
1263
1264
1265
...
1478
1479
1480
1481
1482
1483
 
1484
1485
1486
...
1586
1587
1588
1589
1590
1591
 
 
 
 
 
1592
1593
1594
...
1844
1845
1846
 
 
1847
1848
1849
...
1864
1865
1866
1867
 
1868
1869
1870
 
1871
1872
1873
...
2366
2367
2368
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2369
2370
2371
...
1
2
3
 
4
5
6
 
 
 
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
29
30
31
32
33
34
35
36
37
38
39
40
...
290
291
292
293
294
295
 
296
297
298
299
300
...
453
454
455
 
456
457
458
459
...
602
603
604
 
605
606
607
608
609
610
611
612
...
765
766
767
 
768
769
770
771
772
773
 
 
 
774
775
776
777
...
785
786
787
 
 
788
789
790
791
792
 
 
793
794
795
796
797
798
799
800
801
 
802
803
804
805
806
807
808
809
 
810
811
812
813
814
815
816
817
818
819
820
821
822
823
 
 
 
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
...
901
902
903
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
904
905
906
...
909
910
911
912
913
914
915
916
 
917
918
919
920
921
922
 
 
 
 
 
 
 
923
924
925
926
927
928
929
930
931
932
933
934
935
...
948
949
950
 
951
952
953
954
 
955
956
 
957
958
959
960
...
1082
1083
1084
 
 
 
 
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
...
1110
1111
1112
 
 
 
 
 
 
1113
1114
1115
...
1126
1127
1128
 
 
1129
1130
1131
1132
1133
...
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
...
1190
1191
1192
1193
1194
1195
1196
1197
1198
...
1215
1216
1217
 
1218
1219
 
1220
1221
1222
1223
1224
1225
1226
1227
 
 
 
 
 
 
1228
1229
1230
1231
 
1232
1233
1234
1235
1236
1237
...
1263
1264
1265
 
1266
1267
1268
1269
...
1276
1277
1278
 
 
 
 
1279
1280
1281
...
1288
1289
1290
 
 
1291
1292
1293
...
1314
1315
1316
 
 
 
 
 
 
1317
1318
1319
...
1325
1326
1327
 
1328
1329
1330
1331
...
1544
1545
1546
 
 
 
1547
1548
1549
1550
...
1650
1651
1652
 
1653
 
1654
1655
1656
1657
1658
1659
1660
1661
...
1911
1912
1913
1914
1915
1916
1917
1918
...
1933
1934
1935
 
1936
1937
1938
 
1939
1940
1941
1942
...
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
0
@@ -1,32 +1,40 @@
0
 /*
0
  * libev event processing core, watcher management
0
  *
0
- * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
0
+ * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de>
0
  * All rights reserved.
0
  *
0
- * Redistribution and use in source and binary forms, with or without
0
- * modification, are permitted provided that the following conditions are
0
- * met:
0
+ * Redistribution and use in source and binary forms, with or without modifica-
0
+ * tion, are permitted provided that the following conditions are met:
0
+ *
0
+ * 1. Redistributions of source code must retain the above copyright notice,
0
+ * this list of conditions and the following disclaimer.
0
+ *
0
+ * 2. Redistributions in binary form must reproduce the above copyright
0
+ * notice, this list of conditions and the following disclaimer in the
0
+ * documentation and/or other materials provided with the distribution.
0
+ *
0
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
0
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
0
+ * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
0
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
0
+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
0
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
0
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
0
+ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
0
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
0
  *
0
- * * Redistributions of source code must retain the above copyright
0
- * notice, this list of conditions and the following disclaimer.
0
- *
0
- * * Redistributions in binary form must reproduce the above
0
- * copyright notice, this list of conditions and the following
0
- * disclaimer in the documentation and/or other materials provided
0
- * with the distribution.
0
- *
0
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0
+ * Alternatively, the contents of this file may be used under the terms of
0
+ * the GNU General Public License ("GPL") version 2 or any later version,
0
+ * in which case the provisions of the GPL are applicable instead of
0
+ * the above. If you wish to allow the use of your version of this file
0
+ * only under the terms of the GPL and not to allow others to use your
0
+ * version of this file under the BSD license, indicate your decision
0
+ * by deleting the provisions above and replace them with the notice
0
+ * and other provisions required by the GPL. If you do not delete the
0
+ * provisions above, a recipient may use your version of this file under
0
+ * either the BSD or the GPL.
0
  */
0
 
0
 #ifdef __cplusplus
0
@@ -282,9 +290,11 @@ typedef ev_watcher *W;
0
 typedef ev_watcher_list *WL;
0
 typedef ev_watcher_time *WT;
0
 
0
+#if EV_USE_MONOTONIC
0
 /* sig_atomic_t is used to avoid per-thread variables or locking but still */
0
 /* giving it a reasonably high chance of working on typical architetcures */
0
-static sig_atomic_t have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
0
+static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
0
+#endif
0
 
0
 #ifdef _WIN32
0
 # include "ev_win32.c"
0
@@ -443,7 +453,7 @@ ev_sleep (ev_tstamp delay)
0
 
0
       nanosleep (&ts, 0);
0
 #elif defined(_WIN32)
0
- Sleep (delay * 1e3);
0
+ Sleep ((unsigned long)(delay * 1e3));
0
 #else
0
       struct timeval tv;
0
 
0
@@ -592,7 +602,11 @@ fd_reify (EV_P)
0
       if (events)
0
         {
0
           unsigned long argp;
0
- anfd->handle = _get_osfhandle (fd);
0
+ #ifdef EV_FD_TO_WIN32_HANDLE
0
+ anfd->handle = EV_FD_TO_WIN32_HANDLE (fd);
0
+ #else
0
+ anfd->handle = _get_osfhandle (fd);
0
+ #endif
0
           assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0));
0
         }
0
 #endif
0
@@ -751,15 +765,13 @@ adjustheap (WT *heap, int N, int k)
0
 typedef struct
0
 {
0
   WL head;
0
- sig_atomic_t volatile gotsig;
0
+ EV_ATOMIC_T gotsig;
0
 } ANSIG;
0
 
0
 static ANSIG *signals;
0
 static int signalmax;
0
 
0
-static int sigpipe [2];
0
-static sig_atomic_t volatile gotsig;
0
-static ev_io sigev;
0
+static EV_ATOMIC_T gotsig;
0
 
0
 void inline_size
0
 signals_init (ANSIG *base, int count)
0
@@ -773,24 +785,102 @@ signals_init (ANSIG *base, int count)
0
     }
0
 }
0
 
0
-static void
0
-sighandler (int signum)
0
+/*****************************************************************************/
0
+
0
+void inline_speed
0
+fd_intern (int fd)
0
 {
0
-#if _WIN32
0
- signal (signum, sighandler);
0
+#ifdef _WIN32
0
+ int arg = 1;
0
+ ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
0
+#else
0
+ fcntl (fd, F_SETFD, FD_CLOEXEC);
0
+ fcntl (fd, F_SETFL, O_NONBLOCK);
0
 #endif
0
+}
0
 
0
- signals [signum - 1].gotsig = 1;
0
+static void noinline
0
+evpipe_init (EV_P)
0
+{
0
+ if (!ev_is_active (&pipeev))
0
+ {
0
+ while (pipe (evpipe))
0
+ syserr ("(libev) error creating signal/async pipe");
0
 
0
- if (!gotsig)
0
+ fd_intern (evpipe [0]);
0
+ fd_intern (evpipe [1]);
0
+
0
+ ev_io_set (&pipeev, evpipe [0], EV_READ);
0
+ ev_io_start (EV_A_ &pipeev);
0
+ ev_unref (EV_A); /* watcher should not keep loop alive */
0
+ }
0
+}
0
+
0
+void inline_size
0
+evpipe_write (EV_P_ EV_ATOMIC_T *flag)
0
+{
0
+ if (!*flag)
0
     {
0
- int old_errno = errno;
0
- gotsig = 1;
0
- write (sigpipe [1], &signum, 1);
0
+ int old_errno = errno; /* save errno because write might clobber it */
0
+
0
+ *flag = 1;
0
+ write (evpipe [1], &old_errno, 1);
0
+
0
       errno = old_errno;
0
     }
0
 }
0
 
0
+static void
0
+pipecb (EV_P_ ev_io *iow, int revents)
0
+{
0
+ {
0
+ int dummy;
0
+ read (evpipe [0], &dummy, 1);
0
+ }
0
+
0
+ if (gotsig && ev_is_default_loop (EV_A))
0
+ {
0
+ int signum;
0
+ gotsig = 0;
0
+
0
+ for (signum = signalmax; signum--; )
0
+ if (signals [signum].gotsig)
0
+ ev_feed_signal_event (EV_A_ signum + 1);
0
+ }
0
+
0
+#if EV_ASYNC_ENABLE
0
+ if (gotasync)
0
+ {
0
+ int i;
0
+ gotasync = 0;
0
+
0
+ for (i = asynccnt; i--; )
0
+ if (asyncs [i]->sent)
0
+ {
0
+ asyncs [i]->sent = 0;
0
+ ev_feed_event (EV_A_ asyncs [i], EV_ASYNC);
0
+ }
0
+ }
0
+#endif
0
+}
0
+
0
+/*****************************************************************************/
0
+
0
+static void
0
+ev_sighandler (int signum)
0
+{
0
+#if EV_MULTIPLICITY
0
+ struct ev_loop *loop = &default_loop_struct;
0
+#endif
0
+
0
+#if _WIN32
0
+ signal (signum, ev_sighandler);
0
+#endif
0
+
0
+ signals [signum - 1].gotsig = 1;
0
+ evpipe_write (EV_A_ &gotsig);
0
+}
0
+
0
 void noinline
0
 ev_feed_signal_event (EV_P_ int signum)
0
 {
0
@@ -811,42 +901,6 @@ ev_feed_signal_event (EV_P_ int signum)
0
     ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
0
 }
0
 
0
-static void
0
-sigcb (EV_P_ ev_io *iow, int revents)
0
-{
0
- int signum;
0
-
0
- read (sigpipe [0], &revents, 1);
0
- gotsig = 0;
0
-
0
- for (signum = signalmax; signum--; )
0
- if (signals [signum].gotsig)
0
- ev_feed_signal_event (EV_A_ signum + 1);
0
-}
0
-
0
-void inline_speed
0
-fd_intern (int fd)
0
-{
0
-#ifdef _WIN32
0
- int arg = 1;
0
- ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
0
-#else
0
- fcntl (fd, F_SETFD, FD_CLOEXEC);
0
- fcntl (fd, F_SETFL, O_NONBLOCK);
0
-#endif
0
-}
0
-
0
-static void noinline
0
-siginit (EV_P)
0
-{
0
- fd_intern (sigpipe [0]);
0
- fd_intern (sigpipe [1]);
0
-
0
- ev_io_set (&sigev, sigpipe [0], EV_READ);
0
- ev_io_start (EV_A_ &sigev);
0
- ev_unref (EV_A); /* child watcher should not keep loop alive */
0
-}
0
-
0
 /*****************************************************************************/
0
 
0
 static WL childs [EV_PID_HASHSIZE];
0
@@ -855,19 +909,27 @@ static WL childs [EV_PID_HASHSIZE];
0
 
0
 static ev_signal childev;
0
 
0
+#ifndef WIFCONTINUED
0
+# define WIFCONTINUED(status) 0
0
+#endif
0
+
0
 void inline_speed
0
-child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status)
0
+child_reap (EV_P_ int chain, int pid, int status)
0
 {
0
   ev_child *w;
0
+ int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
0
 
0
   for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
0
- if (w->pid == pid || !w->pid)
0
- {
0
- ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */
0
- w->rpid = pid;
0
- w->rstatus = status;
0
- ev_feed_event (EV_A_ (W)w, EV_CHILD);
0
- }
0
+ {
0
+ if ((w->pid == pid || !w->pid)
0
+ && (!traced || (w->flags & 1)))
0
+ {
0
+ ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */
0
+ w->rpid = pid;
0
+ w->rstatus = status;
0
+ ev_feed_event (EV_A_ (W)w, EV_CHILD);
0
+ }
0
+ }
0
 }
0
 
0
 #ifndef WCONTINUED
0
@@ -886,13 +948,13 @@ childcb (EV_P_ ev_signal *sw, int revents)
0
         || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED)))
0
       return;
0
 
0
- /* make sure we are called again until all childs have been reaped */
0
+ /* make sure we are called again until all children have been reaped */
0
   /* we need to do it this way so that the callback gets called before we continue */
0
   ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
0
 
0
- child_reap (EV_A_ sw, pid, pid, status);
0
+ child_reap (EV_A_ pid, pid, status);
0
   if (EV_PID_HASHSIZE > 1)
0
- child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
0
+ child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
0
 }
0
 
0
 #endif
0
@@ -1020,13 +1082,19 @@ loop_init (EV_P_ unsigned int flags)
0
       }
0
 #endif
0
 
0
- ev_rt_now = ev_time ();
0
- mn_now = get_clock ();
0
- now_floor = mn_now;
0
- rtmn_diff = ev_rt_now - mn_now;
0
+ ev_rt_now = ev_time ();
0
+ mn_now = get_clock ();
0
+ now_floor = mn_now;
0
+ rtmn_diff = ev_rt_now - mn_now;
0
 
0
       io_blocktime = 0.;
0
       timeout_blocktime = 0.;
0
+ backend = 0;
0
+ backend_fd = -1;
0
+ gotasync = 0;
0
+#if EV_USE_INOTIFY
0
+ fs_fd = -2;
0
+#endif
0
 
0
       /* pid check not overridable via env */
0
 #ifndef _WIN32
0
@@ -1042,12 +1110,6 @@ loop_init (EV_P_ unsigned int flags)
0
       if (!(flags & 0x0000ffffUL))
0
         flags |= ev_recommended_backends ();
0
 
0
- backend = 0;
0
- backend_fd = -1;
0
-#if EV_USE_INOTIFY
0
- fs_fd = -2;
0
-#endif
0
-
0
 #if EV_USE_PORT
0
       if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
0
 #endif
0
@@ -1064,8 +1126,8 @@ loop_init (EV_P_ unsigned int flags)
0
       if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags);
0
 #endif
0
 
0
- ev_init (&sigev, sigcb);
0
- ev_set_priority (&sigev, EV_MAXPRI);
0
+ ev_init (&pipeev, pipecb);
0
+ ev_set_priority (&pipeev, EV_MAXPRI);
0
     }
0
 }
0
 
0
@@ -1074,6 +1136,15 @@ loop_destroy (EV_P)
0
 {
0
   int i;
0
 
0
+ if (ev_is_active (&pipeev))
0
+ {
0
+ ev_ref (EV_A); /* signal watcher */
0
+ ev_io_stop (EV_A_ &pipeev);
0
+
0
+ close (evpipe [0]); evpipe [0] = 0;
0
+ close (evpipe [1]); evpipe [1] = 0;
0
+ }
0
+
0
 #if EV_USE_INOTIFY
0
   if (fs_fd >= 0)
0
     close (fs_fd);
0
@@ -1119,6 +1190,9 @@ loop_destroy (EV_P)
0
 #endif
0
   array_free (prepare, EMPTY);
0
   array_free (check, EMPTY);
0
+#if EV_ASYNC_ENABLE
0
+ array_free (async, EMPTY);
0
+#endif
0
 
0
   backend = 0;
0
 }
0
@@ -1141,19 +1215,23 @@ loop_fork (EV_P)
0
   infy_fork (EV_A);
0
 #endif
0
 
0
- if (ev_is_active (&sigev))
0
+ if (ev_is_active (&pipeev))
0
     {
0
- /* default loop */
0
+ /* this "locks" the handlers against writing to the pipe */
0
+ /* while we modify the fd vars */
0
+ gotsig = 1;
0
+#if EV_ASYNC_ENABLE
0
+ gotasync = 1;
0
+#endif
0
 
0
       ev_ref (EV_A);
0
- ev_io_stop (EV_A_ &sigev);
0
- close (sigpipe [0]);
0
- close (sigpipe [1]);
0
-
0
- while (pipe (sigpipe))
0
- syserr ("(libev) error creating pipe");
0
+ ev_io_stop (EV_A_ &pipeev);
0
+ close (evpipe [0]);
0
+ close (evpipe [1]);
0
 
0
- siginit (EV_A);
0
+ evpipe_init (EV_A);
0
+ /* now iterate over everything, in case we missed something */
0
+ pipecb (EV_A_ &pipeev, EV_READ);
0
     }
0
 
0
   postfork = 0;
0
@@ -1185,7 +1263,7 @@ ev_loop_destroy (EV_P)
0
 void
0
 ev_loop_fork (EV_P)
0
 {
0
- postfork = 1;
0
+ postfork = 1; /* must be in line with ev_default_fork */
0
 }
0
 
0
 #endif
0
@@ -1198,10 +1276,6 @@ int
0
 ev_default_loop (unsigned int flags)
0
 #endif
0
 {
0
- if (sigpipe [0] == sigpipe [1])
0
- if (pipe (sigpipe))
0
- return 0;
0
-
0
   if (!ev_default_loop_ptr)
0
     {
0
 #if EV_MULTIPLICITY
0
@@ -1214,8 +1288,6 @@ ev_default_loop (unsigned int flags)
0
 
0
       if (ev_backend (EV_A))
0
         {
0
- siginit (EV_A);
0
-
0
 #ifndef _WIN32
0
           ev_signal_init (&childev, childcb, SIGCHLD);
0
           ev_set_priority (&childev, EV_MAXPRI);
0
@@ -1242,12 +1314,6 @@ ev_default_destroy (void)
0
   ev_signal_stop (EV_A_ &childev);
0
 #endif
0
 
0
- ev_ref (EV_A); /* signal watcher */
0
- ev_io_stop (EV_A_ &sigev);
0
-
0
- close (sigpipe [0]); sigpipe [0] = 0;
0
- close (sigpipe [1]); sigpipe [1] = 0;
0
-
0
   loop_destroy (EV_A);
0
 }
0
 
0
@@ -1259,7 +1325,7 @@ ev_default_fork (void)
0
 #endif
0
 
0
   if (backend)
0
- postfork = 1;
0
+ postfork = 1; /* must be in line with ev_loop_fork */
0
 }
0
 
0
 /*****************************************************************************/
0
@@ -1478,9 +1544,7 @@ static int loop_done;
0
 void
0
 ev_loop (EV_P_ int flags)
0
 {
0
- loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)
0
- ? EVUNLOOP_ONE
0
- : EVUNLOOP_CANCEL;
0
+ loop_done = EVUNLOOP_CANCEL;
0
 
0
   call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */
0
 
0
@@ -1586,9 +1650,12 @@ ev_loop (EV_P_ int flags)
0
         queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
0
 
0
       call_pending (EV_A);
0
-
0
     }
0
- while (expect_true (activecnt && !loop_done));
0
+ while (expect_true (
0
+ activecnt
0
+ && !loop_done
0
+ && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK))
0
+ ));
0
 
0
   if (loop_done == EVUNLOOP_ONE)
0
     loop_done = EVUNLOOP_CANCEL;
0
@@ -1844,6 +1911,8 @@ ev_signal_start (EV_P_ ev_signal *w)
0
 
0
   assert (("ev_signal_start called with illegal signal number", w->signum > 0));
0
 
0
+ evpipe_init (EV_A);
0
+
0
   {
0
 #ifndef _WIN32
0
     sigset_t full, prev;
0
@@ -1864,10 +1933,10 @@ ev_signal_start (EV_P_ ev_signal *w)
0
   if (!((WL)w)->next)
0
     {
0
 #if _WIN32
0
- signal (w->signum, sighandler);
0
+ signal (w->signum, ev_sighandler);
0
 #else
0
       struct sigaction sa;
0
- sa.sa_handler = sighandler;
0
+ sa.sa_handler = ev_sighandler;
0
       sigfillset (&sa.sa_mask);
0
       sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
0
       sigaction (w->signum, &sa, 0);
0
@@ -2366,6 +2435,44 @@ ev_fork_stop (EV_P_ ev_fork *w)
0
 }
0
 #endif
0
 
0
+#if EV_ASYNC_ENABLE
0
+void
0
+ev_async_start (EV_P_ ev_async *w)
0
+{
0
+ if (expect_false (ev_is_active (w)))
0
+ return;
0
+
0
+ evpipe_init (EV_A);
0
+
0
+ ev_start (EV_A_ (W)w, ++asynccnt);
0
+ array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2);
0
+ asyncs [asynccnt - 1] = w;
0
+}
0
+
0
+void
0
+ev_async_stop (EV_P_ ev_async *w)
0
+{
0
+ clear_pending (EV_A_ (W)w);
0
+ if (expect_false (!ev_is_active (w)))
0
+ return;
0
+
0
+ {
0
+ int active = ((W)w)->active;
0
+ asyncs [active - 1] = asyncs [--asynccnt];
0
+ ((W)asyncs [active - 1])->active = active;
0
+ }
0
+
0
+ ev_stop (EV_A_ (W)w);
0
+}
0
+
0
+void
0
+ev_async_send (EV_P_ ev_async *w)
0
+{
0
+ w->sent = 1;
0
+ evpipe_write (EV_A_ &gotasync);
0
+}
0
+#endif
0
+
0
 /*****************************************************************************/
0
 
0
 struct ev_once
...
1
2
3
4
5
6
7
 
8
9
10
 
 
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
19
20
21
22
23
24
25
26
27
 
 
 
 
 
 
 
 
 
 
28
29
30
...
68
69
70
 
 
 
 
 
 
 
 
 
71
72
73
...
110
111
112
 
113
114
115
...
120
121
122
123
 
124
125
126
...
217
218
219
 
220
221
222
...
296
297
298
 
 
 
 
 
 
 
 
 
 
 
 
 
299
300
301
...
321
322
323
 
 
 
324
325
326
...
397
398
399
 
 
 
 
 
 
 
 
 
 
 
 
400
401
402
...
447
448
449
450
 
451
452
453
454
455
456
 
457
458
459
460
461
462
463
 
 
464
465
466
467
468
 
469
470
471
...
541
542
543
 
 
 
 
 
 
544
545
546
...
1
 
 
 
 
 
 
2
3
 
 
4
5
6
 
 
 
 
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
 
 
 
 
 
 
 
 
 
 
28
29
30
31
32
33
34
35
36
37
38
39
40
...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
129
130
131
132
133
134
135
...
140
141
142
 
143
144
145
146
...
237
238
239
240
241
242
243
...
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
...
355
356
357
358
359
360
361
362
363
...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
...
496
497
498
 
499
500
501
502
503
504
505
506
507
508
509
510
511
 
 
512
513
514
515
516
517
518
519
520
521
522
...
592
593
594
595
596
597
598
599
600
601
602
603
0
@@ -1,30 +1,40 @@
0
 /*
0
- * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
0
- * All rights reserved.
0
- *
0
- * Redistribution and use in source and binary forms, with or without
0
- * modification, are permitted provided that the following conditions are
0
- * met:
0
+ * libev native API header
0
  *
0
- * * Redistributions of source code must retain the above copyright
0
- * notice, this list of conditions and the following disclaimer.
0
+ * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de>
0
+ * All rights reserved.
0
  *
0
- * * Redistributions in binary form must reproduce the above
0
- * copyright notice, this list of conditions and the following
0
- * disclaimer in the documentation and/or other materials provided
0
- * with the distribution.
0
+ * Redistribution and use in source and binary forms, with or without modifica-
0
+ * tion, are permitted provided that the following conditions are met:
0
+ *
0
+ * 1. Redistributions of source code must retain the above copyright notice,
0
+ * this list of conditions and the following disclaimer.
0
+ *
0
+ * 2. Redistributions in binary form must reproduce the above copyright
0
+ * notice, this list of conditions and the following disclaimer in the
0
+ * documentation and/or other materials provided with the distribution.
0
+ *
0
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
0
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
0
+ * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
0
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
0
+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
0
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
0
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
0
+ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
0
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
0
  *
0
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0
+ * Alternatively, the contents of this file may be used under the terms of
0
+ * the GNU General Public License ("GPL") version 2 or any later version,
0
+ * in which case the provisions of the GPL are applicable instead of
0
+ * the above. If you wish to allow the use of your version of this file
0
+ * only under the terms of the GPL and not to allow others to use your
0
+ * version of this file under the BSD license, indicate your decision
0
+ * by deleting the provisions above and replace them with the notice
0
+ * and other provisions required by the GPL. If you do not delete the
0
+ * provisions above, a recipient may use your version of this file under
0
+ * either the BSD or the GPL.
0
  */
0
 
0
 #ifndef EV_H__
0
@@ -68,6 +78,15 @@ typedef double ev_tstamp;
0
 # define EV_EMBED_ENABLE 1
0
 #endif
0
 
0
+#ifndef EV_ASYNC_ENABLE
0
+# define EV_ASYNC_ENABLE 1
0
+#endif
0
+
0
+#ifndef EV_ATOMIC_T
0
+# include <signal.h>
0
+# define EV_ATOMIC_T sig_atomic_t volatile
0
+#endif
0
+