#include <ace/OS.h>
class ACE_Errno_Guard {
public:ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref, int error);ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref);~ACE_Errno_Guard (void);int operator= (const ACE_ERRNO_TYPE &errno_ref);int operator= (int error);int operator== (int error);int operator!= (int error);private:ACE_ERRNO_TYPE *errno_ptr_;int error_;};
int error = errno; call_some_function_that_might_change_errno (); errno = error;
This can be replaced with
{ ACE_Errno_Guard guard (errno); call_some_function_that_might_change_errno (); }
This implementation is more elegant and more efficient since it avoids an unnecessary second access to thread-specific storage by caching a pointer to the value of errno in TSS.
ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref, int error);
error into error_ and initialize the
errno_ptr_ to the address of errno_ref.
ACE_Errno_Guard (ACE_ERRNO_TYPE &errno_ref);
errno into error_ and initialize the
errno_ptr_ to the address of errno_ref.
~ACE_Errno_Guard (void);
errno to error.
int operator= (const ACE_ERRNO_TYPE &errno_ref);
errno_ref to error_.
int operator= (int error);
error to error_.
int operator== (int error);
error with error_ for equality.
int operator!= (int error);
error with error_ for inequality.
schmidt@cs.wustl.edu, Jesper S. M|ller
stophph@diku.dk, and a cast of thousands...