Asynchronous File I/O on Linux
Richard Pieri
richard.pieri-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Sat May 15 19:27:47 EDT 2010
On May 15, 2010, at 5:56 PM, Mark Woodward wrote:
>
> OK, so, the methodology is quite similar, fine. Now the question
> remains, is it possible to quickly "clone" an existing file handle so
> that it will be a new and distinct file handle with the same permissions
> and modes with its own distict view of current location, i.e. seek on
> one does not affect seek on the other?
Part of the difficulty finding an answer is, I think, your incorrect use of "asynchronous I/O". This isn't it. What you've described is random access.
A file handle is really a pointer to a structure in the kernel somewhere that contains, among other things, the file read/write pointer. If you clone the descriptor then you get a pointer to the same structure. What you want is a completely new file handle for the same file. That's easy: open(). So you'd do something like:
fh1 = open(filename, O_WRONLY, mode);
fh2 = open(filename, O_WRONLY, mode);
readblock(block,size,offset,fd1);
readblock(block,size,offset,fd2);
close(fd1);
close(fd2);
I think.
--Rich P.
More information about the Discuss
mailing list