Get C network programming Vol 2 Systematic reuse with ACE and frameworks 6. print Edition Schmidt free all chapters
Get C network programming Vol 2 Systematic reuse with ACE and frameworks 6. print Edition Schmidt free all chapters
https://ebookultra.com/download/php-programming-with-pear-1st-edition-
schmidt-stephan/
https://ebookultra.com/download/programming-the-network-with-perl-1st-
edition-paul-barry/
https://ebookultra.com/download/systematic-instruction-for-students-
with-moderate-and-severe-disabilities-belva-c-collins/
https://ebookultra.com/download/programming-in-c-2-e-second-edition-
dey/
STL Tutorial and Reference Guide C Programming With the
Standard Template Library 2 (Draft) Edition David R.
Musser
https://ebookultra.com/download/stl-tutorial-and-reference-guide-c-
programming-with-the-standard-template-library-2-draft-edition-david-
r-musser/
https://ebookultra.com/download/programming-with-c-zambak-1st-edition-
osman-ay/
https://ebookultra.com/download/rapid-french-vol-2-with-audio-second-
edition-earworms/
https://ebookultra.com/download/programming-with-visual-c-concepts-
and-projects-1st-edition-james-allert/
C network programming Vol 2 Systematic reuse with
ACE and frameworks 6. print Edition Schmidt Digital
Instant Download
Author(s): Schmidt, Douglas C;Huston, Stephen D
ISBN(s): 9780201795257, 0201795256
Edition: 6. print
File Details: PDF, 2.08 MB
Year: 2002
Language: english
C++ Network Programming
Volume 2
The C++ In-Depth Series
Bjarne Stroustrup, Editor
“I have made this letter longer than usual, because I lack the time to make it short.”
—BLAISE PASCAL
T he advent of the ISO/ANSI C++ standard marked the beginning of a new era for C++
programmers. The standard offers many new facilities and opportunities, but how can a
real-world programmer find the time to discover the key nuggets of wisdom within this
mass of information? The C++ In-Depth Series minimizes learning time and confusion by
giving programmers concise, focused guides to specific topics.
Each book in this series presents a single topic, at a technical level appropriate to that
topic. The Series’ practical approach is designed to lift professionals to their next level
of programming skills. Written by experts in the field, these short, in-depth monographs
can be read and referenced without the distraction of unrelated material. The books are
cross-referenced within the Series, and also reference The C++ Programming Language by
Bjarne Stroustrup.
As you develop your skills in C++, it becomes increasingly important to separate essential
information from hype and glitz, and to find the in-depth content you need in order to grow.
The C++ In-Depth Series provides the tools, concepts, techniques, and new approaches to
C++ that will give you a critical edge.
For more information, check out the series web site at www.awprofessional.com/series/indepth/
C++ Network Programming
Volume 2
Douglas C. Schmidt
Stephen D. Huston
The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any
kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages
in connection with or arising out of the use of the information or programs contained herein.
The publisher offers discounts on this book when ordered in quantity for bulk purchases and special sales. For more
information, please contact:
International Sales
(317) 581-3793
[email protected]
Schmidt, Douglas C.
C++ network programming / Douglas C. Schmidt, Stephen D. Huston.
p. cm.
Includes bibliographical references and index.
Contents: Vol. 2. Systematic reuse with ACE and frameworks.
ISBN 0-201-79525-6 (v. 2 : pbk.)
1. C++ (Computer program language) 2. Object-oriented programming (Computer
science) 3. Computer networks. I. Huston, Stephen D. II. Title.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form,
or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher.
Printed in the United States of America. Published simultaneously in Canada.
For information on obtaining permission for use of material from this work, please submit a written request to:
ISBN: 0-201-79525-6
2 3 4 5 6 7 8 9 10— O P M—06050403
Second printing, February 2005
Contents
Foreword vii
v
vi CONTENTS
Glossary 319
Bibliography 329
Index 337
Foreword
The ADAPTIVE Communication Environment (ACE) toolkit has achieved enormous suc-
cess in the area of middleware for networked computing. Due to its flexibility, perfor-
mance, platform coverage, and other key properties, ACE enjoys broad acceptance by the
networked application software community, as evidenced by its use in thousands of applica-
tions, in scores of countries, and in dozens of domains. ACE has also received considerable
attention beyond the middleware community since it’s an open-source role model for high-
quality and well-designed pattern-oriented software architectures.
But why is ACE so successful? Addressing this question properly takes some thought.
To start off, let’s reconsider the Foreword from C++ Network Programming: Mastering
Complexity with ACE and Patterns (C++NPv1) and resume the mass transit analogy pre-
sented there by my colleague Steve Vinoski. Steve’s right that a high-quality mass transit
system consists of more than just aircraft, airports, trains, train stations, and rails. It also
needs less obvious infrastructure, such as scheduling, routing, ticketing, maintenance, and
monitoring. But even a complete collection of ingredients is still not sufficient to develop
an effective mass transit system. Arranging these ingredients so they seamlessly fulfill their
primary objective—fast and reliable transportation of people—is equally important. Would
you use a mass transit system whose ticketing was located in a train maintenance location
or an airport hangar, or whose planned and actual scheduling and routing weren’t available
to the public? I doubt it!
The success of mass transit systems depends on more than the knowledge of the infra-
structure parts that are provided—it depends on how these different parts must be connected
and integrated with their environment. This knowledge enables architects of mass transit
systems to integrate individual parts into higher-level building blocks and to connect these
building blocks effectively. For example, ticketing, information points, baggage offices, and
boarding are integrated in train stations located at city centers or major suburban centers.
Likewise, airports are often located near large cities and connected by frequent express
trains.
vii
viii Foreword
Even mass transit centers themselves are arranged so that activities can be performed
effectively. For example, when you enter a train station or airport via the main entrance, you
find ticket agents, information centers, and timetables. You also find shops to satisfy your
travel needs. As you enter the main train hall or airport concourse, you find other informa-
tion centers, up-to-date scheduling information, and the platforms and gates for boarding
the trains and planes. Mass transit centers thus not only provide all necessary services
to begin and end a journey, they also organize their internal “control flows” effectively.
While the core structures and control flows in most train stations and airports are similar,
their concrete realization can differ widely. Yet we all recognize these mass transit center
patterns immediately since they follow key invariants that we’ve learned through years of
experience.
So what’s the connection between successful mass transit system design and the success
of ACE? The answer is simple: In addition to the basic network computing ingredients (the
wrapper facades that Doug and Steve introduced in C++NPv1), ACE also includes use-
ful object-oriented frameworks that build upon these wrapper facades and provide useful
higher-level communication services, such as event demultiplexing and dispatching, con-
nection management, service configuration, concurrency, and hierarchically layered stream
processing. The ACE framework services satisfy many networked software needs by or-
ganizing the structures and internal control flows of your applications effectively via key
patterns learned through years of experience.
The ACE frameworks offer you a number of important benefits:
• You needn’t develop the capabilities provided by ACE, which will save considerable
time and effort. You can therefore focus on your key responsibility: implementing
the application functionality required by your customers and end users.
• The ACE frameworks reify the extensive network programming expertise that Doug,
Steve, and their colleagues have gained over several decades. In particular, the ACE
frameworks efficiently implement the canonical classes, class relationships, and con-
trol flows common to networked applications. The ACE frameworks are tested reg-
ularly by thousands of users from around the world, which has yielded many useful
corrections and improvements. As an ACE user, you can directly leverage the cor-
rectness, effectiveness, and efficiency of the ACE frameworks in your applications.
• A framework isn’t a framework if it can’t be adapted to specific user needs. This
means you can adapt the ACE frameworks at key points of variation in networked
applications. For example, the ACE Reactor framework can be adapted to use dif-
ferent event demultiplexer functions, such as WaitForMultipleObjects() or
select(). Likewise, the ACE Acceptor-Connector framework can be configured
with different IPC mechanisms. While this adaptability is beneficial by itself, ACE
goes a step further: for many adaptations you can configure the desired strategies
from available and interchangeable implementations. In addition to the different Re-
Foreword ix
actor implementations mentioned above, for instance, ACE provides wrapper facades
for various IPC mechanisms, such as the Sockets, SSL, TLI, and shared memory, that
help to configure the ACE Acceptor-Connector framework for specific platforms and
applications.
• Last but not least, the ACE frameworks don’t exist in isolation. You can therefore
combine them in novel ways to create networked applications and entirely new types
of middleware. For example, you can integrate the Reactor framework with the
Acceptor-Connector framework to separate connection establishment from service
processing functionality in event-driven applications. You can likewise introduce
various forms of concurrency into your applications using the ACE Task framework.
As a result of advising and leading many software projects over the years, I’ve found
that ACE greatly simplifies the task of employing reusable middleware that can be cus-
tomized readily to meet the needs of networked applications. Not all networked applica-
tions need heavyweight middleware, such as application servers, web services, and complex
component models. Yet most networked applications can benefit from portable and efficient
host infrastructure middleware like ACE. This flexibility is the core of ACE’s success since
you needn’t commit to an entire middleware suite if you don’t use all of it. Instead, you
can combine just the essential ACE middleware classes you need to compose applications
that are small, but as powerful as necessary. For this reason, I predict that ACE will still be
widely used long after the influence of today’s heavyweight middleware has waned.
ACE’s tremendous flexibility also needn’t lead to a sea of incompatible middleware
implementations. For example, if you build an embedded system that speaks the CORBA
Internet inter-ORB protocol (IIOP) to the outside world, you can use The ACE ORB (TAO),
which is a CORBA-compliant, open-source, real-time object request broker (ORB) built
using the ACE wrapper facades and frameworks. If CORBA is overkill for your application
needs, however, you can build custom, yet interoperable, middleware using the appropriate
ACE classes. Both solutions can be based on the same core structures and protocols, such
as the ACE Common Data Representation (CDR) classes and its TCP/IP Socket wrapper
facades. They can therefore communicate seamlessly with one another, just as you can
take a train from Paris to Istanbul—the famous Orient Express—and travel through many
European countries without having to change trains due to incompatible railroad networks.
As Steve Vinoski and I have pointed out, there are many similarities between high-
quality mass transit systems and high-quality networking middleware. To me and thousands
of other C++ developers around the world, ACE is the toolkit for building the latter! Af-
ter saying so many good things about ACE, however, let’s return to the main intent of this
foreword: introducing the second volume (C++NPv2) of the C++ Network Programming
series. As with all software technologies and middleware, the more you understand your
tools, the better you’ll be able to apply them. It turns out that using ACE in your appli-
cations is just one aspect of improving your networked software. To benefit significantly
x Foreword
from ACE’s many advantages, you therefore also need a sound understanding of the core
concepts, patterns, and usage rules that underlie its powerful frameworks.
For years, a common way to learn ACE involved studying its code, comments, and ex-
ample applications. Clearly, this process was time consuming and error prone. Moreover,
even after managing to read the several hundred thousand lines of C++ code in ACE, it was
easy to miss the forest for the trees. As the Greek philosopher Thucydides noted two mil-
lennia ago: “A man who has the knowledge but lacks the power to clearly express himself
is no better off than if he had never any idea at all.”
We’re therefore fortunate that Doug and Steve found time in their busy schedules to
create such a high-quality book on the ACE frameworks. C++NPv2 explains the ideas
and concepts underlying the ACE frameworks in an easily accessible form using the popu-
lar concurrency and networking patterns from the POSA [POSA1, POSA2] and “Gang of
Four” [GoF] patterns books. These patterns, in turn, reify thoughtful and time-proven solu-
tions to common networking problems. For example, they tell you what the problems are,
why these problems are hard, what the solutions to these problems are, and why these solu-
tions applied to ACE are of high quality. If you want thorough coverage of the patterns and
frameworks in ACE that are shaping the next generation of networked application software
then read this book. I’ve learned much from it and I’m sure you will too.
Frank Buschmann
Senior Principal Engineer
Siemens Corporate Technology
Munich, Germany
About This Book
Software for networked applications must possess the following qualities to be successful
in today’s competitive, fast-paced computing industry:
• Affordability, to ensure that the total ownership costs of software acquisition and
evolution are not prohibitively high
• Extensibility, to support successions of quick updates and additions to address new
requirements and take advantage of emerging markets
• Flexibility, to support a growing range of multimedia data types, traffic patterns, and
end-to-end quality of service (QoS) requirements
• Portability, to reduce the effort required to support applications on heterogeneous
OS platforms and compilers
• Predictability and efficiency, to provide low latency to delay-sensitive real-time ap-
plications, high performance to bandwidth-intensive applications, and usability over
low-bandwidth networks, such as wireless links
• Reliability, to ensure that applications are robust, fault tolerant, and highly available
• Scalability, to enable applications to handle large numbers of clients simultaneously
xi
xii About This Book
This book describes how the ACE frameworks are designed and how they can help
developers navigate between the limitations of
1. Low-level native operating system APIs, which are inflexible and nonportable
2. High-level middleware, such as distribution middleware and common middleware
services, which often lacks the efficiency and flexibility to support networked appli-
cations with stringent QoS and portability requirements
The skills required to produce and use networked application frameworks have traditionally
been locked in the heads of expert developers or buried deep within the source code of
numerous projects that are spread throughout an enterprise or an industry. Neither of these
locations is ideal, of course, since it’s time consuming and error prone to reengineer this
knowledge for each new application or project. To address this problem, this book illustrates
the key patterns [POSA2, POSA1, GoF] that underlie the structure and functionality of the
ACE frameworks. Our coverage of these patterns also makes it easier to understand the
design, implementation, and effective use of the open-source ACE toolkit itself.
Intended Audience
This book is intended for “hands on” C++ developers or advanced students interested in
understanding how to design object-oriented frameworks and apply them to develop net-
worked applications. It builds upon material from C++NPv1 that shows how developers
can apply patterns to master complexities arising from using native OS APIs to program
networked applications. It’s therefore important to have a solid grasp of the following top-
ics covered in C++NPv1 before reading this book:
• Networked application design dimensions, including the alternative communica-
tion protocols and data transfer mechanisms discussed in Chapter 1 of C++NPv1
• Internet programming mechanisms, such as TCP / IP connection management and
data transfer APIs [Ste98] discussed in Chapter 2 of C++NPv1
• Concurrency design dimensions, including the use of processes and threads, iter-
ative versus concurrent versus reactive servers, and threading models [Ste99] dis-
cussed in Chapters 5 through 9 of C++NPv1
• Synchronization techniques necessary to coordinate the interactions of processes
and threads on various OS platforms [KSS96, Lew95, Ric97] discussed in Chapter
10 of C++NPv1
• Object-oriented design and programming techniques [Boo94, Mey97] that can
simplify OS APIs and avoid programming mistakes through the use of patterns, such
as Wrapper Facade [POSA2] and Proxy [POSA1, GoF] discussed in Chapter 3 and
Appendix A of C++NPv1
xiv About This Book
The ACE frameworks are highly flexible and powerful, due in large part to their use of
C++ language features [Bja00]. You should therefore be familiar with C++ class inheritance
and virtual functions (dynamic binding) as well as templates (parameterized types) and
the mechanisms your compiler(s) offer to instantiate them. ACE provides a great deal of
assistance in overcoming differences between C++ compilers. As always, however, you
need to know the capabilities of your development tools and how to use them. Knowing
your tools makes it easier to follow the source code examples in this book and to build and
run them on your systems. Finally, as you read the examples in this book, keep in mind the
points noted in Sidebar 7 (page 46) regarding UML diagrams and C++ code.
• Chapter 3 describes the design and use of the ACE Reactor framework, which imple-
ments the Reactor pattern [POSA2] to allow event-driven applications to demultiplex
and dispatch service requests that are delivered to an application from one or more
clients.
• Chapter 4 then describes the design and use of the most common implementations
of the ACE_Reactor interface, which support a wide range of OS event demul-
tiplexing mechanisms, including select(), WaitForMultipleObjects(),
XtAppMainLoop(), and /dev/poll.
• Chapter 5 describes the design and use of the ACE Service Configurator framework.
This framework implements the Component Configurator pattern [POSA2] to allow
an application to link/unlink its component service implementations at run time with-
out having to modify, recompile, or relink the application statically.
• Chapter 6 describes the design and effective use of the ACE Task framework. This
framework can be used to implement key concurrency patterns, such as Active Object
and Half-Sync/Half-Async [POSA2].
• Chapter 7 describes the design and effective use of the ACE Acceptor-Connector
framework. This framework implements the Acceptor-Connector pattern [POSA2] to
decouple the connection and initialization of cooperating peer services in a networked
system from the processing they perform once connected and initialized.
• Chapter 8 describes the design and use of the ACE Proactor framework. This frame-
work implements the Proactor and Acceptor-Connector patterns [POSA2] to allow
event-driven applications to efficiently demultiplex and dispatch service requests trig-
gered by the completion of asynchronously initiated operations.
• Chapter 9 describes the design and use of the ACE Streams framework. This frame-
work implements the Pipes and Filters pattern [POSA1] to provide a structure for
systems that process streams of data.
• The book concludes with a glossary of technical terms, a list of references for further
study, and a general subject index.
The chapters are organized to build upon each other and to minimize forward references.
We therefore recommend that you read the chapters in order.
Although this book illustrates the key capabilities of ACE’s most important frameworks,
we don’t cover all uses and methods of those frameworks. For additional coverage of ACE,
we refer you to The ACE Programmer’s Guide [HJS] and the online ACE reference doc-
umentation, generated by Doxygen [Dim01]. ACE’s reference documentation is available
at http://ace.ece.uci.edu/Doxygen/ and http://www.riverace.com/
docs/.
xvi About This Book
Related Material
This book is based on ACE version 5.3, released in the fall of 2002. ACE 5.3 and all the
sample applications described in our books are open-source software. Sidebar 3 (page 19)
explains how you can obtain a copy of ACE so you can follow along, see the actual ACE
classes and frameworks in complete detail, and run the code examples interactively as you
read the book.
To learn more about ACE, or to report errors you find in the book, we recommend you
subscribe to the ACE mailing list, [email protected]. You can subscribe by
sending a request to [email protected]. Include the following
command in the body of the e-mail (the subject is ignored):
subscribe ace-users [emailaddress@domain]
You must supply emailaddress@domain only if your message’s From address is not
the address you wish to subscribe. If you use this alternate address method, the list server
will require an extra authorization step before allowing you to join the list.
Postings to the ace-users list are also forwarded to the comp.soft-sys.ace
USENET newsgroup, along with postings to several other ACE-related mailing lists. Read-
ing the messages via the newsgroup is a good way to keep up with ACE news and activity
if you don’t require immediate delivery of the 30 to 50 messages that are posted daily on
the mailing lists.
Archives of postings to the comp.soft-sys.ace newsgroup are available at http:
//groups.google.com/. Enter comp.soft-sys.ace in the search box to go to
a list of archived messages. Google has a complete, searchable archive of over 40,000
messages. You can also post a message to the newsgroup from Google’s site.
Acknowledgments
Champion reviewing honors go to Alain Decamps, Don Hinton, Alexander Maack, Chris
Uzdavinis, and Johnny Willemsen, who reviewed the book multiple times and provided ex-
tensive, detailed comments that improved its form and content substantially. Many thanks
also to the official reviewers, Timothy Culp, Dennis Mancl, Phil Mesnier, and Jason Pa-
sion, who read the entire book and gave us many helpful comments. Many other ACE
users provided feedback on this book, including Marc M. Adkins, Tomer Amiaz, Vi Thuan
Banh, Kevin Bailey, Stephane Bastien, John Dilley, Eric Eide, Andrew Finnell, Dave Find-
lay, Jody Hagins, Jon Harnish, Jim Havlicek, Martin Johnson, Christopher Kohlhoff, Alex
Libman, Harald Mitterhofer, Llori Patterson, Nick Pratt, Dieter Quehl, Tim Rozmajzl, Irma
Rastegayeva, Eamonn Saunders, Harvinder Sawhney, Christian Schuhegger, Michael Sear-
les, Kalvinder Singh, Henny Sipma, Stephen Sturtevant, Leo Stutzmann, Tommy Svensson,
Bruce Trask, Dominic Williams, and Vadim Zaliva.
About This Book xvii
We are deeply indebted to all the members, past and present, of the DOC groups at
Washington University in St. Louis and the University of California, Irvine, as well as the
team members at Riverace Corporation and Object Computing Inc., who developed, refined,
and optimized many of the ACE capabilities presented in this book. This group includes Ev-
erett Anderson, Alex Arulanthu, Shawn Atkins, John Aughey, Luther Baker, Jaiganesh Bal-
asubramanian, Darrell Brunsch, Don Busch, Chris Cleeland, Angelo Corsaro, Chad Elliot,
Sergio Flores-Gaitan, Chris Gill, Pradeep Gore, Andy Gokhale, Priyanka Gontla, Myrna
Harbibson, Tim Harrison, Shawn Hannan, John Heitmann, Joe Hoffert, James Hu, Frank
Hunleth, Prashant Jain, Vishal Kachroo, Ray Klefstad, Kitty Krishnakumar, Yamuna Krish-
namurthy, Michael Kircher, Fred Kuhns, David Levine, Chanaka Liyanaarachchi, Michael
Moran, Ebrahim Moshiri, Sumedh Mungee, Bala Natarajan, Ossama Othman, Jeff Parsons,
Kirthika Parameswaran, Krish Pathayapura, Irfan Pyarali, Sumita Rao, Carlos O’Ryan,
Rich Siebel, Malcolm Spence, Marina Spivak, Naga Surendran, Steve Totten, Bruce Trask,
Nanbor Wang, and Seth Widoff.
We also want to thank the thousands of C++ developers from over 50 countries who’ve
contributed to ACE for over a decade. ACE’s excellence and success is a testament to the
skills and generosity of many talented developers and the forward-looking companies that
had the vision to contribute their work to ACE’s open-source code base. Without their
support, constant feedback, and encouragement, we would never have written this book.
In recognition of the efforts of the ACE open-source community, we maintain a list of all
contributors at http://ace.ece.uci.edu/ACE-members.html.
We are also grateful for the support from colleagues and sponsors of our research
on patterns and development of the ACE toolkit, notably the contributions of Ron Akers
(Motorola), Steve Bachinsky (SAIC), John Bay (DARPA), Detlef Becker (Siemens), Frank
Buschmann (Siemens), Dave Busigo (DARPA), John Buttitto (Sun), Becky Callison (Boe-
ing), Wei Chiang (Nokia Inc.), Joe Cross (Lockheed Martin), Lou DiPalma (Raytheon),
Bryan Doerr (Savvis), Karlheinz Dorn (Siemens), Scott Ellard (Madison), Matt Emerson
(Escient Convergence Group, Inc.), Sylvester Fernandez (Lockheed Martin), Nikki Ford
(DARPA), Andreas Geisler (Siemens), Helen Gill (NSF), Inc.), Jody Hagins (ATD), Andy
Harvey (Cisco), Sue Kelly (Sandia National Labs), Gary Koob (DARPA), Petri Koske-
lainen (Nokia Inc.), Sean Landis (Motorola), Patrick Lardieri (Lockheed Martin), Doug Lea
(SUNY Oswego), Joe Loyall (BBN), Kent Madsen (EO Thorpe), Ed Margand (DARPA),
Mike Masters (NSWC), Major Ed Mays (U.S. Marine Corps), John Mellby (Raytheon),
Jeanette Milos (DARPA), Stan Moyer (Telcordia), Ivan Murphy (Siemens), Russ Nose-
worthy (Object Sciences), Adam Porter (U. of Maryland), Dieter Quehl (Siemens), Vi-
jay Raghavan (Vanderbilt U.), Lucie Robillard (U.S. Air Force), Craig Rodrigues (BBN),
Rick Schantz (BBN), Andreas Schulke (Siemens), Steve Shaffer (Kodak), Tom Shields
(Raytheon), Dave Sharp (Boeing), Naval Sodha (Ericsson), Paul Stephenson (Ericsson),
Tatsuya Suda (UCI), Umar Syyid (Storetrax, Inc.), Janos Sztipanovits (Vanderbilt U.), Gau-
tam Thaker (Lockheed Martin), Lothar Werzinger (Krones), and Don Winter (Boeing).
xviii About This Book
Very special thanks go to Susan Cooper, our copy editor, for enhancing our written
material. In addition, we are grateful for the encouragement and patience of our editor,
Debbie Lafferty, our production coordinator, Elizabeth Ryan, the series editor and inventor
of C++, Bjarne Stroustrup, and everyone else at Addison-Wesley who made it possible to
publish this book.
Finally, we would also like to acknowledge our gratitude and indebtedness to the late
W. Richard Stevens, the father of network programming literature. The following poem by
Samuel Butler sums up our view of Richard’s enduring influence:
Steve’s Acknowledgments
Wow. . . C++NPv1 took almost 3 years to complete—this volume took roughly nine months.
Thank you to my wife Jane who cheerfully endured this process. Your persistent exhorta-
tion to keep life in balance and “be the tortoise” really helped me stay the course, and
without your infinite patience through many long days and nights, I would not have com-
pleted this—thank you! Thanks to Doug Schmidt for getting the bulk of this book down
and organized in world-class time amidst a full-time job and his usual, amazing amount
of work on ACE. Finally, thank you to Riverace’s customers who supported this work so
enthusiastically. It’s a privilege to serve you.
Doug’s Acknowledgments
I’d like to thank my wife Sonja and my parents for their love and support during the writing
of this book. Now that it’s done we’ll have lots more time to have fun! Thanks also to Steve
Huston, who time-shared his overloaded schedule to wrap up the book. I’d also like to thank
my friends and colleagues at the College of William and Mary; Washington University, St.
Louis; University of California, Irvine; Vanderbilt University; DARPA; and Siemens—as
well as the thousands of ACE and TAO developers and users worldwide—who have greatly
enriched my intellectual and interpersonal life over the past two decades. I look forward to
working with all of you in the future.
C HAPTER 1
C HAPTER S YNOPSIS
Object-oriented frameworks help reduce the cost and improve the quality of networked ap-
plications by reifying software designs and pattern languages that have proven effective in
particular application domains. This chapter illustrates what frameworks are and compares
them with other popular software development techniques, such as class libraries, compo-
nents, patterns, and model-integrated computing. It then illustrates the process of applying
frameworks to networked applications and outlines the ACE frameworks that are the fo-
cus of this book. These frameworks are based on a pattern language [POSA1, POSA2]
that has been applied to thousands of production networked applications and middleware
worldwide.
1
2 CHAPTER 1 Object-Oriented Frameworks for Network Programming
• Opportunistic reuse, in which developers cut and paste code from existing programs
to create new ones. Opportunistic reuse works in a limited way for individual pro-
grammers or small groups. It doesn’t scale up across business units or enterprises,
however, and therefore doesn’t significantly reduce development cycle time and cost
or improve software quality. Worse, opportunistic reuse can actually impede devel-
opment progress since cut-and-paste code often begins to diverge as it proliferates,
forcing developers to fix the same bugs multiple times in multiple places.
• Systematic reuse, which is an intentional and concerted effort to create and apply
multiuse software architectures, patterns, frameworks, and components throughout
a product line [CN02]. In a well-honed systematic reuse process, each new project
leverages time-proven designs and implementations, only adding new code that’s spe-
cific to a particular application. This type of reuse is essential to increase software
productivity and quality by breaking the costly cycle of rediscovering, reinventing,
and revalidating common software artifacts.
Middleware [SS02] is a class of software that can increase systematic reuse levels
significantly by functionally bridging the gap between the end-to-end functional require-
ments of networked applications and the underlying operating systems and network pro-
tocol stacks. Middleware provides capabilities that are critical to networked applications
because they automate common network programming tasks. Developers who use mid-
dleware can therefore program their networked applications more like stand-alone applica-
tions, rather than wrestling with the many tedious and error-prone details associated with
low-level OS event demultiplexing, message buffering and queueing, marshaling and de-
marshaling, and connection management mechanisms. Popular examples of middleware
include Java virtual machines (JVMs), Enterprise JavaBeans (EJB), .NET, the Common
Object Request Broker Architecture (CORBA), and the ADAPTIVE Communication Envi-
ronment (ACE).
Systematically developing high-quality, reusable middleware for networked applica-
tions presents many hard technical challenges, including
• Detecting and recovering from transient and partial failures of networks and hosts in
an application-independent manner
• Minimizing the impact of latency and jitter on end-to-end application performance
• Determining how to partition a distributed application into separate component ser-
vices
• Deciding where and when to distribute and load balance services in a network
Since reusable middleware is inherently abstract, it’s hard to validate its quality and to man-
age its production. Moreover, the skills required to develop, deploy, and support reusable
networked application middleware have traditionally been a “black art,” locked in the heads
of expert developers and architects. These technical impediments to systematic reuse are of-
ten exacerbated by a myriad of nontechnical impediments [Hol97], such as organizational,
Section 1.1 An Overview of Object-Oriented Frameworks 3
Networking Event
loop
Callbacks GUI
Application- Domain-specific
specific Callbacks framework
functionality capabilities
Event
loop
Callbacks
Event
Database
loop
the events. The use of virtual hook methods in the handler classes decouples the applica-
tion’s classes from the framework, allowing each to be changed independently as long as
the interface signature and interaction protocols aren’t modified.
A framework is a “semi-complete” application that programmers can customize to form
complete applications by inheriting from and instantiating classes in the framework. Inheri-
tance enables the features of framework base classes to be shared selectively by subclasses.
If a base class provides default implementations of its methods, application developers need
only override those virtual methods whose default behavior doesn’t meet their needs.
Since a framework is a semi-complete application, it enables larger-scale reuse of soft-
ware than can be achieved by reusing individual classes or stand-alone functions. The
amount of reuse increases due to a framework’s ability to integrate application-defined and
application-independent classes. In particular, a framework abstracts the canonical control
flow of applications in a domain into families of related classes, which can collaborate to
integrate customizable application-independent code with customized application-defined
code.
Local
Application- invocations Math Event
Networking
specific classes loop
functionality
ADT Callbacks GUI
classes
Application-specific
Database
event handler Callbacks
classes
functionality
Event
GUI loop
classes Callbacks
Glue
Event Network Event
code Database
loop IPC classes loop
Frameworks can be classified in terms of the techniques used to extend them, which
range along a continuum from whitebox frameworks to blackbox frameworks [HJE95],
as described below:
• Whitebox frameworks. Extensibility is achieved in a whitebox framework via
object-oriented language features, such as inheritance and dynamic binding.
Existing functionality can be reused and customized by inheriting from frame-
work base classes and overriding predefined hook methods [Pre95] using pat-
terns such as Template Method [GoF], which defines an algorithm with some
steps supplied by a derived class. To extend a whitebox framework, application
developers must have some knowledge of its internal structure.
• Blackbox frameworks. Extensibility is achieved in a blackbox framework by
defining interfaces that allow objects to be plugged into the framework via
composition and delegation. Existing functionality can be reused by defin-
ing classes that conform to a particular interface and then integrating these
classes into the framework using patterns such as Function Object [Kuh97],
Bridge/Strategy [GoF], and Pluggable Factory [Vli98b, Vli99, Cul99], which pro-
vide a blackbox abstraction for selecting one of many implementations. Black-
box frameworks can be easier to use than whitebox frameworks since appli-
cation developers need less knowledge of the framework’s internal structure.
Blackbox frameworks can also be harder to design, however, since framework
developers must define crisp interfaces that anticipate a range of use cases.
Another way that class libraries differ from frameworks is that the classes in a library
are typically passive since they perform their processing by borrowing the thread from so-
called self-directed applications that invoke their methods. As a result, developers must
continually rewrite much of the control logic needed to bind the reusable classes together to
form complete networked applications. In contrast, frameworks are active since they direct
the flow of control within an application via various callback-driven event handling patterns,
such as Reactor [POSA2] and Observer [GoF]. These patterns invert the application’s flow
of control using the Hollywood Principle: “Don’t call us, we’ll call you” [Vli98a]. Since
frameworks are active and manage the application’s control flow, they can perform a broader
range of activities on behalf of applications than is possible with passive class libraries.
Frameworks and class libraries are complementary technologies in practice. Frame-
works provide a foundational structure to applications. Since frameworks are focused on a
specific domain, however, they aren’t expected to satisfy the broadest range of application
development needs. Class libraries are therefore often used in conjunction within frame-
works and applications to implement commonly needed code artifacts, such as strings, files,
and time/date classes.
Section 1.2 Comparing Software Development and Reuse Techniques 7
Deployment and
configuration
metadata
Trading Logging
Deployment and component component
configuration
mechanism
Containers Containers
Application server
For example, the ACE frameworks use the ACE wrapper facade classes to ensure their
portability. Likewise, applications can use the ACE container classes described in [HJS]
to help implement their event handlers. Whereas the ACE container classes and wrapper
facades are passive, the ACE frameworks are active and provide inversion of control at run
time. The ACE toolkit provides both frameworks and a library of classes to help program-
mers address a range of challenges that arise when developing networked applications.
Traditionally, patterns and pattern languages have been locked in the heads of expert
developers or buried deep within the source code of software applications and systems.
Allowing this valuable information to reside only in these locations is risky and expensive.
Explicitly capturing and documenting patterns for networked applications helps to
• Preserve important design information for programmers who enhance and main-
tain existing software. This information will be lost if it isn’t documented, which can
increase software entropy and decrease software maintainability and quality.
• Guide design choices for developers who are building new applications. Since pat-
terns document the common traps and pitfalls in their domain, they help developers
to select suitable architectures, protocols, algorithms, and platform features without
wasting time and effort (re)implementing solutions that are known to be inefficient
or error prone.
Knowledge of patterns and pattern languages helps to reduce development effort and
maintenance costs. Reuse of patterns alone, however, does not create flexible and effi-
cient software. Although patterns enable reuse of abstract design and architecture knowl-
edge, software abstractions documented as patterns don’t directly yield reusable code. It’s
therefore essential to augment the study of patterns with the creation and use of frame-
works. Frameworks help developers avoid costly reinvention of standard software artifacts
by reifying common patterns and pattern languages and by refactoring common implemen-
tation roles.
ACE users can write networked applications quickly because the frameworks in ACE
implement the core patterns associated with service access, event handling, concurrency,
and synchronization [POSA2]. This knowledge transfer makes ACE more accessible and
directly applicable compared to many other common knowledge transfer activities, such as
seminars, conferences, or design and code reviews. Although these other activities are use-
ful, they are limited because participants must learn from past work of others, and then try
to apply it to their current and future projects. In comparison, ACE provides direct knowl-
edge transfer by embodying framework usage patterns in a powerful toolkit containing both
networked application domain experience and working code.
For example, JAWS [HS99] is a high-performance, open-source, adaptive Web server
built using the ACE frameworks. Figure 1.4 (page 10) illustrates how the JAWS Web server
is structured as a set of collaborating frameworks whose design is guided by the patterns
listed along the borders of the figure. These patterns help resolve common design challenges
that arise when developing concurrent servers, including encapsulating low-level operating
system APIs, decoupling event demultiplexing and connection management from protocol
processing, scaling up server performance via multithreading, minimizing server threading
overhead, using asynchronous I/O effectively, and enhancing server configurability. More
information on the patterns and design of JAWS appears in Chapter 1 of POSA2.
10 CHAPTER 1 Object-Oriented Frameworks for Network Programming
State
Memento
framework filesystem
Component configurator
/home/...
Protocol
Event dispatcher
Acceptor
handler
Protocol
filter
Concurrency
State
Protocol pipeline strategy
framework framework
Integrated
model
Model Platform-
interpreter Executable specific Application
and code specifications code code
synthesizer Integrate and Synthesize
generator
generate
System
constraints
• Provide correctness proofs for various algorithms by analyzing the models automati-
cally and offering refinements to satisfy various constraints.
• Generate code that’s highly dependable and robust since the modeling tools them-
selves can be synthesized from meta-models using provably correct technologies.
• Rapidly prototype new concepts and applications that can be modeled quickly using
this paradigm, compared to the effort required to prototype them manually.
• Reuse domain-specific modeling insights, saving significant amounts of time and
effort, while also reducing application time-to-market and improving consistency and
quality.
As shown in Figure 1.5, the MIC development process uses a set of tools to analyze
the interdependent features of the application captured in a model and determine the feasi-
bility of supporting different QoS requirements in the context of the specified constraints.
Another set of tools then translates models into executable specifications that capture the
platform behavior, constraints, and interactions with the environment. These executable
specifications in turn can be used to synthesize application software.
Earlier efforts at model-based development and code synthesis attempted by CASE
tools generally failed to deliver on their potential for the following reasons [All02]:
• They attempted to generate entire applications, including the infrastructure and the
application logic, which led to inefficient, bloated code that was hard to optimize,
validate, evolve, or integrate with existing code.
• Due to the lack of sophisticated domain-specific languages and associated modeling
tools, it was hard to achieve round-trip engineering, that is, moving back and forth
seamlessly between model representations and the synthesized code.
• Since CASE tools and early modeling languages dealt primarily with a restricted
set of platforms (such as mainframes) and legacy programming languages (such as
COBOL), they did not adapt well to the distributed computing paradigm that arose
12 CHAPTER 1 Object-Oriented Frameworks for Network Programming
Many of the limitations with model-integrated computing outlined above can be over-
come by integrating MIC tools and processes with object-oriented frameworks [GSNW02].
This integration helps to overcome problems with earlier-generation CASE tools since it
does not require the modeling tools to generate all the code. Instead, large portions of ap-
plications can be composed from reusable, prevalidated framework classes. Likewise, inte-
grating MIC with frameworks helps address environments where application requirements
and functionality change at a rapid pace by synthesizing and assembling newer extended
framework classes and automating the configuration of many QoS-critical aspects, such as
concurrency, distribution, transactions, security, and dependability.
The combination of model-integrated computing with frameworks, components, and
patterns is an area of active research [Bay02]. In the DOC group, for example, there are
R&D efforts underway to develop a MIC tool suite called the Component Synthesis with
Model-Integrated Computing (CoSMIC) [GSNW02]. CoSMIC extends the popular GME
modeling and synthesis tools [LBM+ 01] and the ACE ORB (TAO) [SLM98] to support
the development, assembly, and deployment of QoS-enabled networked applications. To
ensure the QoS requirements can be realized in the middleware layer, CoSMIC’s model-
integrated computing tools can specify and analyze the QoS requirements of application
components in their accompanying metadata.
HI
HOST INFRASTRUCTURE MIDDLEWARE
SOCKETS & TLI
LEVEL OF USER
open()/close()/putmsg()/getmsg() SPACE
ABSTRACTION
TPI
STREAMS NPI
KERNEL
SPACE
LO FRAMEWORK DLPI
Figure 1.6: Levels of Abstraction for Network Programming
Capability Description
Local endpoint Create and destroy local communication endpoints, allowing ac-
management cess to available networking facilities.
Connection establishment Enable applications to establish connections actively or passively
and connection with remote peers and to shutdown all or part of the connections
termination when transmissions are complete.
Options management Negotiate and enable/disable protocol and endpoint options.
Data transfer mechanisms Exchange data with peer applications.
Name/address translation Convert human-readable names to low-level network addresses
and vice versa.
These capabilities are covered in Chapter 2 of C++NPv1 in the context of the Socket API.
14 CHAPTER 1 Object-Oriented Frameworks for Network Programming
Many IPC APIs are modeled loosely on the UNIX file I/O API, which defines the
open(), read(), write(), close(), ioctl(), lseek(), and select() func-
tions [Rit84]. Due to syntactic and semantic differences between file I/O and network I/O,
however, networking APIs provide additional functionality that’s not supported directly by
the standard UNIX file I/O APIs. For example, the pathnames used to identify files on a
UNIX system aren’t globally unique across hosts in a heterogeneous distributed environ-
ment. Different naming schemes, such as IP host addresses and TCP / UDP port numbers,
have therefore been devised to uniquely identify communication endpoints used by net-
worked applications.
Host infrastructure middleware frameworks. Many networked applications exchange
messages using synchronous and/or asynchronous request/response protocols in conjunc-
tion with host infrastructure middleware frameworks. Host infrastructure middleware en-
capsulates OS concurrency and IPC mechanisms to automate many low-level aspects of
networked application development, including
• Connection management and event handler initialization
• Event detection, demultiplexing, and event handler dispatching
• Message framing atop bytestream protocols, such as TCP
• Presentation conversion issues involving network byte ordering and parameter mar-
shaling and demarshaling
• Concurrency models and synchronization of concurrent operations
• Networked application composition from dynamically configured services
• Hierarchical structuring of layered networked applications and services
• Management of quality of service (QoS) properties, such as scheduling access to
processors, networks, and memory
The increasing availability and popularity of high-quality and affordable host infrastructure
middleware is helping to raise the level of abstraction at which developers of networked
applications can work effectively. For example, [C++NPv1, SS02] present an overview of
higher-level distributed object computing middleware, such as CORBA [Obj02] and The
ACE ORB (TAO) [SLM98], which is an implementation of CORBA built using the frame-
works and classes in ACE. It’s still useful, however, to understand how lower level IPC
mechanisms work to fully comprehend the challenges that arise when designing, porting,
and optimizing networked applications.
NETWORKED
JAWS ADAPTIVE
SERVICE WEB SERVER
COMPONENTS STANDARDS-BASED MIDDLEWARE
LAYER THE ACE ORB
(TAO)
TOKEN GATEWAY
SERVER SERVER
C++ PROCESS/
STREAMS LOG
WRAPPER THREAD
SERVICE
SHARED
MALLOC
MANAGERS MSG
FACADE REACTOR/
CONFIGU-
RATOR
LAYER SYNCH SPIPE SOCK SAP/ FIFO PROACTOR MEM FILE
WRAPPERS SAP TLI SAP SAP MAP SAP
OS ADAPTATION LAYER
C
PROCESSES/
WIN32 NAMED
SOCKETS/ UNIX SELECT/ DYNAMIC SHARED FILE SYS
APIs THREADS
PIPES & UNIX
TLI FIFOS IO COMP LINKING MEMORY APIS
STREAM PIPES
www.riverace.com/. The core ACE library contains roughly a quarter million lines
of C++ code that comprises approximately 500 classes. Many of these classes cooperate to
form ACE’s major frameworks. The ACE toolkit also includes higher-level components, as
well as a large set of examples and an extensive automated regression test suite.
To separate concerns, reduce complexity, and permit functional subsetting, ACE is de-
signed using a layered architecture [POSA1], shown in Figure 1.7. The capabilities pro-
vided by ACE span the session, presentation, and application layers in the OSI reference
model [Bla91]. The foundation of the ACE toolkit is its combination of an OS adaptation
layer and C++ wrapper facades, which together encapsulate core OS network programming
mechanisms to run portably on all the OS platforms shown in Sidebar 2 (page 16). The
higher layers of ACE build on this foundation to provide reusable frameworks, networked
service components, and standards-based middleware.
Acceptor-
Reactor Proactor
Connector
Service
Streams Task
Configurator
ACE users in the form of expertise embodied in well-tested and reusable C++ software
artifacts. The ACE frameworks implement a pattern language for programming concurrent
object-oriented networked applications. Figure 1.8 illustrates the ACE frameworks. To
illustrate how the ACE frameworks rely on and use each other, the lines between boxes
represent a dependency in the direction of the arrow. Each framework is outlined below.
ACE Reactor and Proactor frameworks. These frameworks implement the Reactor and
Proactor patterns [POSA2], respectively. Both are architectural patterns that allow appli-
cations to be driven by events that are delivered to the application from one or more event
sources, the most important of which are I/O endpoints. The Reactor framework facilitates
a reactive I/O model, with events signaling the ability to begin a synchronous I/O opera-
tion. The Proactor framework is designed for a proactive I/O model where one or more
asynchronous I/O operations are initiated and the completion of each operation triggers an
event. Proactive I/O models can achieve the performance benefits of concurrency without
incurring many of its liabilities. The Reactor and Proactor frameworks automate the detec-
tion, demultiplexing, and dispatching of application-defined handlers in response to many
Section 1.4 A Tour through the ACE Frameworks 17
types of events. Chapters 3 and 4 describe the ACE Reactor framework and Chapter 8
describes the ACE Proactor framework.
ACE Task framework. This framework implements various concurrency patterns, such
as Active Object and Half-Sync/Half-Async [POSA2]. Active Object is a design pattern
that decouples the thread that executes a method from the thread that invoked it. Its purpose
is to enhance concurrency and simplify synchronized access to objects that reside in their
own threads of control. Half-Sync/Half-Async is an architectural pattern that decouples
asynchronous and synchronous processing in concurrent systems, to simplify programming
without reducing performance unduly. This pattern incorporates two intercommunicating
layers, one for asynchronous and one for synchronous service processing. A queueing
layer mediates communication between services in the asynchronous and synchronous lay-
ers. Chapter 5 of C++NPv1 describes the design dimensions associated with concurrent
networked applications and Chapter 6 of this book describes the ACE Task framework.
ACE Streams framework. This framework implements the Pipes and Filters pattern,
which is an architectural pattern that provides a structure for systems that process a stream
of data [POSA1]. The ACE Streams framework simplifies the development and compo-
sition of hierarchically layered services, such as user-level protocol stacks and network
management agents [SS94]. Chapter 9 describes this framework.
When used together, the ACE frameworks outlined above enable the development of
networked applications that can be updated and extended without the need to modify, re-
18 CHAPTER 1 Object-Oriented Frameworks for Network Programming
Application-specific
Local
event handler Callbacks
invocations
functionality
Event
IPC loop
classes Callbacks
Event
ACE reactor
loop
Figure 1.9: Applying Class Libraries to Develop and Use ACE Frameworks
compile, relink, or restart running applications. ACE achieves this unprecedented flexibility
and extensibility by combining
• OS mechanisms, such as event demultiplexing, IPC, dynamic linking, multithread-
ing, multiprocessing, and synchronization [Ste99]
• C++ language features, such as templates, inheritance, and dynamic binding [Bja00]
• Patterns, such as Component Configurator [POSA2], Strategy [GoF], and Han-
dler/Callback [Ber95]
The ACE frameworks provide inversion of control via callbacks, as shown below:
The callback methods in ACE’s framework classes are defined as C++ virtual methods.
This use of dynamic binding allows networked applications to freely implement and extend
interface methods without modifying or rebuilding existing framework classes. In contrast,
the ACE wrapper facades rarely use callbacks or virtual methods, so they aren’t as exten-
sible as the ACE frameworks. The ACE wrapper facades do support a broad range of use
Section 1.5 Example: A Networked Logging Service 19
cases, however, and can be integrated together via generic programming [Ale01] techniques
based on the C++ traits and traits classes idioms outlined in Sidebar 40 (page 165).
Figure 1.9 illustrates how the class libraries and frameworks in ACE are complemen-
tary technologies. The ACE toolkit simplifies the implementation of its frameworks via
its class libraries of containers, which include lists, queues, hash tables, strings, and other
reusable data structures. Likewise, application-defined code invoked by event handlers in
the ACE Reactor framework can use the ACE wrapper facades and the C++ standard library
classes [Jos99] to perform IPC, synchronization, file management, and string processing op-
erations. Sidebar 3 describes how to build the ACE library so that you can experiment with
the examples we present in this book.
illustrate key points and ACE capabilities throughout this book by extending and enhancing
the networked logging service example introduced in C++NPv1, which collects and records
diagnostic information sent from one or more client applications.
The logging service in C++NPv1 used many of ACE’s wrapper facades in a two-tier
client/server architecture. This book’s logging service examples use a more powerful archi-
tecture that illustrates a broader complement of capabilities and patterns, and demonstrates
how ACE’s frameworks can help achieve efficient, predictable, and scalable networked ap-
plications. This service also helps to demonstrate key design and implementation consider-
ations and solutions that will arise when you develop your own concurrent object-oriented
networked applications.
Figure 1.10 illustrates the application processes and daemons in our networked logging
service, which we outline below.
Client application processes (such as P1 , P2 , and P3 ) run on client hosts and generate log
records ranging from debugging messages to critical error messages. The logging informa-
tion sent by a client application contains the time the log record was created, the process
identifier of the application, the priority level of the log record, and a variable-sized string
containing the log record text message. Client applications send these log records to a client
logging daemon running on their local host.
Client logging daemons run on every host machine participating in the networked logging
service. Each client logging daemon receives log records from that host’s client applications
via some form of local IPC mechanism, such as shared memory, pipes, or sockets. The
client logging daemon uses a remote IPC mechanism, such as TCP / IP, to forward log records
to a server logging daemon running on a designated host.
Server logging daemons collect and output the incoming log records they receive from
client applications via client logging daemons. A server logging daemon 2 can determine
which client host sent each message by using addressing information it obtains from the
underlying Socket API. There’s generally one server logging daemon per system configu-
ration, though they could be replicated to avoid a single point of failure.
Figure 1.11 (page 22) shows the progression of networked application servers that we’ll
develop and use in this book. These client and server logging daemons will illustrate how
to use the ACE frameworks and wrapper facades with the following concurrency models.
Concurrency Model Section
Reactive 3.5, 4.2, 5.4
Thread pool 4.3, 4.4, 6.3
Thread-per-connection 7.2, 7.3
Producer/consumer 6.2, 7.4, 9.2
Proactive 8.2 – 8.5
2
We use the terms server logging daemon and logging server interchangeably throughout this book.
Section 1.6 Summary 21
Console
Server logging Storage
Local IPC daemon device
Client TCP connection
P1 logging Tango Mambo
daemon
P2
TCP connection
P3
Printer
Server
Network
Client Client P1
Tango logging
daemon
P2
Local IPC P3
Client Mambo
int spawn (void){
if (ACE_OS::fork()==-1)
ACE_ERROR((LM_ERROR, if (Options::instance()->debug())
"unable to fork in function spawn")); ACE_DEBUG((LM_DEBUG,
"sending request to server%s",
server_host));
1.6 Summary
Networked application software has been developed manually from scratch for decades.
The continual rediscovery and reinvention of core concepts and capabilities associated with
this process has kept the costs of engineering and evolving networked applications too high
for too long. Improving the quality and quantity of systematic software reuse is essential to
resolve this problem.
Middleware is a class of software that’s particularly effective at providing systemati-
cally reusable artifacts for networked applications. Developing and using middleware is
therefore an important way to increase reuse. There are many technical and nontechni-
cal challenges that make middleware development and reuse hard, however. This chapter
described how object-oriented frameworks can be applied to overcome many of these chal-
22 CHAPTER 1 Object-Oriented Frameworks for Network Programming
Reactive
Logging Server
(Chapters 3, 4)
Acceptor- Producer/
Proactive
Connector Consumer
Client
Client Client
Logging
Logging Logging
Daemon
Daemon Daemon
(Chapter 8)
(Chapter 7) (Chapter 6)
C HAPTER S YNOPSIS
A service is a set of functionality offered to a client by a server. Common services available
on the Internet today include
23
24 CHAPTER 2 Service and Configuration Design Dimensions
select()
SVC1 SVC2 SVC3
SVC1 SVC2
select()
Logging service ⇒ From the standpoint of an individual log record, our server logging
daemon seems like a short-duration service. Each log record is limited to a maximum length
of 4K bytes, though in practice most are much smaller. The actual time spent handling
a log record is relatively short. Since a client may transmit many log records, however,
we optimize performance by designing client logging daemons to establish connections
with their peer server logging daemons. We then reuse these connections for subsequent
logging requests. It would be wasteful and time consuming to set up and tear down a socket
connection for each logging request, particularly when small requests are sent frequently.
We therefore model our client and server logging daemons as long-duration services.
cess to perform the requested service externally. External services may be more robust than
internal services since the failure of one need not cause the failure of another. To increase
robustness, therefore, mission-critical application services are often isolated in separate pro-
cesses. The price for this robustness, however, can be a reduction in performance due to
process management and IPC overhead.
Some server frameworks support both internal and external services. For example, the
INETD superserver [Ste98] is a daemon that listens for connection requests or messages on
certain ports and runs programs to perform the services associated with those ports. System
administrators can choose between internal and external services in INETD by modifying
the inetd.conf configuration file as follows:
• INETD can be configured to execute short-duration services, such as ECHO and DAY-
TIME , internally via calls to statically linked functions in the INETD program.
• INETD can also be configured to run longer-duration services, such as FTP and TEL -
NET , externally by spawning separate processes.
Sidebar 4 (page 31) describes this and other service provisioning mechanisms that use both
internal and external services.
Logging service ⇒ All logging server implementations in this book are designed as inter-
nal services. As long as only one type of service is configured into our logging server, we
needn’t isolate it from harmful side effects of other services. There are valid reasons to pro-
tect the processing of different client sessions from each other, however, particularly if ser-
vices are linked dynamically using the Component Configurator pattern [POSA2]. Chapter
8 in C++NPv1 therefore illustrates how to implement a logging server as an external service
using the ACE_Process and ACE_Process_Manager classes.
We are surprised at Dr. Ewer's statement that the Greek Church has
no cultus of St. Mary ever-Virgin, as we are that many Anglicans,
like Dr. Pusey, who object to the Roman Church on account of that
cultus, should seek communion with the schismatic Greeks, with
whom that cultus is pushed to an extreme far beyond anything in
the Latin Church. The truth is, that all that offends Protestants in
the Church of Rome, except the papacy, exists in even a more
offensive form in the Greek schismatic Church. The schismatic
Greek bishops exercise over their flocks a tyranny which is
impracticable in the Roman Church, where the papal authority
restricts that of bishops and tempers their administration of their
dioceses.
But it is time to bring our remarks to a close. We are unable to
recognize the Catholicity we profess in that proposed by Dr. Ewer.
The one holy catholic apostolic church he sets forth does not
appear to us to be the church of the fathers, nor the one of which
we are an affectionate if an unworthy son. In our judgment, Dr.
Ewer is still in the Protestant family, and following private judgment
as his rule, though denouncing it. He has not grasped the central,
or, as Dr. Channing would say, the "seminal" principle of the
Catholic Church. Yet he seems to be well disposed, and to be
seeking it, and has made large strides toward it. We think his
discourses are not only brilliant, bold, and energetic, but fitted to
have great influence in turning the public mind toward the Catholic
Church. We have given our reasons why we do not admit that he
has as yet found that church; but still we think his discourses will
help many to find it, though he himself may not find it. He has, as
yet, strong prejudices against the Church of Rome, and is
undeniably anti-papal. But still there can be no doubt that he would
like to feel himself a Catholic, and have done once for all with
Protestantism. Dr. Ewer stands not alone. There are large numbers
in his communion, and other Protestant communions, who think
and feel as he does, who, from the top of Mount Pisgah, have
obtained—if not the clear vision Moses had—at least some
glimpses, more or less confused, of the promised land, and are
attracted and charmed by what they see of it. We have a feeling of
respectful tenderness toward these men, and of great sympathy
with their trials and struggles. While we must tell them the truth in
firm and manly tones, treat them as men, not as children, we
would, on no account, say or do anything to wound their
susceptibilities, or to create an impression that we do not take a
deep and lively interest in their efforts to arrive at Catholicity. The
spirit is working in them to bring them to light and life. They are
not against us, and to some extent are with us. We would, for their
sakes, they were wholly with us, and we never cease to pray God
that they may find the haven of security and rest it has pleased
him that we should find for ourselves. We once were one of their
number, thought and felt with them, struggled with them, and we
can have for them only words of encouragement and hope. In what
we have said we have had only the desire to assist them to find
and understand the One Holy Catholic Apostolic Church.
The Evening Primrose.
A vesper acolyte,
Born, but for this one night,
To swing thy golden censer of perfume,
While stars the tranquil firmament illume,
For heaven's delight.
Chapter I.
Four little boys: two of them had soft fair hair, and were dressed in
the finest cloth; the other two had very bushy heads, and were
dressed in whatever they could get. It was early Christmas
morning, and the two rich boys were sitting by the window of a
handsome brown-stone house, and they had each a stocking plump
full of dainties; the two poor boys were calling the morning papers
on the stone-cold sidewalk, and if they had any stockings at all,
you may be very sure they were plump full of holes.
"What are you laughing at, Fred," asked their sister Mary, coming
up to them.
"I say, Jim," said the big boy, who was about twelve or thirteen
years old, "did you ever see the beat of that young 'un there? Don't
you choke yerself, youngster, f'fear you'd cheat a friend from doing
that same when you're growed up.—Ere's the 'Erald! Tribune!
Times!—George! Jim, I wish to thunder there'd some new papers
come up. An't yer tired allers a hollerin' out them same old tunes?
—Times! 'Erald! Tribune!—How d'ye s'pose a feller'd feel to wake up
some of these yere mornin's in one o' them big houses?"
"Heerd tell of stranger things 'n that, Dick," replied Jim, who read
the weekly papers. "'Turn again, Whittington, Lord-Mayor of
London,' as the cat said! Turned out true, too."
"You'd better get a cat, Jim, you're such a stunnin' feller; shouldn't
wonder if you'd turn out alderman some of these days!" At which,
for no apparent reason, Dick laughed until every rag was fluttering.
Fred rushed into the house saying, "His Heralds are all gone."
"Tribune, then, and don't keep the door open," instructed the rough
voice from some invisible spot. Mary shut the door all but a little
crack. "Papa wanted a Herald," she said; "you ought to have one
when my papa wants it."
"Thought I had, but couldn't help it; 'Erald's got a great speech to-
day, and I've sold 'em all."
The bushy head made a sort of bow, as the poor newsboy looked
at the fair-haired little girl on the stoop, who condescended to
question him.
"Do you put your money in a savings bank? By and by you'd have
enough to build a house maybe, if you were careful," said Josie.
"Why don't you bring me that paper?" cried their father's voice.
And the two boys ran hastily into the house.
"You may have my candy," said Mary in a stately way. "I can have
plenty more." And she put her store of dainty French candy into
the boy's hand, and, while he was still looking at her in
amazement, followed her brothers into the house and shut the
door.
"Just you pinch me, Jim," Dick said, joining his companion. "Drive
in hearty, now. An't I asleep?"
"Who's that?"
"No, I didn't," Dick said indignantly. "I never took nothin' as warn't
mine yet."
"Let's have a look," said Jem, reaching out his hand for the
package; but Dick would not let him touch it. "I'm going to keep it
always to remember her," he said.
"Guess you want ter eat it yerself," Jem said. "I wouldn't be so
mean."
"I an't gen'rally called mean," Dick answered with great dignity.
"Don't you wonder, Jim," said Dick, as they made friends and
passed on—"don't it seem curious how some folks is rich and purty
like them there, and others is poor and ugly like me and you, Jim?"
"S'posin' me and you had dandified coats and yeller gloves, and the
fixin's to match, s'pose anybody'd know we was newsboys?" Dick
asked thoughtfully.
But not out of all remembrance. The children had a party that
Christmas afternoon; and when they were tired of romping, and
were seated around the room, the girls playing with their dolls; the
Catholic ones telling the others in low voices about the flowers and
lights, and the wonderful manger which they had seen at Mass that
morning; and the boys eagerly listening to the stories of faraway
lands, which one of the older people was telling, little Mary knelt in
an arm-chair, and looked out of the window at the people hurrying
through the driving rain and snow, and at the street-lamps glaring
through the wet and cold. Her kind little heart had been very light,
and a strange joyousness had surrounded her all day, making her
more gentle than ever, so that she had not spoken one hasty word,
or once hesitated to take the lowest part in any of the plays.
Though she did not know it, the little infant Jesus had smiled on
her that morning when she was kind to the poor, homeless
newsboy; and now she understood—for charity had enlarged her
mind—more distinctly than she ever had before, that there were
many cold and desolate children for whom there were no earthly
glad tidings that day, yet who were as much God's own as the little
ones grouped around her father's pleasant parlors. Then, just as
she did the best she could, and prayed in her heart for the children
of the poor, she thought she saw the newsboy to whom she had
spoken in the morning standing close to the railing by the window;
but before she could be sure of it, the servant lighted the gas; she
heard the children calling her for a new game, and she ran lightly
away. But there was one crouched in the cold outside, who
wondered at the sudden light and glow within; and as the
bewildered newsboy saw her dancing past the lighted windows, it
seemed to him that it was not so far, after all, to the heaven and
the angels of whom he had heard; for the "glad tidings" had come
to Dick, even Dick, and they woke up the good, the will to do right,
which is in every heart, and which did not sleep again in him, even
when the little, uncared-for, outcast head rested on the stone steps
that Christmas night.
Chapter II.
Very little idea had poor Dick of right or wrong. No fond mother
took him to her heart when he was a toddling wee one, just big
enough to half understand, and between her kisses told him of
angels and saints, of heroes and martyrs, and of that Queen
Mother up in heaven, dearer than them all, who never forgot those
who once had loved her, and of the beautiful world with its flowers
and fruits, its great rivers and high mountains, its delicious green
and its glorious blue, which a good Father had given to men for
their enjoyment. No loving sister, with bright eyes and tender voice,
tossed him in her strong young arms, and sang to him how knights
and warriors, the great and good of earth, and loved of heaven,
had all been children once like him, only never half so sweet and
dear. No noble father, true in the midst of trials, ever watched with
anxious care that those little feet should walk only in the straight
and narrow path. So it was a hard thing for poor Dick, when he
rubbed his brown hands through his bushy, uncombed hair the next
morning, and pushed the worn old hat over his still sleepy eyes, to
know just what to do to find the temple of Fortune. At times,
though, he had followed the crowd of noisy boys and girls whom
you may see around the doors of any Catholic church at about nine
o'clock on Sunday mornings, and had listened with a critical air, and
slightly supercilious, from some dark corner near the door, to the
talking and the prayers which he did not wholly understand, but
portions of which he did once or twice take into his "inner
consciousness" and fully approve. In some way, he then seemed to
feel that which made him less rough in all his answers, readier in
all his responses to the call for papers, not always gently called for;
and, though he knew not why, there were fewer wicked words on
his lips that day than for many a day before.
It happened that he kept his eyes open and grew thoughtful, and
did not forget his wish to be better; so that, from being a newsboy,
he became an errand-boy in a book-store, where he learned to be
honest and to tell the truth, which was a rapid advance in his
education; for you know it is more than some people have learned
who have lived to be six times Dick's age. Sometimes a little lady
came to that very store to choose her picture-books and Christmas
stories; and it was his place to open the door for her; or perhaps
some one would call out, "Dick, a chair for this lady," and then he
was as happy as a prince. Sometimes he would be sent home with
her purchases, and mounted the steps, entered her father's house,
and always felt "good" again; for always the same picture of a little
girl in blue, with fair hair, and her hands full of dainty French
candy, and a ragged newsboy, dirty and amazed, would be there
before him.
Christmas had come and gone more than once, and it was coming
again, when Dick turned up the gas in a mere closet of a room
very high up in a dingy boarding-house, and made a ghost of a fire
in an old rusty stove. It wouldn't seem to us a very enlivening
prospect; for the room was but slightly furnished, and the stove
smoked, while the wind beat at the not overclean windows, on
which there were no curtains to shut out the dark and cold. But
Dick seemed to think it something very luxurious; for he rubbed his
hands before the blue apology for a flame, and sat down on the
broken wooden stool, with as much zest as that with which I have
seen grand people sink into a great arm-chair after a walk.
"Christmas eve again," he said to the fire, for it was his only
companion. "Let me look at you, Mr. Coals, and see what pictures
you have for me to-night. How many nights, worse nights than this,
I have been glad to crouch under an old shed, or in some alley,
and now to think, thanks to the good God, I have a fire of my own!
Poor little bare feet on the icy pavement to-night, I wish I had you
round my jolly old stove. When I am rich, I will!" Then he laughed
at the idea. "But I won't wait until I am rich, or I would never
deserve to have the chance."
"How are you, Dick?" said a cheery voice, though deep and rough,
at the door. And a man came into the room, which either his figure,
or his coat, or his voice, or the flute under his arm, seemed to fill
to such an extent that the very corners were crowded.
"How are you, Dick? It's blowing a hurricane outside, and you're as
cold as Greenland here. It may do for you, but not for me; old
blood is thin, my boy, old blood is thin." At which Dick laughed
heartily, while putting more coal on the fire; for Carl Stoffs was in
the prime of life, hale and hearty, weighing at least two hundred
pounds, I am sure, and with a round face, very red, but also very
solemn, for Carl Stoffs was a German every inch of him. The stove
grew very red also under his vigorous hands; but whether from
anger or by reflection I will not attempt to say. "And now," he said,
seating himself on the wooden chair, Dick having given it up to his
guest, while he occupied a box instead—"and now, how are you,
boy? Ready for merry Christmas, eh? You'll come to us to-morrow,
so says my wife. In America, you all do mind your wives; mine tells
me to bring you."
"Then I must, I know," Dick said, looking at the other, who was
near three times his size. "I would have a poor chance in opposing
you!" But Carl Stoffs knew well how gratefully the friendless boy
accepted the thoughtful invitation.
"Now, shall we have some music," said he, as he drew out his
flute, and, without waiting an answer, put it to his mouth, and
brought forth such rich, full tones from the instrument that Dick, as
he stared at the now bright fire, seemed to be in a land of
enchantment.
"You are the only man, from the queen of England down, whom I
really envy," said Dick, in one of the pauses. "You can have music
whenever you wish it; I am only a beggar, grateful for every note
thrown in my way. Were you out, last night?"
"I wish I were a musician," said Dick. "It must be jolly to see all
the dancing and the bright dresses!"
"And the pretty ladies, eh? who don't mind you no more than if you
were a stick or a stone. Indeed, my boy, you'd soon get tired of it;
it seems so grand at first, the beautiful picture all in motion; but
your eyes—they ache after a little. Too much light, my boy, too
much light." And the musician went long journeys up and down his
wonderful flute before he spoke again. "They'll go music-mad over
some fool at the piano; but you play until your own music makes
you wild, and never one thinks or cares about you. Last night, I
played only for one. She was always dancing, and she seemed to
go on the wings of the music just as it said to her go. I was not
tired last night."
"Finis," cried the German, rising slowly, and putting on his shaggy
overcoat. "I promised my wife that I would be home at nine, and,
as do all the people here, I mind my wife; but it is one
inconvenient thing. You will come to us after Mass, to-morrow?"
"You are too good to me. When I am rich, perhaps I shall know
how to thank you."
"You should think yourself rich now. You are young; there is no
riches like that."
"Never say that, never, never. The poorest youth is better than the
richest age," said the German earnestly. I shouldn't wonder if Mr.
Stoffs had just found his first gray hair, and was speaking under its
influence. At all events, he did not convince Dick, who said, with
equal earnestness and more quickness:
"I must say it: every day seems too long, every hour goes too
slowly, until I can get at my life's work. This waiting for it kills me."
"My friend, do you call this waiting?" laughed the German. "Was it
waiting and doing nothing that changed you from—"
"It may tell you something wonderful," said his visitor, laughing. For
it was easy for him to understand that some young mother, who
even in her poverty had found the means of reading and believing
stones of princes in disguise, and countesses in cellars, disowned
and disinherited, all for true love's sake, had made a mystery of
leaving a lock of her hair, and perhaps a cheap wedding-ring, to
her boy; and he could not forbear a little ridicule of the folly. "It
may tell you something wonderful. If it gives you possession of half
of New York, don't forget your friends, will you, Dick?" And then,
buttoned up to his chin, and with his cap covering half his face,
and looking just like Santa Claus, Carl Stoffs bundled his cherished
flute under his arm, and obediently went home to his wife.
Dick lingered a moment, after he left, before closing the door. The
room was not wholly his own; but his companion had a father and
a mother in New Jersey, and he had gone home to them, with
something in his pockets for the children's Christmas; so for that
night Dick was in undisputed possession. The passages were dark
and cold; the snow had got through some of the broken windows,
and lay in several little hills on the entry floor; the sash rattled, and
Dick shivered, as he stood irresolute at the door of his room. But
the irresolution did not last long. He bundled up, as well as his
scanty wardrobe permitted, closed the door firmly behind him, and
went down the creaking, broken stairs, and through the dreary
passages, where he could see the snow huddling up to the dark
window-panes, as if it were a white bird trying to get in and
beating its wings against the dirty glass. Dick had not far to walk,
after leaving the house, before he found that which he had come
out to find—somebody without a shelter from the storm. And I
should not wonder if any night, however bitter and cold, that you
or I should take a notion to go out on the same errand, we should
not have to go far for equal success, and that even if we started
from the most delightful dwelling-place in all New York.
Under the remains of some broken steps, or more truly by the side
of them, for they were too broken to shelter a kitten, two dark
figures were lying close together. In one of the pauses of the
storm, when the street-lamp had a chance to shine a little, Dick
could see that the figures were those of two boys asleep. He did
not wait long to rouse them. One woke up at once, cross, and, if I
must tell the truth, with some very wicked words on his lips.
"What yer want 'long o' me? I an't doing nothin'," he muttered.
"I know that; but I will give you a better place to sleep in. Come."
Bad words again. "I an't done nothin' to you. Le' me 'lone."
"I want you to come home with me. Did you ever hear of a
newsboy called Big Dick? That's me."
"I an't afeard o' nothin'. H'ere goes!" And the poor little fellow, still
believing the other was "chaffing," got on his feet. "Do you want
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com