ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzab6_5.4.0.1/xdescriptors.htm

135 lines
9.1 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?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="reference" />
<meta name="DC.Title" content="Example: Pass descriptors between processes" />
<meta name="abstract" content="The sendmsg() and recvmsg() examples show how to design a server program that uses these APIs to handle incoming connections." />
<meta name="description" content="The sendmsg() and recvmsg() examples show how to design a server program that uses these APIs to handle incoming connections." />
<meta name="DC.Relation" scheme="URI" content="xcodesigns.htm" />
<meta name="DC.Relation" scheme="URI" content="x1descriptors.htm" />
<meta name="DC.Relation" scheme="URI" content="x2descriptors.htm" />
<meta name="DC.Relation" scheme="URI" content="cdescriptors.htm" />
<meta name="DC.Relation" scheme="URI" content="designrec.htm" />
<meta name="DC.Relation" scheme="URI" content="generic.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/spawn.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/bind.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/socket.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/listen.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/accept.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/close.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/socketp.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/sendms.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/recvms.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/send.htm" />
<meta name="DC.Relation" scheme="URI" content="../apis/recv.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="xdescriptors" />
<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>Example: Pass descriptors between processes</title>
</head>
<body id="xdescriptors"><a name="xdescriptors"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Pass descriptors between processes</h1>
<div><p>The <span class="apiname">sendmsg()</span> and <span class="apiname">recvmsg()</span> examples
show how to design a server program that uses these APIs to handle incoming
connections.</p>
<div class="section"><p>When the server starts, it creates a pool of worker jobs. These
preallocated (spawned) worker jobs wait until needed. When the client job
connects to the server, the server gives the incoming connection to one of
the worker jobs.</p>
</div>
<div class="section"><p>The following figure illustrates how the server, worker, and client
jobs interact when the system uses the <span class="apiname">sendmsg()</span> and <span class="apiname">recvmsg()</span> server
design. <br /><img src="rxab6507.gif" alt="Server, worker, and client job interaction when you use the sendmsg() and recvmsg() server design." /><br /></p>
</div>
<div class="section"><h4 class="sectiontitle">Flow of socket events: Server that uses <span class="apiname">sendmsg()</span> and <span class="apiname">recvmsg()</span> functions</h4><p>The
following sequence of the socket calls provides a description of the graphic.
It also describes the relationship between the server and worker examples.
The first example uses the following socket calls to create a child process
with the <span class="apiname">sendmsg()</span> and <span class="apiname">recvmsg() </span> function
calls:</p>
<ol><li>The <span class="apiname">socket()</span> function returns a socket descriptor representing
an endpoint. The statement also identifies that the INET (Internet Protocol)
address family with the TCP transport (SOCK_STREAM) are used for this socket.</li>
<li>After the socket descriptor is created, the <span class="apiname">bind()</span> function
gets a unique name for the socket. </li>
<li>The <span class="apiname">listen()</span> allows the server to accept incoming client
connections. </li>
<li> The <span class="apiname">socketpair()</span> function creates a pair of UNIX<sup>®</sup> datagram
sockets. A server can use the <span class="apiname">socketpair()</span> API to create
a pair of AF_UNIX sockets.</li>
<li>The <span class="apiname">spawn()</span> function initializes the parameters
for a work job to handle incoming requests. In this example, the child job
created inherits the socket descriptor that was created by the <span class="apiname">socketpair()</span>.</li>
<li>The server uses the <span class="apiname">accept()</span> function to accept an
incoming connection request. The <span class="apiname">accept()</span> call blocks indefinitely
waiting for the incoming connection to arrive.</li>
<li>The <span class="apiname">sendmsg()</span> function sends an incoming connection
to one of the worker jobs. The child process accepts the connection with the<span class="apiname">recvmsg()</span> function.
The child job is not active when the server called <span class="apiname">sendmsg()</span>.</li>
<li>In this example, the first <span class="apiname">close()</span> function closes
the accepted socket. The second <span class="apiname">close ()</span> call ends the
listening socket.</li>
</ol>
</div>
<div class="section"><h4 class="sectiontitle">Socket flow of events: Worker job that uses <span class="apiname">recvmsg()</span></h4><p>The
second example uses the following sequence of function calls:</p>
<ol><li>After the server has accepted a connection and passed its socket descriptor
to the worker job, the <span class="apiname">recvmsg()</span> function receives the
descriptor. In this example, the <span class="apiname">recvmsg()</span> function waits
until the server sends the descriptor.</li>
<li>The <span class="apiname">recv()</span> function receives a message from the client.
</li>
<li>The <span class="apiname">send()</span> function echoes data back to the client.</li>
<li>The <span class="apiname">close()</span> function ends the worker job.</li>
</ol>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="x1descriptors.htm">Example: Server program used for sendmsg() and recvmsg()</a></strong><br />
This example shows how to use the <span class="apiname">sendmsg()</span> API
to create a pool of worker jobs.</li>
<li class="ulchildlink"><strong><a href="x2descriptors.htm">Example: Worker program used for sendmsg() and recvmsg()</a></strong><br />
This example shows how to use the <span class="apiname">recvmsg()</span> API
client job to receive the worker jobs.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <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>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="cdescriptors.htm" title="The ability to pass an open descriptor between jobs can lead to a new way of designing client/server applications.">Descriptor passing between processes—sendmsg() and recvmsg()</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="generic.htm" title="This code example contains the code for a common client job.">Example: Generic client</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../apis/spawn.htm">spawn()</a></div>
<div><a href="../apis/bind.htm">bind()</a></div>
<div><a href="../apis/socket.htm">socket()</a></div>
<div><a href="../apis/listen.htm">listen()</a></div>
<div><a href="../apis/accept.htm">accept()</a></div>
<div><a href="../apis/close.htm">close()</a></div>
<div><a href="../apis/socketp.htm">socketpair()</a></div>
<div><a href="../apis/sendms.htm">sendmsg()</a></div>
<div><a href="../apis/recvms.htm">recvmsg()</a></div>
<div><a href="../apis/send.htm">send()</a></div>
<div><a href="../apis/recv.htm">recv()</a></div>
</div>
</div>
</body>
</html>