comparison src/http/ngx_http_copy_filter_module.c @ 3071:ffc270f696ed

retry aio sendfile if data are ready
author Igor Sysoev <igor@sysoev.ru>
date Mon, 31 Aug 2009 14:00:16 +0000
parents 6fb94acd3a09
children 2f35eeea86c2
comparison
equal deleted inserted replaced
3070:6fb94acd3a09 3071:ffc270f696ed
131 #endif 131 #endif
132 132
133 r->request_output = 1; 133 r->request_output = 1;
134 } 134 }
135 135
136 rc = ngx_output_chain(ctx, in); 136 for ( ;; ) {
137 137 rc = ngx_output_chain(ctx, in);
138 if (ctx->in == NULL) { 138
139 r->buffered &= ~NGX_HTTP_COPY_BUFFERED; 139 if (ctx->in == NULL) {
140 140 r->buffered &= ~NGX_HTTP_COPY_BUFFERED;
141 } else { 141
142 r->buffered |= NGX_HTTP_COPY_BUFFERED; 142 } else {
143 } 143 r->buffered |= NGX_HTTP_COPY_BUFFERED;
144 144 }
145 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, 145
146 "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args); 146 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
147 "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
147 148
148 #if (NGX_HAVE_FILE_AIO && NGX_HAVE_AIO_SENDFILE) 149 #if (NGX_HAVE_FILE_AIO && NGX_HAVE_AIO_SENDFILE)
149 150
150 if (c->busy_sendfile) { 151 if (c->busy_sendfile) {
151 off_t offset; 152 ssize_t n;
152 ngx_file_t *file; 153 off_t offset;
153 ngx_http_ephemeral_t *e; 154 ngx_file_t *file;
154 155 ngx_http_ephemeral_t *e;
155 file = c->busy_sendfile->file; 156
156 offset = c->busy_sendfile->file_pos; 157 file = c->busy_sendfile->file;
157 158 offset = c->busy_sendfile->file_pos;
158 if (file->aio) { 159
159 c->aio_sendfile = (offset != file->aio->last_offset); 160 if (file->aio) {
160 file->aio->last_offset = offset; 161 c->aio_sendfile = (offset != file->aio->last_offset);
161 162 file->aio->last_offset = offset;
162 if (c->aio_sendfile == 0) { 163
163 ngx_log_error(NGX_LOG_ALERT, c->log, 0, 164 if (c->aio_sendfile == 0) {
164 "sendfile(%V) returned busy again", &file->name); 165 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
166 "sendfile(%V) returned busy again",
167 &file->name);
168 }
165 } 169 }
166 } 170
167 171 c->busy_sendfile = NULL;
168 c->busy_sendfile = NULL; 172 e = (ngx_http_ephemeral_t *) &r->uri_start;
169 e = (ngx_http_ephemeral_t *) &r->uri_start; 173
170 174 n = ngx_file_aio_read(file, e->preload, 4, offset, r->pool);
171 (void) ngx_file_aio_read(file, e->preload, 4, offset, r->pool); 175
172 176 if (n > 0) {
173 if (file->aio) { 177 continue;
174 file->aio->data = r; 178 }
175 file->aio->handler = ngx_http_copy_aio_sendfile_event_handler; 179
176 180 rc = n;
177 r->main->blocked++; 181
178 r->aio = 1; 182 if (file->aio) {
179 } 183 file->aio->data = r;
180 } 184 file->aio->handler = ngx_http_copy_aio_sendfile_event_handler;
181 185
182 #endif 186 r->main->blocked++;
183 187 r->aio = 1;
184 return rc; 188 }
189 }
190 #endif
191
192 return rc;
193 }
185 } 194 }
186 195
187 196
188 #if (NGX_HAVE_FILE_AIO) 197 #if (NGX_HAVE_FILE_AIO)
189 198