nginxtra 1.6.3.9 → 1.8.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +358 -14
  6. data/vendor/nginx/CHANGES.ru +372 -18
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/clang +5 -0
  9. data/vendor/nginx/auto/cc/gcc +5 -0
  10. data/vendor/nginx/auto/lib/google-perftools/conf +1 -1
  11. data/vendor/nginx/auto/lib/openssl/make +0 -5
  12. data/vendor/nginx/auto/lib/perl/conf +9 -1
  13. data/vendor/nginx/auto/make +1 -1
  14. data/vendor/nginx/auto/modules +11 -0
  15. data/vendor/nginx/auto/options +10 -2
  16. data/vendor/nginx/auto/os/darwin +0 -1
  17. data/vendor/nginx/auto/os/freebsd +6 -23
  18. data/vendor/nginx/auto/sources +16 -14
  19. data/vendor/nginx/auto/summary +3 -24
  20. data/vendor/nginx/auto/threads +20 -0
  21. data/vendor/nginx/auto/types/sizeof +2 -12
  22. data/vendor/nginx/auto/unix +50 -6
  23. data/vendor/nginx/configure +5 -0
  24. data/vendor/nginx/contrib/vim/syntax/nginx.vim +183 -50
  25. data/vendor/nginx/src/core/nginx.c +21 -9
  26. data/vendor/nginx/src/core/nginx.h +8 -2
  27. data/vendor/nginx/src/core/ngx_buf.c +88 -0
  28. data/vendor/nginx/src/core/ngx_buf.h +15 -1
  29. data/vendor/nginx/src/core/ngx_conf_file.c +4 -1
  30. data/vendor/nginx/src/core/ngx_connection.c +25 -66
  31. data/vendor/nginx/src/core/ngx_connection.h +1 -3
  32. data/vendor/nginx/src/core/ngx_core.h +11 -3
  33. data/vendor/nginx/src/core/ngx_crypt.c +1 -1
  34. data/vendor/nginx/src/core/ngx_cycle.c +7 -1
  35. data/vendor/nginx/src/core/ngx_cycle.h +6 -2
  36. data/vendor/nginx/src/core/ngx_file.c +13 -5
  37. data/vendor/nginx/src/core/ngx_file.h +6 -0
  38. data/vendor/nginx/src/core/ngx_log.c +215 -21
  39. data/vendor/nginx/src/core/ngx_log.h +9 -1
  40. data/vendor/nginx/src/core/ngx_output_chain.c +104 -15
  41. data/vendor/nginx/src/core/ngx_palloc.c +3 -7
  42. data/vendor/nginx/src/core/ngx_rbtree.c +2 -4
  43. data/vendor/nginx/src/core/ngx_rbtree.h +2 -4
  44. data/vendor/nginx/src/core/ngx_regex.c +14 -6
  45. data/vendor/nginx/src/core/ngx_resolver.c +16 -23
  46. data/vendor/nginx/src/core/ngx_resolver.h +8 -7
  47. data/vendor/nginx/src/core/ngx_shmtx.c +1 -1
  48. data/vendor/nginx/src/core/ngx_slab.c +89 -2
  49. data/vendor/nginx/src/core/ngx_slab.h +3 -0
  50. data/vendor/nginx/src/core/ngx_string.c +58 -2
  51. data/vendor/nginx/src/core/ngx_string.h +1 -0
  52. data/vendor/nginx/src/core/ngx_syslog.c +374 -0
  53. data/vendor/nginx/src/core/ngx_syslog.h +30 -0
  54. data/vendor/nginx/src/core/ngx_thread_pool.c +630 -0
  55. data/vendor/nginx/src/core/ngx_thread_pool.h +36 -0
  56. data/vendor/nginx/src/core/ngx_times.c +19 -2
  57. data/vendor/nginx/src/core/ngx_times.h +1 -0
  58. data/vendor/nginx/src/event/modules/ngx_aio_module.c +1 -1
  59. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +9 -24
  60. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +152 -28
  61. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +43 -25
  62. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +86 -156
  63. data/vendor/nginx/src/event/modules/ngx_poll_module.c +21 -37
  64. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +15 -27
  65. data/vendor/nginx/src/event/modules/ngx_select_module.c +10 -12
  66. data/vendor/nginx/src/event/modules/ngx_win32_select_module.c +7 -9
  67. data/vendor/nginx/src/event/ngx_event.c +5 -33
  68. data/vendor/nginx/src/event/ngx_event.h +15 -50
  69. data/vendor/nginx/src/event/ngx_event_accept.c +11 -10
  70. data/vendor/nginx/src/event/ngx_event_connect.c +0 -11
  71. data/vendor/nginx/src/event/ngx_event_connect.h +1 -4
  72. data/vendor/nginx/src/event/ngx_event_openssl.c +622 -38
  73. data/vendor/nginx/src/event/ngx_event_openssl.h +20 -2
  74. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +5 -1
  75. data/vendor/nginx/src/event/ngx_event_pipe.c +45 -19
  76. data/vendor/nginx/src/event/ngx_event_pipe.h +3 -0
  77. data/vendor/nginx/src/event/ngx_event_posted.c +7 -145
  78. data/vendor/nginx/src/event/ngx_event_posted.h +12 -39
  79. data/vendor/nginx/src/event/ngx_event_timer.c +50 -70
  80. data/vendor/nginx/src/event/ngx_event_timer.h +2 -14
  81. data/vendor/nginx/src/http/modules/ngx_http_addition_filter_module.c +1 -1
  82. data/vendor/nginx/src/http/modules/ngx_http_autoindex_module.c +416 -71
  83. data/vendor/nginx/src/http/modules/ngx_http_charset_filter_module.c +19 -15
  84. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +16 -4
  85. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +601 -134
  86. data/vendor/nginx/src/http/modules/ngx_http_geo_module.c +1 -1
  87. data/vendor/nginx/src/http/modules/ngx_http_geoip_module.c +9 -3
  88. data/vendor/nginx/src/http/modules/ngx_http_gunzip_filter_module.c +9 -3
  89. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +9 -3
  90. data/vendor/nginx/src/http/modules/ngx_http_gzip_static_module.c +0 -2
  91. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +197 -91
  92. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +1 -0
  93. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +65 -162
  94. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +53 -67
  95. data/vendor/nginx/src/http/modules/ngx_http_log_module.c +128 -23
  96. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +25 -6
  97. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +1 -1
  98. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +39 -13
  99. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +697 -141
  100. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +5 -1
  101. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +282 -125
  102. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +4 -1
  103. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +44 -1
  104. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.h +2 -0
  105. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +10 -8
  106. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +18 -3
  107. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +641 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +3 -21
  110. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +0 -5
  111. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +449 -125
  112. data/vendor/nginx/src/http/modules/ngx_http_xslt_filter_module.c +4 -2
  113. data/vendor/nginx/src/http/modules/perl/ngx_http_perl_module.c +2 -1
  114. data/vendor/nginx/src/http/ngx_http.c +10 -5
  115. data/vendor/nginx/src/http/ngx_http.h +4 -4
  116. data/vendor/nginx/src/http/ngx_http_cache.h +26 -1
  117. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +109 -68
  118. data/vendor/nginx/src/http/ngx_http_core_module.c +191 -46
  119. data/vendor/nginx/src/http/ngx_http_core_module.h +16 -4
  120. data/vendor/nginx/src/http/ngx_http_file_cache.c +584 -67
  121. data/vendor/nginx/src/http/ngx_http_parse.c +55 -4
  122. data/vendor/nginx/src/http/ngx_http_request.c +14 -6
  123. data/vendor/nginx/src/http/ngx_http_request.h +12 -4
  124. data/vendor/nginx/src/http/ngx_http_request_body.c +114 -28
  125. data/vendor/nginx/src/http/ngx_http_spdy.c +383 -229
  126. data/vendor/nginx/src/http/ngx_http_spdy.h +8 -5
  127. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +12 -4
  128. data/vendor/nginx/src/http/ngx_http_special_response.c +2 -2
  129. data/vendor/nginx/src/http/ngx_http_upstream.c +808 -132
  130. data/vendor/nginx/src/http/ngx_http_upstream.h +33 -3
  131. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +72 -65
  132. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +1 -2
  133. data/vendor/nginx/src/http/ngx_http_variables.c +47 -3
  134. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +15 -6
  135. data/vendor/nginx/src/mail/ngx_mail.c +2 -3
  136. data/vendor/nginx/src/mail/ngx_mail.h +2 -0
  137. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +140 -11
  138. data/vendor/nginx/src/mail/ngx_mail_core_module.c +3 -3
  139. data/vendor/nginx/src/mail/ngx_mail_handler.c +79 -2
  140. data/vendor/nginx/src/mail/ngx_mail_imap_module.c +3 -1
  141. data/vendor/nginx/src/mail/ngx_mail_pop3_module.c +3 -1
  142. data/vendor/nginx/src/mail/ngx_mail_smtp_module.c +3 -1
  143. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +125 -1
  144. data/vendor/nginx/src/mail/ngx_mail_ssl_module.h +8 -0
  145. data/vendor/nginx/src/misc/ngx_cpp_test_module.cpp +1 -1
  146. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +1 -1
  147. data/vendor/nginx/src/os/unix/ngx_channel.c +0 -7
  148. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +0 -3
  149. data/vendor/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +44 -208
  150. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +25 -17
  151. data/vendor/nginx/src/os/unix/ngx_files.c +109 -0
  152. data/vendor/nginx/src/os/unix/ngx_files.h +6 -0
  153. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +0 -6
  154. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +78 -206
  155. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +25 -14
  156. data/vendor/nginx/src/os/unix/ngx_linux_config.h +4 -1
  157. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +235 -194
  158. data/vendor/nginx/src/os/unix/ngx_os.h +25 -3
  159. data/vendor/nginx/src/os/unix/ngx_posix_init.c +4 -2
  160. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +13 -195
  161. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +0 -1
  162. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +27 -108
  163. data/vendor/nginx/src/os/unix/ngx_setproctitle.h +2 -2
  164. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +12 -67
  165. data/vendor/nginx/src/os/unix/ngx_thread.h +26 -83
  166. data/vendor/nginx/src/os/unix/ngx_thread_cond.c +87 -0
  167. data/vendor/nginx/src/os/unix/ngx_thread_id.c +70 -0
  168. data/vendor/nginx/src/os/unix/ngx_thread_mutex.c +174 -0
  169. data/vendor/nginx/src/os/unix/ngx_user.c +2 -20
  170. data/vendor/nginx/src/os/unix/ngx_writev_chain.c +129 -98
  171. metadata +16 -17
  172. data/vendor/nginx/auto/lib/zlib/patch.zlib.h +0 -10
  173. data/vendor/nginx/src/event/ngx_event_busy_lock.c +0 -286
  174. data/vendor/nginx/src/event/ngx_event_busy_lock.h +0 -65
  175. data/vendor/nginx/src/event/ngx_event_mutex.c +0 -70
  176. data/vendor/nginx/src/http/ngx_http_busy_lock.c +0 -307
  177. data/vendor/nginx/src/http/ngx_http_busy_lock.h +0 -54
  178. data/vendor/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +0 -756
  179. data/vendor/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +0 -122
  180. data/vendor/nginx/src/os/unix/ngx_pthread_thread.c +0 -278
  181. data/vendor/nginx/src/os/unix/rfork_thread.S +0 -73
@@ -0,0 +1,36 @@
1
+
2
+ /*
3
+ * Copyright (C) Nginx, Inc.
4
+ * Copyright (C) Valentin V. Bartenev
5
+ */
6
+
7
+
8
+ #ifndef _NGX_THREAD_POOL_H_INCLUDED_
9
+ #define _NGX_THREAD_POOL_H_INCLUDED_
10
+
11
+
12
+ #include <ngx_config.h>
13
+ #include <ngx_core.h>
14
+ #include <ngx_event.h>
15
+
16
+
17
+ struct ngx_thread_task_s {
18
+ ngx_thread_task_t *next;
19
+ ngx_uint_t id;
20
+ void *ctx;
21
+ void (*handler)(void *data, ngx_log_t *log);
22
+ ngx_event_t event;
23
+ };
24
+
25
+
26
+ typedef struct ngx_thread_pool_s ngx_thread_pool_t;
27
+
28
+
29
+ ngx_thread_pool_t *ngx_thread_pool_add(ngx_conf_t *cf, ngx_str_t *name);
30
+ ngx_thread_pool_t *ngx_thread_pool_get(ngx_cycle_t *cycle, ngx_str_t *name);
31
+
32
+ ngx_thread_task_t *ngx_thread_task_alloc(ngx_pool_t *pool, size_t size);
33
+ ngx_int_t ngx_thread_task_post(ngx_thread_pool_t *tp, ngx_thread_task_t *task);
34
+
35
+
36
+ #endif /* _NGX_THREAD_POOL_H_INCLUDED_ */
@@ -29,6 +29,7 @@ volatile ngx_str_t ngx_cached_err_log_time;
29
29
  volatile ngx_str_t ngx_cached_http_time;
30
30
  volatile ngx_str_t ngx_cached_http_log_time;
31
31
  volatile ngx_str_t ngx_cached_http_log_iso8601;
32
+ volatile ngx_str_t ngx_cached_syslog_time;
32
33
 
33
34
  #if !(NGX_WIN32)
34
35
 
@@ -50,6 +51,8 @@ static u_char cached_http_log_time[NGX_TIME_SLOTS]
50
51
  [sizeof("28/Sep/1970:12:00:00 +0600")];
51
52
  static u_char cached_http_log_iso8601[NGX_TIME_SLOTS]
52
53
  [sizeof("1970-09-28T12:00:00+06:00")];
54
+ static u_char cached_syslog_time[NGX_TIME_SLOTS]
55
+ [sizeof("Sep 28 12:00:00")];
53
56
 
54
57
 
55
58
  static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
@@ -63,6 +66,7 @@ ngx_time_init(void)
63
66
  ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1;
64
67
  ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1;
65
68
  ngx_cached_http_log_iso8601.len = sizeof("1970-09-28T12:00:00+06:00") - 1;
69
+ ngx_cached_syslog_time.len = sizeof("Sep 28 12:00:00") - 1;
66
70
 
67
71
  ngx_cached_time = &cached_time[0];
68
72
 
@@ -73,7 +77,7 @@ ngx_time_init(void)
73
77
  void
74
78
  ngx_time_update(void)
75
79
  {
76
- u_char *p0, *p1, *p2, *p3;
80
+ u_char *p0, *p1, *p2, *p3, *p4;
77
81
  ngx_tm_t tm, gmt;
78
82
  time_t sec;
79
83
  ngx_uint_t msec;
@@ -166,6 +170,11 @@ ngx_time_update(void)
166
170
  tp->gmtoff < 0 ? '-' : '+',
167
171
  ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
168
172
 
173
+ p4 = &cached_syslog_time[slot][0];
174
+
175
+ (void) ngx_sprintf(p4, "%s %2d %02d:%02d:%02d",
176
+ months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,
177
+ tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
169
178
 
170
179
  ngx_memory_barrier();
171
180
 
@@ -174,6 +183,7 @@ ngx_time_update(void)
174
183
  ngx_cached_err_log_time.data = p1;
175
184
  ngx_cached_http_log_time.data = p2;
176
185
  ngx_cached_http_log_iso8601.data = p3;
186
+ ngx_cached_syslog_time.data = p4;
177
187
 
178
188
  ngx_unlock(&ngx_time_lock);
179
189
  }
@@ -184,7 +194,7 @@ ngx_time_update(void)
184
194
  void
185
195
  ngx_time_sigsafe_update(void)
186
196
  {
187
- u_char *p;
197
+ u_char *p, *p2;
188
198
  ngx_tm_t tm;
189
199
  time_t sec;
190
200
  ngx_time_t *tp;
@@ -224,9 +234,16 @@ ngx_time_sigsafe_update(void)
224
234
  tm.ngx_tm_mday, tm.ngx_tm_hour,
225
235
  tm.ngx_tm_min, tm.ngx_tm_sec);
226
236
 
237
+ p2 = &cached_syslog_time[slot][0];
238
+
239
+ (void) ngx_sprintf(p2, "%s %2d %02d:%02d:%02d",
240
+ months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,
241
+ tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
242
+
227
243
  ngx_memory_barrier();
228
244
 
229
245
  ngx_cached_err_log_time.data = p;
246
+ ngx_cached_syslog_time.data = p2;
230
247
 
231
248
  ngx_unlock(&ngx_time_lock);
232
249
  }
@@ -40,6 +40,7 @@ extern volatile ngx_str_t ngx_cached_err_log_time;
40
40
  extern volatile ngx_str_t ngx_cached_http_time;
41
41
  extern volatile ngx_str_t ngx_cached_http_log_time;
42
42
  extern volatile ngx_str_t ngx_cached_http_log_iso8601;
43
+ extern volatile ngx_str_t ngx_cached_syslog_time;
43
44
 
44
45
  /*
45
46
  * milliseconds elapsed since epoch and truncated to ngx_msec_t,
@@ -48,7 +48,7 @@ ngx_event_module_t ngx_aio_module_ctx = {
48
48
  NULL, /* disable an event */
49
49
  NULL, /* add an connection */
50
50
  ngx_aio_del_connection, /* delete an connection */
51
- NULL, /* process the changes */
51
+ NULL, /* trigger a notify */
52
52
  ngx_aio_process_events, /* process the events */
53
53
  ngx_aio_init, /* init the events */
54
54
  ngx_aio_done /* done the events */
@@ -88,7 +88,7 @@ ngx_event_module_t ngx_devpoll_module_ctx = {
88
88
  ngx_devpoll_del_event, /* disable an event */
89
89
  NULL, /* add an connection */
90
90
  NULL, /* delete an connection */
91
- NULL, /* process the changes */
91
+ NULL, /* trigger a notify */
92
92
  ngx_devpoll_process_events, /* process the events */
93
93
  ngx_devpoll_init, /* init the events */
94
94
  ngx_devpoll_done, /* done the events */
@@ -344,7 +344,8 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
344
344
  ngx_err_t err;
345
345
  ngx_int_t i;
346
346
  ngx_uint_t level, instance;
347
- ngx_event_t *rev, *wev, **queue;
347
+ ngx_event_t *rev, *wev;
348
+ ngx_queue_t *queue;
348
349
  ngx_connection_t *c;
349
350
  struct pollfd pfd;
350
351
  struct dvpoll dvp;
@@ -404,8 +405,6 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
404
405
  return NGX_ERROR;
405
406
  }
406
407
 
407
- ngx_mutex_lock(ngx_posted_events_mutex);
408
-
409
408
  for (i = 0; i < events; i++) {
410
409
 
411
410
  fd = event_list[i].fd;
@@ -495,19 +494,13 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
495
494
  rev = c->read;
496
495
 
497
496
  if ((revents & POLLIN) && rev->active) {
498
-
499
- if ((flags & NGX_POST_THREAD_EVENTS) && !rev->accept) {
500
- rev->posted_ready = 1;
501
-
502
- } else {
503
- rev->ready = 1;
504
- }
497
+ rev->ready = 1;
505
498
 
506
499
  if (flags & NGX_POST_EVENTS) {
507
- queue = (ngx_event_t **) (rev->accept ?
508
- &ngx_posted_accept_events : &ngx_posted_events);
500
+ queue = rev->accept ? &ngx_posted_accept_events
501
+ : &ngx_posted_events;
509
502
 
510
- ngx_locked_post_event(rev, queue);
503
+ ngx_post_event(rev, queue);
511
504
 
512
505
  } else {
513
506
  instance = rev->instance;
@@ -523,16 +516,10 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
523
516
  wev = c->write;
524
517
 
525
518
  if ((revents & POLLOUT) && wev->active) {
526
-
527
- if (flags & NGX_POST_THREAD_EVENTS) {
528
- wev->posted_ready = 1;
529
-
530
- } else {
531
- wev->ready = 1;
532
- }
519
+ wev->ready = 1;
533
520
 
534
521
  if (flags & NGX_POST_EVENTS) {
535
- ngx_locked_post_event(wev, &ngx_posted_events);
522
+ ngx_post_event(wev, &ngx_posted_events);
536
523
 
537
524
  } else {
538
525
  wev->handler(wev);
@@ -540,8 +527,6 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
540
527
  }
541
528
  }
542
529
 
543
- ngx_mutex_unlock(ngx_posted_events_mutex);
544
-
545
530
  return NGX_OK;
546
531
  }
547
532
 
@@ -70,12 +70,15 @@ int epoll_wait(int epfd, struct epoll_event *events, int nevents, int timeout)
70
70
  return -1;
71
71
  }
72
72
 
73
+ #if (NGX_HAVE_EVENTFD)
74
+ #define SYS_eventfd 323
75
+ #endif
76
+
73
77
  #if (NGX_HAVE_FILE_AIO)
74
78
 
75
79
  #define SYS_io_setup 245
76
80
  #define SYS_io_destroy 246
77
81
  #define SYS_io_getevents 247
78
- #define SYS_eventfd 323
79
82
 
80
83
  typedef u_int aio_context_t;
81
84
 
@@ -88,7 +91,7 @@ struct io_event {
88
91
 
89
92
 
90
93
  #endif
91
- #endif
94
+ #endif /* NGX_TEST_BUILD_EPOLL */
92
95
 
93
96
 
94
97
  typedef struct {
@@ -98,6 +101,10 @@ typedef struct {
98
101
 
99
102
 
100
103
  static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer);
104
+ #if (NGX_HAVE_EVENTFD)
105
+ static ngx_int_t ngx_epoll_notify_init(ngx_log_t *log);
106
+ static void ngx_epoll_notify_handler(ngx_event_t *ev);
107
+ #endif
101
108
  static void ngx_epoll_done(ngx_cycle_t *cycle);
102
109
  static ngx_int_t ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event,
103
110
  ngx_uint_t flags);
@@ -106,6 +113,9 @@ static ngx_int_t ngx_epoll_del_event(ngx_event_t *ev, ngx_int_t event,
106
113
  static ngx_int_t ngx_epoll_add_connection(ngx_connection_t *c);
107
114
  static ngx_int_t ngx_epoll_del_connection(ngx_connection_t *c,
108
115
  ngx_uint_t flags);
116
+ #if (NGX_HAVE_EVENTFD)
117
+ static ngx_int_t ngx_epoll_notify(ngx_event_handler_pt handler);
118
+ #endif
109
119
  static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
110
120
  ngx_uint_t flags);
111
121
 
@@ -120,6 +130,12 @@ static int ep = -1;
120
130
  static struct epoll_event *event_list;
121
131
  static ngx_uint_t nevents;
122
132
 
133
+ #if (NGX_HAVE_EVENTFD)
134
+ static int notify_fd = -1;
135
+ static ngx_event_t notify_event;
136
+ static ngx_connection_t notify_conn;
137
+ #endif
138
+
123
139
  #if (NGX_HAVE_FILE_AIO)
124
140
 
125
141
  int ngx_eventfd = -1;
@@ -164,7 +180,11 @@ ngx_event_module_t ngx_epoll_module_ctx = {
164
180
  ngx_epoll_del_event, /* disable an event */
165
181
  ngx_epoll_add_connection, /* add an connection */
166
182
  ngx_epoll_del_connection, /* delete an connection */
167
- NULL, /* process the changes */
183
+ #if (NGX_HAVE_EVENTFD)
184
+ ngx_epoll_notify, /* trigger a notify */
185
+ #else
186
+ NULL, /* trigger a notify */
187
+ #endif
168
188
  ngx_epoll_process_events, /* process the events */
169
189
  ngx_epoll_init, /* init the events */
170
190
  ngx_epoll_done, /* done the events */
@@ -193,10 +213,6 @@ ngx_module_t ngx_epoll_module = {
193
213
  * We call io_setup(), io_destroy() io_submit(), and io_getevents() directly
194
214
  * as syscalls instead of libaio usage, because the library header file
195
215
  * supports eventfd() since 0.3.107 version only.
196
- *
197
- * Also we do not use eventfd() in glibc, because glibc supports it
198
- * since 2.8 version and glibc maps two syscalls eventfd() and eventfd2()
199
- * into single eventfd() function with different number of parameters.
200
216
  */
201
217
 
202
218
  static int
@@ -227,7 +243,11 @@ ngx_epoll_aio_init(ngx_cycle_t *cycle, ngx_epoll_conf_t *epcf)
227
243
  int n;
228
244
  struct epoll_event ee;
229
245
 
246
+ #if (NGX_HAVE_SYS_EVENTFD_H)
247
+ ngx_eventfd = eventfd(0, 0);
248
+ #else
230
249
  ngx_eventfd = syscall(SYS_eventfd, 0);
250
+ #endif
231
251
 
232
252
  if (ngx_eventfd == -1) {
233
253
  ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
@@ -307,6 +327,12 @@ ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer)
307
327
  return NGX_ERROR;
308
328
  }
309
329
 
330
+ #if (NGX_HAVE_EVENTFD)
331
+ if (ngx_epoll_notify_init(cycle->log) != NGX_OK) {
332
+ return NGX_ERROR;
333
+ }
334
+ #endif
335
+
310
336
  #if (NGX_HAVE_FILE_AIO)
311
337
 
312
338
  ngx_epoll_aio_init(cycle, epcf);
@@ -344,6 +370,85 @@ ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer)
344
370
  }
345
371
 
346
372
 
373
+ #if (NGX_HAVE_EVENTFD)
374
+
375
+ static ngx_int_t
376
+ ngx_epoll_notify_init(ngx_log_t *log)
377
+ {
378
+ struct epoll_event ee;
379
+
380
+ #if (NGX_HAVE_SYS_EVENTFD_H)
381
+ notify_fd = eventfd(0, 0);
382
+ #else
383
+ notify_fd = syscall(SYS_eventfd, 0);
384
+ #endif
385
+
386
+ if (notify_fd == -1) {
387
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "eventfd() failed");
388
+ return NGX_ERROR;
389
+ }
390
+
391
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
392
+ "notify eventfd: %d", notify_fd);
393
+
394
+ notify_event.handler = ngx_epoll_notify_handler;
395
+ notify_event.log = log;
396
+ notify_event.active = 1;
397
+
398
+ notify_conn.fd = notify_fd;
399
+ notify_conn.read = &notify_event;
400
+ notify_conn.log = log;
401
+
402
+ ee.events = EPOLLIN|EPOLLET;
403
+ ee.data.ptr = &notify_conn;
404
+
405
+ if (epoll_ctl(ep, EPOLL_CTL_ADD, notify_fd, &ee) == -1) {
406
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
407
+ "epoll_ctl(EPOLL_CTL_ADD, eventfd) failed");
408
+
409
+ if (close(notify_fd) == -1) {
410
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
411
+ "eventfd close() failed");
412
+ }
413
+
414
+ return NGX_ERROR;
415
+ }
416
+
417
+ return NGX_OK;
418
+ }
419
+
420
+
421
+ static void
422
+ ngx_epoll_notify_handler(ngx_event_t *ev)
423
+ {
424
+ ssize_t n;
425
+ uint64_t count;
426
+ ngx_err_t err;
427
+ ngx_event_handler_pt handler;
428
+
429
+ if (++ev->index == NGX_MAX_UINT32_VALUE) {
430
+ ev->index = 0;
431
+
432
+ n = read(notify_fd, &count, sizeof(uint64_t));
433
+
434
+ err = ngx_errno;
435
+
436
+ ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
437
+ "read() eventfd %d: %z count:%uL", notify_fd, n, count);
438
+
439
+ if ((size_t) n != sizeof(uint64_t)) {
440
+ ngx_log_error(NGX_LOG_ALERT, ev->log, err,
441
+ "read() eventfd %d failed", notify_fd);
442
+ }
443
+ }
444
+
445
+ handler = ev->data;
446
+ handler(ev);
447
+ }
448
+
449
+ #endif
450
+
451
+
347
452
  static void
348
453
  ngx_epoll_done(ngx_cycle_t *cycle)
349
454
  {
@@ -354,6 +459,17 @@ ngx_epoll_done(ngx_cycle_t *cycle)
354
459
 
355
460
  ep = -1;
356
461
 
462
+ #if (NGX_HAVE_EVENTFD)
463
+
464
+ if (close(notify_fd) == -1) {
465
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
466
+ "eventfd close() failed");
467
+ }
468
+
469
+ notify_fd = -1;
470
+
471
+ #endif
472
+
357
473
  #if (NGX_HAVE_FILE_AIO)
358
474
 
359
475
  if (ngx_eventfd != -1) {
@@ -560,6 +676,27 @@ ngx_epoll_del_connection(ngx_connection_t *c, ngx_uint_t flags)
560
676
  }
561
677
 
562
678
 
679
+ #if (NGX_HAVE_EVENTFD)
680
+
681
+ static ngx_int_t
682
+ ngx_epoll_notify(ngx_event_handler_pt handler)
683
+ {
684
+ static uint64_t inc = 1;
685
+
686
+ notify_event.data = handler;
687
+
688
+ if ((size_t) write(notify_fd, &inc, sizeof(uint64_t)) != sizeof(uint64_t)) {
689
+ ngx_log_error(NGX_LOG_ALERT, notify_event.log, ngx_errno,
690
+ "write() to eventfd %d failed", notify_fd);
691
+ return NGX_ERROR;
692
+ }
693
+
694
+ return NGX_OK;
695
+ }
696
+
697
+ #endif
698
+
699
+
563
700
  static ngx_int_t
564
701
  ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
565
702
  {
@@ -568,7 +705,8 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
568
705
  ngx_int_t instance, i;
569
706
  ngx_uint_t level;
570
707
  ngx_err_t err;
571
- ngx_event_t *rev, *wev, **queue;
708
+ ngx_event_t *rev, *wev;
709
+ ngx_queue_t *queue;
572
710
  ngx_connection_t *c;
573
711
 
574
712
  /* NGX_TIMER_INFINITE == INFTIM */
@@ -612,8 +750,6 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
612
750
  return NGX_ERROR;
613
751
  }
614
752
 
615
- ngx_mutex_lock(ngx_posted_events_mutex);
616
-
617
753
  for (i = 0; i < events; i++) {
618
754
  c = event_list[i].data.ptr;
619
755
 
@@ -674,18 +810,13 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
674
810
  }
675
811
  #endif
676
812
 
677
- if ((flags & NGX_POST_THREAD_EVENTS) && !rev->accept) {
678
- rev->posted_ready = 1;
679
-
680
- } else {
681
- rev->ready = 1;
682
- }
813
+ rev->ready = 1;
683
814
 
684
815
  if (flags & NGX_POST_EVENTS) {
685
- queue = (ngx_event_t **) (rev->accept ?
686
- &ngx_posted_accept_events : &ngx_posted_events);
816
+ queue = rev->accept ? &ngx_posted_accept_events
817
+ : &ngx_posted_events;
687
818
 
688
- ngx_locked_post_event(rev, queue);
819
+ ngx_post_event(rev, queue);
689
820
 
690
821
  } else {
691
822
  rev->handler(rev);
@@ -708,15 +839,10 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
708
839
  continue;
709
840
  }
710
841
 
711
- if (flags & NGX_POST_THREAD_EVENTS) {
712
- wev->posted_ready = 1;
713
-
714
- } else {
715
- wev->ready = 1;
716
- }
842
+ wev->ready = 1;
717
843
 
718
844
  if (flags & NGX_POST_EVENTS) {
719
- ngx_locked_post_event(wev, &ngx_posted_events);
845
+ ngx_post_event(wev, &ngx_posted_events);
720
846
 
721
847
  } else {
722
848
  wev->handler(wev);
@@ -724,8 +850,6 @@ ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
724
850
  }
725
851
  }
726
852
 
727
- ngx_mutex_unlock(ngx_posted_events_mutex);
728
-
729
853
  return NGX_OK;
730
854
  }
731
855