Opened 17 years ago
Closed 15 years ago
#579 closed Support Requests (fixed)
boost.iostreams file_descriptor and sharing
Reported by: | nobody | Owned by: | Jonathan Turkanis |
---|---|---|---|
Milestone: | Component: | iostreams | |
Version: | None | Severity: | Problem |
Keywords: | Cc: |
Description
Hi! I have couple of questions about the behavior of boost::iostreams::file_descriptor. First, I've noticed that it always opens files with exclusive access. That is, it calls CreateFileA with a dwShareMode of 0, which means that "the object cannot be shared and cannot be opened again until the handle is closed". Is this by design? Wouldn't it be reasonable to use a share mode of FILE_SHARE_READ when opening a file only for reading? Second, the function file_descriptor::open has a third parameter 'base', which appears to be extra open mode bits that are always on, in addition to those in the second parameter to stream::open. What is the purpose of this? Since there is a stream::open function with three parameters I can specify these extra bits as well when opening the file, in order to actually get the file opened only for reading, but I worry that this will somehow violate the design of the file_descriptor class. I've modified my copy of file_descriptor::open to use a share mode of FILE_SHARE_READ when opening a file only for reading and am now calling stream::open with three arguments in order to make this happen. Is this safe? It appears to work in the very limited cases I've tried so far. Yours, Gunnar Blomberg (Gunnar.Blomberg@iar.se) PS. Thanks for an excellent library! DS.
Change History (17)
comment:2 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:3 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:4 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:5 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:6 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:7 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:8 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:9 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:10 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:11 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:12 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:13 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:14 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:15 by , 17 years ago
Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar
comment:16 by , 15 years ago
Component: | None → iostreams |
---|---|
Severity: | → Problem |
comment:17 by , 15 years ago
Resolution: | None → fixed |
---|---|
Status: | assigned → closed |
- I don't remember why I originally set the share mode to 0; I think it may have been that more permissive settings caused tests to fail on some platforms. I have now set the mode to FILE_SHARE_READ | FILE_SHARE_WRITE, following the microsoft implementation of fopen (see, e.g., "Microsoft Visual Studio 8/VC/crt/src/fopen.c"), and the relevant tests pass on all my compilers, so I am committing the change ([42357])
- The third parameter to file_descriptor::open is for internal use only. file_descriptors always open files in read-write mode; to open a file in read-only mode, use file_descriptor_source. (I'm not sure this was a good design choice, but changing it now will break existing code.)
Note:
See TracTickets
for help on using tickets.