1
<!-- page01.html,v 1.8 2000/03/19 20:09:23 jcej Exp -->
4
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
5
<META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (X11; I; Linux 2.0.32 i486) [Netscape]">
6
<META NAME="Author" CONTENT="James CE Johnson">
7
<META NAME="Description" CONTENT="A first step towards using ACE productively">
8
<TITLE>ACE Tutorial 006</TITLE>
10
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">
12
<CENTER><B><FONT SIZE=+2>ACE Tutorial 006</FONT></B></CENTER>
14
<CENTER><B><FONT SIZE=+2>Creating a thread-per-connection server</FONT></B></CENTER>
20
<P>In this tutorial, we're going to extend Tutorial 5 to create a thread-per-connection
21
server. This implementation will create a new thread for each client
22
which connects to us. The ACE_Reactor is still used but only for
23
accepting new connections. The Client_Handler objects won't be registered
24
with the reactor. Instead, they'll be responsible for monitoring
25
their peer() directly.
29
Here, we build a thread-per-connection simple server. This is the next
30
step from a simple single-threaded server towards a multithreaded
33
We make use of the Strategy Pattern in this example.
34
The ACE_Acceptor inherits form the ACE_Acceptor_Base class which
35
facilitates us to implement various different concurrency strategies
36
depending on whether the server is single-threaded or the server creates
37
a new thread per connection. This also allows us to extend the
38
capabilities of the server in the future by implementing a different
41
This information is passed on to the Client_Handler
42
(remember ACE_Acceptor < Client_Handler, ACE_SOCK_ACCEPTOR > ?).
43
The Client_Handler is an ACE_Svc_Handler as the Svc_Handler is a
44
derivative of the Event_Handler and is associated with
45
ACE_Sock_Stream. It is also derived form the ACE_Task class which allows
46
us to have a thread per connection.
48
We incorporate the data processing in the svc() method, which will be
49
called per thread for the thread-per-connection server.
51
Note that here all the Client_Handler objects aren't registered with the
52
reactor. The Reactor is only used to accept client connections. Once a
53
thread has been deicated per connection, the Client Handler object
54
reponsible for that client connection now takes up the job of the
55
reactor and handles future events.
57
Thus a simple, thread-per-connection server has been built which doesnt
58
delve too deeply into mutli-threading issues.
60
<font size=-1>* Abstract by Kirthika as always</font>
62
<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page02.html">Continue This Tutorial</A>]</CENTER>