220 lines
14 KiB
HTML
220 lines
14 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="concept" />
|
|
<meta name="DC.Title" content="Asynchronous I/O" />
|
|
<meta name="abstract" content="Asynchronous I/O APIs provide a method for threaded client server models to perform highly concurrent and memory efficient I/O." />
|
|
<meta name="description" content="Asynchronous I/O APIs provide a method for threaded client server models to perform highly concurrent and memory efficient I/O." />
|
|
<meta name="DC.Relation" scheme="URI" content="aconcepts.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/gskstartinit.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/gskstartrecv.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/gskstartsend.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/createiocompletionport.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/destroyiocompletionport.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/waitforiocompletion.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/startaccept.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/startsend.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/startrecv.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../apis/postiocompletion.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xasynchi0.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="designrec.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xcodesigns.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="xsignals.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2001, 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2001, 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="asynchi0" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Asynchronous I/O</title>
|
|
</head>
|
|
<body id="asynchi0"><a name="asynchi0"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Asynchronous I/O</h1>
|
|
<div><p>Asynchronous I/O APIs provide a method for threaded client server
|
|
models to perform highly concurrent and memory efficient I/O.</p>
|
|
<p>In previous threaded client/server models, typically two I/O models have
|
|
prevailed. The first model dedicated one thread per client connection. The
|
|
first model consumes too many threads and can incur a substantial sleep and
|
|
wake up cost. The second model minimizes the number of threads by issuing
|
|
the <span class="apiname">select()</span> API on a large set of client connections and
|
|
delegating a readied client connection or request to a thread. In the second
|
|
model, you must select or mark on each subsequent select, which can cause
|
|
a substantial amount of redundant work.</p>
|
|
<p>Asynchronous I/O and overlapped I/O resolve both these dilemmas by passing
|
|
data to and from user buffers after control has been returned to the user
|
|
application. Asynchronous I/O notifies these worker threads when data is available
|
|
to be read or when a connection has become ready to transmit data. </p>
|
|
<div class="section"><h4 class="sectiontitle">Asynchronous I/O advantages</h4><ul><li>Asynchronous I/O uses system resources more efficiently. Data copies from
|
|
and to user buffers are asynchronous to the application initiating the request.
|
|
This overlapped processing makes efficient use of multiple processors and
|
|
in many cases improves paging rates because system buffers are freed for reuse
|
|
when data arrives.</li>
|
|
<li>Asynchronous I/O minimizes process/thread wait time.</li>
|
|
<li>Asynchronous I/O provides immediate service to client requests.</li>
|
|
<li>Asynchronous I/O decreases the sleep and wake up cost on average.</li>
|
|
<li>Asynchronous I/O handles "bursty application" efficiently.</li>
|
|
<li>Asynchronous I/O provides better scalability.</li>
|
|
<li>Asynchronous I/O provides the most efficient method of handling large
|
|
data transfers. The fillBuffer flag on the <span class="apiname">QsoStartRecv()</span> API
|
|
informs the operating system to acquire a large amount of data before completing
|
|
the Asynchronous I/O. Large amounts of data can also be sent with one asynchronous
|
|
operation.</li>
|
|
<li>Asynchronous I/O minimizes the number of threads that are needed.</li>
|
|
<li>Asynchronous I/O optionally can use timers to specify the maximum time
|
|
allowed for this operation to complete asynchronously. Servers close a client
|
|
connection if it has been idle for a set amount of time. The asynchronous
|
|
timers allow the server to enforce this time limit. </li>
|
|
<li>Asynchronous I/O initiates secure session asynchronously with the <span class="apiname">gsk_secure_soc_startInit()</span> API.</li>
|
|
</ul>
|
|
<div class="p">
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="border" border="1" rules="all"><caption>Table 1. Asynchronous I/O APIs</caption><thead align="left"><tr><th valign="top" width="50%" id="d0e71">Function</th>
|
|
<th valign="top" width="50%" id="d0e73">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr><td valign="top" width="50%" headers="d0e71 "><span class="apiname">gsk_secure_soc_startInit() </span></td>
|
|
<td valign="top" width="50%" headers="d0e73 ">Starts an asynchronous negotiation of a secure session,
|
|
using the attributes set for the SSL environment and the secure session. <div class="note"><span class="notetitle">Note:</span> This
|
|
API only supports sockets with address family AF_INET or AF_INET6 and type
|
|
SOCK_STREAM. </div>
|
|
</td>
|
|
</tr>
|
|
<tr><td valign="top" width="50%" headers="d0e71 "><span class="apiname">gsk_secure_soc_startRecv()</span></td>
|
|
<td valign="top" width="50%" headers="d0e73 ">Starts an asynchronous receive operation on a secure
|
|
session. <div class="note"><span class="notetitle">Note:</span> This API only supports sockets with address family AF_INET
|
|
or AF_INET6 and type SOCK_STREAM. </div>
|
|
</td>
|
|
</tr>
|
|
<tr><td valign="top" width="50%" headers="d0e71 "><span class="apiname">gsk_secure_soc_startSend()</span></td>
|
|
<td valign="top" width="50%" headers="d0e73 ">Starts an asynchronous send operation on a secure
|
|
session. <div class="note"><span class="notetitle">Note:</span> This API only supports sockets with address family AF_INET
|
|
or AF_INET6 and type SOCK_STREAM. </div>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="50%" headers="d0e71 "><span class="apiname">QsoCreateIOCompletionPort()</span></td>
|
|
<td align="left" valign="top" width="50%" headers="d0e73 ">Creates a common wait point for completed
|
|
asynchronous overlapped I/O operations. The <span class="apiname">QsoCreateIOCompletionPort()</span> function
|
|
returns a port handle that represents the wait point. This handle is specified
|
|
on the <span class="apiname">QsoStartRecv()</span>, <span class="apiname">QsoStartSend()</span>, <span class="apiname">QsoStartAccept()</span>, <span class="apiname">gsk_secure_soc_startRecv()</span>, or <span class="apiname">gsk_secure_soc_startSend()</span> functions to initiate
|
|
asynchronous overlapped I/O operations. Also this handle can be used with <span class="apiname">QsoPostIOCompletion()</span> to
|
|
post an event on the associated I/O completion port.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="50%" headers="d0e71 "><span class="apiname">QsoDestroyIOCompletionPort()</span></td>
|
|
<td align="left" valign="top" width="50%" headers="d0e73 ">Destroys an I/O completion port.</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="50%" headers="d0e71 "><span class="apiname">QsoWaitForIOCompletionPort()</span></td>
|
|
<td align="left" valign="top" width="50%" headers="d0e73 ">Waits for completed overlapped I/O operation.
|
|
The I/O completion port represents this wait point.</td>
|
|
</tr>
|
|
<tr><td valign="top" width="50%" headers="d0e71 "><span class="apiname">QsoStartAccept()</span></td>
|
|
<td valign="top" width="50%" headers="d0e73 ">Starts an asynchronous accept operation. <div class="note"><span class="notetitle">Note:</span> This
|
|
API only supports sockets with address family AF_INET or AF_INET6 and type
|
|
SOCK_STREAM. </div>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="50%" headers="d0e71 "><span class="apiname">QsoStartRecv()</span></td>
|
|
<td align="left" valign="top" width="50%" headers="d0e73 ">Starts an asynchronous receive operation.
|
|
<div class="note"><span class="notetitle">Note:</span> This API only supports sockets with address family AF_INET or AF_INET6
|
|
and type SOCK_STREAM. </div>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="50%" headers="d0e71 "><span class="apiname">QsoStartSend()</span></td>
|
|
<td align="left" valign="top" width="50%" headers="d0e73 ">Starts an asynchronous send operation. <div class="note"><span class="notetitle">Note:</span> This
|
|
API only supports sockets with the AF_INET or AF_INET6 address families with
|
|
the SOCK_STREAM socket type.</div>
|
|
</td>
|
|
</tr>
|
|
<tr><td align="left" valign="top" width="50%" headers="d0e71 "><span class="apiname">QsoPostIOCompletion()</span></td>
|
|
<td align="left" valign="top" width="50%" headers="d0e73 ">Allows an application to notify a completion
|
|
port that some function or activity has occurred. </td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">How asynchronous I/O works</h4><p>An application
|
|
creates an I/O completion port using the <span class="apiname">QsoCreateIOCompletionPort()</span> API.
|
|
This API returns a handle that can be used to schedule and wait for completion
|
|
of asynchronous I/O requests. The application starts an input or an output
|
|
function, specifying an I/O completion port handle. When the
|
|
I/O is completed, status information and an application-defined handle is
|
|
posted to the specified I/O completion port. The post to the I/O completion
|
|
port wakes up exactly one of possibly many threads that are waiting. The application
|
|
receives the following items:</p>
|
|
<ul><li>A buffer that was supplied on the original request</li>
|
|
<li>The length of data that was processed to or from that buffer</li>
|
|
<li>An indication of what type of I/O operation has been completed</li>
|
|
<li>Application-defined handle that was passed on the initial I/O request</li>
|
|
</ul>
|
|
<p>This application handle can be the socket descriptor
|
|
identifying the client connection, or a pointer to storage that contains extensive
|
|
information about the state of the client connection. Since the operation
|
|
was completed and the application handle was passed, the worker thread determines
|
|
the next step to complete the client connection. Worker threads that process
|
|
these completed asynchronous operations can handle many different client requests
|
|
and are not tied to just one. Because copying to and from user buffers occurs
|
|
asynchronously to the server processes, the wait time for client request diminishes.
|
|
This can be beneficial on systems where there are multiple processors.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Asynchronous I/O structure</h4><p>An application
|
|
that uses asynchronous I/O has the structure demonstrated by the following
|
|
code fragment.</p>
|
|
<div class="p"> <pre>#include <qsoasync.h>
|
|
struct Qso_OverlappedIO_t
|
|
{
|
|
Qso_DescriptorHandle_t descriptorHandle;
|
|
void *buffer;
|
|
size_t bufferLength;
|
|
int postFlag : 1;
|
|
int fillBuffer : 1;
|
|
int postFlagResult : 1;
|
|
int reserved1 : 29;
|
|
int returnValue;
|
|
int errnoValue;
|
|
int operationCompleted;
|
|
int secureDataTransferSize;
|
|
unsigned int bytesAvailable;
|
|
struct timeval operationWaitTime;
|
|
int postedDescriptor;
|
|
char reserved2[40];
|
|
}</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="aconcepts.htm" title="Advanced socket concepts go beyond a general discussion of what sockets are and how they work. They provide ways to design socket applications for larger and more complex networks.">Advanced socket concepts</a></div>
|
|
</div>
|
|
<div class="relref"><strong>Related reference</strong><br />
|
|
<div><a href="xasynchi0.htm" title="An application creates an I/O completion port using the QsoCreateIOCompletionPort() API.">Example: Use asynchronous I/O</a></div>
|
|
<div><a href="designrec.htm" title="Before working with socket applications, assess the functional requirements, goals, and needs of the socket application.">Socket application design recommendations</a></div>
|
|
<div><a href="xcodesigns.htm" title="There are a number of ways that you can design a connection-oriented socket server on the iSeries. These example programs can be used to create your own connection-oriented designs.">Examples: Connection-oriented designs</a></div>
|
|
<div><a href="xsignals.htm" title="Signals allow you to be notified when a process or application becomes blocked.">Example: Use signals with blocking socket APIs</a></div>
|
|
</div>
|
|
<div class="relinfo"><strong>Related information</strong><br />
|
|
<div><a href="../apis/gskstartinit.htm">gsk_secure_soc_startInit()</a></div>
|
|
<div><a href="../apis/gskstartrecv.htm">gsk_secure_soc_startRecv()</a></div>
|
|
<div><a href="../apis/gskstartsend.htm">gsk_secure_soc_startSend()</a></div>
|
|
<div><a href="../apis/createiocompletionport.htm">QsoCreateIOCompletionPort()</a></div>
|
|
<div><a href="../apis/destroyiocompletionport.htm">QSoDestroyIOCompletionPort()</a></div>
|
|
<div><a href="../apis/waitforiocompletion.htm">QsoWaitForIOCompletionPort()</a></div>
|
|
<div><a href="../apis/startaccept.htm">QsoStartAccept()</a></div>
|
|
<div><a href="../apis/startsend.htm">QsoStartSend()</a></div>
|
|
<div><a href="../apis/startrecv.htm">QsoStartRecv()</a></div>
|
|
<div><a href="../apis/postiocompletion.htm">QsoPostIOCompletion()</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |