IPC_SAP.cpp

Go to the documentation of this file.
00001 // IPC_SAP.cpp,v 4.39 2006/05/30 10:57:22 jwillemsen Exp
00002 
00003 #include "ace/IPC_SAP.h"
00004 
00005 #include "ace/Log_Msg.h"
00006 #include "ace/OS_NS_unistd.h"
00007 #include "ace/os_include/os_signal.h"
00008 #include "ace/OS_NS_errno.h"
00009 #include "ace/OS_NS_fcntl.h"
00010 
00011 #if !defined (__ACE_INLINE__)
00012 #include "ace/IPC_SAP.inl"
00013 #endif /* __ACE_INLINE__ */
00014 
00015 ACE_RCSID(ace, IPC_SAP, "IPC_SAP.cpp,v 4.39 2006/05/30 10:57:22 jwillemsen Exp")
00016 
00017 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00018 
00019 ACE_ALLOC_HOOK_DEFINE(ACE_IPC_SAP)
00020 
00021 void
00022 ACE_IPC_SAP::dump (void) const
00023 {
00024 #if defined (ACE_HAS_DUMP)
00025   ACE_TRACE ("ACE_IPC_SAP::dump");
00026 
00027   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00028   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("handle_ = %d"), this->handle_));
00029   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\npid_ = %d"), this->pid_));
00030   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00031 #endif /* ACE_HAS_DUMP */
00032 }
00033 
00034 // Cache for the process ID.
00035 pid_t ACE_IPC_SAP::pid_ = 0;
00036 
00037 // This is the do-nothing constructor.  It does not perform a
00038 // ACE_OS::socket system call.
00039 
00040 ACE_IPC_SAP::ACE_IPC_SAP (void)
00041   : handle_ (ACE_INVALID_HANDLE)
00042 {
00043   // ACE_TRACE ("ACE_IPC_SAP::ACE_IPC_SAP");
00044 }
00045 
00046 int
00047 ACE_IPC_SAP::enable (int value) const
00048 {
00049   ACE_TRACE ("ACE_IPC_SAP::enable");
00050 
00051   // First-time in initialization.
00052   if (ACE_IPC_SAP::pid_ == 0)
00053     ACE_IPC_SAP::pid_ = ACE_OS::getpid ();
00054 
00055 #if defined (ACE_WIN32) || defined (ACE_VXWORKS)
00056   switch (value)
00057     {
00058     case ACE_NONBLOCK:
00059       {
00060         // nonblocking argument (1)
00061         // blocking:            (0)
00062         int nonblock = 1;
00063         return ACE_OS::ioctl (this->handle_,
00064                               FIONBIO,
00065                               &nonblock);
00066       }
00067     default:
00068       ACE_NOTSUP_RETURN (-1);
00069     }
00070 #else  /* ! ACE_WIN32 && ! VXWORKS */
00071   switch (value)
00072     {
00073 #if defined (SIGURG)
00074     case SIGURG:
00075     case ACE_SIGURG:
00076 #if defined (F_SETOWN)
00077       return ACE_OS::fcntl (this->handle_,
00078                             F_SETOWN,
00079                             ACE_IPC_SAP::pid_);
00080 #else
00081       ACE_NOTSUP_RETURN (-1);
00082 #endif /* F_SETOWN */
00083 #endif /* SIGURG */
00084 #if defined (SIGIO)
00085     case SIGIO:
00086     case ACE_SIGIO:
00087 #if defined (F_SETOWN) && defined (FASYNC)
00088       if (ACE_OS::fcntl (this->handle_,
00089                          F_SETOWN,
00090                          ACE_IPC_SAP::pid_) == -1
00091           || ACE::set_flags (this->handle_,
00092                                         FASYNC) == -1)
00093         return -1;
00094       break;
00095 #else
00096       ACE_NOTSUP_RETURN (-1);
00097 #endif /* F_SETOWN && FASYNC */
00098 #endif /* SIGIO <== */
00099 #if defined (F_SETFD)
00100     case ACE_CLOEXEC:
00101       // Enables the close-on-exec flag.
00102       if (ACE_OS::fcntl (this->handle_,
00103                          F_SETFD,
00104                          1) == -1)
00105         return -1;
00106       break;
00107 #endif /* F_SETFD */
00108     case ACE_NONBLOCK:
00109       if (ACE::set_flags (this->handle_,
00110                                      ACE_NONBLOCK) == ACE_INVALID_HANDLE)
00111         return -1;
00112       break;
00113     default:
00114       return -1;
00115     }
00116   return 0;
00117 #endif /* ! ACE_WIN32 && ! VXWORKS */
00118 
00119   /* NOTREACHED */
00120 }
00121 
00122 int
00123 ACE_IPC_SAP::disable (int value) const
00124 {
00125   ACE_TRACE ("ACE_IPC_SAP::disable");
00126 
00127 #if defined (ACE_WIN32) || defined (ACE_VXWORKS)
00128   switch (value)
00129     {
00130     case ACE_NONBLOCK:
00131       // nonblocking argument (1)
00132       // blocking:            (0)
00133       {
00134         int nonblock = 0;
00135         return ACE_OS::ioctl (this->handle_,
00136                               FIONBIO,
00137                               &nonblock);
00138       }
00139     default:
00140       ACE_NOTSUP_RETURN (-1);
00141     }
00142 #else  /* ! ACE_WIN32 && ! VXWORKS */
00143   switch (value)
00144     {
00145 #if defined (SIGURG)
00146     case SIGURG:
00147     case ACE_SIGURG:
00148 #if defined (F_SETOWN)
00149       return ACE_OS::fcntl (this->handle_,
00150                             F_SETOWN,
00151                             0);
00152 #else
00153       ACE_NOTSUP_RETURN (-1);
00154 #endif /* F_SETOWN */
00155 #endif /* SIGURG */
00156 #if defined (SIGIO)
00157     case SIGIO:
00158     case ACE_SIGIO:
00159 #if defined (F_SETOWN) && defined (FASYNC)
00160       if (ACE_OS::fcntl (this->handle_,
00161                          F_SETOWN,
00162                          0) == -1
00163           || ACE::clr_flags (this->handle_,
00164                                         FASYNC) == -1)
00165         return -1;
00166       break;
00167 #else
00168       ACE_NOTSUP_RETURN (-1);
00169 #endif /* F_SETOWN && FASYNC */
00170 #endif /* SIGIO <== */
00171 #if defined (F_SETFD)
00172     case ACE_CLOEXEC:
00173       // Disables the close-on-exec flag.
00174       if (ACE_OS::fcntl (this->handle_,
00175                          F_SETFD,
00176                          0) == -1)
00177         return -1;
00178       break;
00179 #endif /* F_SETFD */
00180     case ACE_NONBLOCK:
00181       if (ACE::clr_flags (this->handle_,
00182                                      ACE_NONBLOCK) == -1)
00183         return -1;
00184       break;
00185     default:
00186       return -1;
00187     }
00188   return 0;
00189 #endif /* ! ACE_WIN32 && ! VXWORKS */
00190   /* NOTREACHED */
00191 }
00192 
00193 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:52 2006 for ACE by doxygen 1.3.6