ACE Newsletter for February 2005

Welcome to the February 2005 edition of Riverace's ACE News and Tips newsletter. This issue contains a helpful review of how to customize the ACE_Acceptor class to create new service handlers in a specialized way (and differently from last month), news about what's coming up in the next ACE release, and a note about the latest ACE Fix Kit releases.

Please forward this newsletter to anyone you think may be interested! Anyone who wishes to receive their own copy of this newsletter can subscribe at http://www.riverace.com/subscribe2/index.mv. If you no longer wish to subscribe, removal directions are at the bottom of this page.

Please reply with any feedback you have on this newsletter, as well as ideas for information you'd like to see in upcoming newsletters. We want to be as helpful as possible, so please let us know how we can do that.


ACE Tip: Customizing Service Handler Creation When Accepting Connections

Last month we looked at a way to customize creation of an ACE_Svc_Handler-derived class when accepting new connections using the ACE_Acceptor class. That method involved deriving a new class from ACE_Acceptor and reimplementing the make_svc_handler() method. A different way to customize this behavior is to use the ACE_Strategy_Acceptor class instead of ACE_Acceptor.

ACE_Strategy_Acceptor uses programmer-supplied strategy classes to perform the major steps that ACE_Acceptor implements internally (and allows users to override). When is this capability preferred?

  • When you want to write code that customizes ACE's behavior, but keep a wider separation between ACE's code and yours.
  • When you want to implement a variety of different customizations without having to derive classes for each.
  • It's more straight-forward to set up new handlers with a separate thread manager, or on a reactor other than the one used by the acceptor.
  • When the (very minor) cost of an extra level of procedure call is not a concern. ACE_Strategy_Acceptor is derived from ACE_Acceptor and reimplements its make_svc_handler() method to forward the call to the strategy object.

Like ACE_Acceptor, ACE_Strategy_Acceptor is a class template (the complete reference for this class is at http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/classACE__Strategy__Acceptor.html). The first template argument to ACE_Acceptor is the class representing the service handler for each new connected service. The strategies used with ACE_Strategy_Acceptor are also class templates that take one or both of ACE_Strategy_Acceptor's template arguments. For our example, we're interested in the ACE_Creation_Strategy<SVC_HANDLER> class.

ACE_Creation_Strategy is described at http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/classACE__Creation__Strategy.html, and as with the ACE_Acceptor, you need to reimplement the make_svc_handler() method. It has the same signature, but its default implementation is slightly different than that of ACE_Acceptor:

template <class SVC_HANDLER> ACE_INLINE int
ACE_Creation_Strategy<SVC_HANDLER>::make_svc_handler (SVC_HANDLER *&sh)
{
  ACE_TRACE ("ACE_Creation_Strategy<SVC_HANDLER>::make_svc_handler");
  if (sh == 0)
    ACE_NEW_RETURN (sh, SVC_HANDLER (this->thr_mgr_), -1);
  sh->reactor (this->reactor_);
  return 0;
}

Note that the new handler gets the ACE_Thread_Manager and ACE_Reactor pointers from members in the ACE_Strategy_Acceptor object. If your objective is simply to set a thread manager and/or a reactor different from the acceptor's, you can use the default ACE_Creation_Strategy and open it with the pointers you want. Of course, they default to process singletons.

Continuing the example from last month, let's say our new handlers need to have a pointer to a central processor for all messages that the service handler receives. The processor is represented by a Processor class, and each new handler requires a pointer to the central Processor class. Rather than keep a globally-accessible pointer to a Processor, we can derive a new class from ACE_Creation_Strategy that has the Processor pointer and passes it to each new service handler.

The new strategy class could be defined thusly:

class My_Strategy : public ACE_Creation_Strategy<Service>
{
public:
  My_Strategy (Processor *processor,
               ACE_Thread_Manager *thr_mgr = 0,
               ACE_Reactor *r = ACE_Reactor::instance ())
    : ACE_Creation_Strategy<Service> (thr_mgr, r),
      processor_ (processor) { };
  
  int make_svc_handler (Service *&sh)
    {
      if (sh == 0)
        ACE_NEW_RETURN (sh,
                        Service (this->processor_,
                                 this->thr_mgr_),
                        -1);
      // Set the reactor of the newly created <SVC_HANDLER> to the
      // one specified for this strategy.
      sh->reactor (this->reactor_);
      return 0;
    }

private:
  Processor *processor_;
}

After an instance of My_Strategy is created, its pointer can be passed to either the constructor or the open() method of ACE_Strategy_Acceptor object. Then, when ACE_Strategy_Acceptor accepts a new connection for the service, the My_Strategy::make_svc_handler() hook allocates a new Service, passing the Processor* to it. Note that although the Service(Processor*) constructor is used, Service must still define a default constructor to satisfy the template requirements of ACE_Creation_Strategy.

Section 7.3 in C++NPv2 discusses the entire sequence of steps involved in ACE_Acceptor's acceptance sequence. If you have more questions about this aspect of the ACE Acceptor-Connector framework, please feel free to file a support request to get further clarification and information. If you're not a Riverace support customer, you can learn more about our support services at http://www.riverace.com/support.htm.


ACE.next: What's New?

The ACE development community is hard at work on the next version of ACE. Here are some of the things you can look forward to (items in bold are new or changed since last month):

  • Native library path-searching. Previous ACE versions's implementation of ACE_DLL (used in loading dynamic services) implemented a search of the configured path-search to try and locate the desired library file (DLL) and then used the full pathname to load the library. This skirted some platforms's rules for path search and security settings. This has been changed in the next ACE version to make use of all of the native platform's path-search and security facilities.
  • Improved wide-character support. Wide-character support has been included in ACE for many years on Windows (also known as Unicode builds). However, wide-character support for POSIX platforms has been sorely lacking. As ACE's reach expands, this has become a more important issue. Riverace is leading the completion of wide-character support in the next version of ACE. This support is also available now in the ACE 5.4b fix kit.
  • GNU autotools support. Riverace is the lead developer in charge of adding auto-configure support to ACE. For native-build, non-Windows systems, autoconf will very likely become the way to configure and build ACE. This will help insure that ACE uses the latest features available on each supported platform, and reduce the work required to build ACE. No more picking the right config.h or platform_macros.GNU file. Just do ./configure then make. Ahhh...
  • New compiler support. Support for g++ 3.4 and Microsoft Visual C++ 2005 are being added.
  • Newer C++ Features Being Used. As the range of ACE-supported compilers matures and older compilers are taken out of service, ACE can make more use of newer C++ features while still maintaining its stellar portability record. For example, many methods that returned 1 or 0 as an int now return bool. Small steps, yes, but significant ones. You'll see more modern C++ usage as time goes on.
  • The ACE and ACE_OS classes, previously containing a number of static member functions, are now C++ namespaces. Similar ACE-internal classes, such as ACE_Sock_Connect, are no longer in use.

As you can see, the pace of changes is slowing and the ACE development team is beginning to focus more on testing in preparation for the release of ACE 5.5.


New ACE Fix Kits Released!

Riverace released ACE versions 5.3e and 5.4b, containing lots of new fixes and improvements to the ACE 5.3 and 5.4 release series, respectively. These kits provide fixes to previously released ACE versions, and are not beta test kits in the ACE develoment stream. The small price for these kits provides you with tremendous value in the ability to maintain stability in your projects while picking up important fixes to ACE.


New Project Coming Up?

If you're planning a new project to start soon, or find yourself grappling with how to apply ACE to your current project, remember that Riverace provides world-class development and consulting services with special expertise in ACE. We can help you be sure that your new system is designed to take full advantage of ACE's power and flexibility, getting your system delivered in the shortest possible time and with the highest level of quality. Please contact Steve Huston at 888-384-8154 (toll-free in the US) or +1 508-541-9180 to discuss how Riverace can help you.

Useful ACE Information

  • Riverace-supported ACE Releases (don't forget, ACE Annual Support customers get no-charge access to all Fix Kits!)
  5.3 (January 15, 2003) Fix Kits: a, b, c, e
  5.4 (January 14, 2004) Fix Kits: a, b

Quotables

"I also wanted to take this opportunity to express my appreciation for the quality and responsiveness of your organization.  It is a very rare pleasure to work with an organization that provides in-depth technical support while remaining strongly customer focused - a fact you clearly demonstrate on every interaction.  With your help, we have been able to dramatically improve our development schedule while reducing the overall cost and resources required.  Riverace has exceeded our expectations without exception."

Christopher W. Midgley
Chief Technology Officer
LiveVault Corporation

This Newsletter...

... is produced by Riverace Corporation to educate the ACE user community about ACE and available ACE resources, give tips on how to use ACE more effectively, and explain how Riverace can help you make the most of this powerful toolkit.

About Us

Riverace Corporation is the premier support service provider for the ACE toolkit worldwide. Steve Huston, Riverace's President/CEO and founder, has over 20 years' experience developing network protocols and applications. He has coauthored three books on ACE's design and usage and is considered an expert by ACE users around the world. Riverace has been focused on providing world-class technical support and consulting services for ACE since 1997.