Steve HustonRiverace Corporation
Steve's Networked Programming Newsletter
Making Nets Work
February 2008

Thank you for subscribing to my newsletter. I've written an article inspired by an issue I've seen come up on the ace-users mailing list twice in the past few weeks, socket writes that resulted in a SIGPIPE signal and a process crash. If you haven't come across this, you will at some point - it's a common issue.

I've also noted a platform support change for ACE which will take affect March 1, 2008.

Thank you to those of you who emailed me ideas and suggestions for what to include in the next version of ACE! As plans form, you'll hear more news about that here, so stay tuned.

As always, be sure to forward this note to other people you work with to be sure they know what's happening in the world of networked application development.

In This Issue
How to Handle a SIGPIPE Signal Using ACE
Upcoming Changes to the Supported ACE Platforms
Do You Need Help Designing Your Next System?
How to Handle a SIGPIPE Signal Using ACE

Most sockets programmers are familiar with the idiom of checking for a -1 return code from sockets calls, and the ACE class methods which wrap them, to detect errors resulting from socket operations such as send() and recv(). However, there is one situation where a failed send() call will raise a SIGPIPE signal rather than return -1. If the connection has been broken (for example, by the peer abruptly closing, or resetting, the connection) a send() call will raise a SIGPIPE (broken pipe) signal. This sounds rather inconvenient, but the biggest problem is that, by default, a SIGPIPE signal will cause your process to abort - probably not what you wanted in that situation.

There is a more graceful way to alter the way that send() responds to a broken socket. If you change the handling of SIGPIPE so that the signal is ignored, the signal will not be raised, and send() will return -1 when a broken socket is detected, allowing you to handle the failure more gracefully.

If you are using ACE (and why wouldn't you?) it's very easy to implement this behavior using the ACE_Sig_Action class. Simply add these three lines of code to a method or application where you'll be doing socket writes:

ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN);
ACE_Sig_Action original_action;
no_sigpipe.register_action (SIGPIPE, &original_action);

These three lines change the SIGPIPE to be ignored, as you want, while preserving the original handling action for SIGPIPE soit can be restored later. Of course, if you are changing SIGPIPE handling for your entire application, and not just a method, you need not save and restore the signal action. To restore the action, add one more line after the send() calls are complete:

no_sigpipe.restore_action (SIGPIPE, original_action);

This technique is illustrated and explained more on pages 173-174 in C++NPv2.
Upcoming Changes to the Supported ACE Platforms
Riverace periodically polls our customer base concerning which platforms are being used with ACE. We use this survey to guide when we discontinue support for various platforms and also as input to add new platforms. In this way we stay abreast of what our customers want, and apply the available resources to provide support where it's needed.

During the most recent platform survey we identified one platform that is no longer used. We are also making a change due to normal technology progression. These changes are:
  1. On Solaris 9, g++ 3.2 will be replaced with g++ 3.4.6.
  2. The Microsoft Visual C++ 6 on Windows platform will be removed.
These changes will be effective on March 1, 2008. All the affected Riverace customers have been notified. If these changes affect your ACE development and support needs, please contact Steve Huston to discuss how we may be able to help alleviate any adverse effects on your products.
Do You Need Help Designing Your Next System?
Nobody has to tell you that designing a well-formed, efficient, maintainable networked application is hard. You've had to deal with it. The problem is that networking fucntionality is usually in a supporting role to your system's main purposes, and your skills and experience are much better used to focus on specific business and technology issues. It may make more sense to bring in seasoned expertise to help design your next system.

I've helped many companies get great networked applications built - I may be able to help you as well. Let's talk and see if I can help take care of the networking, and let you focus on applying your expertise and experience to the business features that'll really help your system stand out.

Call me at 508-541-9180 or email me at shuston@riverace.com.
Join Our Mailing List