Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > 21280410b6ea906d791d7a12afae2579 > files > 88

libace5-doc-5.4-2mdk.i586.rpm

<!-- page01.html,v 1.8 2000/03/19 20:09:23 jcej Exp -->
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (X11; I; Linux 2.0.32 i486) [Netscape]">
   <META NAME="Author" CONTENT="James CE Johnson">
   <META NAME="Description" CONTENT="A first step towards using ACE productively">
   <TITLE>ACE Tutorial 006</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">

<CENTER><B><FONT SIZE=+2>ACE Tutorial 006</FONT></B></CENTER>

<CENTER><B><FONT SIZE=+2>Creating a thread-per-connection server</FONT></B></CENTER>


<P>
<HR WIDTH="100%">

<P>In this tutorial, we're going to extend Tutorial 5 to create a thread-per-connection
server.&nbsp; This implementation will create a new thread for each client
which connects to us.&nbsp; The ACE_Reactor is still used but only for
accepting new connections.&nbsp; The Client_Handler objects won't be registered
with the reactor.&nbsp; Instead, they'll be responsible for monitoring
their peer() directly.
<P>
Abstract:<sup>*</sup>
<ul>
Here, we build a thread-per-connection simple server. This is the next
step from a simple single-threaded server towards a multithreaded
server.
<p>
We make use of the Strategy Pattern in this example.
The ACE_Acceptor inherits form the ACE_Acceptor_Base class which
facilitates us to implement various different concurrency strategies
depending on whether the server is single-threaded or the server creates
a new thread per connection. This also allows us to extend the
capabilities of the server in the future by implementing a different
strategy.
<p>
This information is passed on to the Client_Handler
(remember ACE_Acceptor < Client_Handler, ACE_SOCK_ACCEPTOR > ?).
The Client_Handler is an ACE_Svc_Handler as the Svc_Handler is a
derivative of the Event_Handler and is associated with
ACE_Sock_Stream. It is also derived form the ACE_Task class which allows
us to have a thread per connection.
<p>
We incorporate the data processing in the svc() method, which will be
called per thread for the thread-per-connection server.
<p>
Note that here all the Client_Handler objects  aren't registered with the
reactor. The Reactor is only used to accept client connections. Once a
thread has been deicated per connection, the Client  Handler object
reponsible for that client connection now takes up the job of the
reactor and handles future events.
<p>
Thus a simple, thread-per-connection server has been built which doesnt
delve too deeply into mutli-threading issues.
</ul>
<font size=-1>* Abstract by Kirthika as always</font>
<P><HR WIDTH="100%">
<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page02.html">Continue This Tutorial</A>]</CENTER>