ACE Newsletter for September 2004

Welcome to the September 2004 edition of Riverace's ACE News and Tips newsletter. This issue contains a tip for ensuring complete cleanup of an ACE_Svc_Handler-derived service instance, news about what's coming up in the next ACE release, and a note about our redesigned web site.

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.


Tip: Use the Default Behavior When Closing an ACE_Svc_Handler

Last month we looked at a tip for using the default behavior provided by the ACE_Svc_Handler::open() hook method. It's very useful because it does everything a service needs to do to get going (in most cases): register the new handler for input events and return.

The default behavior of the shutdown sequence in ACE_Svc_Handler is applicable to even more situations than the initialization code in open(). This is because the hooks involved in both reactive shutdown and active-object shutdown cooperate to the same effect: removing any reactor registrations and insuring that the ACE_Svc_Handler-derived object is removed:

  • Reactive shutdown (handle_close()). Recall that when either 1) an event handler callback returns -1 or 2) ACE_Reactor::remove_handler() is called without including the DONT_CALL flag the Reactor framework calls the handler's handle_close() hook. The default behavior of ACE_Svc_Handler::handle_close() is to destroy the handler by calling ACE_Svc_Handler::destroy().
  • Active-object shutdown (close()). Recall that when an ACE_Svc_Handler-derived object is turned into an active object using the activate() method, the handler's svc() method is executed in the spawned thread(s). When svc() returns, the thread exits, but just before it exits, the ACE Task framework calls back to the close() hook method, still in the context of the exiting thread. The ACE_Svc_Handler::close() method calls the handle_close() method to complete the service handler's cleanup.

Therefore, regardless of whether the ACE_Svc_Handler object is reactive or active, cleanup processing ends up in the same place: ACE_Svc_Handler::destroy(). destroy() will delete the object if it was dynamically allocated and not part of a module in the ACE Streams framework. If the object was not dynamically allocated, its destruction is the responsibility of the enclosing scope, and if the object is part of a module in an ACE_Stream, the stream and/or the code controlling the stream is responsible for managing the lifetime of the object. destroy() enforces the policy and prevents resource leaks.

Whether the ACE_Svc_Handler object is destroyed directly in destroy() or later, the same thing happens: ~ACE_Svc_Handler calls ACE_Svc_Handler::shutdown() to complete the cleanup of the service handler. shutdown() performs these cleanup operations:

  • If a reactor is associated with the handler:
    • Cancel all timers scheduled with the reactor.
    • Remove all registered events for the handler's peer stream object (for example, a socket).
  • If the handler is associated with a recycler, purge the handler from the recycler.
  • Close the peer stream object.

So, we see that the vast majority of what usually needs cleaning up upon shutdown of a service handler is handled by the framework, simply by allowing the default hooks to execute. If your application requires some further specialized shutdown/cleanup processing, the recommended location for it is usually in your handler's handle_close() hook method. Just be sure to call ACE_Svc_Handler::destroy() as the last action in your handle_close() method to incorporate the rest of the framework's cleanup behavior.

For more information on cleaning up an ACE_Svc_Handler, see APG section 7.6. In particular, Figure 7.3 on page 176 has a UML diagram depicting the interactions we looked at here. Additionally, C++NPv2 section 7.2 has lots of background information and an expanded discussion of shutdown processing, as well as a description (Sidebar 48 on page 212) of how ACE_Svc_Handler::destroy() knows whether or not the object was dynamically allocated.


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 since last month):

  • 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 being included in the ACE 5.4b fix kit, which will be available by mid September.
  • 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.

New Web Site: www.riverace.com Relaunched

The Riverace Corporation web site (http://www.riverace.com/) has been redesigned and redeployed. The goals were to make the site easier to navigate and make it easier to find what you need quickly. Since most site visitors are looking for either ACE kits or documentation, there are direct links to those sections of the site right on the top banner of each page. There are also expanded sections for the ACE books including supplemental information such as errata and sample chapters. We're also filling out the platform-specific pages to give more helpful information on tools and tips for using ACE across the platforms the Riverace supports.

If you have any feedback on the site, or ideas on what could be done to further improve its usefulness, please send email to shuston@riverace.com with your ideas.


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 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
  5.4 (January 14, 2004) Fix Kits: a

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.