Modify

Opened 12 years ago

Closed 10 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.

Attachments (0)

Change History (17)

comment:1 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:2 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:3 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:4 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:5 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:6 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:7 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:8 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:9 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:10 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:11 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:12 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:13 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:14 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:15 Changed 12 years ago by nobody

Logged In: NO 

I forgot to mention that this is under Win32. Sorry!

/Gunnar

comment:16 Changed 10 years ago by Daryle Walker

Component: Noneiostreams
Severity: Problem

comment:17 Changed 10 years ago by Jonathan Turkanis

Resolution: Nonefixed
Status: assignedclosed
  1. 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])
  1. 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.)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonathan Turkanis.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.