xref: /unit/src/nxt_job_file.h (revision 65:10688b89aa16)
10Sigor@sysoev.ru 
20Sigor@sysoev.ru /*
30Sigor@sysoev.ru  * Copyright (C) Igor Sysoev
40Sigor@sysoev.ru  * Copyright (C) NGINX, Inc.
50Sigor@sysoev.ru  */
60Sigor@sysoev.ru 
70Sigor@sysoev.ru #ifndef _NXT_JOB_FILE_H_INCLUDED_
80Sigor@sysoev.ru #define _NXT_JOB_FILE_H_INCLUDED_
90Sigor@sysoev.ru 
100Sigor@sysoev.ru 
110Sigor@sysoev.ru /*
120Sigor@sysoev.ru  * nxt_job_file_read() allows to open a file, to get its type, size, and
130Sigor@sysoev.ru  * modification time, to read or map file content to memory, and to close
140Sigor@sysoev.ru  * the file.  It can be done as one operation for small file or as several
150Sigor@sysoev.ru  * operations for large file.  On each operation completion ready_handler
160Sigor@sysoev.ru  * or error_handler completion handlers are called.  Since they are job
170Sigor@sysoev.ru  * operations, they can be run by a thread pool.
180Sigor@sysoev.ru  *
190Sigor@sysoev.ru  * If a file is not opened then it is opened and its type, size, and
200Sigor@sysoev.ru  * modification time are got.  Then file content starting from given offset
210Sigor@sysoev.ru  * is read or mapped in memory if there is a buffer supplied.  The offset
220Sigor@sysoev.ru  * field is correspondingly updated.
230Sigor@sysoev.ru  *
240Sigor@sysoev.ru  * If there is no buffer but the read_ahead flag is set then the first
250Sigor@sysoev.ru  * byte is read to initiate read ahead operation.
260Sigor@sysoev.ru  *
270Sigor@sysoev.ru  * If the close flag is set then file descriptor is closed when the file
280Sigor@sysoev.ru  * is completely read.
290Sigor@sysoev.ru  *
300Sigor@sysoev.ru  * The complete flag is set by nxt_job_file_read() when the file is
310Sigor@sysoev.ru  * completely read.
320Sigor@sysoev.ru  *
330Sigor@sysoev.ru  * The test_before_open flag allows to save syscalls in some case, for
340Sigor@sysoev.ru  * example, not to open and then not to close a directory.  It calls
350Sigor@sysoev.ru  * nxt_file_info() to get file type, size, and modification time before
360Sigor@sysoev.ru  * opening the file.  A custom read_required() callback combined with this
370Sigor@sysoev.ru  * flag can also omit opening and reading on some conditions.  However,
380Sigor@sysoev.ru  * if the callback forces opening then additional nxt_file_info() is
390Sigor@sysoev.ru  * called after opening.  The default read_required() callback always
400Sigor@sysoev.ru  * forces opening and reading.
410Sigor@sysoev.ru  */
420Sigor@sysoev.ru 
430Sigor@sysoev.ru 
440Sigor@sysoev.ru typedef struct nxt_job_file_s  nxt_job_file_t;
450Sigor@sysoev.ru 
460Sigor@sysoev.ru struct nxt_job_file_s {
470Sigor@sysoev.ru     nxt_job_t           job;
480Sigor@sysoev.ru 
490Sigor@sysoev.ru     nxt_file_t          file;
500Sigor@sysoev.ru 
510Sigor@sysoev.ru     nxt_off_t           offset;
520Sigor@sysoev.ru     nxt_buf_t           *buffer;
530Sigor@sysoev.ru 
540Sigor@sysoev.ru     nxt_work_handler_t  ready_handler;
550Sigor@sysoev.ru     nxt_work_handler_t  error_handler;
560Sigor@sysoev.ru 
570Sigor@sysoev.ru     nxt_int_t           (*read_required)(nxt_job_file_t *jbf);
580Sigor@sysoev.ru 
590Sigor@sysoev.ru     uint16_t            directory_end;
600Sigor@sysoev.ru 
610Sigor@sysoev.ru     uint16_t            close_before_open:1;
620Sigor@sysoev.ru     uint16_t            test_before_open:1;
630Sigor@sysoev.ru     uint16_t            read_ahead:1;
640Sigor@sysoev.ru     uint16_t            close:1;
650Sigor@sysoev.ru     uint16_t            complete:1;
660Sigor@sysoev.ru };
670Sigor@sysoev.ru 
680Sigor@sysoev.ru 
69*65Sigor@sysoev.ru NXT_EXPORT nxt_job_file_t *nxt_job_file_create(nxt_mp_t *mp);
700Sigor@sysoev.ru NXT_EXPORT void nxt_job_file_init(nxt_job_file_t *jbf);
711Sigor@sysoev.ru NXT_EXPORT void nxt_job_file_read(nxt_task_t *task, nxt_job_t *job);
720Sigor@sysoev.ru 
730Sigor@sysoev.ru 
740Sigor@sysoev.ru #endif /* _NXT_JOB_FILE_H_INCLUDED_ */
75