uTools-Manuals/docs/php/dio_fcntl.html
2019-04-28 19:00:34 +08:00

177 lines
8.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Performs a c library fcntl on fd</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.dio-fcntl" class="refentry">
<div class="refnamediv">
<h1 class="refname">dio_fcntl</h1>
<p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5 &lt; 5.1.0)</p><p class="refpurpose"><span class="refname">dio_fcntl</span> &mdash; <span class="dc-title">Performs a c library fcntl on fd</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.dio-fcntl-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>dio_fcntl</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$fd</code></span>
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$cmd</code></span>
[, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$args</code></span>
] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>
<p class="para rdfs-comment">
The <span class="function"><strong>dio_fcntl()</strong></span> function performs the
operation specified by <code class="parameter">cmd</code> on the file
descriptor <code class="parameter">fd</code>. Some commands require
additional arguments <code class="parameter">args</code> to be supplied.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.dio-fcntl-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">fd</code></dt>
<dd>
<p class="para">
The file descriptor returned by <span class="function"><a href="dio_open.html" class="function">dio_open()</a></span>.
</p>
</dd>
<dt>
<code class="parameter">cmd</code></dt>
<dd>
<p class="para">
Can be one of the following operations:
<ul class="itemizedlist">
<li class="listitem">
<p class="para">
<strong><code>F_SETLK</code></strong> - Lock is set or cleared. If the lock
is held by someone else <span class="function"><strong>dio_fcntl()</strong></span> returns
-1.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>F_SETLKW</code></strong> - like <strong><code>F_SETLK</code></strong>,
but in case the lock is held by someone else,
<span class="function"><strong>dio_fcntl()</strong></span> waits until the lock is released.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>F_GETLK</code></strong> - <span class="function"><strong>dio_fcntl()</strong></span>
returns an associative array (as described below) if someone else
prevents lock. If there is no obstruction key &quot;type&quot; will set
to <strong><code>F_UNLCK</code></strong>.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>F_DUPFD</code></strong> - finds the lowest numbered available
file descriptor greater than or equal to <code class="parameter">args</code>
and returns them.
</p>
</li>
<li class="listitem">
<p class="para">
<strong><code>F_SETFL</code></strong> - Sets the file descriptors flags to
the value specified by <code class="parameter">args</code>, which can be
<strong><code>O_APPEND</code></strong>, <strong><code>O_NONBLOCK</code></strong> or
<strong><code>O_ASYNC</code></strong>. To use <strong><code>O_ASYNC</code></strong>
you will need to use the <a href="ref.pcntl.html" class="link">PCNTL</a>
extension.
</p>
</li>
</ul>
</p>
</dd>
<dt>
<code class="parameter">args</code></dt>
<dd>
<p class="para">
<code class="parameter">args</code> is an associative array, when
<code class="parameter">cmd</code> is <strong><code>F_SETLK</code></strong> or
<strong><code>F_SETLLW</code></strong>, with the following keys:
<ul class="itemizedlist">
<li class="listitem">
<p class="para">
<em>start</em> - offset where lock begins
</p>
</li>
<li class="listitem">
<p class="para">
<em>length</em> - size of locked area. zero means to end
of file
</p>
</li>
<li class="listitem">
<p class="para">
<em>whence</em> - Where l_start is relative to: can be
<strong><code>SEEK_SET</code></strong>,
<strong><code>SEEK_END</code></strong> and <strong><code>SEEK_CUR</code></strong>
</p>
</li>
<li class="listitem">
<p class="para">
<em>type</em> - type of lock: can be
<strong><code>F_RDLCK</code></strong> (read lock),
<strong><code>F_WRLCK</code></strong> (write lock) or
<strong><code>F_UNLCK</code></strong> (unlock)
</p>
</li>
</ul>
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.dio-fcntl-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns the result of the C call.
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.dio-fcntl-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2742">
<p><strong>Example #1 Setting and clearing a lock</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$fd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dio_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'/dev/ttyS0'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">O_RDWR</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">dio_fcntl</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">F_SETLK</span><span style="color: #007700">,&nbsp;Array(</span><span style="color: #DD0000">"type"</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">F_WRLCK</span><span style="color: #007700">))&nbsp;==&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;appears&nbsp;locked<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"The&nbsp;lock&nbsp;can&nbsp;not&nbsp;be&nbsp;cleared.&nbsp;It&nbsp;is&nbsp;held&nbsp;by&nbsp;someone&nbsp;else."</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Lock&nbsp;successfully&nbsp;set/cleared"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">dio_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.dio-fcntl-notes">
<h3 class="title">注释</h3>
<blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数未在 Windows 平台下实现。</span></p></blockquote>
</div>
</div></div></div></body></html>