Boost C++ Libraries: Ticket #579: boost.iostreams file_descriptor and sharing https://svn.boost.org/trac10/ticket/579 <pre class="wiki">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. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/579 Trac 1.4.3 nobody Wed, 08 Mar 2006 11:15:18 GMT <link>https://svn.boost.org/trac10/ticket/579#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:1</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Wed, 08 Mar 2006 15:16:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:2</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Thu, 09 Mar 2006 07:26:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:3</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Thu, 09 Mar 2006 15:04:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:4</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Fri, 10 Mar 2006 11:50:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:5</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Mon, 13 Mar 2006 07:20:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:6</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Wed, 15 Mar 2006 07:16:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:7</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Fri, 17 Mar 2006 08:32:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:8</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Mon, 20 Mar 2006 07:10:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:9</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Wed, 22 Mar 2006 13:57:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:10</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Fri, 24 Mar 2006 10:17:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:11</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Thu, 30 Mar 2006 09:06:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:12</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Mon, 03 Apr 2006 10:51:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:13</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Fri, 07 Apr 2006 06:37:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:14</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>nobody</dc:creator> <pubDate>Mon, 10 Apr 2006 12:57:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/579#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/579#comment:15</guid> <description> <pre class="wiki">Logged In: NO I forgot to mention that this is under Win32. Sorry! /Gunnar </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Daryle Walker</dc:creator> <pubDate>Fri, 03 Aug 2007 12:01:00 GMT</pubDate> <title>component changed; severity set https://svn.boost.org/trac10/ticket/579#comment:16 https://svn.boost.org/trac10/ticket/579#comment:16 <ul> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">iostreams</span> </li> <li><strong>severity</strong> → <span class="trac-field-new">Problem</span> </li> </ul> Ticket Jonathan Turkanis Sun, 30 Dec 2007 04:22:15 GMT status, resolution changed https://svn.boost.org/trac10/ticket/579#comment:17 https://svn.boost.org/trac10/ticket/579#comment:17 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">fixed</span> </li> </ul> <ol><li>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 (<a class="changeset" href="https://svn.boost.org/trac10/changeset/42357" title="ported changes from branches/iostreams_dev revisions 42343-42356">[42357]</a>) </li></ol><ol start="2"><li>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.) </li></ol> Ticket