#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1999-01-17 14:20 EST by
In this tutorial, we will build a little on what we learned in the first
tutorial and add a few extras. In the end, we will have a better server
object that is actually simpler and more maintainable than the one we created
before.
SHAR_EOF
$shar_touch -am 0117141599 'hdr' &&
chmod 0664 'hdr' ||
$echo 'restore of' 'hdr' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'hdr:' 'MD5 check failed'
8a98117995f511d0ed9b699587b5b6a5 hdr
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'hdr'`"
test 607 -eq "$shar_count" ||
$echo 'hdr:' 'original size' '607,' 'current size' "$shar_count!"
fi
fi
# ============= bodies ==============
if test -f 'bodies' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'bodies' '(file already exists)'
else
$echo 'x -' extracting 'bodies' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'bodies' &&
PAGE=2
server.cpp
handler.h
SHAR_EOF
$shar_touch -am 0117141899 'bodies' &&
chmod 0664 'bodies' ||
$echo 'restore of' 'bodies' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'bodies:' 'MD5 check failed'
9ec2171f52b5b973c247ef550fb7b035 bodies
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'bodies'`"
test 28 -eq "$shar_count" ||
$echo 'bodies:' 'original size' '28,' 'current size' "$shar_count!"
fi
fi
# ============= page01.pre ==============
if test -f 'page01.pre' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'page01.pre' '(file already exists)'
else
$echo 'x -' extracting 'page01.pre' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'page01.pre' &&
X
To begin, let's ask ourselves the same thing we did at the beginning of tutorial 001:
XWhat do you need to create a server?
Previously, we created a solution which addressed each one of these questions specifically. At the end of it all, we realized that our only application-specific coding was confined to the handler portion of the program. We hinted that there may be a way to eliminate hand-coding an acceptor each time we want to create a server. Here, we will explore that approach.
X SHAR_EOF $shar_touch -am 0117141599 'page01.pre' && chmod 0664 'page01.pre' || $echo 'restore of' 'page01.pre' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'page01.pre:' 'MD5 check failed' c5a9075793a200d7b2e49a092ee1ce6c page01.pre SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page01.pre'`" test 1027 -eq "$shar_count" || $echo 'page01.pre:' 'original size' '1027,' 'current size' "$shar_count!" fi fi # ============= page02.pre ============== if test -f 'page02.pre' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'page02.pre' '(file already exists)' else $echo 'x -' extracting 'page02.pre' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'page02.pre' && XLike Tutorial 1, this is also a rather small program. I'm going to add a couple of new ideas along the way but to make up for it I'm also going to simplify the acceptor a great deal. X
Kirthika's Abstract:
Here, the Logging_Acceptor is an ACE_Acceptor class which is associated with the Logging_Handler and the ACE_SOCK_ACCEPTOR. This will now accept connection requests from the clients on being opened with the reactor instance passed to it.
We also implement a signal to capture CTRL-C [ which generates SIGINT ] using ACE_SigAction and ACE_SignalHandler. This signal can now be used to stop the reactor from handling events.
Then, the reactor is allowed to loop infintely until it is shut down using a ^C, after which both the reactor as well as the acceptor are destroyed.
The Logging_Handler derives from the ACE_Svc_Handler instead of the Event_Handler since the Svc_Handler has inbuilt SOCK_Stream and provides all the calls needed by the reactor. The Svc_Handler has the ability to react to events and communicate to remote tasks using the underlying data stream passed to it.
A timer is scheduled in the reactor which does nothing but simply display how it could be used to provide periodic processing when needed. The ACE_TimeValue is used to set the time period.
Also, optimisations have been made in the form of a separate function for destroying the objects used.
Thus a simpler server has now been built which successfully demonstrates how simple a task, writing a server can become on using the various ACE components judiciously.
We begin by looking at the main (server.cpp) portion program: X
Now lets take a look at the new Logging_Handler: X
Well, that's it for the second tutorial. We've found a much easier way
to create a server, especially the acceptor part. At the same time, we
introduced more functionality and robustness. Not bad for a day's work.