Insane_DNS/libraries/asio-1.28.1/doc/asio/overview/files.html

86 lines
6.3 KiB
HTML
Raw Permalink Normal View History

2023-10-24 21:59:30 -04:00
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Files</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../index.html" title="Asio">
<link rel="up" href="../overview.html" title="Overview">
<link rel="prev" href="timers.html" title="Timers">
<link rel="next" href="pipes.html" title="Pipes">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../asio.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="timers.html"><img src="../../prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../home.png" alt="Home"></a><a accesskey="n" href="pipes.html"><img src="../../next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="asio.overview.files"></a><a class="link" href="files.html" title="Files">Files</a>
</h3></div></div></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
This feature requires I/O completion ports on Windows, and io_uring on
Linux (define <code class="computeroutput"><span class="identifier">ASIO_HAS_IO_URING</span></code>
to enable).
</p></td></tr>
</table></div>
<p>
Asio provides support for manipulating stream-oriented and random-access
files. For example, to write to a newly created stream-oriented file:
</p>
<pre class="programlisting"><span class="identifier">asio</span><span class="special">::</span><span class="identifier">stream_file</span> <span class="identifier">file</span><span class="special">(</span>
<span class="identifier">my_io_context</span><span class="special">,</span> <span class="string">"/path/to/file"</span><span class="special">,</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">stream_file</span><span class="special">::</span><span class="identifier">write_only</span>
<span class="special">|</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">stream_file</span><span class="special">::</span><span class="identifier">create</span>
<span class="special">|</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">stream_file</span><span class="special">::</span><span class="identifier">truncate</span><span class="special">);</span>
<span class="identifier">file</span><span class="special">.</span><span class="identifier">async_write_some</span><span class="special">(</span><span class="identifier">my_buffer</span><span class="special">,</span>
<span class="special">[](</span><span class="identifier">error_code</span> <span class="identifier">e</span><span class="special">,</span> <span class="identifier">size_t</span> <span class="identifier">n</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// ...</span>
<span class="special">});</span>
</pre>
<p>
or to read from a random-access file:
</p>
<pre class="programlisting"><span class="identifier">asio</span><span class="special">::</span><span class="identifier">random_access_file</span> <span class="identifier">file</span><span class="special">(</span>
<span class="identifier">my_io_context</span><span class="special">,</span> <span class="string">"/path/to/file"</span><span class="special">,</span>
<span class="identifier">asio</span><span class="special">::</span><span class="identifier">random_access_file</span><span class="special">::</span><span class="identifier">read_only</span><span class="special">);</span>
<span class="identifier">file</span><span class="special">.</span><span class="identifier">async_read_some_at</span><span class="special">(</span><span class="number">1234</span><span class="special">,</span> <span class="identifier">my_buffer</span><span class="special">,</span>
<span class="special">[](</span><span class="identifier">error_code</span> <span class="identifier">e</span><span class="special">,</span> <span class="identifier">size_t</span> <span class="identifier">n</span><span class="special">)</span>
<span class="special">{</span>
<span class="comment">// ...</span>
<span class="special">});</span>
</pre>
<h5>
<a name="asio.overview.files.h0"></a>
<span><a name="asio.overview.files.see_also"></a></span><a class="link" href="files.html#asio.overview.files.see_also">See
Also</a>
</h5>
<p>
<a class="link" href="../reference/basic_file.html" title="basic_file">basic_file</a>, <a class="link" href="../reference/basic_random_access_file.html" title="basic_random_access_file">basic_random_access_file</a>,
<a class="link" href="../reference/basic_stream_file.html" title="basic_stream_file">basic_stream_file</a>,
<a class="link" href="../reference/file_base.html" title="file_base">file_base</a>, <a class="link" href="../reference/random_access_file.html" title="random_access_file">random_access_file</a>,
<a class="link" href="../reference/stream_file.html" title="stream_file">stream_file</a>.
</p>
</div>
<div class="copyright-footer">Copyright © 2003-2023 Christopher M. Kohlhoff<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="timers.html"><img src="../../prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../home.png" alt="Home"></a><a accesskey="n" href="pipes.html"><img src="../../next.png" alt="Next"></a>
</div>
</body>
</html>