00001
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
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
00032 }
00033
00034
00035 pid_t ACE_IPC_SAP::pid_ = 0;
00036
00037
00038
00039
00040 ACE_IPC_SAP::ACE_IPC_SAP (void)
00041 : handle_ (ACE_INVALID_HANDLE)
00042 {
00043
00044 }
00045
00046 int
00047 ACE_IPC_SAP::enable (int value) const
00048 {
00049 ACE_TRACE ("ACE_IPC_SAP::enable");
00050
00051
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
00061
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
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
00083 #endif
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
00098 #endif
00099 #if defined (F_SETFD)
00100 case ACE_CLOEXEC:
00101
00102 if (ACE_OS::fcntl (this->handle_,
00103 F_SETFD,
00104 1) == -1)
00105 return -1;
00106 break;
00107 #endif
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
00118
00119
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
00132
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
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
00155 #endif
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
00170 #endif
00171 #if defined (F_SETFD)
00172 case ACE_CLOEXEC:
00173
00174 if (ACE_OS::fcntl (this->handle_,
00175 F_SETFD,
00176 0) == -1)
00177 return -1;
00178 break;
00179 #endif
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
00190
00191 }
00192
00193 ACE_END_VERSIONED_NAMESPACE_DECL