summaryrefslogtreecommitdiff
path: root/docs/tutorials/006/page01.html
blob: 3ff14911f04967a7e3df0d077124b222204b0065 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!-- $Id$ -->
<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>