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
@@ -36,6 +36,28 @@ static ssize_t ngx_file_aio_result(ngx_file_t *file, ngx_event_aio_t *aio,
36
36
  static void ngx_file_aio_event_handler(ngx_event_t *ev);
37
37
 
38
38
 
39
+ ngx_int_t
40
+ ngx_file_aio_init(ngx_file_t *file, ngx_pool_t *pool)
41
+ {
42
+ ngx_event_aio_t *aio;
43
+
44
+ aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t));
45
+ if (aio == NULL) {
46
+ return NGX_ERROR;
47
+ }
48
+
49
+ aio->file = file;
50
+ aio->fd = file->fd;
51
+ aio->event.data = aio;
52
+ aio->event.ready = 1;
53
+ aio->event.log = file->log;
54
+
55
+ file->aio = aio;
56
+
57
+ return NGX_OK;
58
+ }
59
+
60
+
39
61
  ssize_t
40
62
  ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
41
63
  ngx_pool_t *pool)
@@ -48,25 +70,11 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
48
70
  return ngx_read_file(file, buf, size, offset);
49
71
  }
50
72
 
51
- aio = file->aio;
52
-
53
- if (aio == NULL) {
54
- aio = ngx_pcalloc(pool, sizeof(ngx_event_aio_t));
55
- if (aio == NULL) {
56
- return NGX_ERROR;
57
- }
58
-
59
- aio->file = file;
60
- aio->fd = file->fd;
61
- aio->event.data = aio;
62
- aio->event.ready = 1;
63
- aio->event.log = file->log;
64
- #if (NGX_HAVE_AIO_SENDFILE)
65
- aio->last_offset = -1;
66
- #endif
67
- file->aio = aio;
73
+ if (file->aio == NULL && ngx_file_aio_init(file, pool) != NGX_OK) {
74
+ return NGX_ERROR;
68
75
  }
69
76
 
77
+ aio = file->aio;
70
78
  ev = &aio->event;
71
79
 
72
80
  if (!ev->ready) {
@@ -9,6 +9,12 @@
9
9
  #include <ngx_core.h>
10
10
 
11
11
 
12
+ #if (NGX_THREADS)
13
+ #include <ngx_thread_pool.h>
14
+ static void ngx_thread_read_handler(void *data, ngx_log_t *log);
15
+ #endif
16
+
17
+
12
18
  #if (NGX_HAVE_FILE_AIO)
13
19
 
14
20
  ngx_uint_t ngx_file_aio = 1;
@@ -64,6 +70,109 @@ ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
64
70
  }
65
71
 
66
72
 
73
+ #if (NGX_THREADS)
74
+
75
+ typedef struct {
76
+ ngx_fd_t fd;
77
+ u_char *buf;
78
+ size_t size;
79
+ off_t offset;
80
+
81
+ size_t read;
82
+ ngx_err_t err;
83
+ } ngx_thread_read_ctx_t;
84
+
85
+
86
+ ssize_t
87
+ ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file, u_char *buf,
88
+ size_t size, off_t offset, ngx_pool_t *pool)
89
+ {
90
+ ngx_thread_task_t *task;
91
+ ngx_thread_read_ctx_t *ctx;
92
+
93
+ ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
94
+ "thread read: %d, %p, %uz, %O",
95
+ file->fd, buf, size, offset);
96
+
97
+ task = *taskp;
98
+
99
+ if (task == NULL) {
100
+ task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_read_ctx_t));
101
+ if (task == NULL) {
102
+ return NGX_ERROR;
103
+ }
104
+
105
+ task->handler = ngx_thread_read_handler;
106
+
107
+ *taskp = task;
108
+ }
109
+
110
+ ctx = task->ctx;
111
+
112
+ if (task->event.complete) {
113
+ task->event.complete = 0;
114
+
115
+ if (ctx->err) {
116
+ ngx_log_error(NGX_LOG_CRIT, file->log, ctx->err,
117
+ "pread() \"%s\" failed", file->name.data);
118
+ return NGX_ERROR;
119
+ }
120
+
121
+ return ctx->read;
122
+ }
123
+
124
+ ctx->fd = file->fd;
125
+ ctx->buf = buf;
126
+ ctx->size = size;
127
+ ctx->offset = offset;
128
+
129
+ if (file->thread_handler(task, file) != NGX_OK) {
130
+ return NGX_ERROR;
131
+ }
132
+
133
+ return NGX_AGAIN;
134
+ }
135
+
136
+
137
+ #if (NGX_HAVE_PREAD)
138
+
139
+ static void
140
+ ngx_thread_read_handler(void *data, ngx_log_t *log)
141
+ {
142
+ ngx_thread_read_ctx_t *ctx = data;
143
+
144
+ ssize_t n;
145
+
146
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "thread read handler");
147
+
148
+ n = pread(ctx->fd, ctx->buf, ctx->size, ctx->offset);
149
+
150
+ if (n == -1) {
151
+ ctx->err = ngx_errno;
152
+
153
+ } else {
154
+ ctx->read = n;
155
+ ctx->err = 0;
156
+ }
157
+
158
+ #if 0
159
+ ngx_time_update();
160
+ #endif
161
+
162
+ ngx_log_debug4(NGX_LOG_DEBUG_CORE, log, 0,
163
+ "pread: %z (err: %i) of %uz @%O",
164
+ n, ctx->err, ctx->size, ctx->offset);
165
+ }
166
+
167
+ #else
168
+
169
+ #error pread() is required!
170
+
171
+ #endif
172
+
173
+ #endif /* NGX_THREADS */
174
+
175
+
67
176
  ssize_t
68
177
  ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
69
178
  {
@@ -375,6 +375,7 @@ size_t ngx_fs_bsize(u_char *name);
375
375
 
376
376
  #if (NGX_HAVE_FILE_AIO)
377
377
 
378
+ ngx_int_t ngx_file_aio_init(ngx_file_t *file, ngx_pool_t *pool);
378
379
  ssize_t ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size,
379
380
  off_t offset, ngx_pool_t *pool);
380
381
 
@@ -382,5 +383,10 @@ extern ngx_uint_t ngx_file_aio;
382
383
 
383
384
  #endif
384
385
 
386
+ #if (NGX_THREADS)
387
+ ssize_t ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file,
388
+ u_char *buf, size_t size, off_t offset, ngx_pool_t *pool);
389
+ #endif
390
+
385
391
 
386
392
  #endif /* _NGX_FILES_H_INCLUDED_ */
@@ -100,12 +100,6 @@ typedef struct aiocb ngx_aiocb_t;
100
100
  #endif
101
101
 
102
102
 
103
- #if (__FreeBSD_version < 430000 || __FreeBSD_version < 500012)
104
-
105
- pid_t rfork_thread(int flags, void *stack, int (*func)(void *arg), void *arg);
106
-
107
- #endif
108
-
109
103
  #ifndef IOV_MAX
110
104
  #define IOV_MAX 1024
111
105
  #endif
@@ -29,30 +29,26 @@
29
29
  */
30
30
 
31
31
 
32
- #if (IOV_MAX > 64)
33
- #define NGX_HEADERS 64
34
- #define NGX_TRAILERS 64
35
- #else
36
- #define NGX_HEADERS IOV_MAX
37
- #define NGX_TRAILERS IOV_MAX
38
- #endif
39
-
40
-
41
32
  ngx_chain_t *
42
33
  ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
43
34
  {
44
- int rc, flags;
45
- u_char *prev;
46
- off_t size, send, prev_send, aligned, sent, fprev;
47
- size_t header_size, file_size;
48
- ngx_uint_t eintr, eagain, complete;
49
- ngx_err_t err;
50
- ngx_buf_t *file;
51
- ngx_array_t header, trailer;
52
- ngx_event_t *wev;
53
- ngx_chain_t *cl;
54
- struct sf_hdtr hdtr;
55
- struct iovec *iov, headers[NGX_HEADERS], trailers[NGX_TRAILERS];
35
+ int rc, flags;
36
+ off_t send, prev_send, sent;
37
+ size_t file_size;
38
+ ssize_t n;
39
+ ngx_uint_t eintr, eagain;
40
+ ngx_err_t err;
41
+ ngx_buf_t *file;
42
+ ngx_event_t *wev;
43
+ ngx_chain_t *cl;
44
+ ngx_iovec_t header, trailer;
45
+ struct sf_hdtr hdtr;
46
+ struct iovec headers[NGX_IOVS_PREALLOCATE];
47
+ struct iovec trailers[NGX_IOVS_PREALLOCATE];
48
+ #if (NGX_HAVE_AIO_SENDFILE)
49
+ ngx_uint_t ebusy;
50
+ ngx_event_aio_t *aio;
51
+ #endif
56
52
 
57
53
  wev = c->write;
58
54
 
@@ -81,151 +77,52 @@ ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
81
77
  eagain = 0;
82
78
  flags = 0;
83
79
 
84
- header.elts = headers;
85
- header.size = sizeof(struct iovec);
86
- header.nalloc = NGX_HEADERS;
87
- header.pool = c->pool;
80
+ #if (NGX_HAVE_AIO_SENDFILE && NGX_SUPPRESS_WARN)
81
+ aio = NULL;
82
+ file = NULL;
83
+ #endif
84
+
85
+ header.iovs = headers;
86
+ header.nalloc = NGX_IOVS_PREALLOCATE;
88
87
 
89
- trailer.elts = trailers;
90
- trailer.size = sizeof(struct iovec);
91
- trailer.nalloc = NGX_TRAILERS;
92
- trailer.pool = c->pool;
88
+ trailer.iovs = trailers;
89
+ trailer.nalloc = NGX_IOVS_PREALLOCATE;
93
90
 
94
91
  for ( ;; ) {
95
- file = NULL;
96
- file_size = 0;
97
- header_size = 0;
98
92
  eintr = 0;
99
- complete = 0;
93
+ #if (NGX_HAVE_AIO_SENDFILE)
94
+ ebusy = 0;
95
+ #endif
100
96
  prev_send = send;
101
97
 
102
- header.nelts = 0;
103
- trailer.nelts = 0;
104
-
105
98
  /* create the header iovec and coalesce the neighbouring bufs */
106
99
 
107
- prev = NULL;
108
- iov = NULL;
109
-
110
- for (cl = in; cl && send < limit; cl = cl->next) {
111
-
112
- if (ngx_buf_special(cl->buf)) {
113
- continue;
114
- }
115
-
116
- if (!ngx_buf_in_memory_only(cl->buf)) {
117
- break;
118
- }
119
-
120
- size = cl->buf->last - cl->buf->pos;
121
-
122
- if (send + size > limit) {
123
- size = limit - send;
124
- }
125
-
126
- if (prev == cl->buf->pos) {
127
- iov->iov_len += (size_t) size;
128
-
129
- } else {
130
- if (header.nelts >= IOV_MAX){
131
- break;
132
- }
100
+ cl = ngx_output_chain_to_iovec(&header, in, limit - send, c->log);
133
101
 
134
- iov = ngx_array_push(&header);
135
- if (iov == NULL) {
136
- return NGX_CHAIN_ERROR;
137
- }
138
-
139
- iov->iov_base = (void *) cl->buf->pos;
140
- iov->iov_len = (size_t) size;
141
- }
142
-
143
- prev = cl->buf->pos + (size_t) size;
144
- header_size += (size_t) size;
145
- send += size;
102
+ if (cl == NGX_CHAIN_ERROR) {
103
+ return NGX_CHAIN_ERROR;
146
104
  }
147
105
 
106
+ send += header.size;
148
107
 
149
108
  if (cl && cl->buf->in_file && send < limit) {
150
109
  file = cl->buf;
151
110
 
152
111
  /* coalesce the neighbouring file bufs */
153
112
 
154
- do {
155
- size = cl->buf->file_last - cl->buf->file_pos;
156
-
157
- if (send + size > limit) {
158
- size = limit - send;
113
+ file_size = (size_t) ngx_chain_coalesce_file(&cl, limit - send);
159
114
 
160
- aligned = (cl->buf->file_pos + size + ngx_pagesize - 1)
161
- & ~((off_t) ngx_pagesize - 1);
162
-
163
- if (aligned <= cl->buf->file_last) {
164
- size = aligned - cl->buf->file_pos;
165
- }
166
- }
167
-
168
- file_size += (size_t) size;
169
- send += size;
170
- fprev = cl->buf->file_pos + size;
171
- cl = cl->next;
172
-
173
- } while (cl
174
- && cl->buf->in_file
175
- && send < limit
176
- && file->file->fd == cl->buf->file->fd
177
- && fprev == cl->buf->file_pos);
178
- }
179
-
180
-
181
- if (file) {
115
+ send += file_size;
182
116
 
183
117
  /* create the trailer iovec and coalesce the neighbouring bufs */
184
118
 
185
- prev = NULL;
186
- iov = NULL;
187
-
188
- while (cl && send < limit) {
189
-
190
- if (ngx_buf_special(cl->buf)) {
191
- cl = cl->next;
192
- continue;
193
- }
194
-
195
- if (!ngx_buf_in_memory_only(cl->buf)) {
196
- break;
197
- }
198
-
199
- size = cl->buf->last - cl->buf->pos;
200
-
201
- if (send + size > limit) {
202
- size = limit - send;
203
- }
204
-
205
- if (prev == cl->buf->pos) {
206
- iov->iov_len += (size_t) size;
207
-
208
- } else {
209
- if (trailer.nelts >= IOV_MAX){
210
- break;
211
- }
212
-
213
- iov = ngx_array_push(&trailer);
214
- if (iov == NULL) {
215
- return NGX_CHAIN_ERROR;
216
- }
217
-
218
- iov->iov_base = (void *) cl->buf->pos;
219
- iov->iov_len = (size_t) size;
220
- }
119
+ cl = ngx_output_chain_to_iovec(&trailer, cl, limit - send, c->log);
221
120
 
222
- prev = cl->buf->pos + (size_t) size;
223
- send += size;
224
- cl = cl->next;
121
+ if (cl == NGX_CHAIN_ERROR) {
122
+ return NGX_CHAIN_ERROR;
225
123
  }
226
- }
227
124
 
228
- if (file) {
125
+ send += trailer.size;
229
126
 
230
127
  if (ngx_freebsd_use_tcp_nopush
231
128
  && c->tcp_nopush == NGX_TCP_NOPUSH_UNSET)
@@ -258,28 +155,29 @@ ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
258
155
  * but corresponding pointer is not NULL
259
156
  */
260
157
 
261
- hdtr.headers = header.nelts ? (struct iovec *) header.elts: NULL;
262
- hdtr.hdr_cnt = header.nelts;
263
- hdtr.trailers = trailer.nelts ? (struct iovec *) trailer.elts: NULL;
264
- hdtr.trl_cnt = trailer.nelts;
158
+ hdtr.headers = header.count ? header.iovs : NULL;
159
+ hdtr.hdr_cnt = header.count;
160
+ hdtr.trailers = trailer.count ? trailer.iovs : NULL;
161
+ hdtr.trl_cnt = trailer.count;
265
162
 
266
163
  /*
267
164
  * the "nbytes bug" of the old sendfile() syscall:
268
- * http://www.freebsd.org/cgi/query-pr.cgi?pr=33771
165
+ * http://bugs.freebsd.org/33771
269
166
  */
270
167
 
271
168
  if (!ngx_freebsd_sendfile_nbytes_bug) {
272
- header_size = 0;
169
+ header.size = 0;
273
170
  }
274
171
 
275
172
  sent = 0;
276
173
 
277
174
  #if (NGX_HAVE_AIO_SENDFILE)
278
- flags = c->aio_sendfile ? SF_NODISKIO : 0;
175
+ aio = file->file->aio;
176
+ flags = (aio && aio->preload_handler) ? SF_NODISKIO : 0;
279
177
  #endif
280
178
 
281
179
  rc = sendfile(file->file->fd, c->fd, file->file_pos,
282
- file_size + header_size, &hdtr, &sent, flags);
180
+ file_size + header.size, &hdtr, &sent, flags);
283
181
 
284
182
  if (rc == -1) {
285
183
  err = ngx_errno;
@@ -295,7 +193,7 @@ ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
295
193
 
296
194
  #if (NGX_HAVE_AIO_SENDFILE)
297
195
  case NGX_EBUSY:
298
- c->busy_sendfile = file;
196
+ ebusy = 1;
299
197
  break;
300
198
  #endif
301
199
 
@@ -330,85 +228,58 @@ ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
330
228
 
331
229
  ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
332
230
  "sendfile: %d, @%O %O:%uz",
333
- rc, file->file_pos, sent, file_size + header_size);
231
+ rc, file->file_pos, sent, file_size + header.size);
334
232
 
335
233
  } else {
336
- rc = writev(c->fd, header.elts, header.nelts);
337
-
338
- ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
339
- "writev: %d of %uz", rc, header_size);
340
-
341
- if (rc == -1) {
342
- err = ngx_errno;
343
-
344
- switch (err) {
345
- case NGX_EAGAIN:
346
- break;
347
-
348
- case NGX_EINTR:
349
- eintr = 1;
350
- break;
234
+ n = ngx_writev(c, &header);
351
235
 
352
- default:
353
- wev->error = 1;
354
- ngx_connection_error(c, err, "writev() failed");
355
- return NGX_CHAIN_ERROR;
356
- }
357
-
358
- ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
359
- "writev() not ready");
236
+ if (n == NGX_ERROR) {
237
+ return NGX_CHAIN_ERROR;
360
238
  }
361
239
 
362
- sent = rc > 0 ? rc : 0;
363
- }
364
-
365
- if (send - prev_send == sent) {
366
- complete = 1;
240
+ sent = (n == NGX_AGAIN) ? 0 : n;
367
241
  }
368
242
 
369
243
  c->sent += sent;
370
244
 
371
- for ( /* void */ ; in; in = in->next) {
245
+ in = ngx_chain_update_sent(in, sent);
372
246
 
373
- if (ngx_buf_special(in->buf)) {
374
- continue;
375
- }
247
+ #if (NGX_HAVE_AIO_SENDFILE)
376
248
 
249
+ if (ebusy) {
377
250
  if (sent == 0) {
378
- break;
379
- }
251
+ c->busy_count++;
380
252
 
381
- size = ngx_buf_size(in->buf);
253
+ if (c->busy_count > 2) {
254
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
255
+ "sendfile(%V) returned busy again",
256
+ &file->file->name);
382
257
 
383
- if (sent >= size) {
384
- sent -= size;
258
+ c->busy_count = 0;
259
+ aio->preload_handler = NULL;
385
260
 
386
- if (ngx_buf_in_memory(in->buf)) {
387
- in->buf->pos = in->buf->last;
388
- }
389
-
390
- if (in->buf->in_file) {
391
- in->buf->file_pos = in->buf->file_last;
261
+ send = prev_send;
262
+ continue;
392
263
  }
393
264
 
394
- continue;
265
+ } else {
266
+ c->busy_count = 0;
395
267
  }
396
268
 
397
- if (ngx_buf_in_memory(in->buf)) {
398
- in->buf->pos += (size_t) sent;
399
- }
269
+ n = aio->preload_handler(file);
400
270
 
401
- if (in->buf->in_file) {
402
- in->buf->file_pos += sent;
271
+ if (n > 0) {
272
+ send = prev_send + sent;
273
+ continue;
403
274
  }
404
275
 
405
- break;
276
+ return in;
406
277
  }
407
278
 
408
- #if (NGX_HAVE_AIO_SENDFILE)
409
- if (c->busy_sendfile) {
410
- return in;
279
+ if (flags == SF_NODISKIO) {
280
+ c->busy_count = 0;
411
281
  }
282
+
412
283
  #endif
413
284
 
414
285
  if (eagain) {
@@ -425,10 +296,11 @@ ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
425
296
  }
426
297
 
427
298
  if (eintr) {
299
+ send = prev_send + sent;
428
300
  continue;
429
301
  }
430
302
 
431
- if (!complete) {
303
+ if (send - prev_send != sent) {
432
304
  wev->ready = 0;
433
305
  return in;
434
306
  }