ne_get_range directly to char array buffer

Henrik Holst henrik.holst at millistream.com
Tue Apr 11 12:40:18 EDT 2017


well beats me unfortunately, have no major experience with mmap:ed files in
this way. From what I can see the neon code does a simple write() to the fd
so at least neon doesn't do anything strange. Perhaps mmap works in such a
way that writes to the fd does not update the mmap:ed area and only writes
to the mmap:ed buffer ends up in the file so to speak. I.e it might not
work the way I first thought it did.

For your specific task I would either accept to work with local files and
not with a memory buffer, or simply fork of the code from ne_get_range and
replace the write() portion of the code as a simply write to buffer.

/HH

2017-04-11 18:20 GMT+02:00 Jordi Mueters <jordimueters at hotmail.com>:

> Okay so I am still at kernel 3.10 unfortunately but I get what you're
> trying to say.
>
> Just to see how it works I simply use open, then mmap and then
> ne_get_range with the file descriptor returned by open.
>
> Here's the code I'm using:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *ne_content_range range; range.start = offset; range.end = offset + (size
> - 1); int fd = open("/tmp/neon-buffer", O_RDWR | O_CREAT | O_EXCL,
> S_IRWXU); if(fd == -1) { return 0; } mmap(buf, size, PROT_READ, MAP_FIXED |
> MAP_PRIVATE, fd, 0); int ret = ne_get_range(sess,
> ne_path_escape(ne_concat(parsed_uri.path, path + 1, NULL)), &range, fd);
>  if(ret == NE_ERROR) { return 0; }*
>
>
> I removed an unlink and munmap call I had right after ne_get_range to see
> if the temp file would contain actual data.
>
> Unfortunately my temp file is empty after calling ne_get_range... Any
> suggestions?
>
> ------------------------------
> *Van:* neon-bounces at lists.manyfish.co.uk <neon-bounces at lists.manyfish.
> co.uk> namens Jordi Mueters <jordimueters at hotmail.com>
> *Verzonden:* dinsdag 11 april 2017 16:09:49
> *Aan:* Henrik Holst
>
> *CC:* neon at lists.manyfish.co.uk
> *Onderwerp:* Re: ne_get_range directly to char array buffer
>
>
> Unfortunately I can't do that. fileno returns -1 when you request the file
> descriptor of a FILE created by fmemopen.
>
> Quote from the Linux Programmer's Manual:
>
>
>
>
> *There is no file descriptor associated with the file stream returned by
> this function (i.e., fileno(3) will return an error if called on the
> returned stream).*
>
> ------------------------------
> *Van:* Henrik Holst <henrik.holst at millistream.com>
> *Verzonden:* dinsdag 11 april 2017 16:07:53
> *Aan:* Jordi Mueters
> *CC:* neon at lists.manyfish.co.uk
> *Onderwerp:* Re: ne_get_range directly to char array buffer
>
> Hi,
>
>   you can use fileno(3) in order to get the filedescriptor from a FILE
> pointer. "int fileno(FILE *stream);"
>
> /HH
>
> 2017-04-11 15:40 GMT+02:00 Jordi Mueters <jordimueters at hotmail.com>:
>
>> Hi all, hope someone can help me with the following.
>>
>> I am using ne_get_range to read part of a file on webdav.
>>
>> This method requires a file descriptor.
>>
>>
>> I, however, have no interest in reading into an actual file, I want the
>> content to stay in memory (preferably directly written directly into a char
>> array I manage).
>>
>> My thinking is that I can create a pointer to a FILE using  fmemopen.
>> Unfortunately fmemopen returns a FILE which does not have a file descriptor.
>>
>>
>> The proposal is to overload ne_get_range to accept a FILE pointer
>> instead of a file descriptor. This won't break any functionality because
>> I'm sure everyone has to call fileno to get the filedescriptor anyways and
>> with the change they don't have to anymore.
>>
>>
>> If anyone has a more suitable solution (to read the range directly into
>> my char array) please let me know.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.manyfish.co.uk/pipermail/neon/attachments/20170411/706dcb26/attachment.html 


More information about the neon mailing list