diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c index 939c5c07e..38bf7c057 100644 --- a/src/event/modules/ngx_aio_module.c +++ b/src/event/modules/ngx_aio_module.c @@ -3,9 +3,11 @@ int ngx_posix_aio_process_events(ngx_log_t *log) { unmask signal - listen via signal; + listen via SIGIO; - aio_suspend()/aiowait()/aio_waitcomplete(); + /* BUG: SIGIO can be delivered before aio_*() */ + + aio_suspend()/aiowait()/aio_waitcomplete() with timeout mask signal @@ -20,7 +22,7 @@ int ngx_posix_aio_process_events(ngx_log_t *log) { unmask signal - /* BUG: signal can be delivered before select() */ + /* BUG: AIO signal can be delivered before select() */ select(listen); diff --git a/src/http/ngx_http_filter.c b/src/http/ngx_http_filter.c index 5eb6b4597..abb91de50 100644 --- a/src/http/ngx_http_filter.c +++ b/src/http/ngx_http_filter.c @@ -209,7 +209,12 @@ int ngx_http_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src, ngx_log_t *log) if (n == NGX_ERROR) { ngx_log_error(NGX_LOG_ERR, log, ngx_errno, ngx_read_file_n " failed for client"); - return NGX_ERROR; + return n; + +#if (NGX_FILE_AIO) + } else if (n == NGX_AGAIN) { + return n; +#endif } else { ngx_assert((n == size), /* void */ ; , log, @@ -229,19 +234,3 @@ int ngx_http_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src, ngx_log_t *log) return NGX_OK; } - - - - - - /* if no hunk is passed and there is no our hunk - or our hunk is still busy then call next filter */ - if (hunk == NULL - && (ctx->hunk == NULL - || ((ctx->hunk != NULL) - && (ctx->hunk->pos.mem < ctx->hunk->last.mem)) - ) - ) - ctx->next_filter(r, NULL); - } -} diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h index 2649fe9b4..dd66db29d 100644 --- a/src/os/unix/ngx_errno.h +++ b/src/os/unix/ngx_errno.h @@ -12,8 +12,9 @@ typedef int ngx_err_t; #define NGX_EAGAIN EWOULDBLOCK #define NGX_EADDRINUSE EADDRINUSE -#define ngx_errno errno -#define ngx_socket_errno errno +#define ngx_errno errno +#define ngx_socket_errno errno +#define ngx_set_socket_errno(err) errno = err #define ngx_strerror_r(err, errstr, size) \ ngx_cpystrn(errstr, strerror(err), size) - (errstr) diff --git a/src/os/unix/ngx_file.c b/src/os/unix/ngx_file.c new file mode 100644 index 000000000..1b05b920e --- /dev/null +++ b/src/os/unix/ngx_file.c @@ -0,0 +1,61 @@ + + +ssize_t ngx_read_file(ngx_file_t file, char *buf, size_t size) +{ + read(); +} + +#if 0 + +ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset) +{ + if (!file->read->ready) { + + ngx_memzero(&file->iocb, sizeof(iocb)); + file->iocb.aio_fildes = file->fd; + file->iocb.aio_buf = buf; + file->iocb.aio_nbytes = size; + file->iocb.aio_offset = offset; +#if (USE_AIO_KQUEUE) + file->iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT; + file->iocb.aio_sigevent.sigev_notify_kqueue = tid->kq; + file->iocb.aio_sigevent.sigev_value = (union sigval) file; +#endif +#if (USE_AIO_SIGNAL) + file->iocb.aio_sigevent.sigev_notify = SIGEV_SIGNAL; + file->iocb.aio_sigevent.sigev_signo = NGX_SIGAIO; +#ifndef __FreeBSD__ + file->iocb.aio_sigevent.sigev_value.sival_ptr = file; +#endif +#endif + + if (aio_read(&file->iocb) == -1) { + ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, + "aio_read() failed"); + return NGX_ERROR; + + n = aio_error(&file->iocb); + if (n == EINPROGRESS) + return NGX_AGAIN; + + if (n == -1) { + ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, + "aio_read() failed"); + return NGX_ERROR; + } + } + + ngx_assert(file->iocb.aio_buf == buf), return NGX_ERROR, + "ngx_aio_read_file: another buffer is passed"); + + n = aio_return(&file->iocb); + if (n == -1) { + ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, + "aio_read() failed"); + return NGX_ERROR; + } + + return n; +} + +#endif diff --git a/src/os/unix/ngx_file.h b/src/os/unix/ngx_file.h index 0e05b8424..5fda89624 100644 --- a/src/os/unix/ngx_file.h +++ b/src/os/unix/ngx_file.h @@ -10,16 +10,19 @@ typedef struct stat ngx_file_info_t; #define ngx_open_file open -#define ngx_open_file_n "open" +#define ngx_open_file_n "open()" + +#define ngx_read_file read +#define ngx_read_file_n "read()" #define NGX_FILE_RDONLY O_RDONLY #define ngx_file_type(file, sb) stat(file, sb) -#define ngx_file_type_n "stat" +#define ngx_file_type_n "stat()" #define ngx_stat_fd(fd, sb) fstat(fd, sb) -#define ngx_stat_fd_n "fstat" +#define ngx_stat_fd_n "fstat()" #define ngx_is_dir(sb) (S_ISDIR(sb.st_mode)) #define ngx_file_size(sb) sb.st_size