autodoc.git/
traditional_manual/
chapter_9.html
Branch:
Tag:
Non-build tags
All tags
No tags
2020-05-13
2020-05-13 13:27:50 by Henrik Grubbström (Grubba) <grubba@grubba.org>
bf9cb30d7c536816b899b70d862e74cd7ebc02a0 (
6677
lines) (+
1277
/-
5400
)
[
Show
|
Annotate
]
Branch:
master
Documentation
[Stdio]
: Document low-level classes.
1760:
<hr /> <dl class='group--doc'> <dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>accept</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stdio.File</code> <b><span class='method'>accept</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Get the first connection request waiting for this port and return
-
it as a connected socket.</p>
-
<p> If no connection request is waiting and the port is in nonblocking
-
mode (i.e. an accept callback is installed) then zero is returned.
-
Otherwise this function waits until a connection has arrived.</p>
-
<p> In Pike 7.8 and later the returned object is created via <code>fd_factory()</code>.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>In Pike 7.7 and later the resulting file object will be assigned
-
to the same backend as the port object.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>bind</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>bind</span>(</b><code class='datatype'>int</code>|<code class='datatype'>string</code> <code class='argument'>port</code>, <code class='datatype'>void</code>|<code class='datatype'>function</code>(:<code class='datatype void'>void</code>) <code class='argument'>accept_callback</code>, <code class='datatype'>void</code>|<code class='datatype'>string</code> <code class='argument'>ip</code>, <code class='datatype'>void</code>|<code class='datatype'>string</code> <code class='argument'>reuse_port</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Opens a socket and binds it to port number on the local machine.
-
If the second argument is present, the socket is set to
-
nonblocking and the callback funcition is called whenever
-
something connects to it. The callback will receive the id for
-
this port as argument and should typically call <code>accept</code> to
-
establish a connection.</p>
-
<p> If the optional argument <code>ip</code> is given, <code>bind</code> will try to bind
-
to an interface with that host name or IP number. Omitting this
-
will bind to all available IPv4 addresses; specifying "::" will
-
bind to all IPv4 and IPv6 addresses.</p>
-
<p> If the OS supports TCP_FASTOPEN it is enabled automatically.</p>
-
<p> If the OS supports SO_REUSEPORT it is enabled if the fourth argument is true.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>1 is returned on success, zero on failure. <code>errno</code> provides
-
further details about the error in the latter case.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>accept</code>, <code>set_id</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>bind_unix</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>bind_unix</span>(</b><code class='datatype'>string</code> <code class='argument'>path</code>, <code class='datatype'>void</code>|<code class='datatype'>function</code>(:<code class='datatype void'>void</code>) <code class='argument'>accept_callback</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Opens a Unix domain socket at the given path in the file system.
-
If the second argument is present, the socket is set to
-
nonblocking and the callback funcition is called whenever
-
something connects to it. The callback will receive the id for
-
this port as argument and should typically call <code>accept</code> to
-
establish a connection.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>1 is returned on success, zero on failure. <code>errno</code> provides
-
further details about the error in the latter case.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function is only available on systems that support Unix domain
-
sockets.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p><code>path</code> had a quite restrictive length limit (~100 characters)
-
prior to Pike 7.8.334.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>accept</code>, <code>set_id</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>close</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>close</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Closes the socket.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
+
<span class='homogen--name'><b>create</b></span> </dt> <dd><p><code><span class='object'>Stdio.Port</span> <span class='class'>Stdio.Port</span><b>(</b><b>)</b></code><br>
1880:
<hr /> <dl class='group--doc'> <dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>create</b></span>
-
</dt>
-
<dd><p><code><span class='object'>Stdio.Port</span> <span class='class'>Stdio.Port</span><b>(</b><code class='datatype'>int</code>|<code class='datatype'>string</code> <code class='argument'>port</code>, <code class='datatype'>void</code>|<code class='datatype'>function</code>(:<code class='datatype void'>void</code>) <code class='argument'>accept_callback</code>, <code class='datatype'>void</code>|<code class='datatype'>string</code> <code class='argument'>ip</code><b>)</b></code><br>
-
<code><span class='object'>Stdio.Port</span> <span class='class'>Stdio.Port</span><b>(</b><code class='argument'>"stdin"</code>, <code class='datatype'>void</code>|<code class='datatype'>function</code>(:<code class='datatype void'>void</code>) <code class='argument'>accept_callback</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>When called with an int or any string except <code class='expr'>"stdin"</code> as
-
first argument, this function does the same as <code>bind()</code> would do
-
with the same arguments.</p>
-
<p> When called with <code class='expr'>"stdin"</code> as argument, a socket is created
-
out of the file descriptor 0. This is only useful if that actually
-
IS a socket to begin with, and is equivalent to creating a port and
-
initializing it with <code>listen_fd</code>(0).</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>bind</code>, <code>listen_fd</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>errno</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>errno</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>If the last call done on this port failed, this function will
-
return an integer describing what went wrong. Refer to your unix
-
manual for further information.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
+
<span class='homogen--name'><b>fd_factory</b></span> </dt> <dd><p><code><code class='modifier'>protected</code> <code class='object unresolved'>Fd</code> <b><span class='method'>fd_factory</span>(</b><b>)</b></code></p></dd>
1939:
</dt> <dd><p><code><span class='datatype'>inherit _port</span> : <span class='inherit'>_port</span></code></p></dd> </dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>listen_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>listen_fd</span>(</b><code class='datatype'>int</code> <code class='argument'>fd</code>, <code class='datatype'>void</code>|<code class='datatype'>function</code>(:<code class='datatype void'>void</code>) <code class='argument'>accept_callback</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>This function does the same as <code>bind</code>, except that instead of
-
creating a new socket and bind it to a port, it expects the file
-
descriptor <code>fd</code> to be an already open port.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function is only for the advanced user, and is generally used
-
when sockets are passed to Pike at exec time.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>bind</code>, <code>accept</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_address</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string</code> <b><span class='method'>query_address</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Get the address and port of the local socket end-point.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>This function returns the address and port of a socket end-point
-
on the form <code class='expr'>"x.x.x.x port"</code> (IPv4) or
-
<code class='expr'>"x:x:x:x:x:x:x:x port"</code> (IPv6).</p>
-
<p> If there is some error querying or formatting the address,
-
<code class='expr'>0</code> (zero) is returned and <code>errno()</code> will return the
-
error code.</p>
-
</dd>
-
<dt class='head--doc'>Throws</dt>
-
<dd class='body--doc'><p>An error is thrown if the socket isn't bound.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_backend</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Pike.Backend</code> <b><span class='method'>query_backend</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Return the backend used for the accept callback.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>set_backend</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>query_fd</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the file descriptor number associated with this object.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_id</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>mixed</code> <b><span class='method'>query_id</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>This function returns the id for this port. The id is normally the
-
first argument to accept_callback.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>set_id</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_backend</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_backend</span>(</b><code class='object unresolved'>Pike.Backend</code> <code class='argument'>backend</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the backend used for the accept callback.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The backend keeps a reference to this object as long as the port
-
is accepting connections, but this object does not keep a
-
reference to the backend.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>query_backend</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_id</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>mixed</code> <b><span class='method'>set_id</span>(</b><code class='datatype'>mixed</code> <code class='argument'>id</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>This function sets the id used for accept_callback by this port.
-
The default id is <code>this_object()</code>.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>In Pike 8.0 and earlier the default value was <code class='expr'>0</code> (zero)
-
(even though it was documented as above).</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>query_id</code></p>
-
</dd></dl>
+
</dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.UDP</b></h2> </dt><dd><dl class='group--doc'> <dt class='head--doc'>Description</dt>
2074:
<hr /> <dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>MSG_OOB</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.UDP.<code class='constant'>MSG_OOB</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Flag to specify to <code>read()</code> to read out of band packets.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>MSG_PEEK</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.UDP.<code class='constant'>MSG_PEEK</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Flag to specify to <code>read()</code> to cause it to not remove the packet
-
from the input buffer.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_fd</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>UDP</code> Stdio.UDP.<b><span class='variable'>_fd</span></b></code></p></dd>
-
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Read only</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_membership</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>add_membership</span>(</b><code class='datatype'>string</code> <code class='argument'>group</code>, <code class='datatype'>void</code>|<code class='datatype'>string</code> <code class='argument'>address</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Join a multicast group.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-group'></span>Parameter <code class='parameter'>group</code></dt>
-
<dd></dd><dd class='body--doc'><p><code>group</code> contains the address of the multicast group the
-
application wants to join. It must be a valid multicast address.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-address'></span>Parameter <code class='parameter'>address</code></dt>
-
<dd></dd><dd class='body--doc'><p><code>address</code> is the address of the local interface with which
-
the system should join to the multicast group. If not provided
-
the system will select an appropriate interface.</p>
-
<p> See also the Unix man page for setsocketopt IPPROTO_IP IP_ADD_MEMBERSHIP
-
and IPPROTO_IPV6 IPV6_JOIN_GROUP.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The <code>address</code> parameter is currently not supported for IPv6.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function did not support IPv6 in Pike 7.8 and earlier.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>drop_membership()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>bind</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>UDP</code> <b><span class='method'>bind</span>(</b><code class='datatype'>int</code>|<code class='datatype'>string</code> <code class='argument'>port</code>, <code class='datatype'>string</code>|<code class='datatype'>void</code> <code class='argument'>address</code>, <code class='datatype'>string</code>|<code class='datatype'>bool</code> <code class='argument'>no_reuseaddr</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Binds a port for receiving or transmitting UDP.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-port'></span>Parameter <code class='parameter'>port</code></dt>
-
<dd></dd><dd class='body--doc'><p>Either a port number or the name of a service as listed in
-
<tt>/etc/services</tt>.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-address'></span>Parameter <code class='parameter'>address</code></dt>
-
<dd></dd><dd class='body--doc'><p>Local address to bind to.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-no_reuseaddr'></span>Parameter <code class='parameter'>no_reuseaddr</code></dt>
-
<dd></dd><dd class='body--doc'><p>If set to <code class='expr'>1</code>, Pike will not set the <code class='expr'>SO_REUSEADDR</code> option
-
on the UDP port.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p><code class='expr'>SO_REUSEADDR</code> is never applied when binding a random port
-
(<code class='expr'>bind(0)</code>).</p>
-
<p> In general, <code class='expr'>SO_REUSEADDR</code> is not desirable on UDP ports.
-
Unless used for receiving multicast, be sure to never bind a
-
non-random port without setting <code class='expr'>no_reuseaddr</code> to <code class='expr'>1</code>.</p>
-
</dd>
-
<dt class='head--doc'>Throws</dt>
-
<dd class='body--doc'><p>Throws error when unable to bind port.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>close</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>close</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Closes an open UDP port.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This method was introduced in Pike 7.5.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>connect</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>address</code>, <code class='datatype'>int</code>|<code class='datatype'>string</code> <code class='argument'>port</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Establish an UDP connection.</p>
-
<p> This function connects an UDP socket previously created with
-
<code>Stdio.UDP()</code> to a remote socket. The <code>address</code> is the IP name or
-
number for the remote machine.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> on success, <code class='expr'>0</code> (zero) otherwise.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>If the socket is in nonblocking mode, you have to wait
-
for a write or close callback before you know if the connection
-
failed or not.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>bind()</code>, <code>query_address()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>drop_membership</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>drop_membership</span>(</b><code class='datatype'>string</code> <code class='argument'>group</code>, <code class='datatype'>void</code>|<code class='datatype'>string</code> <code class='argument'>address</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Leave a multicast group.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-group'></span>Parameter <code class='parameter'>group</code></dt>
-
<dd></dd><dd class='body--doc'><p><code>group</code> contains the address of the multicast group the
-
application wants to join. It must be a valid multicast address.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-address'></span>Parameter <code class='parameter'>address</code></dt>
-
<dd></dd><dd class='body--doc'><p><code>address</code> is the address of the local interface with which
-
the system should join to the multicast group. If not provided
-
the system will select an appropriate interface.</p>
-
<p> See also the Unix man page for setsocketopt IPPROTO_IP IP_DROP_MEMBERSHIP
-
and IPPROTO_IPV6 IPV6_LEAVE_GROUP.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The <code>address</code> parameter is currently not supported for IPv6.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function did not support IPv6 in Pike 7.8 and earlier.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>add_membership()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>dup</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stdio.UDP</code> <b><span class='method'>dup</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Duplicate the udp socket.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>fd_factory()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>enable_broadcast</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>enable_broadcast</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the broadcast flag.
-
If enabled then sockets receive packets sent to a broadcast
-
address and they are allowed to send packets to a
-
broadcast address.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> on success, <code class='expr'>0</code> (zero) otherwise.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This is normally only avalable to root users.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>enable_multicast</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>enable_multicast</span>(</b><code class='datatype'>string</code> <code class='argument'>reply_address</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the local device for a multicast socket.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-reply_address'></span>Parameter <code class='parameter'>reply_address</code></dt>
-
<dd></dd><dd class='body--doc'><p>Local address that should appear in the multicast packets.</p>
-
<p> See also the Unix man page for setsocketopt IPPROTO_IP IP_MULTICAST_IF
-
and IPPROTO_IPV6 IPV6_MULTICAST_IF.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function did not support IPv6 in Pike 7.8.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>errno</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>errno</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the error code for the last command on this object.
-
Error code is normally cleared when a command is successful.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>fd_factory</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>UDP</code> <b><span class='method'>fd_factory</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Factory creating <code>Stdio.UDP</code> objects.</p>
-
<p> This function is called by <code>dup()</code>
-
and other functions creating new UDP objects.</p>
-
<p> The default implementation calls <code class='expr'>object_program(this_object())()</code>
-
to create the new object, and returns the <code>UDP</code> inherit in it.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Note that this function must return the <code>UDP</code> inherit in the object.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>dup()</code>, <code>Stdio.File()->fd_factory()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>get_type</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>array</code>(<code class='datatype'>int</code>) <b><span class='method'>get_type</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns socket type and protocol family.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
+
<dt class='head--type'><span class='homogen--type'>Inherit</span> <span class='homogen--name'><b>UDP</b></span> </dt>
2362:
<hr /> <dl class='group--doc'> <dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_address</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string</code> <b><span class='method'>query_address</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the local address of a socket on the form "x.x.x.x port".
-
If this file is not a socket, not connected or some other error occurs,
-
zero is returned.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_backend</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Pike.Backend</code> <b><span class='method'>query_backend</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Return the backend used for the read callback.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>set_backend</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>query_fd</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Gets the file descriptor for this UDP port.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_mtu</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>query_mtu</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Get the Max Transfer Unit for the object (if any).</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><table class='box'><tr><td><code><code class='key'>-1</code></code></td><td><p>Returns <code class='expr'>-1</code> if the object is not a socket or
-
if the mtu is unknown.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>(1..)</code></code></td><td><p>Returns a positive value with the mtu on success.</p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The returned value is adjusted to take account for the
-
IP and UDP headers, so that it should be usable without
-
further adjustment unless further IP options are in use.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>mapping</code>(<code class='datatype'>string</code>:<code class='datatype'>int</code>|<code class='datatype'>string</code>) <b><span class='method'>read</span>(</b><b>)</b></code><br>
-
<code><code class='datatype'>mapping</code>(<code class='datatype'>string</code>:<code class='datatype'>int</code>|<code class='datatype'>string</code>) <b><span class='method'>read</span>(</b><code class='datatype'>int</code> <code class='argument'>flag</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read from the UDP socket.</p>
-
<p> Flag <code>flag</code> is a bitfield, 1 for out of band data and 2 for peek</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>mapping(string:int|string) in the form
-
([
-
"data" : string received data
-
"ip" : string received from this ip
-
"port" : int ...and this port
-
])</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>set_read_callback()</code>, <code>MSG_OOB</code>, <code>MSG_PEEK</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>send</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>send</span>(</b><code class='datatype'>string</code> <code class='argument'>to</code>, <code class='datatype'>int</code>|<code class='datatype'>string</code> <code class='argument'>port</code>, <code class='datatype'>string</code> <code class='argument'>message</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>send</span>(</b><code class='datatype'>string</code> <code class='argument'>to</code>, <code class='datatype'>int</code>|<code class='datatype'>string</code> <code class='argument'>port</code>, <code class='datatype'>string</code> <code class='argument'>message</code>, <code class='datatype'>int</code> <code class='argument'>flags</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Send data to a UDP socket.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-to'></span>Parameter <code class='parameter'>to</code></dt>
-
<dd></dd><dd class='body--doc'><p>The recipient address. For <code>connect()</code>ed objects specifying a
-
recipient of either <code>UNDEFINED</code> or <code class='expr'>""</code> causes the default
-
recipient to be used.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-port'></span>Parameter <code class='parameter'>port</code></dt>
-
<dd></dd><dd class='body--doc'><p>The recipient port number. For <code>connect()</code>ed objects specifying
-
port number <code class='expr'>0</code> casues the default recipient port to be used.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-flag'></span>Parameter <code class='parameter'>flag</code></dt>
-
<dd></dd><dd class='body--doc'><p>A flag bitfield with <code class='expr'>1</code> for out of band data and
-
<code class='expr'>2</code> for don't route flag.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><table class='box'><tr><td><code><code class='key'>(0..)</code></code></td><td><p>The number of bytes that were actually written.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>(..-1)</code></code></td><td><p>Failed to send the <code>message</code>. Check <code>errno()</code> for
-
the cause. Common causes are:</p>
-
<table class='box'><tr><td><code><code class='key'>System.EMSGSIZE</code></code></td><td><p>The <code>message</code> is too large to send unfragmented.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>System.EWOULDBLOCK</code></code></td><td><p>The send buffers are full.</p>
-
</td></tr>
-
</table></td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>Throws</dt>
-
<dd class='body--doc'><p>Throws errors on invalid arguments and uninitialized object.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Versions of Pike prior to 8.1.5 threw errors also on EMSGSIZE
-
(<code class='expr'>"Too big message"</code>) and EWOULDBLOCK
-
(<code class='expr'>"Message would block."</code>). These versions of Pike also
-
did not update the object errno on this function failing.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Versions of Pike prior to 8.1.13 did not support the default
-
recipient for <code>connect()</code>ed objects.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>connect()</code>, <code>errno()</code>, <code>query_mtu()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_backend</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_backend</span>(</b><code class='object unresolved'>Pike.Backend</code> <code class='argument'>backend</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the backend used for the read callback.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The backend keeps a reference to this object as long as there can
-
be calls to the read callback, but this object does not keep a
-
reference to the backend.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>query_backend</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_blocking</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>object</code> <b><span class='method'>set_blocking</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Sets this object to be blocking.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_buffer</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_buffer</span>(</b><code class='datatype'>int</code> <code class='argument'>bufsize</code>, <code class='datatype'>string</code> <code class='argument'>mode</code><b>)</b></code><br>
-
<code><code class='datatype'>void</code> <b><span class='method'>set_buffer</span>(</b><code class='datatype'>int</code> <code class='argument'>bufsize</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set internal socket buffer.</p>
-
<p> This function sets the internal buffer size of a socket or stream.</p>
-
<p> The second argument allows you to set the read or write buffer by
-
specifying <code class='expr'>"r"</code> or <code class='expr'>"w"</code>.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>It is not guaranteed that this function actually does anything,
-
but it certainly helps to increase data transfer speed when it does.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>open_socket()</code>, <code>accept()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_fd</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>UDP</code> <b><span class='method'>set_fd</span>(</b><code class='datatype'>int</code> <code class='argument'>fd</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Use the file descriptor <code>fd</code> for UDP.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>bind</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_multicast_ttl</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>set_multicast_ttl</span>(</b><code class='datatype'>int</code> <code class='argument'>ttl</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the time-to-live value of outgoing multicast packets
-
for this socket.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-ttl'></span>Parameter <code class='parameter'>ttl</code></dt>
-
<dd></dd><dd class='body--doc'><p>The number of router hops sent multicast packets should
-
survive.</p>
-
<p> It is very important for multicast packets to set the
-
smallest TTL possible. The default before calling this
-
function is 1 which means that multicast packets don't
-
leak from the local network unless the user program
-
explicitly requests it.</p>
-
<p> See also the Unix man page for setsocketopt IPPROTO_IP IP_MULTICAST_TTL
-
and IPPROTO_IPV6 IPV6_MULTICAST_HOPS.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function did not support IPv6 in Pike 7.8 and earlier.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>add_membership()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
+
<span class='homogen--name'><b>set_nonblocking</b></span> </dt> <dd><p><code><code class='object unresolved'>UDP</code> <b><span class='method'>set_nonblocking</span>(</b><b>)</b></code><br>
2625:
<hr /> <dl class='group--doc'> <dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_nonblocking</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>object</code> <b><span class='method'>set_nonblocking</span>(</b><code class='datatype'>function</code>(:<code class='datatype void'>void</code>)|<code class='datatype'>void</code> <code class='argument'>rcb</code>, <code class='datatype'>function</code>(:<code class='datatype void'>void</code>)|<code class='datatype'>void</code> <code class='argument'>wcb</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Sets this object to be nonblocking and the read and write callbacks.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
+
<span class='homogen--name'><b>set_read_callback</b></span> </dt> <dd><p><code><code class='object unresolved'>UDP</code> <b><span class='method'>set_read_callback</span>(</b><code class='datatype'>function</code>(<code class='datatype'>mapping</code>(<code class='datatype'>string</code>:<code class='datatype'>int</code>|<code class='datatype'>string</code>), <code class='datatype'>mixed</code> ... :<code class='datatype void'>void</code>) <code class='argument'>read_cb</code>, <code class='datatype'>mixed</code> ... <code class='argument'>extra_args</code><b>)</b></code></p></dd>
2658:
<dt class='head--doc'>See also</dt> <dd class='body--doc'><p><code>read()</code></p> </dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_type</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>UDP</code> <b><span class='method'>set_type</span>(</b><code class='datatype'>int</code> <code class='argument'>sock_type</code><b>)</b></code><br>
-
<code><code class='object unresolved'>UDP</code> <b><span class='method'>set_type</span>(</b><code class='datatype'>int</code> <code class='argument'>sock_type</code>, <code class='datatype'>int</code> <code class='argument'>family</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Sets socket type and protocol family.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>wait</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>wait</span>(</b><code class='datatype'>int</code>|<code class='datatype'>float</code> <code class='argument'>timeout</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Check for data and wait max. <code>timeout</code> seconds.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> if data are ready, <code class='expr'>0</code> (zero) otherwise.</p>
-
</dd></dl>
+
</dd></dl></dd> <dt><a name='9.7'></a> <h2 class='header'>9.7. Terminal I/O</h2></dt>
4060:
<hr /> <dl class='group--doc'> <dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>IPPROTO_IP</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>IPPROTO_IP</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used in <code>File.setsockopt()</code> to set IP-level options</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>IPPROTO_TCP</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>IPPROTO_TCP</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used in <code>File.setsockopt()</code> to set TCP-level options</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>IP_TOS</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>IP_TOS</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used in <code>File.setsockopt()</code> to set Type Of Service</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>NOTE_ATTRIB</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>NOTE_ATTRIB</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used with <code>Stdio.File()->set_fs_event_callback()</code> to monitor
-
for attribute changes on a file.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Available on systems that use kqueue.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>NOTE_DELETE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>NOTE_DELETE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used with <code>Stdio.File()->set_fs_event_callback()</code> to monitor
-
for deletion of a file.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Available on systems that use kqueue.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>NOTE_EXTEND</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>NOTE_EXTEND</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used with <code>Stdio.File()->set_fs_event_callback()</code> to monitor
-
for extension events on a file.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Available on systems that use kqueue.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>NOTE_LINK</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>NOTE_LINK</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used with <code>Stdio.File()->set_fs_event_callback()</code> to monitor
-
for changes to a file's link count.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Available on systems that use kqueue.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>NOTE_RENAME</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>NOTE_RENAME</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used with <code>Stdio.File()->set_fs_event_callback()</code> to monitor
-
for move or rename events on a file.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Available on systems that use kqueue.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>NOTE_REVOKE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>NOTE_REVOKE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used with <code>Stdio.File()->set_fs_event_callback()</code> to monitor
-
for access revokation (unmount, etc).</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Available on systems that use kqueue.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>NOTE_WRITE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>NOTE_WRITE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used with <code>Stdio.File()->set_fs_event_callback()</code> to monitor
-
for writes to a file.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Available on systems that use kqueue.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_BIDIRECTIONAL</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_BIDIRECTIONAL</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The file is bi-directional.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_BUFFERED</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_BUFFERED</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The file is buffered (usually 4KB).</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_IPC</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_IPC</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The file may be used for inter process communication.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_NONBLOCK</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_NONBLOCK</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The file supports nonblocking I/O.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_REVERSE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_REVERSE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Request reversed operation.</p>
-
<p> Used as argument to <code>Stdio.File()->pipe()</code>, when
-
<code>PROP_BIDIRECTIONAL</code> hasn't been specified, to
-
request the direction of the resulting pipe to
-
reversed.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_SEND_FD</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_SEND_FD</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The <code>Stdio.File</code> object might support the <code>Stdio.File()->send_fd()</code>
-
operation.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->pipe()</code>, <code>Stdio.File()->send_fd()</code>,
-
<code>Stdio.File()->receive_fd()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_SHUTDOWN</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_SHUTDOWN</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The file supports shutting down transmission in either
-
direction.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->close()</code>, <code>Stdio.File()->pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_TTY</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_TTY</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The <code>Stdio.File</code> object supports tty operations.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This constant is only present on platforms where pseudo tty
-
(aka pty) operations are available, and may thus be used to
-
detect whether such operations should be attempted.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>SOL_SOCKET</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>SOL_SOCKET</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used in <code>File.setsockopt()</code> to set socket-level options</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>SO_KEEPALIVE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>SO_KEEPALIVE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used in <code>File.setsockopt()</code> to control TCP/IP keep-alive packets.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>TCP_NODELAY</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>TCP_NODELAY</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used in <code>File.setsockopt()</code> to control Nagle's Algorithm.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
+
<span class='homogen--name'><b>TCSADRAIN</b></span> </dt> <dd><p><code><code class='datatype'>constant</code> <code class='datatype'>string</code> Stdio.<code class='constant'>TCSADRAIN</code></code></p></dd>
4415:
<hr /> <dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>XATTR_CREATE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>XATTR_CREATE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used by <code>setxattr</code> function and method to signify a pure
-
create, which will fail if the attribute already exists.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>XATTR_REPLACE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>XATTR_REPLACE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Used by <code>setxattr</code> function and method to signify a replace,
-
which will fail the the attribute does not already exists.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>__HAVE_OOB__</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>__HAVE_OOB__</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Exists and has the value 1 if OOB operations are available.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>In Pike 7.5 and later OOB operations are always present.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>__HAVE_SEND_FD__</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>__HAVE_SEND_FD__</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Support for sending of file descriptors over
-
<code>Stdio.File()->pipe()</code> objects with <code>PROP_SEND_FD</code>
-
capability is supported.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File()->send_fd()</code>, <code>Stdio.File()->receive_fd()</code>,
-
<code>Stdio.File()->read()</code>, <code>Stdio.File()->write()</code>,
-
<code>Stdio.File()->pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>__OOB__</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> Stdio.<code class='constant'>__OOB__</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Implementation level of nonblocking I/O OOB support.</p>
-
<table class='box'><tr><td><code><code class='key'>0</code></code></td><td><p>Nonblocking OOB support is not supported.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>1</code></code></td><td><p>Nonblocking OOB works a little.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>2</code></code></td><td><p>Nonblocking OOB almost works.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>3</code></code></td><td><p>Nonblocking OOB works as intended.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>-1</code></code></td><td><p>Unknown level of nonblocking OOB support.</p>
-
</td></tr>
-
</table><p>This constant only exists when OOB operations are
-
available, i.e. when <code>__HAVE_OOB__</code> is 1.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
+
<dt class='head--type'><span class='homogen--type'>Method</span> <span class='homogen--name'><b>append_file</b></span> </dt>
4693:
<hr /> <dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>get_all_active_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>array</code>(<code class='datatype'>int</code>) <b><span class='method'>get_all_active_fd</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the id of all the active file descriptors.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>gethostip</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>mapping</code>(<code class='datatype'>string</code>:<code class='datatype'>mapping</code>) <b><span class='method'>gethostip</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the IP addresses of the host.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns a mapping that maps interface name to a mapping with
-
more information about that interface. That information mapping
-
looks as follows.</p>
-
<table class='box'><tr><td><code><code class='key'>"ips"</code> : <code class='datatype'>array</code>(<code class='datatype'>string</code>)</code></td><td><p>A list of all IP addresses bound to this interface.</p>
-
</td></tr>
-
</table></dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>getprotobyname</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>getprotobyname</span>(</b><code class='datatype'>string(8bit)</code> <code class='argument'>name</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the protocol number of the protocol <code class='expr'>name</code>.
-
This calls the POSIX function getprotobyname.
-
If the protocol cannot be found an error is thrown.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
+
<dt class='head--type'><span class='homogen--type'>Inherit</span> <span class='homogen--name'><b>_Stdio</b></span> </dt>
5122:
<dt class='head--doc'>See also</dt> <dd class='body--doc'><p><code>append_file()</code>, <code>read_bytes()</code>, <code>Stdio.File()->open()</code></p> </dd></dl>
-
<dl><dt><h2 class='header'>
Enum
<b class='ms datatype'>Stdio.
FileModeFlags
</b></h2>
+
<dl><dt><h2 class='header'>
Class
<b class='ms datatype'>Stdio.
BlockFile
</b></h2>
</dt><dd><dl class='group--doc'> <dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File mode flags returned by <code>Fd()->mode()</code>.</p>
-
</dd></dl>
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>FILE_APPEND</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>FILE_APPEND</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File open for appending.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>FILE_CREATE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>FILE_CREATE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Create a new file if it didn't exist earlier.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>FILE_EXCLUSIVE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>FILE_EXCLUSIVE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Exclusive access to the file.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>FILE_NONBLOCKING</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>FILE_NONBLOCKING</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File opened in nonblocking mode.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>FILE_READ</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>FILE_READ</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File open for reading.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>FILE_TRUNC</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>FILE_TRUNC</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Truncate the file on open.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>FILE_WRITE</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>FILE_WRITE</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File open for writing.</p>
-
</dd></dl>
-
</dd></dl><dl><dt><h2 class='header'>Enum <b class='ms datatype'>Stdio.FilePropertyFlags</b></h2>
-
</dt><dd><dl class='group--doc'>
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File properties for use with eg <code>Fd()->pipe()</code>,
-
and returned by eg <code>Fd()->mode()</code>.</p>
-
</dd></dl>
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_BIDIRECTIONAL</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_BIDIRECTIONAL</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File supports both sending and receiving.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_BUFFERED</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_BUFFERED</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File has internal buffering.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_IPC</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_IPC</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File can be used for interprocess communication.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_NONBLOCK</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_NONBLOCK</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File supports nonblocking operation.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_SEND_FD</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_SEND_FD</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File is capable of sending open file descriptors.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_SHUTDOWN</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_SHUTDOWN</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File supports unidirectional close.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Constant</span>
-
<span class='homogen--name'><b>PROP_TTY</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>constant</code> <code class='datatype'>int</code> Stdio.<code class='constant'>PROP_TTY</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>File supports tty operations.</p>
-
</dd></dl>
-
</dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.BlockFile</b></h2>
-
</dt><dd><dl class='group--doc'>
-
<dt class='head--doc'>Description</dt>
+
<dd class='body--doc'><p>The Stdio.BlockFile API.</p> <p> This class exists purely for typing reasons.</p> <p> Use in types in place of <code>Stdio.File</code> where only blocking
5336:
</dt> <dd><p><code><code class='datatype'>int</code> <b><span class='method'>tell</span>(</b><b>)</b></code></p></dd> </dl>
-
</dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.
Buffer
</b></h2>
+
</dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.
FakeFile
</b></h2>
</dt><dd><dl class='group--doc'> <dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>A buffer to use as input or buffering when doing I/O. It is
-
similar to <code>String.Buffer</code>, but can only contain 8bit data and is
-
designed for protocol parsing. It is optimized for reading from
-
the beginning and adding to the end, and will try to minimize the
-
amount of data copying that is done.</p>
-
<p> The class maintains two separate offsets, one for reading and one
-
for writing. The functions that add data all do so at the write
-
offset (the end of the buffer), and reading is done from the read
-
offset (the start of the buffer).</p>
-
<p> The class can also be used to directly read from and write to
-
filedescriptors if so desired. This eliminates at least one memory
-
copy.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The "avoid copy" part means that a Buffer will never shrink
-
unless you call the <code>trim</code> function.</p>
-
</dd></dl>
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>__set_on_write</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>__set_on_write</span>(</b><code class='datatype'>function</code>(:<code class='datatype void'>void</code>) <code class='argument'>write_callback</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>This tells the buffer to trigger the write callback for the
-
specified file descriptor when data is added to the buffer.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This is used internally by <code>Stdio.File</code> and <code>SSL.File</code> to
-
handle nonblocking buffered mode, and is not necessarily
-
intended to be used directly by anything but implementations
-
of File or Stream like programs. Do not use this yourself
-
on buffers with Files or Streams in buffer modes.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>_encode</b></span><br>
-
<span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>_decode</b></span><br>
-
</dt>
-
<dd><p><code><span class='datatype'>string(8bit)</span> <b><span class='method'>encode_value</span>(</b><span class='class'>Stdio.Buffer</span> <span class='argument'>data</span>)</b></code><br>
-
<code><span class='class'>Stdio.Buffer</span> <b><span class='method'>decode_value</span>(</b><span class='datatype'>string(8bit)</span> <span class='argument'>data</span>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Encode and decode Stdio.Buffer objects.
-
Only the buffer data is kept, no other state is saved.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>_search</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(-1..)</code> <b><span class='method'>search</span>(</b><span class='class'>Stdio.Buffer</span> <span class='argument'>from</span>, <code class='datatype'>int(8bit)</code> <code class='argument'>character</code>, <code class='datatype'>int</code>|<code class='datatype'>void</code> <code class='argument'>start</code>, <code class='datatype'>int</code>|<code class='datatype'>void</code> <code class='argument'>end</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Search forward from the indicated <code>start</code> position for the specified
-
<code>character</code>.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-character'></span>Parameter <code class='parameter'>character</code></dt>
-
<dd></dd><dd class='body--doc'><p>Character to search for.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-start'></span>Parameter <code class='parameter'>start</code></dt>
-
<dd></dd><dd class='body--doc'><p>Start position relative to the current read position of the buffer.</p>
-
<p> Negative <code>start</code> values are supported and indicate positions
-
prior to the current read position.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-end'></span>Parameter <code class='parameter'>end</code></dt>
-
<dd></dd><dd class='body--doc'><p>Don't search past this position of the buffer.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns the first found position of <code>character</code> relative to the
-
current read position of the buffer on success, and <code>UNDEFINED</code>
-
on not found. The read position is not advanced.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read_cstring()</code>, <code>search()</code>, <code>lfun::_search()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>_search</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(-1..)</code> <b><span class='method'>search</span>(</b><span class='class'>Stdio.Buffer</span> <span class='argument'>from</span>, <code class='datatype'>string(8bit)</code> <code class='argument'>substring</code>, <code class='datatype'>int</code>|<code class='datatype'>void</code> <code class='argument'>start</code>, <code class='datatype'>int</code>|<code class='datatype'>void</code> <code class='argument'>end</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Search forward from the indicated <code>start</code> position for the specified
-
<code>substring</code>.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-substring'></span>Parameter <code class='parameter'>substring</code></dt>
-
<dd></dd><dd class='body--doc'><p>Substring to search for.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-start'></span>Parameter <code class='parameter'>start</code></dt>
-
<dd></dd><dd class='body--doc'><p>Start position relative to the current read position of the buffer.</p>
-
<p> Negative <code>start</code> values are supported and indicate positions
-
prior to the current read position.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-end'></span>Parameter <code class='parameter'>end</code></dt>
-
<dd></dd><dd class='body--doc'><p>Don't search past this position of the buffer.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns the first found position of <code>substring</code> relative to the
-
current read position of the buffer on success, and <code>UNDEFINED</code>
-
on not found. The read position is not advanced.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read_cstring()</code>, <code>search()</code>, <code>lfun::_search()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>_sizeof</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>sizeof</span>(</b> <span class='class'>Stdio.Buffer</span> <span class='argument'>arg</span> <b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the buffer size, in bytes.
-
This is how much you can read from the buffer until it runs out of data.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>`[]</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(-1..255)</code> res = <code class='class'>Stdio.Buffer()</code>[ <code class='class'>off</code> ]</code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Return the character at the specified offset.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns the character at offset <code>off</code> on success,
-
and <code class='expr'>-1</code> otherwise.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>`[]=</b></span>
-
</dt>
-
<dd><p><code><code class='class'>Stdio.Buffer()</code>[ <code class='class'>off</code> ] = <code class='class'>char</code></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the character at the specified offset to <code>char</code>.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add</span>(</b><code class='object unresolved'>AddArgument</code> ... <code class='argument'>data</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><pre><code>private typedef System.Memory|Stdio.Buffer|String.Buffer BufferObject;
-
private typedef BufferObject|string(8bit)|int(8bit)|array(AddArgument) AddArgument;</code></pre><p>Add the items in data to the end of the buffer.</p>
-
<p> The supported argument types are:</p>
-
<table class='box'><tr><td><code><code class='datatype'>string(8bit)</code></code></td><td><p>An eight bit string.</p>
-
</td></tr>
-
<tr><td><code><code class='datatype'>int(8bit)</code></code></td><td><p>A single byte</p>
-
</td></tr>
-
<tr><td><code><code class='object unresolved'>System.Memory</code></code></td><td><p>A chunk of memory. The whole memory area is added.</p>
-
</td></tr>
-
<tr><td><code><code class='object unresolved'>Stdio.Buffer</code></code></td><td><p>A chunk of memory. The whole memory area is added.</p>
-
</td></tr>
-
<tr><td><code><code class='object unresolved'>String.Buffer</code></code></td><td><p>A chunk of memory. The whole memory area is added.</p>
-
</td></tr>
-
<tr><td><code><code class='datatype'>array</code>(<code class='object unresolved'>AddArgument</code>)</code></td><td><p>Add all elements in the array individually. Each element may be
-
any one of the types listed here.</p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>sprintf</code>, <code>add_int8</code>, <code>add_int16</code>, <code>add_int32</code>, <code>add_int</code>
-
and
-
<code>add_hstring</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_hint</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_hint</span>(</b><code class='datatype'>int</code> <code class='argument'>i</code>, <code class='datatype'>int(0..)</code> <code class='argument'>size_width</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>First add the size of the integer when encoded to base 256 as a
-
<code>size_width</code> integer, then add the integer to the buffer, both
-
in network byte order.</p>
-
<p> <code>size_width</code> must be less than Int.NATIVE_MAX.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_hstring</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_hstring</span>(</b><code class='datatype'>string(8bit)</code> <code class='argument'>data</code>, <code class='datatype'>int</code> <code class='argument'>size_size</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_hstring</span>(</b><code class='object unresolved'>Stdio.Buffer</code> <code class='argument'>data</code>, <code class='datatype'>int</code> <code class='argument'>size_size</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_hstring</span>(</b><code class='object unresolved'>System.Memory</code> <code class='argument'>data</code>, <code class='datatype'>int</code> <code class='argument'>size_size</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_hstring</span>(</b><code class='object unresolved'>String.Buffer</code> <code class='argument'>data</code>, <code class='datatype'>int</code> <code class='argument'>size_size</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_hstring</span>(</b><code class='datatype'>int(8bit)</code> <code class='argument'>data</code>, <code class='datatype'>int</code> <code class='argument'>size_size</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_hstring</span>(</b><code class='datatype'>array</code> <code class='argument'>data</code>, <code class='datatype'>int</code> <code class='argument'>size_size</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_hstring</span>(</b><code class='datatype'>int</code>|<code class='datatype'>string(8bit)</code>|<code class='object unresolved'>Stdio.Buffer</code>|<code class='object unresolved'>System.Memory</code>|<code class='datatype'>array</code> <code class='argument'>data</code>, <code class='datatype'>int</code> <code class='argument'>size_size</code>, <code class='datatype'>int</code> <code class='argument'>offset</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Adds length of data followed by <code>data</code> to the buffer.</p>
-
<p> This is identical to
-
<tt>sprintf("%"+size_size+"H",(string)Stdio.Buffer(data))</tt> but
-
significantly faster.</p>
-
<p> <code>size_size</code> is the number of bytes used to represent the length of the data.
-
It must be less than Int.NATIVE_MAX.</p>
-
<p> <code>offset</code> is added to the length of the data prior to writing out
-
the length. Typical usage involves adding <code>size_size</code> to account
-
for the room used by the size.</p>
-
<p> The supported <code>data</code> argument types are</p>
-
<table class='box'><tr><td><code><code class='datatype'>int(8bit)</code></code></td><td><p>An eight bit character.</p>
-
</td></tr>
-
<tr><td><code><code class='datatype'>string(8bit)</code></code></td><td><p>An eight bit string.</p>
-
</td></tr>
-
<tr><td><code><code class='object unresolved'>System.Memory</code></code></td><td><p>A chunk of memory. The whole memory area is added.</p>
-
</td></tr>
-
<tr><td><code><code class='object unresolved'>Stdio.Buffer</code></code></td><td><p>A chunk of memory. The whole memory area is added.</p>
-
</td></tr>
-
<tr><td><code><code class='object unresolved'>String.Buffer</code></code></td><td><p>A chunk of memory. The whole memory area is added.</p>
-
</td></tr>
-
<tr><td><code><code class='datatype'>array</code></code></td><td><p>Add all elements in the array individually. Each element may be
-
any one of the types listed here.</p>
-
</td></tr>
-
</table></dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_int</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_int</span>(</b><code class='datatype'>int</code> <code class='argument'>i</code>, <code class='datatype'>int(0..)</code> <code class='argument'>width</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Adds a generic integer to the buffer as an (width*8)bit
-
network byteorder number.</p>
-
<p> <code>width</code> must be less than Int.NATIVE_MAX.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_int16</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_int16</span>(</b><code class='datatype'>int(16bit)</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Add a 16-bit network byte order value to the buffer</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_int16</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_int16</span>(</b><code class='argument'>Gmp.mpz</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Add a 16-bit network byte order value to the buffer</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_int32</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_int32</span>(</b><code class='datatype'>int</code> <code class='argument'>i</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Adds a 32 bit network byte order value to the buffer</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_int32</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_int32</span>(</b><code class='object unresolved'>Gmp.mpz</code> <code class='argument'>i</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Adds a 32 bit network byte order value to the buffer</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_int8</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_int8</span>(</b><code class='datatype'>int(8bit)</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Adds a single byte to the buffer.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_int8</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_int8</span>(</b><code class='argument'>Gmp.mpz</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Adds a single byte to the buffer.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_ints</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_ints</span>(</b><code class='datatype'>array</code>(<code class='datatype'>int</code>) <code class='argument'>integers</code>, <code class='datatype'>int(8bit)</code> <code class='argument'>len</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Add the integers in the specified array, <code>len</code> bytes per int.
-
Equivalent to calling <code>add_int</code> for each integer, but faster,
-
and if an error occurs the buffer will contain no new
-
data. Either all or none of the integers will be added.</p>
-
<p> Errors can occur if one of the elements in <code>integers</code> is not
-
actually an integer, if sizeof(integers)*len is bigger than can
-
be represented in a size_t, or if the buffer cannot grow due to
-
an out of memory condition.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>add_padding</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>add_padding</span>(</b><code class='datatype'>int(0..)</code> <code class='argument'>nbytes</code>, <code class='datatype'>int(8bit)</code>|<code class='datatype'>void</code> <code class='argument'>byte</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Add <code>nbytes</code> bytes of padding, if <code>byte</code> is not specified the
-
area will be filled with 0's, otherwise the specified byte will
-
be repeated.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>allocate</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>allocate</span>(</b><code class='datatype'>int(0..)</code> <code class='argument'>n</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Make sure that at least <code>n</code> bytes of space are available in this buffer.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>cast</b></span>
-
</dt>
-
<dd><p><code><b>(</b><span class='datatype'><code class='datatype'>string(8bit)</code></span><b>)</b><span class='class'>Stdio.Buffer</span>()</code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Convert the buffer to a string.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This only works for buffers whose length is less than 0x7fffffff.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>clear</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>clear</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Clear the buffer.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>consume</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(0..)</code>|<code class='datatype'>int(-1..-1)</code> <b><span class='method'>consume</span>(</b><code class='datatype'>int(0..)</code> <code class='argument'>n</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Discard the first <code>n</code> bytes from the buffer</p>
-
<p> Returns -1 on error and the amount of space still left otherwise.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>create</b></span>
-
</dt>
-
<dd><p><code><span class='object'>Stdio.Buffer</span> <span class='class'>Stdio.Buffer</span><b>(</b><code class='datatype'>int</code>|<code class='datatype'>void</code> <code class='argument'>len</code><b>)</b></code><br>
-
<code><span class='object'>Stdio.Buffer</span> <span class='class'>Stdio.Buffer</span><b>(</b><code class='datatype'>string(8bit)</code> <code class='argument'>contents</code><b>)</b></code><br>
-
<code><span class='object'>Stdio.Buffer</span> <span class='class'>Stdio.Buffer</span><b>(</b><code class='object unresolved'>System.Memory</code>|<code class='object unresolved'>String.Buffer</code> <code class='argument'>contents</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>If passed an integer or no argument, create a buffer of that
-
size, or if no argument is given, 226 bytes.</p>
-
<p> If <code>contents</code> are specified a new buffer with the contents of
-
the given string/System.Memory or String.Buffer will be created.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>In the <code>String.Buffer</code> case the data has to be copied unless
-
there is only one reference to the String.Buffer object, since
-
modifications of the String.Buffer would cause the Buffer to
-
point into invalid memory.</p>
-
<p> In all other cases this will not copy the string data, instead
-
data will be read from the source until it needs to be modified,
-
so the buffer creation is fast regardless of the length of the
-
string.</p>
-
<p> However, as an example, if the buffer is created with a 100Gb
-
<code>System.Memory</code> mmap:ed file as the <code>contents</code> and you later on
-
try to modify the buffer using one of the <code>add</code> functions (or
-
<code>sprintf</code> and similar) the old contents <b>will</b> be copied.</p>
-
<p> You can use <code>read_only()</code> to avoid accidents.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>input_from</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(-1..)</code> <b><span class='method'>input_from</span>(</b><code class='object unresolved'>Stdio.Stream</code> <code class='argument'>f</code>, <code class='datatype'>int</code>|<code class='datatype'>void</code> <code class='argument'>nbytes</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read data from <code>f</code> into this buffer. If <code>nbytes</code> is not
-
specified, read until there is no more data to read (currently).</p>
-
<p> Returns the amount of data that was read, or <code class='expr'>-1</code> on
-
read error.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Please note that this funcition will read all data from the
-
filedescriptor unless it's set to be non-blocking.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>lock</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>object</code> <b><span class='method'>lock</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Makes this buffer read only until the returned object is released.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This currently simply returns a 0-length subbuffer.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>match</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>mixed</code> <b><span class='method'>match</span>(</b><code class='datatype'>string(8bit)</code> <code class='argument'>format</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Reads data from the beginning of the buffer to match the
-
specifed format, then return the match.</p>
-
<p> The non-matching data will be left in the buffer.</p>
-
<p> This function is very similar to <code>sscanf</code>, but the
-
result is the sum of the matches. Most useful to match
-
a single value.</p>
-
</dd>
-
<dt class='head--doc'>Example</dt>
-
<dd class='example'><pre><pre><code><span class='comment'>// get the next whitespace separated word from the buffer.</span>
-
buffer->match<span class='delim'>(</span><span class='string'>"%*[ \t\r\n]%[^ \t\r\n]"</span><span class='delim'>)</span><span class='delim'>;</span>
-
</code></pre></pre></dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>output_to</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(-1..)</code> <b><span class='method'>output_to</span>(</b><code class='object unresolved'>Stdio.Stream</code>|<code class='datatype'>function</code>(<code class='datatype'>string(8bit)</code>:<code class='datatype'>int</code>) <code class='argument'>fun</code>, <code class='datatype'>int(0..)</code>|<code class='datatype'>void</code> <code class='argument'>nbytes</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Write data from the buffer to the indicated file.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-fun'></span>Parameter <code class='parameter'>fun</code></dt>
-
<dd></dd><dd class='body--doc'><p>Write function. Either one of:</p>
-
<table class='box'><tr><td><code><code class='object unresolved'>Stdio.Stream</code></code></td><td><p>A file object in which the function <code class='expr'>write()</code> will
-
be called.</p>
-
</td></tr>
-
<tr><td><code><code class='datatype'>function</code>(<code class='datatype'>string(8bit)</code>:<code class='datatype'>int</code>)</code></td><td><p>A function which will be called with a <code class='expr'>string(8bit)</code>
-
to write and is expected to return an <code class='expr'>int</code> indicating
-
the number of bytes successfully written or <code class='expr'>-1</code> on
-
failure.</p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'><span id='p-nbytes'></span>Parameter <code class='parameter'>nbytes</code></dt>
-
<dd></dd><dd class='body--doc'><p>If <code>nbytes</code> is not specified the whole buffer will be written
-
if possible. Otherwise at most <code>nbytes</code> will be written.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Will return the number of bytes that have been written successfully.</p>
-
<p> If no bytes have been written successfully and <code class='expr'>fun()</code> failed
-
with an error, <code class='expr'>-1</code> will be returned.</p>
-
</dd>
-
<dt class='head--doc'>Deprecated</dt>
-
<dd class='body--doc'><p>This function is going to get deprecated. In case you want to use
-
it against an <code>Stdio.File</code> like object, please consider using
-
the <code class='expr'>f->write(buf)</code> API. If you want to use it against a custom
-
write function, please consider supporting the <code class='expr'>f->write(buf)</code>
-
API in it.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>range_error</b></span>
-
</dt>
-
<dd><p><code><code class='modifier'>protected</code> <code class='object unresolved'>bool</code> <b><span class='method'>range_error</span>(</b><code class='datatype'>int</code> <code class='argument'>howmuch</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>This function is called when an attempt is made to read out of bounds.</p>
-
<p> The default implementation simply returns <code class='expr'>0</code> (zero).</p>
-
<p> Override this function to change the behavior.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-howmuch'></span>Parameter <code class='parameter'>howmuch</code></dt>
-
<dd></dd><dd class='body--doc'><p>The argument <code>howmuch</code> indicates how much data is needed:</p>
-
<table class='box'><tr><td><code><code class='key'>(1..)</code></code></td><td><p>Need <code>howmuch</code> bytes more</p>
-
</td></tr>
-
<tr><td><code><code class='key'>0</code></code></td><td><p>The amount of data needed is not certain.
-
This most often happens when <code>sscanf</code> or <code>read_json</code> is used</p>
-
</td></tr>
-
<tr><td><code><code class='key'>(..-1)</code></code></td><td><p>Tried to <code>unread</code> -<code>howmuch</code> bytes. There is usually no way to satisfy
-
the requested range.</p>
-
<p> The only supported way is to extract the data from the buffer,
-
add the requested amount of "go backbuffer", add the data
-
back, and forward -<code>howmuch</code> bytes.</p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p><code>true</code> if the operation should be retried, <code>false</code> otherwise.</p>
-
<p> Do not return true unless you have added data to the buffer,
-
doing so could result in an infinite loop (since no data is
-
added, the range_error will be called again immediately).</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string(8bit)</code> <b><span class='method'>read</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read all data from the buffer.</p>
-
<p> If there is not enough data available this returns 0.</p>
-
<p> This is basically equivalent to (string)buffer, but it also
-
removes the data from the buffer.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>try_read()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string(8bit)</code> <b><span class='method'>read</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read <code>n</code> bytes of data from the buffer.</p>
-
<p> If there is not enough data available this returns 0.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>try_read()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_buffer</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>read_buffer</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>read_buffer</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code>, <code class='object unresolved'>bool</code> <code class='argument'>copy</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Same as <code>read</code>, but returns the result as an Buffer.</p>
-
<p> No data is copied unless <code>copy</code> is specified and true, the new buffer
-
points into the old one.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>As long as the subbuffer exists no data can be added to the main buffer.</p>
-
<p> Usually this is OK, since it often represents something that
-
should be parsed before the next whatever is extracted from
-
the buffer, but do take care.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_cstring</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string(8bit)</code> <b><span class='method'>read_cstring</span>(</b><code class='datatype'>void</code>|<code class='datatype'>int(8bit)</code> <code class='argument'>sentinel</code>, <code class='datatype'>void</code>|<code class='datatype'>int(8bit)</code> <code class='argument'>escape</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Reads a \0 terminated C-string and returns the
-
string excluding the terminating \0.</p>
-
<p> If there is not enough data available return UNDEFINED.</p>
-
<p> Note that pike string can not be longer than 0x7fffffff bytes (~2Gb).</p>
-
</dd>
-
<dt class='head--doc'><span id='p-sentinel'></span>Parameter <code class='parameter'>sentinel</code></dt>
-
<dd></dd><dd class='body--doc'><p>A different character can be used as end sentinel of the string.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-escape'></span>Parameter <code class='parameter'>escape</code></dt>
-
<dd></dd><dd class='body--doc'><p>An optional character used as a prefix to quote the following
-
character. UNDEFINED and the same value as <code>sentinel</code> mean
-
that there is no escape character.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Escape characters (if any) are left untouched in the returned string.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>_search()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_hbuffer</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>read_hbuffer</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>read_hbuffer</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code>, <code class='object unresolved'>bool</code> <code class='argument'>copy</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Same as <code>read_hstring</code>, but returns the result as an Buffer.</p>
-
<p> No data is copied unless <code>copy</code> is specified and true, the new
-
buffer points into the old one.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>As long as the subbuffer exists no data can be added to the
-
main buffer.</p>
-
<p> Usually this is OK, since it often represents something that
-
should be parsed before the next whatever is extracted from
-
the buffer, but do take care.</p>
-
<p> If you need to unlink the new buffer after it has been
-
created, call <code>trim</code> in it.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_hint</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>read_hint</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read a network byte order unsigned number of size n*8 bits, then
-
read another network byte order number of the size indicated by
-
the first size.</p>
-
<p> Will return -1 if there is not enough buffer space available
-
unless error mode is set to throw errors.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_hstring</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string(8bit)</code> <b><span class='method'>read_hstring</span>(</b><code class='datatype'>int(0..)</code> <code class='argument'>n</code>, <code class='datatype'>void</code>|<code class='datatype'>int</code> <code class='argument'>offset</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Identical in functionality to <code>read</code>(<code>read_number</code>(<code>n</code>)) but
-
faster.</p>
-
<p> Read a network byte order number of size n*8 bits, then return the
-
indicated number of bytes as a string.</p>
-
<p> <code>offset</code> is substracted from the specified length prior to reading the
-
string. Typical usage involves substracting <code>n</code> to account
-
for the room used by the size.</p>
-
<p> If there is not enough data available return 0.</p>
-
<p> Note that pike string can not be longer than 0x7fffffff bytes (~2Gb).</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_int</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>read_int</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read a network byte order unsigned number of size n*8 bits, then
-
return it.</p>
-
<p> Will return -1 if there is not enough buffer space available
-
unless error mode is set to throw errors.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read_le_int</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_int16</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(16bit)</code> <b><span class='method'>read_int16</span>(</b><b>)</b></code></p></dd>
-
</dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_int24</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(24bit)</code> <b><span class='method'>read_int24</span>(</b><b>)</b></code></p></dd>
-
</dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_int32</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(32bit)</code> <b><span class='method'>read_int32</span>(</b><b>)</b></code></p></dd>
-
</dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_int8</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(8bit)</code> <b><span class='method'>read_int8</span>(</b><b>)</b></code></p></dd>
-
</dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_ints</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>array</code>(<code class='datatype'>int</code>) <b><span class='method'>read_ints</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code>, <code class='datatype'>int</code> <code class='argument'>width</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read a list of <code>n</code> network byte order unsigned numbers each of
-
size <code>width</code>*8 bits, then return it.</p>
-
<p> Will return 0 if there is not enough buffer space available
-
unless error mode is set to throw errors.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_json</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>mixed</code> <b><span class='method'>read_json</span>(</b><code class='datatype'>int</code>|<code class='datatype'>void</code> <code class='argument'>require_whitespace_separator</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read a single JSON expression from the buffer and return it.</p>
-
<p> If <code>require_whitespace_separator</code> is true there must be a whitespace
-
after each json value (as an example, newline or space).</p>
-
<p> The JSON is assumed to be utf-8 encoded.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>UNDEFINED if no data is available to read.
-
The read value otherwise.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Unless whitespaces are required this function only really work correctly
-
with objects, arrays and strings.</p>
-
<p> There is really no way to see where one value starts and the other ends
-
for most other cases</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_le_int</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>read_le_int</span>(</b><code class='datatype'>int</code> <code class='argument'>n</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read a big endian byte order unsigned number of size n*8 bits,
-
then return it.</p>
-
<p> Will return -1 if there is not enough buffer space available
-
unless error mode is set to throw errors.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read_int</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_only</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>read_only</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Make the buffer permanently read only.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>You can use lock() to do this temporarily.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_sint</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>read_sint</span>(</b><code class='datatype'>int</code> <code class='argument'>size</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read a network byte order two:s complement signed number of size
-
n*8 bits, then return it.</p>
-
<p> Will return UNDEFINED if there is not enough buffer space
-
available unless error mode is set to throw errors.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>rewind_on_error</b></span><br>
-
<span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>rewind_key</b></span><br>
-
</dt>
-
<dd><p><code><code class='object unresolved'>RewindKey</code> <b><span class='method'>rewind_on_error</span>(</b><b>)</b></code><br>
-
<code><code class='object unresolved'>RewindKey</code> <b><span class='method'>rewind_key</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>These functions are very similar. The <code>rewind_on_error</code> variant
-
will create an object that, when it goes out of scope without
-
having been destructed explicitly, will cause the buffer to
-
rewind to the location it had when this function is called.</p>
-
<p> This will happen if you throw an error <i>or</i> otherwise let the
-
object fall out of scope.</p>
-
<p> Use <code>destruct(RewindKey)</code> or <code>RewindKey.release</code> to stop the
-
buffer from being rewound.</p>
-
<p> The second version (<code>rewind_key</code>) requires you to explicitly
-
call <code>RewindKey.rewind</code> to do the rewind.</p>
-
<p> Take some care with these objects, if you create multiple ones
-
at once the results might be somewhat confusing if you do not
-
release them in the reverse order they were created in (then
-
again, you almost certainly really only need one)</p>
-
<p> You can call <code>RewindKey.update</code> in the generated object to
-
change where it will be rewound to.</p>
-
<p> The typical use-case of this functionality is when parsing a
-
packet protocol with variable length packets where the length is
-
not immediately known. It saves you from keeping track of how
-
much to rewind if you had not actually gotten the whole packet
-
yet.</p>
-
</dd>
-
<dt class='head--doc'>Example</dt>
-
<dd class='example'><pre><pre><code><span class='type'>void</span> parse_packet<span class='delim'>(</span> <span class='ns'>Stdio</span><span class='delim'>.</span>Buffer b <span class='delim'>)</span>
-
<span class='delim'>{</span>
-
<span class='ns'>Stdio</span><span class='delim'>.</span>Buffer<span class='delim'>.</span>RewindKey rewind <span class='delim'>=</span> b->rewind_on_error<span class='delim'>(</span><span class='delim'>)</span><span class='delim'>;</span>
-
b->set_error_mode<span class='delim'>(</span>1<span class='delim'>)</span><span class='delim'>;</span>
-
-
<span class='lang'>switch</span><span class='delim'>(</span> b->read_int8<span class='delim'>(</span><span class='delim'>)</span> <span class='delim'>)</span> <span class='comment'>// packet type</span>
-
<span class='delim'>{</span>
-
<span class='lang'>case</span> DATA<span class='delim'>:</span>
-
<span class='type'>int</span> channel <span class='delim'>=</span> b->read_int8<span class='delim'>(</span><span class='delim'>)</span><span class='delim'>;</span>
-
<span class='ns'>Stdio</span><span class='delim'>.</span>Buffer data <span class='delim'>=</span> b->read_hbuffer<span class='delim'>(</span> 4 <span class='delim'>)</span><span class='delim'>;</span>
-
<span class='comment'>// we have read the whole packet, so no longer rewind on error.</span>
-
rewind->release<span class='delim'>(</span><span class='delim'>)</span><span class='delim'>;</span>
-
<span class='lang'>return</span> handle_data_packet<span class='delim'>(</span> channel<span class='delim'>,</span> data <span class='delim'>)</span><span class='delim'>;</span>
-
<span class='delim'>}</span>
-
<span class='delim'>}</span>
-
</code></pre></pre></dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Just calling <code>rewind_on_error</code> without assigning the return
-
value to something will not do anything. You need to keep the
-
object around while the rewind-to position is still valid.</p>
-
<p> Keeping the object around forbids the buffer from moving data
-
inside itself, this means that it can only grow. So do not keep
-
the rewind key when it is not needed.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_error_mode</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>set_error_mode</span>(</b><code class='datatype'>int</code> <code class='argument'>m</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Buffer</code> <b><span class='method'>set_error_mode</span>(</b><code class='datatype'>program</code> <code class='argument'>m</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the error mode of this buffer to <code>m</code>.</p>
-
<p> If true operations that would normally return 0 (like trying to
-
read too much) will instead throw an error. If <code>m</code> is a program
-
a clone of it will be thrown on error.</p>
-
<p> This is useful when parsing received data, you do not have to
-
verify that each and every read operation suceeds.</p>
-
<p> However, the non-error mode is more useful when checking to see
-
if a packet/segment/whatever has arrived.</p>
-
<p> The thrown error object will have the constant buffer_error set
-
to a non-false value.</p>
-
</dd>
-
<dt class='head--doc'>Example</dt>
-
<dd class='example'><pre><pre><code><span class='type'>void</span> read_callback<span class='delim'>(</span><span class='type'>int</span> i<span class='delim'>,</span> <span class='type'>string</span><span class='delim'>(</span>8bit<span class='delim'>)</span> new_data<span class='delim'>)</span>
-
<span class='delim'>{</span>
-
inbuffer->add<span class='delim'>(</span> new_data <span class='delim'>)</span><span class='delim'>;</span>
-
-
<span class='lang'>while</span><span class='delim'>(</span> Buffer packet <span class='delim'>=</span> inbuffer->read_hbuffer<span class='delim'>(</span>2<span class='delim'>)</span> <span class='delim'>)</span>
-
<span class='delim'>{</span>
-
packet->set_error_mode<span class='delim'>(</span>Buffer<span class='delim'>.</span>THROW_ERROR<span class='delim'>)</span><span class='delim'>;</span>
-
<span class='lang'>if</span><span class='delim'>(</span> <span class='type'>mixed</span> e <span class='delim'>=</span> <span class='lang'>catch</span><span class='delim'>(</span> handle_packet<span class='delim'>(</span> packet <span class='delim'>)</span> <span class='delim'>)</span> <span class='delim'>)</span>
-
<span class='lang'>if</span><span class='delim'>(</span> e->buffer_error <span class='delim'>)</span>
-
protocol_error<span class='delim'>(</span><span class='delim'>)</span><span class='delim'>;</span> <span class='comment'>// illegal data in packet</span>
-
<span class='lang'>else</span>
-
throw<span class='delim'>(</span>e<span class='delim'>)</span><span class='delim'>;</span> <span class='comment'>// the other code did something bad</span>
-
<span class='delim'>}</span>
-
<span class='delim'>}</span>
-
-
<span class='type'>void</span> handle_packet<span class='delim'>(</span> Buffer pack <span class='delim'>)</span>
-
<span class='delim'>{</span>
-
<span class='lang'>switch</span><span class='delim'>(</span> pack->read_int8<span class='delim'>(</span><span class='delim'>)</span> <span class='delim'>)</span>
-
<span class='delim'>{</span>
-
...
-
<span class='lang'>case</span> HEADER_FRAME<span class='delim'>:</span>
-
<span class='type'>int</span> num_headers <span class='delim'>=</span> pack->read_int32<span class='delim'>(</span><span class='delim'>)</span><span class='delim'>;</span>
-
<span class='lang'>for</span><span class='delim'>(</span> <span class='type'>int</span> i <span class='delim'>=</span> 0<span class='delim'>;</span> i<span class='delim'><</span>num_headers<span class='delim'>;</span> i++ <span class='delim'>)</span>
-
headers<span class='delim'>[</span>pack->read_hstring<span class='delim'>(</span>2<span class='delim'>)</span><span class='delim'>]</span> <span class='delim'>=</span> pack->read_hstring<span class='delim'>(</span>2<span class='delim'>)</span><span class='delim'>;</span>
-
...
-
<span class='delim'>}</span>
-
<span class='delim'>}</span>
-
</code></pre></pre></dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_max_waste</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_max_waste</span>(</b><code class='datatype'>float</code> <code class='argument'>factor</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Configure how much free space should be allowed, at most, as a
-
factor of the current buffer size.</p>
-
<p> The default is 0.5, leaving at most half the buffer as waste.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>sprintf</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Buffer</code> <b><span class='method'>sprintf</span>(</b><code class='object unresolved'>strict_sprintf_format</code> <code class='argument'>format</code>, <code class='object unresolved'>sprintf_args</code> ... <code class='argument'>args</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Appends the output from <code>sprintf</code> at the end of the buffer.</p>
-
<p> This is somewhat faster than add(sprintf(...)) since no
-
intermediate string is created.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>sscanf</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>array</code> <b><span class='method'>sscanf</span>(</b><code class='datatype'>string(8bit)</code> <code class='argument'>format</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Reads data from the beginning of the buffer to match the
-
specifed format, then return an array with the matches.</p>
-
<p> The non-matching data will be left in the buffer.</p>
-
<p> See <code>array_sscanf</code> for more information.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>trim</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>trim</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Frees unused memory.</p>
-
<p> Note that calling this function excessively will slow things
-
down, since the data often has to be copied.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function could possibly throw an out-of-memory error
-
if the realloc fails to find a new (smaller) memory area.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>truncate</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(0..)</code>|<code class='datatype'>int(-1..-1)</code> <b><span class='method'>truncate</span>(</b><code class='datatype'>int(0..)</code> <code class='argument'>n</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Truncates the buffer to a length of <code>n</code> bytes.</p>
-
<p> Returns -1 on error and the number of bytes removed otherwise.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>try_read</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string(8bit)</code> <b><span class='method'>try_read</span>(</b><code class='datatype'>int</code> <code class='argument'>len</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Attempt to read some data from the buffer.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-len'></span>Parameter <code class='parameter'>len</code></dt>
-
<dd></dd><dd class='body--doc'><p>Read at most <code>len</code> bytes from the buffer.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>If the buffer contains less than <code>len</code> bytes
-
of data, the entire buffer contents are returned.
-
Otherwise the first <code>len</code> bytes are returned.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>unread</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(0..)</code>|<code class='datatype'>int(-1..-1)</code> <b><span class='method'>unread</span>(</b><code class='datatype'>int(0..)</code> <code class='argument'>n</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Rewind the buffer <code>n</code> bytes.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>This function returns how many more bytes of buffer is
-
available to rewind, or -1 on error.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Unless you add new data to the buffer using any of the add
-
functions you can always rewind.</p>
-
<p> You can call <code>unread(0)</code> to see how much.</p>
-
</dd></dl>
-
<dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.Buffer.RewindKey</b></h2>
-
</dt><dd><dl class='group--doc'>
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The return value of <code>Buffer.rewind_on_error()</code> and
-
<code>Buffer.rewind_key()</code></p>
-
<p> This object will cause the buffer to unwind to the position it was
-
at when the object was created either when it is released (when it
-
falls out of scope, explicit destruct does not count) or when
-
<code>rewind</code> is called, depending on which function was used to
-
create it.</p>
-
</dd></dl>
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>release</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>release</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Do not rewind if the object is released.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This is equivalent to calling destruct() on the object</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>rewind</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>rewind</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Rewinds the buffer explicitly.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Destructs this <code>RewindKey</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>update</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>update</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Update the location the buffer will be rewound to to the current
-
position of the buffer.</p>
-
</dd></dl>
-
</dd></dl></dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.FakeFile</b></h2>
-
</dt><dd><dl class='group--doc'>
-
<dt class='head--doc'>Description</dt>
+
<dd class='body--doc'><p>A string wrapper that pretends to be a <code>Stdio.File</code> object in addition to some features of a <code>Stdio.FILE</code> object.</p> </dd></dl>
7197:
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>write</span>(</b><code class='object unresolved'>sprintf_format</code>|<code class='datatype'>array</code>(<code class='datatype'>string(8bit)</code>) <code class='argument'>data</code>, <code class='object unresolved'>sprintf_args</code> ... <code class='argument'>args</code><b>)</b></code></p></dd> </dl> </dd></dl></dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.Fd</b></h2>
-
</dt><dd>
<dl class='group--doc'>
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Low level I/O operations.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This is not the class you want. Use <code>Stdio.File</code> and friends instead.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File</code>, <code>Stdio.FILE</code>, <code>_Stdio.Fd_ref</code></p>
-
</dd></dl>
+
</dt><dd>
<hr /> <dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_errno</b></span>
-
</dt>
-
<dd><p><code><code class='modifier'>protected</code> <code class='datatype'>int(0..)</code> Stdio.Fd.<b><span class='variable'>_errno</span></b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Variable containing the internal value returned by <code>errno()</code>.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>errno()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_fd</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Fd</code> Stdio.Fd.<b><span class='variable'>_fd</span></b></code></p></dd>
-
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Read only</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_read_callback</b></span><br>
-
<span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_write_callback</b></span><br>
-
<span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_read_oob_callback</b></span><br>
-
<span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_write_oob_callback</b></span><br>
-
<span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_fs_event_callback</b></span><br>
-
</dt>
-
<dd><p><code><code class='datatype'>mixed</code> Stdio.Fd.<b><span class='variable'>_read_callback</span></b></code><br>
-
<code><code class='datatype'>mixed</code> Stdio.Fd.<b><span class='variable'>_write_callback</span></b></code><br>
-
<code><code class='datatype'>mixed</code> Stdio.Fd.<b><span class='variable'>_read_oob_callback</span></b></code><br>
-
<code><code class='datatype'>mixed</code> Stdio.Fd.<b><span class='variable'>_write_oob_callback</span></b></code><br>
-
<code><code class='datatype'>mixed</code> Stdio.Fd.<b><span class='variable'>_fs_event_callback</span></b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Callback functions installed by <code>Stdio.File()->set_callbacks()</code> et al.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
+
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>close</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>close</span>(</b><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>close</span>(</b><code class='datatype'>string</code> <code class='argument'>direction</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Close a file or stream.</p>
-
<p> If direction is not specified, both the read and the write
-
direction are closed. Otherwise only the directions specified is
-
closed.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> if the file or stream now is closed in
-
all directions, and <code class='expr'>0</code> otherwise.</p>
-
</dd>
-
<dt class='head--doc'>Throws</dt>
-
<dd class='body--doc'><p>An exception is thrown if an I/O error occurs.</p>
-
<p> The default behaviour for sockets is typically to flush buffered
-
data in the background, but this can be changed with <code>linger()</code>.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p><code>close()</code> has no effect if this file object has been associated
-
with an already opened file, i.e. if <code>open()</code> was given an
-
integer as the first argument.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>linger()</code>, <code>open()</code>, <code>open_socket()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>connect</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>dest_addr</code>, <code class='datatype'>int</code> <code class='argument'>dest_port</code><b>)</b></code><br>
-
<code><code class='datatype'>bool</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>dest_addr</code>, <code class='datatype'>int</code> <code class='argument'>dest_port</code>, <code class='datatype'>string</code> <code class='argument'>src_addr</code>, <code class='datatype'>int</code> <code class='argument'>src_port</code><b>)</b></code><br>
-
<code><code class='datatype'>string(8bit)</code>|<code class='datatype'>int(0..0)</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>dest_addr</code>, <code class='datatype'>int</code> <code class='argument'>dest_port</code>, <code class='datatype'>string</code>|<code class='datatype'>int(0..0)</code> <code class='argument'>src_addr</code>, <code class='datatype'>int</code>|<code class='datatype'>int(0..0)</code> <code class='argument'>src_port</code>, <code class='datatype'>string(8bit)</code> <code class='argument'>data</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Open a TCP/IP connection to the specified destination.</p>
-
<p> In nonblocking mode, success is indicated with the write-callback,
-
and failure with the close-callback or the read_oob-callback.</p>
-
<p> If the <code>data</code> argument is included the socket will use
-
TCP_FAST_OPEN if available, if not the data will <i>not be
-
sent</i>. In the data case the function either returns the data
-
that has not been sent (only one packet can be sent with this
-
option) or 0 if the connection failed immediately.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> or the remaining <code class='expr'>data</code> on success, and
-
<code class='expr'>0</code> on failure.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>In nonblocking mode <code class='expr'>0</code> (zero) may be returned and <code>errno()</code> set
-
to <tt>EWOULDBLOCK</tt> or <tt>WSAEWOULDBLOCK</tt>. This should not be regarded
-
as a connection failure.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>connect_unix</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>connect_unix</span>(</b><code class='datatype'>string</code> <code class='argument'>filename</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Open a UNIX domain socket connection to the specified destination.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-filename'></span>Parameter <code class='parameter'>filename</code></dt>
-
<dd></dd><dd class='body--doc'><p>Filename to create.</p>
-
<p> In nonblocking mode, success is indicated with the write-callback,
-
and failure with the close-callback or the read_oob-callback.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> on success, and <code class='expr'>0</code> on failure.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>In nonblocking mode <code class='expr'>0</code> (zero) may be returned and <code>errno()</code> set
-
to <tt>EWOULDBLOCK</tt> or <tt>WSAEWOULDBLOCK</tt>. This should not be regarded
-
as a connection failure.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p><code>path</code> had a quite restrictive length limit (~100 characters)
-
prior to Pike 7.8.334.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>create</b></span>
-
</dt>
-
<dd><p><code><span class='object'>Stdio.Fd</span> <span class='class'>Stdio.Fd</span><b>(</b><code class='datatype'>string</code> <code class='argument'>filename</code><b>)</b></code><br>
-
<code><span class='object'>Stdio.Fd</span> <span class='class'>Stdio.Fd</span><b>(</b><code class='datatype'>string</code> <code class='argument'>filename</code>, <code class='datatype'>string</code> <code class='argument'>mode</code><b>)</b></code><br>
-
<code><span class='object'>Stdio.Fd</span> <span class='class'>Stdio.Fd</span><b>(</b><code class='datatype'>string</code> <code class='argument'>filename</code>, <code class='datatype'>string</code> <code class='argument'>mode</code>, <code class='datatype'>int</code> <code class='argument'>access</code><b>)</b></code><br>
-
<code><span class='object'>Stdio.Fd</span> <span class='class'>Stdio.Fd</span><b>(</b><code class='datatype'>int</code> <code class='argument'>fd</code><b>)</b></code><br>
-
<code><span class='object'>Stdio.Fd</span> <span class='class'>Stdio.Fd</span><b>(</b><code class='datatype'>int</code> <code class='argument'>fd</code>, <code class='datatype'>string</code> <code class='argument'>mode</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>See <code>open()</code>.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>open()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>dup</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stdio.Fd</code> <b><span class='method'>dup</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Duplicate the file.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>dup2()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>dup2</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>dup2</span>(</b><code class='object unresolved'>Stdio.File</code> <code class='argument'>to</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Duplicate a file over another.</p>
-
<p> This function works similarly to <code>assign()</code>, but instead of making
-
the argument a reference to the same file, it creates a new file
-
with the same properties and places it in the argument.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> on success and <code class='expr'>0</code> (zero) on failure.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p><code>to</code> need not be open, in which
-
case a new fd is allocated.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Note also that <code>to</code> is also assigned to the same backend (if any)
-
as this object.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>assign()</code>, <code>dup()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>errno</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>errno</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Return the errno for the latest failed file operation.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>fd_factory</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Fd</code> <b><span class='method'>fd_factory</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Factory creating <code>Stdio.Fd</code> objects.</p>
-
<p> This function is called by <code>openat()</code>, <code>pipe()</code>, <code>dup()</code>
-
and other functions creating new file objects.</p>
-
<p> The default implementation calls <code class='expr'>object_program(this_object())()</code>
-
to create the new object, and returns the <code>Fd</code> inherit in it.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Note that this function must return the <code>Fd</code> inherit in the object.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.Port()->fd_factory()</code>, <code>openat()</code>, <code>pipe()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>get_dir</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>array</code>(<code class='datatype'>string</code>) <b><span class='method'>get_dir</span>(</b><code class='datatype'>string</code>|<code class='datatype'>void</code> <code class='argument'>path</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Get directory contents relative to an open directory.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-path'></span>Parameter <code class='parameter'>path</code></dt>
-
<dd></dd><dd class='body--doc'><p>Path relative to the open directory. Defaults to the
-
directory itself.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns an array of filenames.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Not available on all architectures.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>predef::get_dir()</code>, <code>statat()</code>, <code>openat()</code>, <code>unlinkat()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>getxattr</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string</code> <b><span class='method'>getxattr</span>(</b><code class='datatype'>string</code> <code class='argument'>attr</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Return the value of a specified attribute, or 0 if it does not exist</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>grantpt</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string</code> <b><span class='method'>grantpt</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>If this file has been created by calling <code>openpt()</code>, return the
-
filename of the associated pts-file. This function should only be
-
called once.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns the filename of the corresponding pts.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function is only available on some platforms.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>is_open</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>is_open</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns true if the file is open.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>If the file is a socket that has been closed from the remote side,
-
this function might still return true.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Most methods can't be called for a file descriptor that isn't
-
open. Notable exceptions <code>errno</code>, <code>mode</code>, and the set and query
-
functions for callbacks and backend.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>linger</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>linger</span>(</b><code class='datatype'>int(-1..65535)</code>|<code class='datatype'>void</code> <code class='argument'>seconds</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the socket linger behaviour on <code>close()</code>.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-seconds'></span>Parameter <code class='parameter'>seconds</code></dt>
-
<dd></dd><dd class='body--doc'><table class='box'><tr><td><code><code class='key'>-1</code></code></td><td><p>Reset to default behaviour. This typically means that
-
<code>close()</code> will return immediately, but any buffered
-
data will still be sent if possible.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>0</code></code></td><td><p>Terminate the connection immediately on <code>close()</code>,
-
and discard any buffered data.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>(1..65535)</code></code></td><td><p>Have <code>close()</code> wait for at most <code>seconds</code> seconds
-
for any buffered data to be sent after which the
-
connection is terminated.</p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> on success, and <code class='expr'>0</code> (zero) on failure.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This operation is only valid on sockets.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This function was not available in Pike 7.8.775 and earlier.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>close()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>listxattr</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>array</code>(<code class='datatype'>string</code>) <b><span class='method'>listxattr</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Return an array of all extended attributes set on the file</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>lock</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stdio.FileLockKey</code> <b><span class='method'>lock</span>(</b><b>)</b></code><br>
-
<code><code class='object unresolved'>Stdio.FileLockKey</code> <b><span class='method'>lock</span>(</b><code class='datatype'>bool</code> <code class='argument'>is_recursive</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Makes an exclusive file lock on this file.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>trylock()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>mode</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>FileModeFlags</code>|<code class='object unresolved'>FilePropertyFlags</code> <b><span class='method'>mode</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the open mode and capabilities for the file.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns an <code>`|()</code> of the following flags:</p>
-
<table class='box'><tr><td><code><code class='key'>0x1000</code></code></td><td><p><code>FILE_READ</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x2000</code></code></td><td><p><code>FILE_WRITE</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x4000</code></code></td><td><p><code>FILE_APPEND</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x8000</code></code></td><td><p><code>FILE_CREATE</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0100</code></code></td><td><p><code>FILE_TRUNC</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0200</code></code></td><td><p><code>FILE_EXCLUSIVE</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0400</code></code></td><td><p><code>FILE_NONBLOCKING</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0080</code></code></td><td><p><code>PROP_TTY</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0040</code></code></td><td><p><code>PROP_SEND_FD</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0010</code></code></td><td><p><code>PROP_BIDIRECTIONAL</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0008</code></code></td><td><p><code>PROP_BUFFERED</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0004</code></code></td><td><p><code>PROP_SHUTDOWN</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0002</code></code></td><td><p><code>PROP_NONBLOCK</code></p>
-
</td></tr>
-
<tr><td><code><code class='key'>0x0001</code></code></td><td><p><code>PROP_IPC</code></p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>In some versions of Pike 7.8 the <tt>PROP_</tt> flags were
-
filtered from the result.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>open()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>open</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>open</span>(</b><code class='datatype'>string</code> <code class='argument'>filename</code>, <code class='datatype'>string</code> <code class='argument'>mode</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>open</span>(</b><code class='datatype'>string</code> <code class='argument'>filename</code>, <code class='datatype'>string</code> <code class='argument'>mode</code>, <code class='datatype'>int</code> <code class='argument'>access</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>open</span>(</b><code class='datatype'>int</code> <code class='argument'>fd</code>, <code class='datatype'>string</code> <code class='argument'>mode</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Open a file, or use an existing fd.</p>
-
<p> If <code>filename</code> is given, attempt to open the named file. If <code>fd</code>
-
is given instead, it should be the file descriptor for an already
-
opened file, which will then be used by this object.</p>
-
<p> <code>mode</code> describes how the file is opened. It's a case-insensitive
-
string consisting of one or more of the following letters:</p>
-
<dl class='group--doc'><dt>"r"</dt>
-
<dd><p>Open for reading.</p>
-
</dd>
-
<dt>"w"</dt>
-
<dd><p>Open for writing.</p>
-
</dd>
-
<dt>"a"</dt>
-
<dd><p>Append new data to the end.</p>
-
</dd>
-
<dt>"c"</dt>
-
<dd><p>Create the file if it doesn't exist already.</p>
-
</dd>
-
<dt>"t"</dt>
-
<dd><p>Truncate the file to zero length if it already contains data.
-
Use only together with <code class='expr'>"w"</code>.</p>
-
</dd>
-
<dt>"x"</dt>
-
<dd><p>Open exclusively - the open fails if the file already exists.
-
Use only together with <code class='expr'>"c"</code>. Note that it's not safe to
-
assume that this is atomic on some systems.</p>
-
</dd>
-
</dl><p><code>access</code> specifies the permissions to use if a new file is
-
created. It is a UNIX style permission bitfield:</p>
-
<dl class='group--doc'><dt>0400</dt>
-
<dd><p>User has read permission.</p>
-
</dd>
-
<dt>0200</dt>
-
<dd><p>User has write permission.</p>
-
</dd>
-
<dt>0100</dt>
-
<dd><p>User has execute permission.</p>
-
</dd>
-
<dt>0040</dt>
-
<dd><p>Group has read permission.</p>
-
</dd>
-
<dt>0020</dt>
-
<dd><p>Group has write permission.</p>
-
</dd>
-
<dt>0010</dt>
-
<dd><p>Group has execute permission.</p>
-
</dd>
-
<dt>0004</dt>
-
<dd><p>Others have read permission.</p>
-
</dd>
-
<dt>0002</dt>
-
<dd><p>Others have write permission.</p>
-
</dd>
-
<dt>0001</dt>
-
<dd><p>Others have execute permission.</p>
-
</dd>
-
</dl><p>It's system dependent on which of these bits that are actually
-
heeded. If <code>access</code> is not specified, it defaults to
-
<code class='expr'>00666</code>, but note that on UNIX systems it's masked with the
-
process umask before use.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns nonzero on success and <code class='expr'>0</code> (zero) on failure. If
-
there is a failure then <code>errno</code> returns the error code.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>close()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>open_socket</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>open_socket</span>(</b><code class='datatype'>int</code>|<code class='datatype'>void</code> <code class='argument'>port</code>, <code class='datatype'>string</code>|<code class='datatype'>void</code> <code class='argument'>addr</code>, <code class='datatype'>int</code>|<code class='datatype'>string</code>|<code class='datatype'>void</code> <code class='argument'>family_hint</code><b>)</b></code></p></dd>
-
</dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>openat</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stdio.File</code> <b><span class='method'>openat</span>(</b><code class='datatype'>string</code> <code class='argument'>filename</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Stdio.File</code> <b><span class='method'>openat</span>(</b><code class='datatype'>string</code> <code class='argument'>filename</code>, <code class='datatype'>string</code> <code class='argument'>mode</code><b>)</b></code><br>
-
<code><code class='object unresolved'>Stdio.File</code> <b><span class='method'>openat</span>(</b><code class='datatype'>string</code> <code class='argument'>filename</code>, <code class='datatype'>string</code> <code class='argument'>mode</code>, <code class='datatype'>int</code> <code class='argument'>access</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Open a file relative to an opened directory.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns a new file object on success, and <code class='expr'>0</code> (zero) on failure.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Not available on all architectures.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>open()</code>, <code>statat()</code>, <code>unlinkat()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>openpt</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>openpt</span>(</b><code class='datatype'>string</code> <code class='argument'>mode</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Open the master end of a pseudo-terminal pair.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>This function returns <code class='expr'>1</code> for success, <code class='expr'>0</code> otherwise.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>grantpt()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>peek</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int(-1..1)</code> <b><span class='method'>peek</span>(</b><b>)</b></code><br>
-
<code><code class='datatype'>int(-1..1)</code> <b><span class='method'>peek</span>(</b><code class='datatype'>int</code>|<code class='datatype'>float</code> <code class='argument'>timeout</code><b>)</b></code><br>
-
<code><code class='datatype'>int(-1..1)</code> <b><span class='method'>peek</span>(</b><code class='datatype'>int</code>|<code class='datatype'>float</code> <code class='argument'>timeout</code>, <code class='datatype'>int</code> <code class='argument'>not_eof</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Check if there is data available to read,
-
or wait some time for available data to read.</p>
-
<p> More specifically, a later call to <code>read()</code> will return
-
immediately, either due to data being present, or due to
-
some error (eg if a socket has been closed).</p>
-
</dd>
-
<dt class='head--doc'><span id='p-timeout'></span>Parameter <code class='parameter'>timeout</code></dt>
-
<dd></dd><dd class='body--doc'><p>Timeout in seconds.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-not_eof'></span>Parameter <code class='parameter'>not_eof</code></dt>
-
<dd></dd><dd class='body--doc'><p>Flag for specifying handling of end of file.
-
The following values are currently defined:</p>
-
<table class='box'><tr><td><code><code class='key'>0</code></code></td><td><p>Traditional (and default) behaviour. Return <code class='expr'>1</code>
-
at EOF.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>1</code></code></td><td><p>Regard EOF as an error. Return <code class='expr'>-1</code> and set <code>errno()</code>
-
to return <code class='expr'>EPIPE</code> at EOF.</p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><table class='box'><tr><td><code><code class='key'>1</code></code></td><td><p>There is data available to <code>read()</code>, or <code>not_eof</code> is
-
<code class='expr'>0</code> (zero) and we're at EOF. A later call to
-
<code>read()</code> will not block.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>0</code></code></td><td><p>There is no data available (ie timeout).</p>
-
</td></tr>
-
<tr><td><code><code class='key'>-1</code></code></td><td><p>Error condition. The error code returned by <code>errno()</code>
-
has been updated.</p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>errno()</code>, <code>read()</code></p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The function may be interrupted prematurely
-
of the timeout (due to signals);
-
check the timing manually if this is imporant.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>pipe</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stdio.File</code> <b><span class='method'>pipe</span>(</b><b>)</b></code><br>
-
<code><code class='object unresolved'>Stdio.File</code> <b><span class='method'>pipe</span>(</b><code class='datatype'>int</code> <code class='argument'>flags</code><b>)</b></code></p></dd>
-
</dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>proxy</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>proxy</span>(</b><code class='object unresolved'>Stdio.File</code> <code class='argument'>from</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Starts a thread that asynchronously copies data from <code>from</code>
-
to this file.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.sendfile()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_address</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string</code> <b><span class='method'>query_address</span>(</b><b>)</b></code><br>
-
<code><code class='datatype'>string</code> <b><span class='method'>query_address</span>(</b><code class='datatype'>bool</code> <code class='argument'>local</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Get address and port of a socket end-point.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-local'></span>Parameter <code class='parameter'>local</code></dt>
-
<dd></dd><dd class='body--doc'><p>If the argument <code>local</code> is not specified, or is <code class='expr'>0</code>
-
(zero), the remote end-point is returned. Otherwise, if <code>local</code>
-
is <code class='expr'>1</code>, the local end-point is returned.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>This function returns the address and port of a socket end-point
-
on the form <code class='expr'>"x.x.x.x port"</code> (IPv4) or
-
<code class='expr'>"x:x:x:x:x:x:x:x port"</code> (IPv6). IPv6 addresses
-
may use the contracted syntax.</p>
-
<p> If this file is not a socket, is not connected, or some other
-
error occurs, <code class='expr'>0</code> (zero) is returned and <code>errno()</code> will
-
return the error code.</p>
-
</dd>
-
<dt class='head--doc'>Throws</dt>
-
<dd class='body--doc'><p>An error is thrown if the socket (or file) isn't open.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>connect()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_backend</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Pike.Backend</code> <b><span class='method'>query_backend</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Return the backend used for the callbacks.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>set_backend</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>query_fd</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the file descriptor number associated with this object.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>query_mtu</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>query_mtu</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Get the Max Transfer Unit for the object (if any).</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><table class='box'><tr><td><code><code class='key'>-1</code></code></td><td><p>Returns <code class='expr'>-1</code> if the object is not a socket or
-
if the mtu is unknown.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>(1..)</code></code></td><td><p>Returns a positive value with the mtu on success.</p>
-
</td></tr>
-
</table></dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string</code> <b><span class='method'>read</span>(</b><b>)</b></code><br>
-
<code><code class='datatype'>string</code> <b><span class='method'>read</span>(</b><code class='datatype'>int</code> <code class='argument'>len</code><b>)</b></code><br>
-
<code><code class='datatype'>string</code> <b><span class='method'>read</span>(</b><code class='datatype'>int</code> <code class='argument'>len</code>, <code class='datatype'>bool</code> <code class='argument'>not_all</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Read data from a file or a stream.</p>
-
<p> Attempts to read <code>len</code> bytes from the file, and return it as a
-
string. Less than <code>len</code> bytes can be returned if:</p>
-
<ul>
-
<li><p>end-of-file is encountered for a normal file, or</p>
-
</li><li><p>it's a stream that has been closed from the other end, or</p>
-
</li><li><p>it's a stream in nonblocking mode, or</p>
-
</li><li><p>it's a stream and <code>not_all</code> is set, or</p>
-
</li><li><p><code>not_all</code> isn't set and an error occurred (see below).</p>
-
</li></ul><p>If <code>not_all</code> is nonzero, <code>read()</code> does not try its best to read
-
as many bytes as you have asked for, but merely returns as much as
-
the system read function returns. This is mainly useful with
-
stream devices which can return exactly one row or packet at a
-
time. If <code>not_all</code> is used in blocking mode, <code>read()</code> only
-
blocks if there's no data at all available.</p>
-
<p> If something goes wrong and <code>not_all</code> is set, zero is returned.
-
If something goes wrong and <code>not_all</code> is zero or left out, then
-
either zero or a string shorter than <code>len</code> is returned. If the
-
problem persists then a later call to <code>read()</code> fails and returns
-
zero, however.</p>
-
<p> If everything went fine, a call to <code>errno()</code> directly afterwards
-
returns zero. That includes an end due to end-of-file or remote
-
close.</p>
-
<p> If no arguments are given, <code>read()</code> reads to the end of the file
-
or stream.</p>
-
<p> If any file descriptors have been sent by the other side of the
-
stream, <code>receive_fd()</code> will be called once for every sent file
-
descriptor.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>It's not necessary to set <code>not_all</code> to avoid blocking reading
-
when nonblocking mode is used.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>When at the end of a file or stream, repeated calls to <code>read()</code>
-
will return the empty string since it's not considered an error.
-
The empty string is never returned in other cases, unless nonblocking
-
mode is used or <code>len</code> is zero.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read_oob()</code>, <code>write()</code>, <code>receive_fd()</code>, <code>send_fd()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>read</span>(</b><code class='object unresolved'>System.Memory</code> <code class='argument'>dst</code>, <code class='datatype'>void</code>|<code class='datatype'>int(0..)</code> <code class='argument'>offset</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Reads data from a file or stream into the buffer <code>dst</code> at offset
-
<code>offset</code>. Tries to read as many bytes as buffer space available.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>The number of bytes read. Returns <code class='expr'>-1</code> on error and
-
<code>errno()</code> will return the corresponding error code.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>read</span>(</b><code class='object unresolved'>Stdio.Buffer</code>|<code class='object unresolved'>String.Buffer</code> <code class='argument'>dst</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Reads data from a file or stream into the buffer <code>dst</code>. Tries to
-
read as many bytes as buffer space available.
-
Will advance the write position in <code>dst</code> by the number of bytes
-
read.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>The number of bytes read. Returns <code class='expr'>-1</code> on error and
-
<code>errno()</code> will return the corresponding error code.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>read_oob</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>string</code> <b><span class='method'>read_oob</span>(</b><b>)</b></code><br>
-
<code><code class='datatype'>string</code> <b><span class='method'>read_oob</span>(</b><code class='datatype'>int</code> <code class='argument'>len</code><b>)</b></code><br>
-
<code><code class='datatype'>string</code> <b><span class='method'>read_oob</span>(</b><code class='datatype'>int</code> <code class='argument'>len</code>, <code class='datatype'>bool</code> <code class='argument'>not_all</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Attempts to read <code>len</code> bytes of out-of-band data from the stream,
-
and returns it as a string. Less than <code>len</code> bytes can be returned
-
if:</p>
-
<ul>
-
<li><p>the stream has been closed from the other end, or</p>
-
</li><li><p>nonblocking mode is used, or</p>
-
</li><li><p><code>not_all</code> is set, or</p>
-
</li><li><p><code>not_all</code> isn't set and an error occurred (see below).</p>
-
</li></ul><p>If <code>not_all</code> is nonzero, <code>read_oob()</code> only returns as many bytes
-
of out-of-band data as are currently available.</p>
-
<p> If something goes wrong and <code>not_all</code> is set, zero is returned.
-
If something goes wrong and <code>not_all</code> is zero or left out, then
-
either zero or a string shorter than <code>len</code> is returned. If the
-
problem persists then a later call to <code>read_oob()</code> fails and
-
returns zero, however.</p>
-
<p> If everything went fine, a call to <code>errno()</code> directly afterwards
-
returns zero. That includes an end due to remote close.</p>
-
<p> If no arguments are given, <code>read_oob()</code> reads to the end of the
-
stream.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>It is not guaranteed that all out-of-band data sent from the
-
other end is received. Most streams only allow for a single byte
-
of out-of-band data at a time.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>It's not necessary to set <code>not_all</code> to avoid blocking reading
-
when nonblocking mode is used.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>When at the end of a file or stream, repeated calls to <code>read()</code>
-
returns the empty string since it's not considered an error. The
-
empty string is never returned in other cases, unless nonblocking
-
mode is used or <code>len</code> is zero.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read()</code>, <code>write_oob()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>receive_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>receive_fd</span>(</b><code class='object unresolved'>Stdio.Fd</code> <code class='argument'>fd</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Remote file descriptor reception handler.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-fd'></span>Parameter <code class='parameter'>fd</code></dt>
-
<dd></dd><dd class='body--doc'><p>File descriptor received from the remote end of a <code>pipe()</code>.
-
This object has been created by <code>fd_factory()</code>.</p>
-
<p> This function is called from <code>read()</code> when a remote file
-
descriptor has been received over a <code>PROP_SEND_FD</code>
-
capable <code>pipe()</code>.</p>
-
<p> The default implementation is just a prototype.</p>
-
<p> Overload this function to enable reception of
-
remote file descriptors.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The capability of sending and receiving remote file
-
descriptors is only available on some operating systems.
-
This capability is indicated by the precence of <code>__HAVE_SEND_FD__</code>.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>send_fd()</code>, <code>read()</code>, <code>fd_factory()</code>, <code>__HAVE_SEND_FD__</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>release_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>release_fd</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the file descriptor number associated with this object, in
-
addition to releasing it so that this object behaves as if closed.
-
Other settings like callbacks and backend remain intact.
-
<code>take_fd</code> can later be used to reinstate the file descriptor so
-
that the state is restored.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>query_fd()</code>, <code>take_fd()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>removexattr</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>removexattr</span>(</b><code class='datatype'>string</code> <code class='argument'>attr</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Remove the specified extended attribute.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>seek</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>seek</span>(</b><code class='datatype'>int</code> <code class='argument'>offset</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>seek</span>(</b><code class='datatype'>int</code> <code class='argument'>offset</code>, <code class='datatype'>string</code> <code class='argument'>whence</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>The seek() function repositions the offset of the open file
-
associated with the file descriptor fd to the argument <code>offset</code>
-
according to the directive <code>whence</code> as follows:</p>
-
<table class='box'><tr><td><code><code class='key'>Stdio.SEEK_SET</code></code></td><td><p>The offset is set to <code>offset</code> bytes.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>Stdio.SEEK_CUR</code></code></td><td><p>The offset is set to its current location plus <code>offset</code> bytes.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>Stdio.SEEK_END</code></code></td><td><p>The offset is set to the size of the file plus <code>offset</code> bytes.</p>
-
</td></tr>
-
</table><p>If <code>whence</code> is not specified it is SEEK_SET if <code>offset</code> is
-
positive, and if <code>offset</code> is negative SEEK_END.</p>
-
<p> The seek() function on most operating systems allows the file
-
offset to be set beyond the end of the file (but this does not
-
change the size of the file). If data is later written at this
-
point, subsequent reads of the data in the gap (a "hole") return
-
null bytes ('\0') until data is actually written into the gap.</p>
-
<p> Seeking file data and holes</p>
-
<p> Stdio.SEEK_DATA and Stdio.SEEK_HOLE are nonstandard extensions
-
present in Linux, Solaris, FreeBSD, and DragonFly BSD; they are
-
proposed for inclusion in the next POSIX revision.</p>
-
<table class='box'><tr><td><code><code class='key'>Stdio.SEEK_DATA</code></code></td><td><p>Adjust the file offset to the next location in the file greater
-
than or equal to offset containing data. If offset points to
-
data, then the file offset is set to offset.</p>
-
</td></tr>
-
<tr><td><code><code class='key'>Stdio.SEEK_HOLE</code></code></td><td><p>Adjust the file offset to the next hole in the file greater than
-
or equal to offset. If offset points into the middle of a hole,
-
then the file offset is set to offset. If there is no hole past
-
offset, then the file offset is adjusted to the end of the file
-
(i.e., there is an implicit hole at the end of any file).</p>
-
</td></tr>
-
</table><p>In both of the above cases, seek() fails if offset points past the
-
end of the file.</p>
-
<p> These operations allow applications to map holes in a sparsely
-
allocated file. This can be useful for applications such as file
-
backup tools, which can save space when creating backups and
-
preserve holes, if they have a mechanism for discovering holes.</p>
-
<p> For the purposes of these operations, a hole is a sequence of
-
zeros that (normally) has not been allocated in the underlying
-
file storage. However, a filesystem is not obliged to report
-
holes, so these operations are not a guaranteed mechanism for
-
mapping the storage space actually allocated to a file.
-
(Furthermore, a sequence of zeros that actually has been written
-
to the underlying storage may or may not be reported as a hole.)</p>
-
<p> In the simplest implementation, a filesystem can support the
-
operations by making SEEK_HOLE always return the offset of the end
-
of the file, and making SEEK_DATA always return offset (i.e., even
-
if the location referred to by offset is a hole, it can be
-
considered to consist of data that is a sequence of zeros).</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Upon successful completion, seek() returns the resulting offset
-
location as measured in bytes from the beginning of the file. On
-
error, the value (off_t) -1 is returned and <code>errno</code> is set to
-
indicate the error.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>tell()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>seek</b></span>
-
</dt>
-
<dd><p><code><code class='modifier'>variant</code> <code class='deprecated'>__deprecated__</code> <code class='datatype'>int</code> <b><span class='method'>seek</span>(</b><code class='datatype'>int</code> <code class='argument'>unit</code>, <code class='datatype'>int</code> <code class='argument'>mult</code><b>)</b></code><br>
-
<code><code class='modifier'>variant</code> <code class='deprecated'>__deprecated__</code> <code class='datatype'>int</code> <b><span class='method'>seek</span>(</b><code class='datatype'>int</code> <code class='argument'>unit</code>, <code class='datatype'>int</code> <code class='argument'>mult</code>, <code class='datatype'>int</code> <code class='argument'>add</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Seek to a specified offset in a file.</p>
-
<p> If <code>mult</code> or <code>add</code> are specified, <code>pos</code> is calculated as
-
<code class='expr'><code>pos</code> = <code>unit</code>*<code>mult</code> + <code>add</code></code>.</p>
-
<p> If <code>pos</code> is negative then it is relative to the end of the file,
-
otherwise it's an absolute offset from the start of the file.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns the new offset, or <code class='expr'>-1</code> on failure.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The arguments <code>mult</code> and <code>add</code> are considered obsolete, and
-
should not be used.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>tell()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>send_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>send_fd</span>(</b><code class='object unresolved'>Stdio.Fd</code> <code class='argument'>fd</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Queues an open file descriptor for sending to the other end of a stream.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The actual sending is performed at the next successful call
-
to <code>write()</code>, this is due to limitations in the system calls.
-
This means that it isn't possible to send a file descriptor
-
without also sending some in-band data.</p>
-
<p> This operation is only supported on <code>pipe()</code>'s created with
-
<code>PROP_SEND_FD</code>.</p>
-
<p> This function is not available on all operating systems, check
-
for <code>__HAVE_SEND_FD__</code>.</p>
-
<p> The queue is emptied on successful <code>write()</code> and when the
-
write direction is <code>close()</code>'d.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>receive_fd()</code>, <code>write()</code>, <code>pipe()</code>, <code>read()</code>, <code>__HAVE_SEND_FD__</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_backend</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_backend</span>(</b><code class='object unresolved'>Pike.Backend</code> <code class='argument'>backend</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the backend used for the callbacks.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The backend keeps a reference to this object only when it is in
-
callback mode. So if this object hasn't got any active callbacks
-
and it runs out of other references, it will still be destructed
-
quickly (after closing, if necessary).</p>
-
<p> Also, this object does not keep a reference to the backend.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>query_backend</code>, <code>set_nonblocking</code>, <code>set_read_callback</code>, <code>set_write_callback</code>, <code>set_fs_event_callback</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_blocking</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_blocking</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Sets this file to blocking operation.</p>
-
<p> This is the inverse operation of <code>set_nonblocking()</code>.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>set_nonblocking()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_buffer</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_buffer</span>(</b><code class='datatype'>int</code> <code class='argument'>bufsize</code>, <code class='datatype'>string</code> <code class='argument'>mode</code><b>)</b></code><br>
-
<code><code class='datatype'>void</code> <b><span class='method'>set_buffer</span>(</b><code class='datatype'>int</code> <code class='argument'>bufsize</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set internal socket buffer.</p>
-
<p> This function sets the internal buffer size of a socket or stream.</p>
-
<p> The second argument allows you to set the read or write buffer by
-
specifying <code class='expr'>"r"</code> or <code class='expr'>"w"</code>.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>It is not guaranteed that this function actually does anything,
-
but it certainly helps to increase data transfer speed when it does.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>open_socket()</code>, <code>accept()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_close_on_exec</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_close_on_exec</span>(</b><code class='datatype'>bool</code> <code class='argument'>yes_no</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Marks the file as to be closed in spawned processes.</p>
-
<p> This function determines whether this file will be closed when
-
calling exec().</p>
-
<p> Default is that the file WILL be closed on exec except for
-
stdin, stdout and stderr.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Process.create_process()</code>, <code>exec()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_keepalive</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>set_keepalive</span>(</b><code class='datatype'>bool</code> <code class='argument'>on_off</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Equivalent to setsockopt(Stdio.SO_KEEPALIVE, on_off), but will set errno
-
if SO_KEEPALIVE is not supported, rather than issuing a compilation error
-
for the missing constant.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_nodelay</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>set_nodelay</span>(</b><code class='datatype'>bool</code>|<code class='datatype'>void</code> <code class='argument'>state</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Control Nagle's Algorithm (RFC 896)</p>
-
</dd>
-
<dt class='head--doc'><span id='p-state'></span>Parameter <code class='parameter'>state</code></dt>
-
<dd></dd><dd class='body--doc'><table class='box'><tr><td><code><code class='key'>0</code></code></td><td><p>Return to the normal state of using Nagle's Algorithm</p>
-
</td></tr>
-
<tr><td><code><code class='key'>1</code></code></td><td><p>(default) Disable Nagling - small writes will not be queued.</p>
-
</td></tr>
-
</table>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> on success, and <code class='expr'>0</code> (zero) on failure.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This operation is only valid on sockets.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p>setsockopt()</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>set_nonblocking</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>set_nonblocking</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Sets this file to nonblocking operation.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Nonblocking operation is not supported on all Stdio.File objects.
-
Notably it is not guaranteed to be supported on objects returned
-
by <code>pipe()</code> unless <code>PROP_NONBLOCK</code> was specified in the call
-
to <code>pipe()</code>.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>set_blocking()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>setsockopt</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>setsockopt</span>(</b><code class='datatype'>int</code> <code class='argument'>level</code>, <code class='datatype'>int</code> <code class='argument'>opt</code>, <code class='datatype'>int</code> <code class='argument'>state</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set socket options like Stdio.SO_KEEPALIVE. This function is always
-
available; the presence or absence of the option constants indicates
-
availability of those features.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>1 if successful, 0 if not (and sets errno())</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>set_keepalive()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>setxattr</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>setxattr</span>(</b><code class='datatype'>string</code> <code class='argument'>attr</code>, <code class='datatype'>string</code> <code class='argument'>value</code>, <code class='datatype'>int</code> <code class='argument'>flags</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Set the attribute <code>attr</code> to the value <code>value</code>.</p>
-
<p> The flags parameter can be used to refine the semantics of the operation.</p>
-
<p> <code>Stdio.XATTR_CREATE</code> specifies a pure create, which
-
fails if the named attribute exists already.</p>
-
<p> <code>Stdio.XATTR_REPLACE</code> specifies a pure replace operation, which
-
fails if the named attribute does not already exist.</p>
-
<p> By default (no flags), the extended attribute will be created if need be,
-
or will simply replace the value if the attribute exists.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>1 if successful, 0 otherwise, setting errno.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>stat</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stat</code> <b><span class='method'>stat</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Get status for an open file.</p>
-
<p> This function returns the same information as the function
-
<code>file_stat()</code>, but for the file it is called in. If file is not
-
an open file, <code class='expr'>0</code> (zero) is returned. Zero is also returned
-
if file is a pipe or socket.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>See <code>file_stat()</code> for a description of the return value.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>file_stat()</code>, <code>statat()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>statat</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stat</code> <b><span class='method'>statat</span>(</b><code class='datatype'>string</code> <code class='argument'>path</code>, <code class='datatype'>void</code>|<code class='datatype'>bool</code> <code class='argument'>symlink</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Get status for a file relative an open directory.</p>
-
<p> This function returns the same information as the function
-
<code>file_stat()</code>, but relative to the file it is called in. If file is not
-
an open file, <code class='expr'>0</code> (zero) is returned. Zero is also returned
-
if file is a pipe or socket.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>See <code>file_stat()</code> for a description of the return value.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Not available on all architectures.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>file_stat()</code>, <code>stat()</code>, <code>openat()</code>, <code>unlinkat()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>sync</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>sync</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Flush buffers to disk.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>0</code> (zero) and sets errno on failure.</p>
-
<p> Returns <code class='expr'>1</code> on success.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>take_fd</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>void</code> <b><span class='method'>take_fd</span>(</b><code class='datatype'>int</code> <code class='argument'>fd</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Rehooks the given file descriptor number to be associated with
-
this object. As opposed to using <code>open</code> with a file descriptor
-
number, it will be closed by this object upon destruct or when
-
<code>close</code> is called.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>release_fd()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
+
<span class='homogen--name'><b>tcdrain</b></span> </dt> <dd><p><code><code class='datatype'>bool</code> <b><span class='method'>tcdrain</span>(</b><b>)</b></code></p></dd>
8686:
<dt class='head--doc'>See also</dt> <dd class='body--doc'><p><code>tcgetattr()</code>, <code>tcsetattr()</code></p> </dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>tell</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>tell</span>(</b><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Returns the current offset in the file.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>seek()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>truncate</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>bool</code> <b><span class='method'>truncate</span>(</b><code class='datatype'>int</code> <code class='argument'>length</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Truncate a file.</p>
-
<p> Truncates the file to the specified length <code>length</code>.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>1</code> on success, and <code class='expr'>0</code> (zero) on failure.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>open()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>trylock</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Stdio.FileLockKey</code> <b><span class='method'>trylock</span>(</b><b>)</b></code><br>
-
<code><code class='object unresolved'>Stdio.FileLockKey</code> <b><span class='method'>trylock</span>(</b><code class='datatype'>bool</code> <code class='argument'>is_recursive</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Attempts to place a file lock on this file.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>lock()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>unlinkat</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>unlinkat</span>(</b><code class='datatype'>string</code> <code class='argument'>f</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Remove a file or directory relative to an open file.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Returns <code class='expr'>0</code> (zero) on failure, <code class='expr'>1</code> otherwise.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>rm()</code>, <code>openat()</code>, <code>statat()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>write</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>write</span>(</b><code class='datatype'>string</code> <code class='argument'>data</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>write</span>(</b><code class='datatype'>string</code> <code class='argument'>format</code>, <code class='datatype'>mixed</code> ... <code class='argument'>extras</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>write</span>(</b><code class='datatype'>array</code>(<code class='datatype'>string</code>) <code class='argument'>data</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>write</span>(</b><code class='datatype'>array</code>(<code class='datatype'>string</code>) <code class='argument'>format</code>, <code class='datatype'>mixed</code> ... <code class='argument'>extras</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>write</span>(</b><code class='object unresolved'>Stdio.Buffer</code>|<code class='object unresolved'>String.Buffer</code>|<code class='object unresolved'>System.Memory</code> <code class='argument'>data</code>, <code class='datatype'>void</code>|<code class='datatype'>int(0..)</code> <code class='argument'>offset</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Write data to a file or a stream.</p>
-
<p> If there are any file descriptors that have been queued for sending
-
(with <code>send_fd()</code>), they will be sent.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-data'></span>Parameter <code class='parameter'>data</code></dt>
-
<dd></dd><dd class='body--doc'><p>Data to write.</p>
-
<p> If <code>data</code> is an array of strings, they are written in sequence.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-format'></span>Parameter <code class='parameter'>format</code></dt>
-
<dd></dd>
-
<dt class='head--doc'><span id='p-extras'></span>Parameter <code class='parameter'>extras</code></dt>
-
<dd></dd><dd class='body--doc'><p>If more than one argument is given, <code>sprintf()</code> is used to format
-
them using <code>format</code>. If <code>format</code> is an array, the strings in it
-
are concatenated and the result is used as format string.</p>
-
</dd>
-
<dt class='head--doc'><span id='p-offset'></span>Parameter <code class='parameter'>offset</code></dt>
-
<dd></dd><dd class='body--doc'><p>The offset in data to start writing from.</p>
-
</dd>
-
<dt class='head--doc'>Returns</dt>
-
<dd class='body--doc'><p>Writes <code>data</code> and returns the number of bytes that were
-
actually written.</p>
-
<table class='box'><tr><td><code><code class='key'>(1..)</code></code></td><td><p>The number of bytes successfully written to the OS buffers.</p>
-
<p> This can be less than the size of the given data if eg:</p>
-
<ul>
-
<li><p>Some data was written successfully and then something went
-
wrong.</p>
-
<p> If only some data was written due to an error and that error
-
persists, then a later call to <code>write()</code> will fail and return
-
<code class='expr'>-1</code>.</p>
-
</li><li><p>Nonblocking mode is used and not all data could be written
-
without blocking.</p>
-
</li></ul>
-
</td></tr>
-
<tr><td><code><code class='key'>0</code></code></td><td><p>No bytes were written. This may be due to</p>
-
<ul>
-
<li><p><code>data</code> or the formatted data being the empty string.</p>
-
</li><li><p>Nonblocking mode is used and no data could be written
-
without blocking.</p>
-
</li></ul>
-
</td></tr>
-
<tr><td><code><code class='key'>-1</code></code></td><td><p>Something went wrong and no bytes were written.</p>
-
</td></tr>
-
</table><p>If everything went fine, a call to <code>errno()</code> directly afterwards
-
returns zero.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>Writing of wide strings is not supported. You have to encode the
-
data somehow, e.g. with <code>string_to_utf8</code> or with one of the
-
charsets supported by <code>Charset.encoder</code>.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>The variant of this function using a buffer object does not release
-
the interpreter lock.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read()</code>, <code>write_oob()</code>, <code>send_fd()</code></p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Method</span>
-
<span class='homogen--name'><b>write_oob</b></span>
-
</dt>
-
<dd><p><code><code class='datatype'>int</code> <b><span class='method'>write_oob</span>(</b><code class='datatype'>string</code> <code class='argument'>data</code><b>)</b></code><br>
-
<code><code class='datatype'>int</code> <b><span class='method'>write_oob</span>(</b><code class='datatype'>string</code> <code class='argument'>format</code>, <code class='datatype'>mixed</code> ... <code class='argument'>extras</code><b>)</b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Write out-of-band data to a stream.</p>
-
<p> Writes out-of-band data to a stream and returns how many bytes
-
that were actually written. It can be less than the size of the
-
given data if some data was written successfully and then
-
something went wrong.</p>
-
<p> -1 is returned if something went wrong and no bytes were written.
-
If only some data was written due to an error and that error
-
persists, then a later call to <code>write_oob()</code> fails and returns
-
-1.</p>
-
<p> If everything went fine, a call to <code>errno()</code> directly afterwards
-
returns zero.</p>
-
<p> If more than one argument is given, <code>sprintf()</code> is used to format
-
them.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>It is not guaranteed that all out-of-band data sent from the
-
other end is received. Most streams only allow for a single byte
-
of out-of-band data at a time. Some streams sends the rest of
-
the data as ordinary data.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>read_oob()</code>, <code>write()</code></p>
-
</dd></dl>
-
</dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.Fd_ref</b></h2>
-
</dt><dd><dl class='group--doc'>
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Proxy class that contains stub functions
-
that call the corresponding functions in
-
<code>Fd</code>.</p>
-
<p> Used by <code>Stdio.File</code>.</p>
-
</dd>
-
<dt class='head--doc'>Note</dt>
-
<dd class='body--doc'><p>This is not the class you want. Use <code>Stdio.File</code> and friends instead.</p>
-
</dd>
-
<dt class='head--doc'>See also</dt>
-
<dd class='body--doc'><p><code>Stdio.File</code>, <code>Stdio.FILE</code>, <code>_Stdio.Fd</code></p>
-
</dd></dl>
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Variable</span>
-
<span class='homogen--name'><b>_fd</b></span>
-
</dt>
-
<dd><p><code><code class='object unresolved'>Fd</code> Stdio.Fd_ref.<b><span class='variable'>_fd</span></b></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Object to which called functions are relayed.</p>
-
</dd></dl>
-
-
-
<hr />
-
<dl class='group--doc'>
-
<dt class='head--type'><span class='homogen--type'>Inherit</span>
-
<span class='homogen--name'><b>Fd</b></span>
-
</dt>
-
<dd><p><code><span class='datatype'>inherit Fd</span> : <span class='inherit'>Fd</span></code></p></dd>
-
-
<dt class='head--doc'>Description</dt>
-
<dd class='body--doc'><p>Fake inherit to propagate the documentation
-
from <code>_Stdio.Fd</code>.</p>
-
</dd></dl>
+
</dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.NonblockingStream</b></h2> </dt><dd><dl class='group--doc'> <dt class='head--doc'>Description</dt>