nginxtra 1.8.1.12 → 1.10.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) 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 +363 -25
  6. data/vendor/nginx/CHANGES.ru +365 -21
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/conf +32 -0
  9. data/vendor/nginx/auto/cc/gcc +1 -1
  10. data/vendor/nginx/auto/cc/icc +2 -2
  11. data/vendor/nginx/auto/cc/msvc +29 -8
  12. data/vendor/nginx/auto/cc/name +2 -25
  13. data/vendor/nginx/auto/cc/sunc +3 -0
  14. data/vendor/nginx/auto/endianness +7 -2
  15. data/vendor/nginx/auto/install +60 -26
  16. data/vendor/nginx/auto/lib/conf +4 -4
  17. data/vendor/nginx/auto/lib/geoip/conf +6 -1
  18. data/vendor/nginx/auto/lib/libgd/conf +6 -1
  19. data/vendor/nginx/auto/lib/libxslt/conf +11 -2
  20. data/vendor/nginx/auto/lib/make +1 -1
  21. data/vendor/nginx/auto/lib/md5/conf +2 -2
  22. data/vendor/nginx/auto/lib/md5/make +2 -2
  23. data/vendor/nginx/auto/lib/openssl/conf +52 -3
  24. data/vendor/nginx/auto/lib/openssl/make +1 -1
  25. data/vendor/nginx/auto/lib/pcre/conf +2 -2
  26. data/vendor/nginx/auto/lib/pcre/make +2 -2
  27. data/vendor/nginx/auto/lib/perl/conf +6 -3
  28. data/vendor/nginx/auto/lib/perl/make +4 -1
  29. data/vendor/nginx/auto/lib/sha1/conf +2 -2
  30. data/vendor/nginx/auto/lib/sha1/make +2 -2
  31. data/vendor/nginx/auto/lib/zlib/conf +2 -2
  32. data/vendor/nginx/auto/lib/zlib/make +2 -2
  33. data/vendor/nginx/auto/make +281 -16
  34. data/vendor/nginx/auto/module +122 -0
  35. data/vendor/nginx/auto/modules +909 -178
  36. data/vendor/nginx/auto/options +81 -19
  37. data/vendor/nginx/auto/os/conf +9 -0
  38. data/vendor/nginx/auto/os/darwin +3 -0
  39. data/vendor/nginx/auto/os/freebsd +0 -20
  40. data/vendor/nginx/auto/os/linux +0 -12
  41. data/vendor/nginx/auto/os/win32 +5 -1
  42. data/vendor/nginx/auto/sources +11 -311
  43. data/vendor/nginx/auto/summary +1 -0
  44. data/vendor/nginx/auto/types/sizeof +5 -3
  45. data/vendor/nginx/auto/types/typedef +9 -4
  46. data/vendor/nginx/auto/types/uintptr_t +7 -2
  47. data/vendor/nginx/auto/unix +72 -12
  48. data/vendor/nginx/conf/fastcgi.conf +1 -0
  49. data/vendor/nginx/conf/fastcgi_params +1 -0
  50. data/vendor/nginx/conf/scgi_params +1 -0
  51. data/vendor/nginx/conf/uwsgi_params +1 -0
  52. data/vendor/nginx/configure +1 -1
  53. data/vendor/nginx/contrib/vim/syntax/nginx.vim +2 -2
  54. data/vendor/nginx/man/nginx.8 +6 -2
  55. data/vendor/nginx/src/core/nginx.c +281 -114
  56. data/vendor/nginx/src/core/nginx.h +2 -2
  57. data/vendor/nginx/src/core/ngx_conf_file.c +54 -13
  58. data/vendor/nginx/src/core/ngx_conf_file.h +8 -52
  59. data/vendor/nginx/src/core/ngx_config.h +0 -5
  60. data/vendor/nginx/src/core/ngx_connection.c +270 -37
  61. data/vendor/nginx/src/core/ngx_connection.h +35 -12
  62. data/vendor/nginx/src/core/ngx_core.h +4 -0
  63. data/vendor/nginx/src/core/ngx_crypt.c +2 -2
  64. data/vendor/nginx/src/core/ngx_cycle.c +72 -25
  65. data/vendor/nginx/src/core/ngx_cycle.h +28 -39
  66. data/vendor/nginx/src/core/ngx_file.c +14 -5
  67. data/vendor/nginx/src/core/ngx_file.h +2 -0
  68. data/vendor/nginx/src/core/ngx_hash.c +13 -1
  69. data/vendor/nginx/src/core/ngx_inet.c +20 -18
  70. data/vendor/nginx/src/core/ngx_log.c +12 -12
  71. data/vendor/nginx/src/core/ngx_log.h +13 -6
  72. data/vendor/nginx/src/core/ngx_module.c +360 -0
  73. data/vendor/nginx/src/core/ngx_module.h +307 -0
  74. data/vendor/nginx/src/core/ngx_open_file_cache.c +2 -2
  75. data/vendor/nginx/src/core/ngx_output_chain.c +8 -4
  76. data/vendor/nginx/src/core/ngx_palloc.c +42 -44
  77. data/vendor/nginx/src/{http/ngx_http_parse_time.c → core/ngx_parse_time.c} +2 -3
  78. data/vendor/nginx/src/core/ngx_parse_time.h +22 -0
  79. data/vendor/nginx/src/core/ngx_proxy_protocol.c +50 -1
  80. data/vendor/nginx/src/core/ngx_proxy_protocol.h +3 -1
  81. data/vendor/nginx/src/core/ngx_regex.c +1 -38
  82. data/vendor/nginx/src/core/ngx_resolver.c +1814 -320
  83. data/vendor/nginx/src/core/ngx_resolver.h +67 -10
  84. data/vendor/nginx/src/core/ngx_rwlock.c +120 -0
  85. data/vendor/nginx/src/core/ngx_rwlock.h +21 -0
  86. data/vendor/nginx/src/core/ngx_slab.c +6 -5
  87. data/vendor/nginx/src/core/ngx_string.c +1 -1
  88. data/vendor/nginx/src/core/ngx_syslog.c +11 -3
  89. data/vendor/nginx/src/core/ngx_syslog.h +2 -1
  90. data/vendor/nginx/src/core/ngx_thread_pool.c +4 -0
  91. data/vendor/nginx/src/core/ngx_times.c +2 -2
  92. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +3 -1
  93. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +5 -2
  94. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +5 -5
  95. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +15 -8
  96. data/vendor/nginx/src/event/modules/ngx_poll_module.c +0 -10
  97. data/vendor/nginx/src/event/modules/ngx_select_module.c +0 -10
  98. data/vendor/nginx/src/event/ngx_event.c +60 -103
  99. data/vendor/nginx/src/event/ngx_event.h +22 -26
  100. data/vendor/nginx/src/event/ngx_event_accept.c +414 -88
  101. data/vendor/nginx/src/event/ngx_event_connect.c +27 -18
  102. data/vendor/nginx/src/event/ngx_event_connect.h +1 -0
  103. data/vendor/nginx/src/event/ngx_event_openssl.c +65 -25
  104. data/vendor/nginx/src/event/ngx_event_openssl.h +17 -0
  105. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +73 -7
  106. data/vendor/nginx/src/event/ngx_event_pipe.c +85 -27
  107. data/vendor/nginx/src/event/ngx_event_pipe.h +10 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_auth_basic_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_auth_request_module.c +2 -2
  110. data/vendor/nginx/src/http/modules/ngx_http_chunked_filter_module.c +2 -2
  111. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +6 -6
  112. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +17 -11
  113. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +2 -2
  114. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +9 -9
  115. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +2 -2
  116. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +2 -2
  117. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +0 -7
  118. data/vendor/nginx/src/http/modules/ngx_http_map_module.c +6 -6
  119. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +2 -1
  120. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +13 -13
  121. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +2 -2
  122. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +26 -21
  123. data/vendor/nginx/src/http/modules/ngx_http_random_index_module.c +1 -1
  124. data/vendor/nginx/src/http/modules/ngx_http_range_filter_module.c +26 -8
  125. data/vendor/nginx/src/http/modules/ngx_http_realip_module.c +73 -3
  126. data/vendor/nginx/src/http/modules/ngx_http_referer_module.c +1 -1
  127. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +6 -6
  128. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +5 -3
  129. data/vendor/nginx/src/http/modules/ngx_http_slice_filter_module.c +526 -0
  130. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +7 -7
  131. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +19 -16
  132. data/vendor/nginx/src/http/modules/ngx_http_static_module.c +1 -1
  133. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +1 -1
  134. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +373 -173
  135. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +72 -46
  136. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +18 -30
  137. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +50 -39
  138. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +38 -129
  139. data/vendor/nginx/src/http/modules/ngx_http_upstream_zone_module.c +246 -0
  140. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +6 -5
  141. data/vendor/nginx/src/http/modules/perl/nginx.xs +9 -9
  142. data/vendor/nginx/src/http/ngx_http.c +46 -43
  143. data/vendor/nginx/src/http/ngx_http.h +4 -9
  144. data/vendor/nginx/src/http/ngx_http_cache.h +4 -0
  145. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +13 -5
  146. data/vendor/nginx/src/http/ngx_http_core_module.c +92 -91
  147. data/vendor/nginx/src/http/ngx_http_core_module.h +12 -8
  148. data/vendor/nginx/src/http/ngx_http_file_cache.c +61 -10
  149. data/vendor/nginx/src/http/ngx_http_request.c +37 -50
  150. data/vendor/nginx/src/http/ngx_http_request.h +10 -15
  151. data/vendor/nginx/src/http/ngx_http_request_body.c +64 -88
  152. data/vendor/nginx/src/http/ngx_http_script.c +3 -3
  153. data/vendor/nginx/src/http/ngx_http_special_response.c +1 -4
  154. data/vendor/nginx/src/http/ngx_http_upstream.c +245 -109
  155. data/vendor/nginx/src/http/ngx_http_upstream.h +11 -5
  156. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +212 -65
  157. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +66 -5
  158. data/vendor/nginx/src/http/ngx_http_variables.c +28 -15
  159. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +1 -1
  160. data/vendor/nginx/src/http/v2/ngx_http_v2.c +4349 -0
  161. data/vendor/nginx/src/http/v2/ngx_http_v2.h +337 -0
  162. data/vendor/nginx/src/http/v2/ngx_http_v2_filter_module.c +1391 -0
  163. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_decode.c +2714 -0
  164. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_encode.c +254 -0
  165. data/vendor/nginx/src/http/v2/ngx_http_v2_module.c +469 -0
  166. data/vendor/nginx/src/http/{ngx_http_spdy_module.h → v2/ngx_http_v2_module.h} +10 -9
  167. data/vendor/nginx/src/http/v2/ngx_http_v2_table.c +349 -0
  168. data/vendor/nginx/src/mail/ngx_mail.c +49 -82
  169. data/vendor/nginx/src/mail/ngx_mail.h +16 -23
  170. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +1 -1
  171. data/vendor/nginx/src/mail/ngx_mail_core_module.c +60 -34
  172. data/vendor/nginx/src/mail/ngx_mail_handler.c +17 -12
  173. data/vendor/nginx/src/mail/ngx_mail_proxy_module.c +1 -14
  174. data/vendor/nginx/src/mail/ngx_mail_smtp_handler.c +1 -1
  175. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +5 -5
  176. data/vendor/nginx/src/os/unix/ngx_atomic.h +10 -10
  177. data/vendor/nginx/src/os/unix/ngx_channel.h +4 -4
  178. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +2 -0
  179. data/vendor/nginx/src/os/unix/ngx_darwin_init.c +1 -0
  180. data/vendor/nginx/src/os/unix/ngx_dlopen.c +28 -0
  181. data/vendor/nginx/src/os/unix/ngx_dlopen.h +31 -0
  182. data/vendor/nginx/src/os/unix/ngx_errno.h +1 -0
  183. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +1 -1
  184. data/vendor/nginx/src/os/unix/ngx_files.c +313 -80
  185. data/vendor/nginx/src/os/unix/ngx_files.h +5 -2
  186. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +3 -1
  187. data/vendor/nginx/src/os/unix/ngx_freebsd_init.c +1 -0
  188. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +13 -0
  189. data/vendor/nginx/src/os/unix/ngx_linux.h +0 -2
  190. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +1 -1
  191. data/vendor/nginx/src/os/unix/ngx_linux_config.h +2 -6
  192. data/vendor/nginx/src/os/unix/ngx_linux_init.c +1 -33
  193. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +55 -12
  194. data/vendor/nginx/src/os/unix/ngx_os.h +3 -9
  195. data/vendor/nginx/src/os/unix/ngx_posix_config.h +14 -1
  196. data/vendor/nginx/src/os/unix/ngx_posix_init.c +2 -1
  197. data/vendor/nginx/src/os/unix/ngx_process.c +1 -1
  198. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +25 -51
  199. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +1 -0
  200. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +24 -28
  201. data/vendor/nginx/src/os/unix/ngx_recv.c +30 -79
  202. data/vendor/nginx/src/os/unix/ngx_send.c +1 -1
  203. data/vendor/nginx/src/os/unix/ngx_setaffinity.c +14 -30
  204. data/vendor/nginx/src/os/unix/ngx_setaffinity.h +15 -1
  205. data/vendor/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  206. data/vendor/nginx/src/os/unix/ngx_solaris_init.c +1 -0
  207. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +23 -0
  208. data/vendor/nginx/src/os/unix/ngx_sunpro_amd64.il +3 -3
  209. data/vendor/nginx/src/os/unix/ngx_sunpro_x86.il +3 -3
  210. data/vendor/nginx/src/os/unix/ngx_udp_recv.c +5 -48
  211. data/vendor/nginx/src/os/unix/ngx_udp_send.c +56 -0
  212. data/vendor/nginx/src/stream/ngx_stream.c +564 -0
  213. data/vendor/nginx/src/stream/ngx_stream.h +212 -0
  214. data/vendor/nginx/src/stream/ngx_stream_access_module.c +451 -0
  215. data/vendor/nginx/src/stream/ngx_stream_core_module.c +562 -0
  216. data/vendor/nginx/src/stream/ngx_stream_handler.c +344 -0
  217. data/vendor/nginx/src/stream/ngx_stream_limit_conn_module.c +632 -0
  218. data/vendor/nginx/src/stream/ngx_stream_proxy_module.c +1674 -0
  219. data/vendor/nginx/src/stream/ngx_stream_ssl_module.c +460 -0
  220. data/vendor/nginx/src/stream/ngx_stream_ssl_module.h +49 -0
  221. data/vendor/nginx/src/stream/ngx_stream_upstream.c +464 -0
  222. data/vendor/nginx/src/stream/ngx_stream_upstream.h +107 -0
  223. data/vendor/nginx/src/stream/ngx_stream_upstream_hash_module.c +656 -0
  224. data/vendor/nginx/src/stream/ngx_stream_upstream_least_conn_module.c +307 -0
  225. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.c +702 -0
  226. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.h +139 -0
  227. data/vendor/nginx/src/stream/ngx_stream_upstream_zone_module.c +242 -0
  228. metadata +39 -15
  229. data/vendor/nginx/src/event/modules/ngx_aio_module.c +0 -171
  230. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +0 -735
  231. data/vendor/nginx/src/http/ngx_http_spdy.c +0 -3701
  232. data/vendor/nginx/src/http/ngx_http_spdy.h +0 -261
  233. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +0 -1222
  234. data/vendor/nginx/src/http/ngx_http_spdy_module.c +0 -408
  235. data/vendor/nginx/src/os/unix/ngx_aio_read.c +0 -109
  236. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +0 -78
  237. data/vendor/nginx/src/os/unix/ngx_aio_write.c +0 -109
  238. data/vendor/nginx/src/os/unix/ngx_aio_write_chain.c +0 -100
@@ -15,10 +15,10 @@
15
15
 
16
16
 
17
17
  typedef struct {
18
- ngx_uint_t command;
19
- ngx_pid_t pid;
20
- ngx_int_t slot;
21
- ngx_fd_t fd;
18
+ ngx_uint_t command;
19
+ ngx_pid_t pid;
20
+ ngx_int_t slot;
21
+ ngx_fd_t fd;
22
22
  } ngx_channel_t;
23
23
 
24
24
 
@@ -48,6 +48,8 @@
48
48
  #include <sys/sysctl.h>
49
49
  #include <xlocale.h>
50
50
 
51
+ #include <dlfcn.h>
52
+
51
53
 
52
54
  #ifndef IOV_MAX
53
55
  #define IOV_MAX 64
@@ -23,6 +23,7 @@ static ngx_os_io_t ngx_darwin_io = {
23
23
  ngx_readv_chain,
24
24
  ngx_udp_unix_recv,
25
25
  ngx_unix_send,
26
+ ngx_udp_unix_send,
26
27
  #if (NGX_HAVE_SENDFILE)
27
28
  ngx_darwin_sendfile_chain,
28
29
  NGX_IO_SENDFILE
@@ -0,0 +1,28 @@
1
+
2
+ /*
3
+ * Copyright (C) Maxim Dounin
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #include <ngx_config.h>
9
+ #include <ngx_core.h>
10
+
11
+
12
+ #if (NGX_HAVE_DLOPEN)
13
+
14
+ char *
15
+ ngx_dlerror(void)
16
+ {
17
+ char *err;
18
+
19
+ err = (char *) dlerror();
20
+
21
+ if (err == NULL) {
22
+ return "";
23
+ }
24
+
25
+ return err;
26
+ }
27
+
28
+ #endif
@@ -0,0 +1,31 @@
1
+
2
+ /*
3
+ * Copyright (C) Maxim Dounin
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #ifndef _NGX_DLOPEN_H_INCLUDED_
9
+ #define _NGX_DLOPEN_H_INCLUDED_
10
+
11
+
12
+ #include <ngx_config.h>
13
+ #include <ngx_core.h>
14
+
15
+
16
+ #define ngx_dlopen(path) dlopen((char *) path, RTLD_NOW | RTLD_GLOBAL)
17
+ #define ngx_dlopen_n "dlopen()"
18
+
19
+ #define ngx_dlsym(handle, symbol) dlsym(handle, symbol)
20
+ #define ngx_dlsym_n "dlsym()"
21
+
22
+ #define ngx_dlclose(handle) dlclose(handle)
23
+ #define ngx_dlclose_n "dlclose()"
24
+
25
+
26
+ #if (NGX_HAVE_DLOPEN)
27
+ char *ngx_dlerror(void);
28
+ #endif
29
+
30
+
31
+ #endif /* _NGX_DLOPEN_H_INCLUDED_ */
@@ -25,6 +25,7 @@ typedef int ngx_err_t;
25
25
  #define NGX_EACCES EACCES
26
26
  #define NGX_EBUSY EBUSY
27
27
  #define NGX_EEXIST EEXIST
28
+ #define NGX_EEXIST_FILE EEXIST
28
29
  #define NGX_EXDEV EXDEV
29
30
  #define NGX_ENOTDIR ENOTDIR
30
31
  #define NGX_EISDIR EISDIR
@@ -84,7 +84,7 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
84
84
  }
85
85
 
86
86
  ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
87
- "aio complete:%d @%O:%z %V",
87
+ "aio complete:%d @%O:%uz %V",
88
88
  ev->complete, offset, size, &file->name);
89
89
 
90
90
  if (ev->complete) {
@@ -12,8 +12,13 @@
12
12
  #if (NGX_THREADS)
13
13
  #include <ngx_thread_pool.h>
14
14
  static void ngx_thread_read_handler(void *data, ngx_log_t *log);
15
+ static void ngx_thread_write_chain_to_file_handler(void *data, ngx_log_t *log);
15
16
  #endif
16
17
 
18
+ static ngx_chain_t *ngx_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *cl);
19
+ static ssize_t ngx_writev_file(ngx_file_t *file, ngx_iovec_t *vec,
20
+ off_t offset);
21
+
17
22
 
18
23
  #if (NGX_HAVE_FILE_AIO)
19
24
 
@@ -73,38 +78,39 @@ ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
73
78
  #if (NGX_THREADS)
74
79
 
75
80
  typedef struct {
76
- ngx_fd_t fd;
77
- u_char *buf;
78
- size_t size;
79
- off_t offset;
81
+ ngx_fd_t fd;
82
+ ngx_uint_t write; /* unsigned write:1; */
83
+
84
+ u_char *buf;
85
+ size_t size;
86
+ ngx_chain_t *chain;
87
+ off_t offset;
80
88
 
81
- size_t read;
82
- ngx_err_t err;
83
- } ngx_thread_read_ctx_t;
89
+ size_t nbytes;
90
+ ngx_err_t err;
91
+ } ngx_thread_file_ctx_t;
84
92
 
85
93
 
86
94
  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)
95
+ ngx_thread_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
96
+ ngx_pool_t *pool)
89
97
  {
90
98
  ngx_thread_task_t *task;
91
- ngx_thread_read_ctx_t *ctx;
99
+ ngx_thread_file_ctx_t *ctx;
92
100
 
93
101
  ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
94
102
  "thread read: %d, %p, %uz, %O",
95
103
  file->fd, buf, size, offset);
96
104
 
97
- task = *taskp;
105
+ task = file->thread_task;
98
106
 
99
107
  if (task == NULL) {
100
- task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_read_ctx_t));
108
+ task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_file_ctx_t));
101
109
  if (task == NULL) {
102
110
  return NGX_ERROR;
103
111
  }
104
112
 
105
- task->handler = ngx_thread_read_handler;
106
-
107
- *taskp = task;
113
+ file->thread_task = task;
108
114
  }
109
115
 
110
116
  ctx = task->ctx;
@@ -112,15 +118,25 @@ ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file, u_char *buf,
112
118
  if (task->event.complete) {
113
119
  task->event.complete = 0;
114
120
 
121
+ if (ctx->write) {
122
+ ngx_log_error(NGX_LOG_ALERT, file->log, 0,
123
+ "invalid thread call, read instead of write");
124
+ return NGX_ERROR;
125
+ }
126
+
115
127
  if (ctx->err) {
116
128
  ngx_log_error(NGX_LOG_CRIT, file->log, ctx->err,
117
129
  "pread() \"%s\" failed", file->name.data);
118
130
  return NGX_ERROR;
119
131
  }
120
132
 
121
- return ctx->read;
133
+ return ctx->nbytes;
122
134
  }
123
135
 
136
+ task->handler = ngx_thread_read_handler;
137
+
138
+ ctx->write = 0;
139
+
124
140
  ctx->fd = file->fd;
125
141
  ctx->buf = buf;
126
142
  ctx->size = size;
@@ -139,7 +155,7 @@ ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file, u_char *buf,
139
155
  static void
140
156
  ngx_thread_read_handler(void *data, ngx_log_t *log)
141
157
  {
142
- ngx_thread_read_ctx_t *ctx = data;
158
+ ngx_thread_file_ctx_t *ctx = data;
143
159
 
144
160
  ssize_t n;
145
161
 
@@ -151,7 +167,7 @@ ngx_thread_read_handler(void *data, ngx_log_t *log)
151
167
  ctx->err = ngx_errno;
152
168
 
153
169
  } else {
154
- ctx->read = n;
170
+ ctx->nbytes = n;
155
171
  ctx->err = 0;
156
172
  }
157
173
 
@@ -160,7 +176,7 @@ ngx_thread_read_handler(void *data, ngx_log_t *log)
160
176
  #endif
161
177
 
162
178
  ngx_log_debug4(NGX_LOG_DEBUG_CORE, log, 0,
163
- "pread: %z (err: %i) of %uz @%O",
179
+ "pread: %z (err: %d) of %uz @%O",
164
180
  n, ctx->err, ctx->size, ctx->offset);
165
181
  }
166
182
 
@@ -176,7 +192,8 @@ ngx_thread_read_handler(void *data, ngx_log_t *log)
176
192
  ssize_t
177
193
  ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
178
194
  {
179
- ssize_t n, written;
195
+ ssize_t n, written;
196
+ ngx_err_t err;
180
197
 
181
198
  ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
182
199
  "write: %d, %p, %uz, %O", file->fd, buf, size, offset);
@@ -189,7 +206,15 @@ ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
189
206
  n = pwrite(file->fd, buf + written, size, offset);
190
207
 
191
208
  if (n == -1) {
192
- ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
209
+ err = ngx_errno;
210
+
211
+ if (err == NGX_EINTR) {
212
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
213
+ "pwrite() was interrupted");
214
+ continue;
215
+ }
216
+
217
+ ngx_log_error(NGX_LOG_CRIT, file->log, err,
193
218
  "pwrite() \"%s\" failed", file->name.data);
194
219
  return NGX_ERROR;
195
220
  }
@@ -221,11 +246,20 @@ ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
221
246
  n = write(file->fd, buf + written, size);
222
247
 
223
248
  if (n == -1) {
224
- ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
249
+ err = ngx_errno;
250
+
251
+ if (err == NGX_EINTR) {
252
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
253
+ "write() was interrupted");
254
+ continue;
255
+ }
256
+
257
+ ngx_log_error(NGX_LOG_CRIT, file->log, err,
225
258
  "write() \"%s\" failed", file->name.data);
226
259
  return NGX_ERROR;
227
260
  }
228
261
 
262
+ file->sys_offset += n;
229
263
  file->offset += n;
230
264
  written += n;
231
265
 
@@ -255,17 +289,13 @@ ngx_open_tempfile(u_char *name, ngx_uint_t persistent, ngx_uint_t access)
255
289
  }
256
290
 
257
291
 
258
- #define NGX_IOVS 8
259
-
260
292
  ssize_t
261
293
  ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
262
294
  ngx_pool_t *pool)
263
295
  {
264
- u_char *prev;
265
- size_t size;
266
296
  ssize_t total, n;
267
- ngx_array_t vec;
268
- struct iovec *iov, iovs[NGX_IOVS];
297
+ ngx_iovec_t vec;
298
+ struct iovec iovs[NGX_IOVS_PREALLOCATE];
269
299
 
270
300
  /* use pwrite() if there is the only buf in a chain */
271
301
 
@@ -277,92 +307,295 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
277
307
 
278
308
  total = 0;
279
309
 
280
- vec.elts = iovs;
281
- vec.size = sizeof(struct iovec);
282
- vec.nalloc = NGX_IOVS;
283
- vec.pool = pool;
310
+ vec.iovs = iovs;
311
+ vec.nalloc = NGX_IOVS_PREALLOCATE;
284
312
 
285
313
  do {
286
- prev = NULL;
287
- iov = NULL;
288
- size = 0;
289
-
290
- vec.nelts = 0;
291
-
292
314
  /* create the iovec and coalesce the neighbouring bufs */
315
+ cl = ngx_chain_to_iovec(&vec, cl);
293
316
 
294
- while (cl && vec.nelts < IOV_MAX) {
295
- if (prev == cl->buf->pos) {
296
- iov->iov_len += cl->buf->last - cl->buf->pos;
317
+ /* use pwrite() if there is the only iovec buffer */
297
318
 
298
- } else {
299
- iov = ngx_array_push(&vec);
300
- if (iov == NULL) {
301
- return NGX_ERROR;
302
- }
319
+ if (vec.count == 1) {
320
+ n = ngx_write_file(file, (u_char *) iovs[0].iov_base,
321
+ iovs[0].iov_len, offset);
303
322
 
304
- iov->iov_base = (void *) cl->buf->pos;
305
- iov->iov_len = cl->buf->last - cl->buf->pos;
323
+ if (n == NGX_ERROR) {
324
+ return n;
306
325
  }
307
326
 
308
- size += cl->buf->last - cl->buf->pos;
309
- prev = cl->buf->last;
310
- cl = cl->next;
327
+ return total + n;
311
328
  }
312
329
 
313
- /* use pwrite() if there is the only iovec buffer */
330
+ n = ngx_writev_file(file, &vec, offset);
314
331
 
315
- if (vec.nelts == 1) {
316
- iov = vec.elts;
332
+ if (n == NGX_ERROR) {
333
+ return n;
334
+ }
317
335
 
318
- n = ngx_write_file(file, (u_char *) iov[0].iov_base,
319
- iov[0].iov_len, offset);
336
+ offset += n;
337
+ total += n;
320
338
 
321
- if (n == NGX_ERROR) {
322
- return n;
323
- }
339
+ } while (cl);
324
340
 
325
- return total + n;
341
+ return total;
342
+ }
343
+
344
+
345
+ static ngx_chain_t *
346
+ ngx_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *cl)
347
+ {
348
+ size_t total, size;
349
+ u_char *prev;
350
+ ngx_uint_t n;
351
+ struct iovec *iov;
352
+
353
+ iov = NULL;
354
+ prev = NULL;
355
+ total = 0;
356
+ n = 0;
357
+
358
+ for ( /* void */ ; cl; cl = cl->next) {
359
+
360
+ if (ngx_buf_special(cl->buf)) {
361
+ continue;
326
362
  }
327
363
 
328
- if (file->sys_offset != offset) {
329
- if (lseek(file->fd, offset, SEEK_SET) == -1) {
330
- ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
331
- "lseek() \"%s\" failed", file->name.data);
332
- return NGX_ERROR;
364
+ size = cl->buf->last - cl->buf->pos;
365
+
366
+ if (prev == cl->buf->pos) {
367
+ iov->iov_len += size;
368
+
369
+ } else {
370
+ if (n == vec->nalloc) {
371
+ break;
333
372
  }
334
373
 
335
- file->sys_offset = offset;
374
+ iov = &vec->iovs[n++];
375
+
376
+ iov->iov_base = (void *) cl->buf->pos;
377
+ iov->iov_len = size;
336
378
  }
337
379
 
338
- n = writev(file->fd, vec.elts, vec.nelts);
380
+ prev = cl->buf->pos + size;
381
+ total += size;
382
+ }
339
383
 
340
- if (n == -1) {
384
+ vec->count = n;
385
+ vec->size = total;
386
+
387
+ return cl;
388
+ }
389
+
390
+
391
+ static ssize_t
392
+ ngx_writev_file(ngx_file_t *file, ngx_iovec_t *vec, off_t offset)
393
+ {
394
+ ssize_t n;
395
+ ngx_err_t err;
396
+
397
+ ngx_log_debug3(NGX_LOG_DEBUG_CORE, file->log, 0,
398
+ "writev: %d, %uz, %O", file->fd, vec->size, offset);
399
+
400
+ #if (NGX_HAVE_PWRITEV)
401
+
402
+ eintr:
403
+
404
+ n = pwritev(file->fd, vec->iovs, vec->count, offset);
405
+
406
+ if (n == -1) {
407
+ err = ngx_errno;
408
+
409
+ if (err == NGX_EINTR) {
410
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
411
+ "pwritev() was interrupted");
412
+ goto eintr;
413
+ }
414
+
415
+ ngx_log_error(NGX_LOG_CRIT, file->log, err,
416
+ "pwritev() \"%s\" failed", file->name.data);
417
+ return NGX_ERROR;
418
+ }
419
+
420
+ if ((size_t) n != vec->size) {
421
+ ngx_log_error(NGX_LOG_CRIT, file->log, 0,
422
+ "pwritev() \"%s\" has written only %z of %uz",
423
+ file->name.data, n, vec->size);
424
+ return NGX_ERROR;
425
+ }
426
+
427
+ #else
428
+
429
+ if (file->sys_offset != offset) {
430
+ if (lseek(file->fd, offset, SEEK_SET) == -1) {
341
431
  ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
342
- "writev() \"%s\" failed", file->name.data);
432
+ "lseek() \"%s\" failed", file->name.data);
343
433
  return NGX_ERROR;
344
434
  }
345
435
 
346
- if ((size_t) n != size) {
347
- ngx_log_error(NGX_LOG_CRIT, file->log, 0,
348
- "writev() \"%s\" has written only %z of %uz",
349
- file->name.data, n, size);
436
+ file->sys_offset = offset;
437
+ }
438
+
439
+ eintr:
440
+
441
+ n = writev(file->fd, vec->iovs, vec->count);
442
+
443
+ if (n == -1) {
444
+ err = ngx_errno;
445
+
446
+ if (err == NGX_EINTR) {
447
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
448
+ "writev() was interrupted");
449
+ goto eintr;
450
+ }
451
+
452
+ ngx_log_error(NGX_LOG_CRIT, file->log, err,
453
+ "writev() \"%s\" failed", file->name.data);
454
+ return NGX_ERROR;
455
+ }
456
+
457
+ if ((size_t) n != vec->size) {
458
+ ngx_log_error(NGX_LOG_CRIT, file->log, 0,
459
+ "writev() \"%s\" has written only %z of %uz",
460
+ file->name.data, n, vec->size);
461
+ return NGX_ERROR;
462
+ }
463
+
464
+ file->sys_offset += n;
465
+
466
+ #endif
467
+
468
+ file->offset += n;
469
+
470
+ return n;
471
+ }
472
+
473
+
474
+ #if (NGX_THREADS)
475
+
476
+ ssize_t
477
+ ngx_thread_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
478
+ ngx_pool_t *pool)
479
+ {
480
+ ngx_thread_task_t *task;
481
+ ngx_thread_file_ctx_t *ctx;
482
+
483
+ ngx_log_debug3(NGX_LOG_DEBUG_CORE, file->log, 0,
484
+ "thread write chain: %d, %p, %O",
485
+ file->fd, cl, offset);
486
+
487
+ task = file->thread_task;
488
+
489
+ if (task == NULL) {
490
+ task = ngx_thread_task_alloc(pool,
491
+ sizeof(ngx_thread_file_ctx_t));
492
+ if (task == NULL) {
350
493
  return NGX_ERROR;
351
494
  }
352
495
 
353
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
354
- "writev: %d, %z", file->fd, n);
496
+ file->thread_task = task;
497
+ }
355
498
 
356
- file->sys_offset += n;
357
- file->offset += n;
358
- offset += n;
359
- total += n;
499
+ ctx = task->ctx;
500
+
501
+ if (task->event.complete) {
502
+ task->event.complete = 0;
503
+
504
+ if (!ctx->write) {
505
+ ngx_log_error(NGX_LOG_ALERT, file->log, 0,
506
+ "invalid thread call, write instead of read");
507
+ return NGX_ERROR;
508
+ }
509
+
510
+ if (ctx->err || ctx->nbytes == 0) {
511
+ ngx_log_error(NGX_LOG_CRIT, file->log, ctx->err,
512
+ "pwritev() \"%s\" failed", file->name.data);
513
+ return NGX_ERROR;
514
+ }
515
+
516
+ file->offset += ctx->nbytes;
517
+ return ctx->nbytes;
518
+ }
519
+
520
+ task->handler = ngx_thread_write_chain_to_file_handler;
521
+
522
+ ctx->write = 1;
523
+
524
+ ctx->fd = file->fd;
525
+ ctx->chain = cl;
526
+ ctx->offset = offset;
527
+
528
+ if (file->thread_handler(task, file) != NGX_OK) {
529
+ return NGX_ERROR;
530
+ }
531
+
532
+ return NGX_AGAIN;
533
+ }
534
+
535
+
536
+ static void
537
+ ngx_thread_write_chain_to_file_handler(void *data, ngx_log_t *log)
538
+ {
539
+ ngx_thread_file_ctx_t *ctx = data;
540
+
541
+ #if (NGX_HAVE_PWRITEV)
542
+
543
+ off_t offset;
544
+ ssize_t n;
545
+ ngx_err_t err;
546
+ ngx_chain_t *cl;
547
+ ngx_iovec_t vec;
548
+ struct iovec iovs[NGX_IOVS_PREALLOCATE];
549
+
550
+ vec.iovs = iovs;
551
+ vec.nalloc = NGX_IOVS_PREALLOCATE;
552
+
553
+ cl = ctx->chain;
554
+ offset = ctx->offset;
555
+
556
+ ctx->nbytes = 0;
557
+ ctx->err = 0;
360
558
 
559
+ do {
560
+ /* create the iovec and coalesce the neighbouring bufs */
561
+ cl = ngx_chain_to_iovec(&vec, cl);
562
+
563
+ eintr:
564
+
565
+ n = pwritev(ctx->fd, iovs, vec.count, offset);
566
+
567
+ if (n == -1) {
568
+ err = ngx_errno;
569
+
570
+ if (err == NGX_EINTR) {
571
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, err,
572
+ "pwritev() was interrupted");
573
+ goto eintr;
574
+ }
575
+
576
+ ctx->err = err;
577
+ return;
578
+ }
579
+
580
+ if ((size_t) n != vec.size) {
581
+ ctx->nbytes = 0;
582
+ return;
583
+ }
584
+
585
+ ctx->nbytes += n;
586
+ offset += n;
361
587
  } while (cl);
362
588
 
363
- return total;
589
+ #else
590
+
591
+ ctx->err = NGX_ENOSYS;
592
+ return;
593
+
594
+ #endif
364
595
  }
365
596
 
597
+ #endif /* NGX_THREADS */
598
+
366
599
 
367
600
  ngx_int_t
368
601
  ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s)