Welcome! Log In Create A New Profile

Advanced

Re: confused about ngx_write_file

November 20, 2017 06:08AM
On Mon, Nov 20, 2017 at 02:59:39AM -0500, hook wrote:
> Hi
> I'm writing some module with using ngx_write_file. I found file's
> offset is incorrect, in this case:
> ```
> u_char av = 0x01 | 0x04;
> // file cur offset -> 4096;
> ngx_write_file(file, &av, 1, 4)
> ```
> file->offset would be 4097, but real offset is 4096.

file->offset is only used for sequential read/write. For other
cases, its value is undefined.

> I'm confused with the codes :
> 192 ssize_t
> 193 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t
> offset)
> 194 {
> ........
> 221
> 222 file->offset += n;
> 223 written += n;
> 224
> 225 if ((size_t) n == size) {
> 226 return written;
> 227 }
> 228
> 229 offset += n;
> 230 size -= n;
> 231 }
>
> should it be:
> 222 written += n;
> 223 offset += n;
> 224
> 225 if (offset > file->offset) {
> 226 file->offset = offset;
> 227 }
> 228
> 229 if ((size_t) n == size) {
> 230 return written;
> 231 }
> 232
> 233 size -= n;
> 234 }
>
>
> Thanks!
>
> Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277386,277386#msg-277386
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>

--
Ruslan Ermilov
Assume stupidity not malice
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

confused about ngx_write_file

hook November 20, 2017 02:59AM

Re: confused about ngx_write_file

ru@nginx.com November 20, 2017 06:08AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 295
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready