ACE Namespace Reference

The namespace containing the ACE framework itself. More...


Classes

struct  If_Then_Else< true, Ta, Tb >
struct  If_Then_Else< false, Ta, Tb >
struct  VP_traits
 Value_Ptr traits template structure. More...

class  Value_Ptr
 Smart pointer implementation designed for use as a class member. More...

struct  If_Then_Else
 Compile-time selection of type based on a boolean value. More...


I/O operations

Notes on common parameters:

handle is the connected endpoint that will be used for I/O.

buf is the buffer to write from or receive into.

len is the number of bytes to transfer.

The timeout parameter in the following methods indicates how long to blocking trying to transfer data. If timeout == 0, then the call behaves as a normal send/recv call, i.e., for blocking sockets, the call will block until action is possible; for non-blocking sockets, EWOULDBLOCK will be returned if no action is immediately possible.

If timeout != 0, the call will wait until the relative time specified in *timeout elapses.

The "_n()" I/O methods keep looping until all the data has been transferred. These methods also work for sockets in non-blocking mode i.e., they keep looping on EWOULDBLOCK. timeout is used to make sure we keep making progress, i.e., the same timeout value is used for every I/O operation in the loop and the timeout is not counted down.

The return values for the "*_n()" methods match the return values from the non "_n()" methods and are specified as follows:

  • On complete transfer, the number of bytes transferred is returned.
  • On timeout, -1 is returned, errno == ETIME.
  • On error, -1 is returned, errno is set to appropriate error.
  • On EOF, 0 is returned, errno is irrelevant.

On partial transfers, i.e., if any data is transferred before timeout / error / EOF, bytes_transferred> will contain the number of bytes transferred.

Methods with iovec parameter are I/O vector variants of the I/O operations.

Methods with the extra flags argument will always result in send getting called. Methods without the extra flags argument will result in send getting called on Win32 platforms, and write getting called on non-Win32 platforms.

ACE_Export ssize_t recv (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0)
ACE_Export ssize_t t_rcv (ACE_HANDLE handle, void *buf, size_t len, int *flags, const ACE_Time_Value *timeout=0)
ACE_Export ssize_t recv (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout=0)
ACE_Export ssize_t recvmsg (ACE_HANDLE handle, struct msghdr *msg, int flags, const ACE_Time_Value *timeout=0)
ACE_Export ssize_t recvfrom (ACE_HANDLE handle, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen, const ACE_Time_Value *timeout=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
recv_n (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
t_rcv_n (ACE_HANDLE handle, void *buf, size_t len, int *flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
recv_n (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_Export ssize_t recv (ACE_HANDLE handle, size_t n,...)
 Receive into a variable number of pieces.

ACE_Export ssize_t recvv (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
recvv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_Export ssize_t recv_n (ACE_HANDLE handle, ACE_Message_Block *message_block, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_Export ssize_t send (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0)
ACE_Export ssize_t t_snd (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0)
ACE_Export ssize_t send (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout=0)
ACE_Export ssize_t sendmsg (ACE_HANDLE handle, const struct msghdr *msg, int flags, const ACE_Time_Value *timeout=0)
ACE_Export ssize_t sendto (ACE_HANDLE handle, const char *buf, int len, int flags, const struct sockaddr *addr, int addrlen, const ACE_Time_Value *timeout=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
send_n (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
t_snd_n (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
send_n (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_Export ssize_t send (ACE_HANDLE handle, size_t n,...)
 Varargs variant.

ACE_Export ssize_t sendv (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
sendv_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_Export ssize_t send_n (ACE_HANDLE handle, const ACE_Message_Block *message_block, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
read_n (ACE_HANDLE handle, void *buf, size_t len, size_t *bytes_transferred=0)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
write_n (ACE_HANDLE handle, const void *buf, size_t len, size_t *bytes_transferred=0)
ACE_Export ssize_t write_n (ACE_HANDLE handle, const ACE_Message_Block *message_block, size_t *bytes_transferred=0)
ACE_Export ssize_t readv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, size_t *bytes_transferred=0)
ACE_Export ssize_t writev_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, size_t *bytes_transferred=0)

Functions

ACE_Export u_int major_version (void)
 e.g., the "5" in ACE 5.1.12.

ACE_Export u_int minor_version (void)
 e.g., the "1" in ACE 5.1.12.

ACE_Export u_int beta_version (void)
ACE_Export const ACE_TCHARcompiler_name (void)
 E.g., the "SunPro C++" in SunPro C++ 4.32.0.

ACE_Export u_int compiler_major_version (void)
 E.g., the "4" in SunPro C++ 4.32.0.

ACE_Export u_int compiler_minor_version (void)
 E.g., the "32" in SunPro C++ 4.32.0.

ACE_Export u_int compiler_beta_version (void)
 E.g., the "0" in SunPro C++ 4.32.0.

ACE_Export int out_of_handles (int error)
ACE_Export bool wild_match (const char *s, const char *pattern, bool case_sensitive=true)
ACE_Export int handle_timed_accept (ACE_HANDLE listener, ACE_Time_Value *timeout, int restart)
ACE_Export ACE_HANDLE handle_timed_complete (ACE_HANDLE listener, const ACE_Time_Value *timeout, int is_tli=0)
ACE_Export int set_handle_limit (int new_limit=-1, int increase_limit_only=0)
ACE_Export int max_handles (void)
ACE_Export ACE_TCHARstrenvdup (const ACE_TCHAR *str)
ACE_Export const char * strend (const char *s)
ACE_Export char * strnew (const char *s)
ACE_NAMESPACE_INLINE_FUNCTION
void 
strdelete (char *s)
 Delete the memory allocated by strnew.

ACE_Export char * strndup (const char *str, size_t n)
ACE_Export char * strnnew (const char *str, size_t n)
ACE_Export const wchar_t * strend (const wchar_t *s)
ACE_Export wchar_t * strnew (const wchar_t *s)
ACE_NAMESPACE_INLINE_FUNCTION
void 
strdelete (wchar_t *s)
ACE_Export wchar_t * strndup (const wchar_t *str, size_t n)
ACE_Export wchar_t * strnnew (const wchar_t *str, size_t n)
ACE_Export const ACE_TCHARexecname (const ACE_TCHAR *pathname)
ACE_Export const ACE_TCHARbasename (const ACE_TCHAR *pathname, ACE_TCHAR delim=ACE_DIRECTORY_SEPARATOR_CHAR)
ACE_Export const ACE_TCHARdirname (const ACE_TCHAR *pathname, ACE_TCHAR delim=ACE_DIRECTORY_SEPARATOR_CHAR)
ACE_Export ACE_TCHARtimestamp (ACE_TCHAR date_and_time[], int time_len, int return_pointer_to_first_digit=0)
ACE_Export pid_t fork (const ACE_TCHAR *program_name=ACE_TEXT("< unknown >"), int avoid_zombies=0)
ACE_Export int daemonize (const ACE_TCHAR pathname[]=ACE_TEXT("/"), bool close_all_handles=ACE_DEFAULT_CLOSE_ALL_HANDLES, const ACE_TCHAR program_name[]=ACE_TEXT("< unknown >"))
ACE_Export size_t round_to_pagesize (size_t len)
 Rounds the request to a multiple of the page size.

ACE_Export size_t round_to_allocation_granularity (size_t len)
 Rounds the request to a multiple of the allocation granularity.

ACE_Export size_t format_hexdump (const char *buffer, size_t size, ACE_TCHAR *obuf, size_t obuf_sz)
ACE_Export u_long hash_pjw (const char *str)
 Computes the hash value of {str} using the "Hash PJW" routine.

ACE_Export u_long hash_pjw (const char *str, size_t len)
 Computes the hash value of {str} using the "Hash PJW" routine.

ACE_Export u_long hash_pjw (const wchar_t *str)
 Computes the hash value of {str} using the "Hash PJW" routine.

ACE_Export u_long hash_pjw (const wchar_t *str, size_t len)
 Computes the hash value of {str} using the "Hash PJW" routine.

ACE_Export ACE_UINT16 crc_ccitt (const char *str)
 Computes CRC-CCITT for the string.

ACE_Export ACE_UINT16 crc_ccitt (const void *buf, size_t len, ACE_UINT16 crc=0)
 Computes CRC-CCITT for the buffer.

ACE_Export ACE_UINT16 crc_ccitt (const iovec *iov, int len, ACE_UINT16 crc=0)
 Computes CRC-CCITT for the @ len iovec buffers.

ACE_Export ACE_UINT32 crc32 (const char *str)
 Computes the ISO 8802-3 standard 32 bits CRC for the string.

ACE_Export ACE_UINT32 crc32 (const void *buf, size_t len, ACE_UINT32 crc=0)
 Computes the ISO 8802-3 standard 32 bits CRC for the buffer.

ACE_Export ACE_UINT32 crc32 (const iovec *iov, int len, ACE_UINT32 crc=0)
ACE_Export u_long gcd (u_long x, u_long y)
 Euclid's greatest common divisor algorithm.

ACE_Export u_long minimum_frame_size (u_long period1, u_long period2)
 Calculates the minimum enclosing frame size for the given values.

ACE_Export u_long is_prime (const u_long n, const u_long min_factor, const u_long max_factor)
ACE_Export int map_errno (int error)
ACE_Export const ACE_TCHARsock_error (int error)
ACE_Export bool is_sock_error (int error)
ACE_Export int process_active (pid_t pid)
ACE_Export int terminate_process (pid_t pid)
ACE_NAMESPACE_INLINE_FUNCTION
void 
unique_name (const void *object, ACE_TCHAR *name, size_t length)
ACE_NAMESPACE_INLINE_FUNCTION
u_long 
log2 (u_long num)
 Computes the base 2 logarithm of {num}.

ACE_NAMESPACE_INLINE_FUNCTION
ACE_TCHAR 
nibble2hex (u_int n)
 Hex conversion utility.

ACE_NAMESPACE_INLINE_FUNCTION
u_char 
hex2byte (ACE_TCHAR c)
 Convert a hex character to its byte representation.

ACE_Export bool debug (void)
ACE_Export void debug (bool onoff)
ACE_Export int select (int width, ACE_Handle_Set *readfds, ACE_Handle_Set *writefds=0, ACE_Handle_Set *exceptfds=0, const ACE_Time_Value *timeout=0)
 Wrapper facade for select that uses ACE_Handle_Sets.

ACE_Export int select (int width, ACE_Handle_Set &readfds, const ACE_Time_Value *timeout=0)
ACE_NAMESPACE_INLINE_FUNCTION
int 
handle_read_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout)
 Timed wait for handle to get read ready.

ACE_NAMESPACE_INLINE_FUNCTION
int 
handle_write_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout)
 Timed wait for handle to get write ready.

ACE_NAMESPACE_INLINE_FUNCTION
int 
handle_exception_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout)
 Timed wait for handle to get exception ready.

ACE_Export int handle_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout, int read_ready, int write_ready, int exception_ready)
 Timed wait for handle to get read, write, or exception ready.

ACE_Export int enter_recv_timedwait (ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val)
ACE_Export int enter_send_timedwait (ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val)
ACE_Export void record_and_set_non_blocking_mode (ACE_HANDLE handle, int &val)
ACE_Export void restore_non_blocking_mode (ACE_HANDLE handle, int val)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
recv_i (ACE_HANDLE handle, void *buf, size_t len)
ACE_Export ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, size_t *bytes_transferred)
ACE_Export ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t t_rcv_n_i (ACE_HANDLE handle, void *buf, size_t len, int *flags, size_t *bytes_transferred)
ACE_Export ssize_t t_rcv_n_i (ACE_HANDLE handle, void *buf, size_t len, int *flags, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, size_t *bytes_transferred)
ACE_Export ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, size_t *bytes_transferred)
ACE_Export ssize_t recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
send_i (ACE_HANDLE handle, const void *buf, size_t len)
ACE_Export ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, size_t *bytes_transferred)
ACE_Export ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t t_snd_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, size_t *bytes_transferred)
ACE_Export ssize_t t_snd_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, size_t *bytes_transferred)
ACE_Export ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t sendv_n_i (ACE_HANDLE handle, const iovec *iov, int iovcnt, size_t *bytes_transferred)
ACE_Export ssize_t sendv_n_i (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export int set_flags (ACE_HANDLE handle, int flags)
 Set flags associated with handle.

ACE_Export int clr_flags (ACE_HANDLE handle, int flags)
 Clear flags associated with handle.

ACE_NAMESPACE_INLINE_FUNCTION
int 
get_flags (ACE_HANDLE handle)
 Return the current setting of flags associated with handle.

ACE_Export ACE_HANDLE handle_timed_open (ACE_Time_Value *timeout, const ACE_TCHAR *name, int flags, int perms, LPSECURITY_ATTRIBUTES sa=0)
ACE_Export int init (void)
ACE_Export int fini (void)
ACE_Export int ldfind (const ACE_TCHAR *filename, ACE_TCHAR pathname[], size_t maxpathnamelen)
ACE_Export FILE * ldopen (const ACE_TCHAR *filename, const ACE_TCHAR *type)
ACE_Export ACE_TCHARldname (const ACE_TCHAR *entry_point)
ACE_Export int get_temp_dir (ACE_TCHAR *buffer, size_t buffer_len)
ACE_Export ACE_HANDLE open_temp_file (const ACE_TCHAR *name, int mode, int perm=0)
ACE_Export size_t strrepl (char *s, char search, char replace)
ACE_Export char * strsplit_r (char *s, const char *token, char *&next_start)
ACE_Export size_t strrepl (wchar_t *s, wchar_t search, wchar_t replace)
 As strrepl, but for wide characters.

ACE_Export wchar_t * strsplit_r (wchar_t *s, const wchar_t *token, wchar_t *&next_start)
 As strsplit_r, but for wide characters.

ACE_Export int bind_port (ACE_HANDLE handle, ACE_UINT32 ip_addr=INADDR_ANY, int address_family=AF_UNSPEC)
 Bind a new unused port to handle.

ACE_Export int get_bcast_addr (ACE_UINT32 &bcast_addr, const ACE_TCHAR *hostname=0, ACE_UINT32 host_addr=0, ACE_HANDLE handle=ACE_INVALID_HANDLE)
ACE_Export int get_fqdn (ACE_INET_Addr const &addr, char hostname[], size_t len)
 Get fully qualified host/domain name.

ACE_Export int get_ip_interfaces (size_t &count, ACE_INET_Addr *&addr_array)
ACE_Export int count_interfaces (ACE_HANDLE handle, size_t &how_many)
ACE_Export ACE_HANDLE get_handle (void)
ACE_Export bool ipv4_enabled (void)
ACE_Export int ipv6_enabled (void)

Variables

size_t allocation_granularity_ = 0
size_t pagesize_ = 0
char debug_
unsigned int init_fini_count_ = 0


Detailed Description

The namespace containing the ACE framework itself.

The ACE namespace contains all types (classes, structures, typedefs, etc), and global functions and variables in the ACE framework.


Function Documentation

const ACE_TCHAR * ACE::basename const ACE_TCHAR pathname,
ACE_TCHAR  delim = ACE_DIRECTORY_SEPARATOR_CHAR
 

Returns the "basename" of a pathname separated by delim. For instance, the basename of "/tmp/foo.cpp" is "foo.cpp" when delim is '/'.

Definition at line 406 of file ACE.cpp.

References ACE_TCHAR, ACE_TRACE, and ACE_OS::strrchr().

Referenced by ACE_Name_Options::process_name().

00407 {
00408   ACE_TRACE ("ACE::basename");
00409   const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);
00410 
00411   if (temp == 0)
00412     return pathname;
00413   else
00414     return temp + 1;
00415 }

u_int ACE::beta_version void   ) 
 

e.g., the "12" in ACE 5.1.12. Returns 0 for "stable" (non-beta) releases.

Definition at line 119 of file ACE.cpp.

References ACE_BETA_VERSION.

00120 {
00121   return ACE_BETA_VERSION;
00122 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL int ACE::bind_port ACE_HANDLE  handle,
ACE_UINT32  ip_addr = INADDR_ANY,
int  address_family = AF_UNSPEC
 

Bind a new unused port to handle.

Definition at line 170 of file Sock_Connect.cpp.

References ACE_INET_Addr, ACE_MAX_DEFAULT_PORT, ACE_TRACE, ACE_OS::bind(), EADDRINUSE, ACE_INET_Addr::get_addr(), ACE_Addr::get_size(), INADDR_ANY, IPPORT_RESERVED, and ACE_INET_Addr::set().

Referenced by ACE_SOCK_CODgram::open(), ACE_SOCK_SEQPACK_Acceptor::shared_open(), ACE_SOCK_Dgram::shared_open(), and ACE_SOCK_Acceptor::shared_open().

00171 {
00172   ACE_TRACE ("ACE::bind_port");
00173 
00174   ACE_INET_Addr addr;
00175 
00176 #if defined (ACE_HAS_IPV6)
00177   if (address_family != PF_INET6)
00178     // What do we do if it is PF_"INET6?  Since it's 4 bytes, it must be an
00179     // IPV4 address. Is there a difference?  Why is this test done? dhinton
00180 #else /* ACE_HAS_IPV6 */
00181     ACE_UNUSED_ARG (address_family);
00182 #endif /* !ACE_HAS_IPV6 */
00183     addr = ACE_INET_Addr ((u_short)0, ip_addr);
00184 #if defined (ACE_HAS_IPV6)
00185  else if (ip_addr != INADDR_ANY)
00186  // address_family == PF_INET6 and a non default IP address means to bind
00187  // to the IPv4-mapped IPv6 address
00188    addr.set ((u_short)0, ip_addr, 1, 1);
00189 #endif /* ACE_HAS_IPV6 */
00190 
00191 #if !defined (ACE_LACKS_WILDCARD_BIND)
00192   // The OS kernel should select a free port for us.
00193   return ACE_OS::bind (handle,
00194                        (sockaddr*)addr.get_addr(),
00195                        addr.get_size());
00196 #else
00197   static u_short upper_limit = ACE_MAX_DEFAULT_PORT;
00198   int round_trip = upper_limit;
00199   int lower_limit = IPPORT_RESERVED;
00200 
00201   // We have to select the port explicitly.
00202 
00203   for (;;)
00204     {
00205       addr.set((u_short)upper_limit,ip_addr);
00206 
00207       if (ACE_OS::bind (handle,
00208                         (sockaddr*)addr.get_addr()
00209                         addr.get_size()) >= 0)
00210         {
00211 #if defined (ACE_WIN32)
00212           upper_limit--;
00213 #endif /* ACE_WIN32 */
00214           return 0;
00215         }
00216       else if (errno != EADDRINUSE)
00217         return -1;
00218       else
00219         {
00220           upper_limit--;
00221 
00222           // Wrap back around when we reach the bottom.
00223           if (upper_limit <= lower_limit)
00224             upper_limit = ACE_MAX_DEFAULT_PORT;
00225 
00226           // See if we have already gone around once!
00227           if (upper_limit == round_trip)
00228             {
00229               errno = EAGAIN;
00230               return -1;
00231             }
00232         }
00233     }
00234 #endif /* ACE_HAS_WILDCARD_BIND */
00235 }

int ACE::clr_flags ACE_HANDLE  handle,
int  flags
 

Clear flags associated with handle.

Definition at line 62 of file Flag_Manip.cpp.

References ACE_CLR_BITS, ACE_NONBLOCK, ACE_NOTSUP_RETURN, ACE_TRACE, F_GETFL, ACE_OS::fcntl(), and ACE_OS::ioctl().

Referenced by ACE_IPC_SAP::disable(), ACE_IO_SAP::disable(), restore_non_blocking_mode(), ACE_SOCK_SEQPACK_Acceptor::shared_accept_finish(), ACE_SOCK_Acceptor::shared_accept_finish(), and ACE_MEM_Acceptor::shared_accept_finish().

00063 {
00064   ACE_TRACE ("ACE::clr_flags");
00065 
00066 #if defined (ACE_LACKS_FCNTL)
00067   switch (flags)
00068     {
00069     case ACE_NONBLOCK:
00070       // nonblocking argument (1)
00071       // blocking:            (0)
00072       {
00073         int nonblock = 0;
00074         return ACE_OS::ioctl (handle, FIONBIO, &nonblock);
00075       }
00076     default:
00077       ACE_NOTSUP_RETURN (-1);
00078     }
00079 #else
00080   int val = ACE_OS::fcntl (handle, F_GETFL, 0);
00081 
00082   if (val == -1)
00083     return -1;
00084 
00085   // Turn flags off.
00086   ACE_CLR_BITS (val, flags);
00087 
00088   if (ACE_OS::fcntl (handle, F_SETFL, val) == -1)
00089     return -1;
00090   else
00091     return 0;
00092 #endif /* ACE_LACKS_FCNTL */
00093 }

u_int ACE::compiler_beta_version void   ) 
 

E.g., the "0" in SunPro C++ 4.32.0.

Definition at line 155 of file ACE.cpp.

00156 {
00157 #ifdef ACE_CC_BETA_VERSION
00158   return ACE_CC_BETA_VERSION;
00159 #else
00160   return 0;
00161 #endif
00162 }

u_int ACE::compiler_major_version void   ) 
 

E.g., the "4" in SunPro C++ 4.32.0.

Definition at line 135 of file ACE.cpp.

00136 {
00137 #ifdef ACE_CC_MAJOR_VERSION
00138   return ACE_CC_MAJOR_VERSION;
00139 #else
00140   return 0;
00141 #endif
00142 }

u_int ACE::compiler_minor_version void   ) 
 

E.g., the "32" in SunPro C++ 4.32.0.

Definition at line 145 of file ACE.cpp.

00146 {
00147 #ifdef ACE_CC_MINOR_VERSION
00148   return ACE_CC_MINOR_VERSION;
00149 #else
00150   return 0;
00151 #endif
00152 }

const ACE_TCHAR * ACE::compiler_name void   ) 
 

E.g., the "SunPro C++" in SunPro C++ 4.32.0.

Definition at line 125 of file ACE.cpp.

References ACE_TEXT.

00126 {
00127 #ifdef ACE_CC_NAME
00128   return ACE_CC_NAME;
00129 #else
00130   return ACE_TEXT ("");
00131 #endif
00132 }

int ACE::count_interfaces ACE_HANDLE  handle,
size_t &  how_many
 

Helper routine for get_ip_interfaces, differs by UNIX platform so put into own subroutine. perform some ioctls to retrieve ifconf list of ifreq structs.

Definition at line 1444 of file Sock_Connect.cpp.

References ACE_ERROR_RETURN, ACE_NOTSUP_RETURN, ACE_TEXT, AF_UNSPEC, caddr_t, ACE_OS::fclose(), ACE_OS::fopen(), ACE_OS::free(), ACE_OS::ioctl(), LM_ERROR, ACE_OS::malloc(), ACE_OS::memset(), and SIOCGIFCONF_CMD.

Referenced by get_ip_interfaces().

01446 {
01447 #if defined (ACE_WIN32) || defined (ACE_HAS_GETIFADDRS) || defined (__hpux) || defined (_AIX) || (defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x600))
01448   // none of these platforms make use of count_interfaces
01449   ACE_UNUSED_ARG (handle);
01450   ACE_UNUSED_ARG (how_many);
01451   ACE_NOTSUP_RETURN (-1); // no implementation
01452 
01453 #elif defined (SIOCGIFNUM)
01454 # if defined (SIOCGLIFNUM)
01455   int cmd = SIOCGLIFNUM;
01456   struct lifnum if_num = {AF_UNSPEC,0,0};
01457 # else
01458   int cmd = SIOCGIFNUM;
01459   int if_num = 0;
01460 # endif /* SIOCGLIFNUM */
01461   if (ACE_OS::ioctl (handle, cmd, (caddr_t)&if_num) == -1)
01462     ACE_ERROR_RETURN ((LM_ERROR,
01463                        ACE_TEXT ("%p\n"),
01464                        ACE_TEXT ("ACE::count_interfaces:")
01465                        ACE_TEXT ("ioctl - SIOCGLIFNUM failed")),
01466                       -1);
01467 # if defined (SIOCGLIFNUM)
01468   how_many = if_num.lifn_count;
01469 # else
01470   how_many = if_num;
01471 # endif /* SIOCGLIFNUM */
01472 return 0;
01473 
01474 #elif (defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS)) && !defined (ACE_LACKS_NETWORKING)
01475   // Note: DEC CXX doesn't define "unix".  BSD compatible OS: HP UX,
01476   // AIX, SunOS 4.x perform some ioctls to retrieve ifconf list of
01477   // ifreq structs no SIOCGIFNUM on SunOS 4.x, so use guess and scan
01478   // algorithm
01479 
01480   // Probably hard to put this many ifs in a unix box..
01481   const int MAX_IF = 50;
01482 
01483   // HACK - set to an unreasonable number
01484   int num_ifs = MAX_IF;
01485 
01486   struct ifconf ifcfg;
01487   size_t ifreq_size = num_ifs * sizeof (struct ifreq);
01488   struct ifreq *p_ifs =
01489     (struct ifreq *) ACE_OS::malloc (ifreq_size);
01490 
01491   if (!p_ifs)
01492     {
01493       errno = ENOMEM;
01494       return -1;
01495     }
01496 
01497   ACE_OS::memset (p_ifs, 0, ifreq_size);
01498   ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf));
01499 
01500   ifcfg.ifc_req = p_ifs;
01501   ifcfg.ifc_len = ifreq_size;
01502 
01503   if (ACE_OS::ioctl (handle,
01504                      SIOCGIFCONF_CMD,
01505                      (caddr_t) &ifcfg) == -1)
01506     {
01507       ACE_OS::free (ifcfg.ifc_req);
01508       ACE_ERROR_RETURN ((LM_ERROR,
01509                          ACE_TEXT ("%p\n"),
01510                          ACE_TEXT ("ACE::count_interfaces:")
01511                          ACE_TEXT ("ioctl - SIOCGIFCONF failed")),
01512                         -1);
01513     }
01514 
01515   int if_count = 0, i;
01516 
01517   // get if address out of ifreq buffers.  ioctl puts a blank-named
01518   // interface to mark the end of the returned interfaces.
01519   for (i = 0;
01520        i < num_ifs;
01521        i++)
01522     {
01523       /* In OpenBSD, the length of the list is returned. */
01524       ifcfg.ifc_len -= sizeof (struct ifreq);
01525       if (ifcfg.ifc_len < 0)
01526         break;
01527 
01528       ++if_count;
01529 #if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS)
01530       ++p_ifs;
01531 #else
01532      if (p_ifs->ifr_addr.sa_len <= sizeof (struct sockaddr))
01533        {
01534           ++p_ifs;
01535        }
01536        else
01537        {
01538           p_ifs = (struct ifreq *)
01539               (p_ifs->ifr_addr.sa_len + (caddr_t) &p_ifs->ifr_addr);
01540        }
01541 #endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) */
01542     }
01543 
01544   ACE_OS::free (ifcfg.ifc_req);
01545 
01546 # if defined (ACE_HAS_IPV6)
01547   FILE* fp = 0;
01548 
01549   if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0)
01550     {
01551       // Scan the lines according to the expected format but don't really read any input
01552       while (fscanf (fp, "%*32s %*02x %*02x %*02x %*02x %*8s\n") != EOF)
01553         {
01554           ++if_count;
01555         }
01556       ACE_OS::fclose (fp);
01557     }
01558 # endif /* ACE_HAS_IPV6 */
01559 
01560   how_many = if_count;
01561   return 0;
01562 #else
01563   ACE_UNUSED_ARG (handle);
01564   ACE_UNUSED_ARG (how_many);
01565   ACE_NOTSUP_RETURN (-1); // no implementation
01566 #endif /* sparc && SIOCGIFNUM */
01567 }

ACE_UINT32 ACE::crc32 const iovec *  iov,
int  len,
ACE_UINT32  crc = 0
 

Computes the ISO 8802-3 standard 32 bits CRC for the @ len iovec buffers.

Definition at line 142 of file ACE_crc32.cpp.

References COMPUTE.

00143 {
00144   crc = ~crc;
00145 
00146   for (int i = 0; i < len; ++i)
00147     {
00148       for (const char *p = (const char *) iov[i].iov_base,
00149                       *e = (const char *) iov[i].iov_base + iov[i].iov_len;
00150            p != e;
00151            ++p)
00152         COMPUTE (crc, *p);
00153     }
00154 
00155   return ~crc;
00156 }

ACE_UINT32 ACE::crc32 const void *  buf,
size_t  len,
ACE_UINT32  crc = 0
 

Computes the ISO 8802-3 standard 32 bits CRC for the buffer.

Definition at line 126 of file ACE_crc32.cpp.

References COMPUTE.

00127 {
00128   crc = ~crc;
00129 
00130   for (const char *p = (const char *) buffer,
00131                   *e = (const char *) buffer + len;
00132        p != e;
00133        ++p)
00134     {
00135       COMPUTE (crc, *p);
00136     }
00137 
00138   return ~crc;
00139 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_UINT32 ACE::crc32 const char *  str  ) 
 

Computes the ISO 8802-3 standard 32 bits CRC for the string.

Definition at line 111 of file ACE_crc32.cpp.

References COMPUTE.

Referenced by ACE_Shared_Memory_Pool::ACE_Shared_Memory_Pool(), and ACE_SV_Semaphore_Simple::name_2_key().

00112 {
00113   ACE_UINT32 crc = 0xFFFFFFFF;
00114 
00115   for (const char *p = string;
00116        *p != 0;
00117        ++p)
00118     {
00119       COMPUTE (crc, *p);
00120     }
00121 
00122   return ~crc;
00123 }

ACE_UINT16 ACE::crc_ccitt const iovec *  iov,
int  len,
ACE_UINT16  crc = 0
 

Computes CRC-CCITT for the @ len iovec buffers.

Definition at line 109 of file ACE_crc_ccitt.cpp.

References COMPUTE.

00110 {
00111   crc = ~crc;
00112 
00113   for (int i = 0; i < len; ++i)
00114     {
00115       for (const char *p = (const char *) iov[i].iov_base,
00116                       *e = (const char *) iov[i].iov_base + iov[i].iov_len;
00117            p != e;
00118            ++p)
00119         COMPUTE (crc, *p);
00120     }
00121 
00122   return ~crc;
00123 }

ACE_UINT16 ACE::crc_ccitt const void *  buf,
size_t  len,
ACE_UINT16  crc = 0
 

Computes CRC-CCITT for the buffer.

Definition at line 93 of file ACE_crc_ccitt.cpp.

References COMPUTE.

00094 {
00095   crc = ~crc;
00096 
00097   for (const char *p = (const char *) buffer,
00098                   *e = (const char *) buffer + len;
00099        p != e;
00100        ++p)
00101     {
00102       COMPUTE (crc, *p);
00103     }
00104 
00105   return ~crc;
00106 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_UINT16 ACE::crc_ccitt const char *  str  ) 
 

Computes CRC-CCITT for the string.

Definition at line 78 of file ACE_crc_ccitt.cpp.

References COMPUTE.

00079 {
00080   ACE_UINT16 crc = 0xFFFF;
00081 
00082   for (const char *p = string;
00083        *p != 0;
00084        ++p)
00085     {
00086       COMPUTE (crc, *p);
00087     }
00088 
00089   return ~crc;
00090 }

int ACE::daemonize const ACE_TCHAR  pathname[] = ACE_TEXT("/"),
bool  close_all_handles = ACE_DEFAULT_CLOSE_ALL_HANDLES,
const ACE_TCHAR  program_name[] = ACE_TEXT("< unknown >")
 

Become a daemon process using the algorithm in Richard Stevens "Advanced Programming in the UNIX Environment." If close_all_handles is non-zero then all open file handles are closed.

Definition at line 2742 of file ACE.cpp.

References ACE_NOTSUP_RETURN, ACE_TCHAR, ACE_TRACE, ACE_OS::chdir(), ACE_OS::close(), ACE_OS::exit(), ACE_OS::fork(), max_handles(), pid_t, ACE_OS::setsid(), SIG_IGN, SIGHUP, ACE_OS::signal(), and ACE_OS::umask().

Referenced by ACE_Service_Config::open_i().

02745 {
02746   ACE_TRACE ("ACE::daemonize");
02747 #if !defined (ACE_LACKS_FORK)
02748   pid_t pid = ACE_OS::fork ();
02749 
02750   if (pid == -1)
02751     return -1;
02752   else if (pid != 0)
02753     ACE_OS::exit (0); // Parent exits.
02754 
02755   // 1st child continues.
02756   ACE_OS::setsid (); // Become session leader.
02757 
02758   ACE_OS::signal (SIGHUP, SIG_IGN);
02759 
02760   pid = ACE_OS::fork (program_name);
02761 
02762   if (pid != 0)
02763     ACE_OS::exit (0); // First child terminates.
02764 
02765   // Second child continues.
02766 
02767   if (pathname != 0)
02768     // change working directory.
02769     ACE_OS::chdir (pathname);
02770 
02771   ACE_OS::umask (0); // clear our file mode creation mask.
02772 
02773   // Close down the I/O handles.
02774   if (close_all_handles)
02775     for (int i = ACE::max_handles () - 1; i >= 0; i--)
02776       ACE_OS::close (i);
02777 
02778   return 0;
02779 #else
02780   ACE_UNUSED_ARG (pathname);
02781   ACE_UNUSED_ARG (close_all_handles);
02782   ACE_UNUSED_ARG (program_name);
02783 
02784   ACE_NOTSUP_RETURN (-1);
02785 #endif /* ACE_LACKS_FORK */
02786 }

void ACE::debug bool  onoff  ) 
 

Definition at line 172 of file ACE.cpp.

00173 {
00174   ACE::debug_ = onoff;
00175 }

bool ACE::debug void   ) 
 

Definition at line 165 of file ACE.cpp.

References debug(), and ACE_OS::getenv().

Referenced by ACE_DLL::ACE_DLL(), ACE_DLL_Manager::ACE_DLL_Manager(), ACE_Service_Config_Guard::ACE_Service_Config_Guard(), ACE_Service_Gestalt::ACE_Service_Gestalt(), ACE_Service_Type_Dynamic_Guard::ACE_Service_Type_Dynamic_Guard(), ACE_Service_Gestalt::add_processed_static_svc(), ACE_Service_Repository::close(), ACE_Service_Gestalt::close(), ACE_DLL_Handle::close(), ACE_Local_Name_Space<, ACE_LOCK >::create_manager_i(), debug(), ACE_Service_Type_Impl::fini(), ACE_Service_Repository::fini(), ACE_Naming_Context::fini(), ACE_Service_Config::fini_svcs(), get_fqdn(), ACE_DLL_Handle::get_handle(), ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_2 >::handle_input(), ACE_Naming_Context::init(), ACE_Dynamic_Service_Dependency::init(), ACE_Service_Gestalt::init_svc_conf_file_queue(), ACE_Service_Gestalt::initialize(), ACE_Service_Gestalt::initialize_i(), ACE_Service_Repository::insert(), ACE_Dynamic_Service_Base::instance(), ACE_SOCK_Dgram_Bcast::mk_broadcast(), ACE_DLL_Handle::open(), ACE_DLL_Manager::open_dll(), ACE_Service_Gestalt::open_i(), ACE_Service_Config::open_i(), ACE_DLL::open_i(), ACE_Service_Gestalt::parse_args_i(), ACE_Service_Gestalt::process_directive(), ACE_Service_Gestalt::process_directive_i(), ACE_Service_Gestalt::process_directives_i(), ACE_Service_Gestalt::process_file(), ACE_Service_Config::reconfigure(), ACE_Service_Repository::relocate_i(), ACE_Framework_Repository::remove_dll_components_i(), ACE_DLL_Handle::symbol(), ACE_DLL_Manager::unload_dll(), ACE_DLL_Manager::~ACE_DLL_Manager(), ACE_Dynamic_Service_Dependency::~ACE_Dynamic_Service_Dependency(), ACE_Service_Config_Guard::~ACE_Service_Config_Guard(), ACE_Service_Gestalt::~ACE_Service_Gestalt(), ACE_Service_Repository::~ACE_Service_Repository(), and ACE_Service_Type_Dynamic_Guard::~ACE_Service_Type_Dynamic_Guard().

00166 {
00167   static const char* debug = ACE_OS::getenv ("ACE_DEBUG");
00168   return (ACE::debug_ != 0) ? ACE::debug_ : (debug != 0 ? (*debug != '0'): false);
00169 }

const ACE_TCHAR * ACE::dirname const ACE_TCHAR pathname,
ACE_TCHAR  delim = ACE_DIRECTORY_SEPARATOR_CHAR
 

Returns the "dirname" of a pathname. For instance, the dirname of "/tmp/foo.cpp" is "/tmp" when delim is '/'. If pathname has no delim ".\0" is returned. This method does not modify pathname and is not reentrant.

Definition at line 418 of file ACE.cpp.

References ACE_TCHAR, ACE_TRACE, MAXPATHLEN, ACE_OS::strrchr(), and ACE_OS::strsncpy().

00419 {
00420   ACE_TRACE ("ACE::dirname");
00421   static ACE_TCHAR return_dirname[MAXPATHLEN + 1];
00422 
00423   const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);
00424 
00425   if (temp == 0)
00426     {
00427       return_dirname[0] = '.';
00428       return_dirname[1] = '\0';
00429 
00430       return return_dirname;
00431     }
00432   else
00433     {
00434       // When the len is truncated, there are problems!  This should
00435       // not happen in normal circomstances
00436       size_t len = temp - pathname + 1;
00437       if (len > (sizeof return_dirname / sizeof (ACE_TCHAR)))
00438         len = sizeof return_dirname / sizeof (ACE_TCHAR);
00439 
00440       ACE_OS::strsncpy (return_dirname,
00441                         pathname,
00442                         len);
00443       return return_dirname;
00444     }
00445 }

int ACE::enter_recv_timedwait ACE_HANDLE  handle,
const ACE_Time_Value timeout,
int &  val
 

Wait for timeout before proceeding to a recv operation. val keeps track of whether we're in non-blocking mode or not.

Definition at line 2230 of file ACE.cpp.

References handle_read_ready(), and record_and_set_non_blocking_mode().

Referenced by recv(), recvfrom(), recvmsg(), recvv(), and t_rcv().

02233 {
02234   int result = ACE::handle_read_ready (handle,
02235                                        timeout);
02236 
02237   if (result == -1)
02238     return -1;
02239 
02240   ACE::record_and_set_non_blocking_mode (handle,
02241                                          val);
02242 
02243   return result;
02244 }

int ACE::enter_send_timedwait ACE_HANDLE  handle,
const ACE_Time_Value timeout,
int &  val
 

Wait for timeout before proceeding to a send operation. val keeps track of whether we're in non-blocking mode or not.

Definition at line 2247 of file ACE.cpp.

References handle_write_ready(), and record_and_set_non_blocking_mode().

Referenced by send(), sendmsg(), sendto(), sendv(), and t_snd().

02250 {
02251   int result = ACE::handle_write_ready (handle,
02252                                         timeout);
02253 
02254   if (result == -1)
02255     return -1;
02256 
02257   ACE::record_and_set_non_blocking_mode (handle,
02258                                          val);
02259 
02260   return result;
02261 }

const ACE_TCHAR * ACE::execname const ACE_TCHAR pathname  ) 
 

On Windows, determines if a specified pathname ends with ".exe" (not case sensitive). If on Windows and there is no ".exe" suffix, a new ACE_TCHAR array is allocated and a copy of pathname with the ".exe" suffix is copied into it. In this case, the caller is responsible for calling delete [] on the returned pointer.

Parameters:
pathname The name to check for a proper suffix.
Return values:
@c pathname if there is a proper suffix for Windows. This is always the return value for non-Windows platforms.
If a suffix needs to be added, returns a pointer to new[] allocated memory containing the original pathname plus a ".exe" suffix. The caller is responsible for freeing the memory using delete [].

Definition at line 287 of file ACE.cpp.

References ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT, ACE_OS::strcasecmp(), ACE_OS::strcpy(), ACE_OS::strecpy(), ACE_OS::strlen(), and ACE_OS::strrchr().

00288 {
00289 #if defined (ACE_WIN32)
00290   const ACE_TCHAR *suffix = ACE_OS::strrchr (old_name, ACE_TEXT ('.'));
00291   if (suffix == 0 || ACE_OS::strcasecmp (suffix, ACE_TEXT (".exe")) != 0)
00292     {
00293       ACE_TCHAR *new_name;
00294 
00295       size_t size =
00296         ACE_OS::strlen (old_name)
00297         + ACE_OS::strlen (ACE_TEXT (".exe"))
00298         + 1;
00299 
00300       ACE_NEW_RETURN (new_name,
00301                       ACE_TCHAR[size],
00302                       0);
00303       ACE_TCHAR *end = new_name;
00304 
00305       end = ACE_OS::strecpy (new_name, old_name);
00306 
00307       // Concatenate the .exe suffix onto the end of the executable.
00308       // end points _after_ the terminating nul.
00309       ACE_OS::strcpy (end - 1, ACE_TEXT (".exe"));
00310 
00311       return new_name;
00312     }
00313 #endif /* ACE_WIN32 */
00314   return old_name;
00315 }

int ACE::fini void   ) 
 

Shut down ACE library services. Can be called only once per program invocation.

Returns:
Returns 0 on success, -1 on failure, and 1 if it had already been called.

Definition at line 27 of file Init_ACE.cpp.

References ACE_TRACE, ACE_Object_Manager::fini(), and ACE_Object_Manager::instance().

00028 {
00029   ACE_TRACE ("ACE::fini");
00030 
00031   if (ACE::init_fini_count_ > 0)
00032     {
00033       if (--ACE::init_fini_count_ == 0)
00034         return ACE_Object_Manager::instance ()->fini ();
00035       else
00036         // Wait for remaining fini () calls.
00037         return 1;
00038     }
00039   else
00040     // More ACE::fini () calls than ACE::init () calls.  Bad
00041     // application!
00042     return -1;
00043 }

pid_t ACE::fork const ACE_TCHAR program_name = ACE_TEXT("< unknown >"),
int  avoid_zombies = 0
 

if avoid_zombies == 0 call ACE_OS::fork directly, else create an orphan process that's inherited by the init process; init cleans up when the orphan process terminates so we don't create zombies. Returns -1 on failure and either the child PID on success if avoid_zombies == 0 or 1 on success if avoid_zombies != 0 (this latter behavior is a known bug that needs to be fixed).

Definition at line 2789 of file ACE.cpp.

References ACE_OS::_exit(), ACE_exitcode, ACE_TCHAR, ACE_OS::fork(), pid_t, ACE_OS::waitpid(), WEXITSTATUS, and WIFEXITED.

Referenced by ACE_Process_Strategy< SVC_HANDLER >::activate_svc_handler(), and ACE_Process::spawn().

02791 {
02792   if (avoid_zombies == 0)
02793     return ACE_OS::fork (program_name);
02794   else
02795     {
02796       // This algorithm is adapted from an example in the Stevens book
02797       // "Advanced Programming in the Unix Environment" and an item in
02798       // Andrew Gierth's Unix Programming FAQ.  It creates an orphan
02799       // process that's inherited by the init process; init cleans up
02800       // when the orphan process terminates.
02801       //
02802       // Another way to avoid zombies is to ignore or catch the
02803       // SIGCHLD signal; we don't use that approach here.
02804 
02805       pid_t pid = ACE_OS::fork ();
02806       if (pid == 0)
02807         {
02808           // The child process forks again to create a grandchild.
02809           switch (ACE_OS::fork (program_name))
02810             {
02811             case 0: // grandchild returns 0.
02812               return 0;
02813             case -1: // assumes all errnos are < 256
02814               ACE_OS::_exit (errno);
02815             default:  // child terminates, orphaning grandchild
02816               ACE_OS::_exit (0);
02817             }
02818         }
02819 
02820       // Parent process waits for child to terminate.
02821       ACE_exitcode status;
02822       if (pid < 0 || ACE_OS::waitpid (pid, &status, 0) < 0)
02823         return -1;
02824 
02825       // child terminated by calling exit()?
02826       if (WIFEXITED ((status)))
02827         {
02828           // child terminated normally?
02829           if (WEXITSTATUS ((status)) == 0)
02830             return 1;
02831           else
02832             errno = WEXITSTATUS ((status));
02833         }
02834       else
02835         // child didn't call exit(); perhaps it received a signal?
02836         errno = EINTR;
02837 
02838       return -1;
02839     }
02840 }

size_t ACE::format_hexdump const char *  buffer,
size_t  size,
ACE_TCHAR obuf,
size_t  obuf_sz
 

Format buffer into printable format. This is useful for debugging.

Definition at line 2298 of file ACE.cpp.

References ACE_OS::ace_isprint(), ACE_TCHAR, ACE_TEXT, ACE_TRACE, and ACE_OS::sprintf().

02302 {
02303   ACE_TRACE ("ACE::format_hexdump");
02304 
02305   u_char c;
02306   ACE_TCHAR textver[16 + 1];
02307 
02308   // We can fit 16 bytes output in text mode per line, 4 chars per byte.
02309   size_t maxlen = (obuf_sz / 68) * 16;
02310 
02311   if (size > maxlen)
02312     size = maxlen;
02313 
02314   size_t i;
02315 
02316   size_t lines = size / 16;
02317   for (i = 0; i < lines; i++)
02318     {
02319       size_t j;
02320 
02321       for (j = 0 ; j < 16; j++)
02322         {
02323           c = (u_char) buffer[(i << 4) + j];    // or, buffer[i*16+j]
02324           ACE_OS::sprintf (obuf,
02325                            ACE_TEXT ("%02x "),
02326                            c);
02327           obuf += 3;
02328           if (j == 7)
02329             {
02330               ACE_OS::sprintf (obuf,
02331                                ACE_TEXT (" "));
02332               ++obuf;
02333             }
02334           textver[j] = ACE_OS::ace_isprint (c) ? c : '.';
02335         }
02336 
02337       textver[j] = 0;
02338 
02339       ACE_OS::sprintf (obuf,
02340                        ACE_TEXT ("  %s\n"),
02341                        textver);
02342 
02343       while (*obuf != '\0')
02344         ++obuf;
02345     }
02346 
02347   if (size % 16)
02348     {
02349       for (i = 0 ; i < size % 16; i++)
02350         {
02351           c = (u_char) buffer[size - size % 16 + i];
02352           ACE_OS::sprintf (obuf,
02353                            ACE_TEXT ("%02x "),
02354                            c);
02355           obuf += 3;
02356           if (i == 7)
02357             {
02358               ACE_OS::sprintf (obuf,
02359                                ACE_TEXT (" "));
02360               ++obuf;
02361             }
02362           textver[i] = ACE_OS::ace_isprint (c) ? c : '.';
02363         }
02364 
02365       for (i = size % 16; i < 16; i++)
02366         {
02367           ACE_OS::sprintf (obuf,
02368                            ACE_TEXT ("   "));
02369           obuf += 3;
02370           if (i == 7)
02371             {
02372               ACE_OS::sprintf (obuf,
02373                                ACE_TEXT (" "));
02374               ++obuf;
02375             }
02376           textver[i] = ' ';
02377         }
02378 
02379       textver[i] = 0;
02380       ACE_OS::sprintf (obuf,
02381                        ACE_TEXT ("  %s\n"),
02382                        textver);
02383     }
02384   return size;
02385 }

u_long ACE::gcd u_long  x,
u_long  y
 

Euclid's greatest common divisor algorithm.

Definition at line 2933 of file ACE.cpp.

Referenced by minimum_frame_size(), and ACE_Get_Opt::permute_args().

02934 {
02935   while (y != 0)
02936     {
02937       u_long r = x % y;
02938       x = y;
02939       y = r;
02940     }
02941 
02942   return x;
02943 }

int ACE::get_bcast_addr ACE_UINT32 &  bcast_addr,
const ACE_TCHAR hostname = 0,
ACE_UINT32  host_addr = 0,
ACE_HANDLE  handle = ACE_INVALID_HANDLE
 

Get our broadcast address based on our host_addr. If hostname is non-0 we'll use it to determine our IP address. If handle is not ACE_INVALID_HANDLE then we'll use this to determine our broadcast address, otherwise we'll have to create a socket internally (and free it). Returns -1 on failure and 0 on success.

Definition at line 238 of file Sock_Connect.cpp.

References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_ERROR, ACE_ERROR_RETURN, ACE_NOTSUP_RETURN, ACE_TCHAR, ACE_TEXT, ACE_TEXT_ALWAYS_CHAR, ACE_TRACE, ACE_UINT64, AF_INET, caddr_t, ACE_OS::close(), ACE_OS::gethostbyname(), IFF_BROADCAST, IFF_LOOPBACK, IFF_UP, ACE_OS::ioctl(), LM_ERROR, ACE_OS::memcpy(), ACE_OS::memset(), SIOCGIFBRDADDR, SIOCGIFCONF_CMD, SOCK_STREAM, and ACE_OS::socket().

00242 {
00243   ACE_TRACE ("ACE::get_bcast_addr");
00244 
00245 #if defined (ACE_LACKS_GET_BCAST_ADDR)
00246   ACE_UNUSED_ARG (bcast_addr);
00247   ACE_UNUSED_ARG (host_name);
00248   ACE_UNUSED_ARG (host_addr);
00249   ACE_UNUSED_ARG (handle);
00250   ACE_NOTSUP_RETURN (-1);
00251 #elif !defined(ACE_WIN32) && !defined(__INTERIX)
00252   ACE_HANDLE s = handle;
00253 
00254   if (s == ACE_INVALID_HANDLE)
00255     s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0);
00256 
00257   if (s == ACE_INVALID_HANDLE)
00258     ACE_ERROR_RETURN ((LM_ERROR,
00259                        ACE_TEXT ("%p\n"),
00260                        ACE_TEXT ("ACE_OS::socket")),
00261                       -1);
00262 
00263   struct ifconf ifc;
00264   char buf[BUFSIZ];
00265 
00266   ifc.ifc_len = sizeof buf;
00267   ifc.ifc_buf = buf;
00268 
00269   // Get interface structure and initialize the addresses using UNIX
00270   // techniques
00271   if (ACE_OS::ioctl (s, SIOCGIFCONF_CMD, (char *) &ifc) == -1)
00272     ACE_ERROR_RETURN ((LM_ERROR,
00273                        ACE_TEXT ("%p\n"),
00274                        ACE_TEXT ("ACE::get_bcast_addr:")
00275                        ACE_TEXT ("ioctl (get interface configuration)")),
00276                       -1);
00277 
00278   struct ifreq *ifr = ifc.ifc_req;
00279 
00280   struct sockaddr_in ip_addr;
00281 
00282   // Get host ip address if necessary.
00283   if (host_name)
00284     {
00285       hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name));
00286 
00287       if (hp == 0)
00288         return -1;
00289       else
00290 #if !defined(_UNICOS)
00291         ACE_OS::memcpy ((char *) &ip_addr.sin_addr.s_addr,
00292                         (char *) hp->h_addr,
00293                         hp->h_length);
00294 #else /* _UNICOS */
00295       {
00296         ACE_UINT64 haddr;  // a place to put the address
00297         char * haddrp = (char *) &haddr;  // convert to char pointer
00298         ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length);
00299         ip_addr.sin_addr.s_addr = haddr;
00300       }
00301 #endif /* ! _UNICOS */
00302     }
00303   else
00304     {
00305       ACE_OS::memset ((void *) &ip_addr, 0, sizeof ip_addr);
00306 #if !defined(_UNICOS)
00307       ACE_OS::memcpy ((void *) &ip_addr.sin_addr,
00308                       (void*) &host_addr,
00309                       sizeof ip_addr.sin_addr);
00310 #else /* _UNICOS */
00311       ip_addr.sin_addr.s_addr = host_addr;   // just copy to the bitfield
00312 #endif /* ! _UNICOS */
00313     }
00314 
00315 #if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__)
00316   for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0;
00317        n--, ifr++)
00318 #else
00319   // see mk_broadcast@SOCK_Dgram_Bcast.cpp
00320   for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) &&
00321         ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
00322           (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1);
00323         ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
00324           (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len,
00325             ifr = (struct ifreq *)
00326               ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) :
00327           (nbytes -= sizeof (struct ifreq), ifr++)))
00328 #endif /* !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) */
00329     {
00330       struct sockaddr_in if_addr;
00331 
00332       // Compare host ip address with interface ip address.
00333       ACE_OS::memcpy (&if_addr,
00334                       &ifr->ifr_addr,
00335                       sizeof if_addr);
00336 
00337       if (ip_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr)
00338         continue;
00339 
00340       if (ifr->ifr_addr.sa_family != AF_INET)
00341         {
00342           ACE_ERROR ((LM_ERROR,
00343                       ACE_TEXT ("%p\n"),
00344                       ACE_TEXT ("ACE::get_bcast_addr:")
00345                       ACE_TEXT ("Not AF_INET")));
00346           continue;
00347         }
00348 
00349       struct ifreq flags = *ifr;
00350       struct ifreq if_req = *ifr;
00351 
00352       if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1)
00353         {
00354           ACE_ERROR ((LM_ERROR,
00355                       ACE_TEXT ("%p\n"),
00356                       ACE_TEXT ("ACE::get_bcast_addr:")
00357                       ACE_TEXT (" ioctl (get interface flags)")));
00358           continue;
00359         }
00360 
00361       if (ACE_BIT_DISABLED (flags.ifr_flags, IFF_UP))
00362         {
00363           ACE_ERROR ((LM_ERROR,
00364                       ACE_TEXT ("%p\n"),
00365                       ACE_TEXT ("ACE::get_bcast_addr:")
00366                       ACE_TEXT ("Network interface is not up")));
00367           continue;
00368         }
00369 
00370       if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_LOOPBACK))
00371         continue;
00372 
00373       if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_BROADCAST))
00374         {
00375           if (ACE_OS::ioctl (s,
00376                              SIOCGIFBRDADDR,
00377                              (char *) &if_req) == -1)
00378             ACE_ERROR ((LM_ERROR,
00379                         ACE_TEXT ("%p\n"),
00380                         ACE_TEXT ("ACE::get_bcast_addr:")
00381                         ACE_TEXT ("ioctl (get broadaddr)")));
00382           else
00383             {
00384               ACE_OS::memcpy (&ip_addr,
00385                               &if_req.ifr_broadaddr,
00386                               sizeof if_req.ifr_broadaddr);
00387 
00388               ACE_OS::memcpy ((void *) &host_addr,
00389                               (void *) &ip_addr.sin_addr,
00390                               sizeof host_addr);
00391 
00392               if (handle == ACE_INVALID_HANDLE)
00393                 ACE_OS::close (s);
00394 
00395               bcast_addr = host_addr;
00396               return 0;
00397             }
00398         }
00399       else
00400         ACE_ERROR ((LM_ERROR,
00401                     ACE_TEXT ("%p\n"),
00402                     ACE_TEXT ("ACE::get_bcast_addr:")
00403                     ACE_TEXT ("Broadcast is not enable for this interface.")));
00404 
00405       if (handle == ACE_INVALID_HANDLE)
00406         ACE_OS::close (s);
00407 
00408       bcast_addr = host_addr;
00409       return 0;
00410     }
00411 
00412   return 0;
00413 #else
00414   ACE_UNUSED_ARG (handle);
00415   ACE_UNUSED_ARG (host_addr);
00416   ACE_UNUSED_ARG (host_name);
00417   bcast_addr = (ACE_UINT32 (INADDR_BROADCAST));
00418   return 0;
00419 #endif /* !ACE_WIN32 && !__INTERIX */
00420 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE::get_flags ACE_HANDLE  handle  ) 
 

Return the current setting of flags associated with handle.

Definition at line 11 of file Flag_Manip.inl.

References ACE_TRACE, F_GETFL, and ACE_OS::fcntl().

Referenced by record_and_set_non_blocking_mode().

00012 {
00013   ACE_TRACE ("ACE::get_flags");
00014 
00015 #if defined (ACE_LACKS_FCNTL)
00016   // ACE_OS::fcntl is not supported.  It
00017   // would be better to store ACE's notion of the flags
00018   // associated with the handle, but this works for now.
00019   ACE_UNUSED_ARG (handle);
00020   return 0;
00021 #else
00022   return ACE_OS::fcntl (handle, F_GETFL, 0);
00023 #endif /* ACE_LACKS_FCNTL */
00024 }

int ACE::get_fqdn ACE_INET_Addr const &  addr,
char  hostname[],
size_t  len
 

Get fully qualified host/domain name.

Definition at line 423 of file Sock_Connect.cpp.

References ACE_DEBUG, ACE_HOSTENT_DATA, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, AF_INET, debug(), ACE_INET_Addr::get_addr(), ACE_Addr::get_type(), ACE_OS::gethostbyaddr_r(), LM_DEBUG, ACE_OS::strchr(), ACE_OS::strcpy(), and ACE_OS::strlen().

00426 {
00427   int h_error;  // Not the same as errno!
00428   hostent hentry;
00429   ACE_HOSTENT_DATA buf;
00430 
00431   char * ip_addr = 0;
00432   int ip_addr_size = 0;
00433   if (addr.get_type () == AF_INET)
00434     {
00435       sockaddr_in * const sock_addr =
00436         reinterpret_cast<sockaddr_in *> (addr.get_addr ());
00437       ip_addr_size = sizeof sock_addr->sin_addr;
00438       ip_addr = (char*) &sock_addr->sin_addr;
00439     }
00440 #ifdef ACE_HAS_IPV6
00441   else
00442     {
00443       sockaddr_in6 * sock_addr =
00444         reinterpret_cast<sockaddr_in6 *> (addr.get_addr ());
00445 
00446       ip_addr_size = sizeof sock_addr->sin6_addr;
00447       ip_addr = (char*) &sock_addr->sin6_addr;
00448     }
00449 #endif  /* ACE_HAS_IPV6 */
00450 
00451    // get the host entry for the address in question
00452    hostent * const hp = ACE_OS::gethostbyaddr_r (ip_addr,
00453                                                  ip_addr_size,
00454                                                  addr.get_type (),
00455                                                  &hentry,
00456                                                  buf,
00457                                                  &h_error);
00458 
00459    // if it's not found in the host file or the DNS datase, there is nothing
00460    // much we can do. embed the IP address
00461    if (hp == 0 || hp->h_name == 0)
00462      return -1;
00463 
00464    if (ACE::debug())
00465      ACE_DEBUG ((LM_DEBUG,
00466                  ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ")
00467                  ACE_TEXT ("canonical host name is %s\n"),
00468                  ACE_TEXT_CHAR_TO_TCHAR (hp->h_name)));
00469 
00470    // check if the canonical name is the FQDN
00471    if (!ACE_OS::strchr(hp->h_name, '.'))
00472      {
00473        // list of address
00474        char** p;
00475        // list of aliases
00476        char** q;
00477 
00478        // for every address and for every alias within the address, check and
00479        // see if we can locate a FQDN
00480        for (p = hp->h_addr_list; *p != 0; ++p)
00481          {
00482            for (q = hp->h_aliases; *q != 0; ++q)
00483              {
00484                if (ACE_OS::strchr(*q, '.'))
00485                  {
00486                    // we got an FQDN from an alias. use this
00487                    if (ACE_OS::strlen (*q) >= len)
00488                      // the hostname is too huge to fit into a
00489                      // buffer of size MAXHOSTNAMELEN
00490                      // should we check other aliases as well
00491                      // before bailing out prematurely?
00492                      // for right now, let's do it. this (short name)
00493                      // is atleast better than embedding the IP
00494                      // address in the profile
00495                      continue;
00496 
00497                    if (ACE::debug ())
00498                      ACE_DEBUG ((LM_DEBUG,
00499                                  ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ")
00500                                  ACE_TEXT ("found fqdn within alias as %s\n"),
00501                                  ACE_TEXT_CHAR_TO_TCHAR(*q)));
00502                    ACE_OS::strcpy (hostname, *q);
00503 
00504                    return 0;
00505                  }
00506              }
00507          }
00508      }
00509 
00510    // The canonical name may be an FQDN when we reach here.
00511    // Alternatively, the canonical name (a non FQDN) may be the best
00512    // we can do.
00513    if (ACE_OS::strlen (hp->h_name) >= len)
00514      {
00515        // The hostname is too large to fit into a buffer of size
00516        // MAXHOSTNAMELEN.
00517        return -2;
00518      }
00519    else
00520      {
00521        ACE_OS::strcpy (hostname, hp->h_name);
00522      }
00523 
00524    return 0;
00525 }

ACE_HANDLE ACE::get_handle void   ) 
 

Routine to return a handle from which ioctl requests can be made. Caller must close the handle.

Definition at line 1572 of file Sock_Connect.cpp.

References ACE_OS::open(), PF_INET, SOCK_DGRAM, and ACE_OS::socket().

Referenced by get_ip_interfaces().

01573 {
01574   // Solaris 2.x
01575   ACE_HANDLE handle = ACE_INVALID_HANDLE;
01576 #if defined (sparc)
01577   handle = ACE_OS::open ("/dev/udp", O_RDONLY);
01578 #elif defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (_AIX) || defined (__hpux) || (defined (ACE_VXWORKS) && (ACE_VXWORKS >= 0x600)) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS)
01579   // Note: DEC CXX doesn't define "unix" BSD compatible OS: HP UX,
01580   // AIX, SunOS 4.x
01581 
01582   handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, 0);
01583 #endif /* sparc */
01584   return handle;
01585 }

int ACE::get_ip_interfaces size_t &  count,
ACE_INET_Addr *&  addr_array
 

Return count and array of all configured IP interfaces on this host, rc = 0 on success (count == number of interfaces else -1). Caller is responsible for calling delete [] on addr_array.

Definition at line 1220 of file Sock_Connect.cpp.

References ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_NOTSUP_RETURN, ACE_TEXT, ACE_TRACE, AF_INET, AF_UNSPEC, caddr_t, ACE_OS::close(), count_interfaces(), ACE_OS::fclose(), ACE_OS::fopen(), ACE_Auto_Basic_Array_Ptr< X >::get(), get_handle(), get_ip_interfaces_win32(), IFCONF, IFREQ, ACE_OS::ioctl(), LM_ERROR, ACE_OS::memset(), ACE_INET_Addr::set(), SIOCGIFCONF_CMD, and ACE_OS::sprintf().

Referenced by ACE_SOCK_Dgram_Mcast::subscribe_ifs(), and ACE_SOCK_Dgram_Mcast::unsubscribe_ifs().

01222 {
01223   ACE_TRACE ("ACE::get_ip_interfaces");
01224 
01225   count = 0;
01226   addrs = 0;
01227 
01228 #if defined (ACE_WIN32)
01229   return get_ip_interfaces_win32 (count, addrs);
01230 #elif defined (ACE_HAS_GETIFADDRS)
01231   return get_ip_interfaces_getifaddrs (count, addrs);
01232 #elif defined (__hpux)
01233   return get_ip_interfaces_hpux (count, addrs);
01234 #elif defined (_AIX)
01235   return get_ip_interfaces_aix (count, addrs);
01236 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x600)
01237   return get_ip_interfaces_vxworks_lt600 (count, addrs);
01238 #elif (defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (ACE_OPENVMS) || (defined (ACE_VXWORKS) && (ACE_VXWORKS == 0x650)) || defined (ACE_HAS_RTEMS)) && !defined (ACE_LACKS_NETWORKING)
01239   // COMMON (SVR4 and BSD) UNIX CODE
01240 
01241   // Call specific routine as necessary.
01242   ACE_HANDLE handle = ACE::get_handle();
01243 
01244   if (handle == ACE_INVALID_HANDLE)
01245     ACE_ERROR_RETURN ((LM_ERROR,
01246                        ACE_TEXT ("%p\n"),
01247                        ACE_TEXT ("ACE::get_ip_interfaces:open")),
01248                       -1);
01249 
01250   size_t num_ifs, num_ifs_found;
01251 
01252   if (ACE::count_interfaces (handle, num_ifs))
01253     {
01254       ACE_OS::close (handle);
01255       return -1;
01256     }
01257 
01258   // ioctl likes to have an extra ifreq structure to mark the end of
01259   // what it returned, so increase the num_ifs by one.
01260   ++num_ifs;
01261 
01262   struct IFREQ *ifs = 0;
01263   ACE_NEW_RETURN (ifs,
01264                   struct IFREQ[num_ifs],
01265                   -1);
01266   ACE_OS::memset (ifs, 0, num_ifs * sizeof (struct IFREQ));
01267 
01268   ACE_Auto_Array_Ptr<struct IFREQ> p_ifs (ifs);
01269 
01270   if (p_ifs.get() == 0)
01271     {
01272       ACE_OS::close (handle);
01273       errno = ENOMEM;
01274       return -1;
01275     }
01276 
01277   struct IFCONF ifcfg;
01278   ACE_OS::memset (&ifcfg, 0, sizeof (struct IFCONF));
01279 
01280 # ifdef SETFAMILY
01281   ifcfg.IFC_FAMILY = AF_UNSPEC;  // request all families be returned
01282   ifcfg.IFC_FLAGS = 0;
01283 # endif
01284 
01285   ifcfg.IFC_REQ = p_ifs.get ();
01286   ifcfg.IFC_LEN = num_ifs * sizeof (struct IFREQ);
01287 
01288   if (ACE_OS::ioctl (handle,
01289                      SIOCGIFCONF_CMD,
01290                      (caddr_t) &ifcfg) == -1)
01291     {
01292       ACE_OS::close (handle);
01293       ACE_ERROR_RETURN ((LM_ERROR,
01294                          ACE_TEXT ("%p\n"),
01295                          ACE_TEXT ("ACE::get_ip_interfaces:")
01296                          ACE_TEXT ("ioctl - SIOCGIFCONF failed")),
01297                         -1);
01298     }
01299 
01300   ACE_OS::close (handle);
01301 
01302   // Now create and initialize output array.
01303 
01304   ACE_NEW_RETURN (addrs,
01305                   ACE_INET_Addr[num_ifs],
01306                   -1); // caller must free
01307 
01308   struct IFREQ *pcur = p_ifs.get ();
01309   num_ifs_found = ifcfg.IFC_LEN / sizeof (struct IFREQ); // get the number of returned ifs
01310 
01311   // Pull the address out of each INET interface.  Not every interface
01312   // is for IP, so be careful to count properly.  When setting the
01313   // INET_Addr, note that the 3rd arg (0) says to leave the byte order
01314   // (already in net byte order from the interface structure) as is.
01315   count = 0;
01316 
01317   for (size_t i = 0;
01318        i < num_ifs_found;
01319        i++)
01320     {
01321       if (pcur->IFR_ADDR.SA_FAMILY == AF_INET
01322 #  if defined (ACE_HAS_IPV6)
01323           || pcur->IFR_ADDR.SA_FAMILY == AF_INET6
01324 #  endif
01325           )
01326 
01327         {
01328 # if !defined(_UNICOS)
01329           struct sockaddr_in *addr =
01330             reinterpret_cast<sockaddr_in *> (&pcur->IFR_ADDR);
01331 
01332           // Sometimes the kernel returns 0.0.0.0 as an IPv4 interface
01333           // address; skip those...
01334           if (addr->sin_addr.s_addr != 0
01335 #  if defined (ACE_HAS_IPV6)
01336               || (addr->sin_family == AF_INET6 &&
01337                   !IN6_IS_ADDR_UNSPECIFIED(&reinterpret_cast<sockaddr_in6 *>(addr)->sin6_addr))
01338 #  endif
01339               )
01340             {
01341               int addrlen = static_cast<int> (sizeof (struct sockaddr_in));
01342 #  if defined (ACE_HAS_IPV6)
01343               if (addr->sin_family == AF_INET6)
01344                 addrlen = static_cast<int> (sizeof (struct sockaddr_in6));
01345 #  endif
01346               addrs[count].set (addr, addrlen);
01347               ++count;
01348             }
01349 # else /* ! _UNICOS */
01350           // need to explicitly copy on the Cray, since the bitfields kinda
01351           // screw things up here
01352           struct sockaddr_in inAddr;
01353 
01354           inAddr.sin_len = pcur->IFR_ADDR.sa_len;
01355           inAddr.sin_family = pcur->IFR_ADDR.sa_family;
01356           memcpy((void *)&(inAddr.sin_addr),
01357                  (const void *)&(pcur->IFR_ADDR.sa_data[8]),
01358                  sizeof(struct in_addr));
01359 
01360           if (inAddr.sin_addr.s_addr != 0)
01361             {
01362               addrs[count].set(&inAddr, sizeof(struct sockaddr_in));
01363               ++count;
01364             }
01365 # endif /* ! _UNICOS */
01366         }
01367 
01368 #if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS)
01369       ++pcur;
01370 #else
01371       if (pcur->ifr_addr.sa_len <= sizeof (struct sockaddr))
01372         {
01373            ++pcur;
01374         }
01375       else
01376         {
01377            pcur = (struct ifreq *)
01378                (pcur->ifr_addr.sa_len + (caddr_t) &pcur->ifr_addr);
01379         }
01380 #endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) */
01381     }
01382 
01383 # if defined (ACE_HAS_IPV6)
01384   // Retrieve IPv6 local interfaces by scanning /proc/net/if_inet6 if
01385   // it exists.  If we cannot open it then ignore possible IPv6
01386   // interfaces, we did our best;-)
01387   FILE* fp;
01388   char addr_p[8][5];
01389   char s_ipaddr[64];
01390   int scopeid;
01391   struct addrinfo hints, *res0;
01392   int error;
01393 
01394   ACE_OS::memset (&hints, 0, sizeof (hints));
01395   hints.ai_flags = AI_NUMERICHOST;
01396   hints.ai_family = AF_INET6;
01397 
01398   if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0)
01399     {
01400       while (fscanf (fp,
01401                      "%4s%4s%4s%4s%4s%4s%4s%4s %02x %*02x %*02x %*02x %*8s\n",
01402                      addr_p[0], addr_p[1], addr_p[2], addr_p[3],
01403                      addr_p[4], addr_p[5], addr_p[6], addr_p[7], &scopeid) != EOF)
01404         {
01405           // Format the address intoa proper IPv6 decimal address specification and
01406           // resolve the resulting text using getaddrinfo().
01407 
01408           const char* ip_fmt = "%s:%s:%s:%s:%s:%s:%s:%s%%%d";
01409           ACE_OS::sprintf (s_ipaddr,
01410                            ip_fmt,
01411                            addr_p[0], addr_p[1], addr_p[2], addr_p[3],
01412                            addr_p[4], addr_p[5], addr_p[6], addr_p[7], scopeid);
01413 
01414           error = getaddrinfo (s_ipaddr, 0, &hints, &res0);
01415           if (error)
01416             continue;
01417 
01418           if (res0->ai_family == AF_INET6 &&
01419                 !IN6_IS_ADDR_UNSPECIFIED (&reinterpret_cast<sockaddr_in6 *> (res0->ai_addr)->sin6_addr))
01420             {
01421               addrs[count].set(reinterpret_cast<sockaddr_in *> (res0->ai_addr), res0->ai_addrlen);
01422               ++count;
01423             }
01424           freeaddrinfo (res0);
01425 
01426         }
01427       ACE_OS::fclose (fp);
01428     }
01429 # endif /* ACE_HAS_IPV6 */
01430 
01431   return 0;
01432 #else
01433   ACE_UNUSED_ARG (count);
01434   ACE_UNUSED_ARG (addrs);
01435   ACE_NOTSUP_RETURN (-1);                      // no implementation
01436 #endif /* ACE_WIN32 */
01437 }

int ACE::get_temp_dir ACE_TCHAR buffer,
size_t  buffer_len
 

Returns the temporary directory including the trailing slash in buffer. Returns -1 for an error or if the buffer_len is not long enough.

Definition at line 593 of file Lib_Find.cpp.

References ACE_TCHAR, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, ACE_TEXT_GetTempPath, ACE_OS::getenv(), ACE_OS::strcpy(), and ACE_OS::strlen().

Referenced by ACE_MEM_Acceptor::accept(), ACE_MMAP_Memory_Pool::ACE_MMAP_Memory_Pool(), ACE_Name_Options::ACE_Name_Options(), ACE_System_Time::ACE_System_Time(), and ACE_FILE_Addr::set().

00594 {
00595   int result;
00596 #if defined (ACE_WIN32)
00597   result = ACE_TEXT_GetTempPath (static_cast<DWORD> (buffer_len),
00598                                  buffer);
00599 
00600   // Make sure to return -1 if there is an error
00601   if (result == 0 && ::GetLastError () != ERROR_SUCCESS
00602       || result > static_cast<int> (buffer_len))
00603     result = -1;
00604 
00605 #else /* ACE_WIN32 */
00606 
00607   // NOTE! Non-Windows platforms don't deal with wide chars for env.
00608   // variables, so do this narrow-char and convert to wide for the
00609   // caller if necessary.
00610 
00611   // On non-win32 platforms, check to see what the TMPDIR environment
00612   // variable is defined to be.  If it doesn't exist, just use /tmp
00613   const char *tmpdir = ACE_OS::getenv ("TMPDIR");
00614 
00615   if (tmpdir == 0)
00616     tmpdir = "/tmp";
00617 
00618   size_t len = ACE_OS::strlen (tmpdir);
00619 
00620   // Check to see if the buffer is large enough for the string,
00621   // another /, and its null character (hence the + 2)
00622   if ((len + 2) > buffer_len)
00623     {
00624       result = -1;
00625     }
00626   else
00627     {
00628       ACE_OS::strcpy (buffer, ACE_TEXT_CHAR_TO_TCHAR (tmpdir));
00629 
00630       // Add a trailing slash because we cannot assume there is already one
00631       // at the end.  And having an extra one should not cause problems.
00632       buffer[len] = ACE_TEXT ('/');
00633       buffer[len + 1] = 0;
00634       result = 0;
00635     }
00636 #endif /* ACE_WIN32 */
00637   return result;
00638 }

ACE_INLINE int ACE::handle_exception_ready ACE_HANDLE  handle,
const ACE_Time_Value timeout
 

Timed wait for handle to get exception ready.

Definition at line 263 of file ACE.inl.

References handle_ready().

00265 {
00266   return ACE::handle_ready (handle,
00267                             timeout,
00268                             0,
00269                             0,
00270                             1);
00271 }

ACE_INLINE int ACE::handle_read_ready ACE_HANDLE  handle,
const ACE_Time_Value timeout
 

Timed wait for handle to get read ready.

Definition at line 241 of file ACE.inl.

References handle_ready().

Referenced by enter_recv_timedwait(), recv_n_i(), recvv_n_i(), and t_rcv_n_i().

00243 {
00244   return ACE::handle_ready (handle,
00245                             timeout,
00246                             1,
00247                             0,
00248                             0);
00249 }

int ACE::handle_ready ACE_HANDLE  handle,
const ACE_Time_Value timeout,
int  read_ready,
int  write_ready,
int  exception_ready
 

Timed wait for handle to get read, write, or exception ready.

Definition at line 2176 of file ACE.cpp.

References ETIME, ACE_Handle_Set::fdset(), ACE_OS::poll(), ACE_OS::select(), and ACE_Handle_Set::set_bit().

Referenced by handle_exception_ready(), handle_read_ready(), and handle_write_ready().

02181 {
02182 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02183   ACE_UNUSED_ARG (write_ready);
02184   ACE_UNUSED_ARG (exception_ready);
02185 
02186   struct pollfd fds;
02187 
02188   fds.fd = handle;
02189   fds.events = read_ready ? POLLIN : POLLOUT;
02190   fds.revents = 0;
02191 
02192   int result = ACE_OS::poll (&fds, 1, timeout);
02193 #else
02194   ACE_Handle_Set handle_set;
02195   handle_set.set_bit (handle);
02196 
02197   // Wait for data or for the timeout to elapse.
02198   int select_width;
02199 #  if defined (ACE_WIN32)
02200   // This arg is ignored on Windows and causes pointer truncation
02201   // warnings on 64-bit compiles.
02202   select_width = 0;
02203 #  else
02204   select_width = int (handle) + 1;
02205 #  endif /* ACE_WIN64 */
02206   int result = ACE_OS::select (select_width,
02207                                read_ready ? handle_set.fdset () : 0, // read_fds.
02208                                write_ready ? handle_set.fdset () : 0, // write_fds.
02209                                exception_ready ? handle_set.fdset () : 0, // exception_fds.
02210                                timeout);
02211 
02212 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02213 
02214   switch (result)
02215     {
02216     case 0:  // Timer expired.
02217       errno = ETIME;
02218       /* FALLTHRU */
02219     case -1: // we got here directly - select() returned -1.
02220       return -1;
02221     case 1: // Handle has data.
02222       /* FALLTHRU */
02223     default: // default is case result > 0; return a
02224       // ACE_ASSERT (result == 1);
02225       return result;
02226     }
02227 }

int ACE::handle_timed_accept ACE_HANDLE  listener,
ACE_Time_Value timeout,
int  restart
 

Wait up to timeout amount of time to passively establish a connection. This method doesn't perform the accept, it just does the timed wait.

Definition at line 2665 of file ACE.cpp.

References ACE_TRACE, ETIMEDOUT, EWOULDBLOCK, ACE_OS::poll(), ACE_Time_Value::sec(), ACE_OS::select(), ACE_Handle_Set::set_bit(), and ACE_Time_Value::usec().

Referenced by ACE_TLI_Acceptor::accept(), ACE_SPIPE_Acceptor::accept(), ACE_SOCK_SEQPACK_Acceptor::shared_accept_start(), and ACE_SOCK_Acceptor::shared_accept_start().

02668 {
02669   ACE_TRACE ("ACE::handle_timed_accept");
02670   // Make sure we don't bomb out on erroneous values.
02671   if (listener == ACE_INVALID_HANDLE)
02672     return -1;
02673 
02674 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02675 
02676   struct pollfd fds;
02677 
02678   fds.fd = listener;
02679   fds.events = POLLIN;
02680   fds.revents = 0;
02681 
02682 #else
02683   // Use the select() implementation rather than poll().
02684   ACE_Handle_Set rd_handle;
02685   rd_handle.set_bit (listener);
02686 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02687 
02688   // We need a loop here if <restart> is enabled.
02689 
02690   for (;;)
02691     {
02692 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02693 
02694       int n = ACE_OS::poll (&fds, 1, timeout);
02695 
02696 #else
02697       int select_width;
02698 #  if defined (ACE_WIN32)
02699       // This arg is ignored on Windows and causes pointer truncation
02700       // warnings on 64-bit compiles.
02701       select_width = 0;
02702 #  else
02703       select_width = int (listener) + 1;
02704 #  endif /* ACE_WIN32 */
02705       int n = ACE_OS::select (select_width,
02706                               rd_handle, 0, 0,
02707                               timeout);
02708 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02709 
02710       switch (n)
02711         {
02712         case -1:
02713           if (errno == EINTR && restart)
02714             continue;
02715           else
02716             return -1;
02717           /* NOTREACHED */
02718         case 0:
02719           if (timeout != 0
02720               && timeout->sec () == 0
02721               && timeout->usec () == 0)
02722             errno = EWOULDBLOCK;
02723           else
02724             errno = ETIMEDOUT;
02725           return -1;
02726           /* NOTREACHED */
02727         case 1:
02728           return 0;
02729           /* NOTREACHED */
02730         default:
02731           errno = EINVAL;
02732           return -1;
02733           /* NOTREACHED */
02734         }
02735     }
02736 }

ACE_HANDLE ACE::handle_timed_complete ACE_HANDLE  listener,
const ACE_Time_Value timeout,
int  is_tli = 0
 

Wait up to timeout amount of time to complete an actively established non-blocking connection. If is_tli is non-0 then we are being called by a TLI wrapper (which behaves slightly differently from a socket wrapper).

Definition at line 2507 of file ACE.cpp.

References ACE_TRACE, ECONNREFUSED, ETIME, EWOULDBLOCK, ACE_OS::getsockopt(), ACE_Handle_Set::is_set(), MSG_PEEK, ACE_OS::poll(), recv(), ACE_OS::select(), ACE_Handle_Set::set_bit(), SO_ERROR, and SOL_SOCKET.

Referenced by ACE_TLI_Connector::complete(), ACE_SOCK_SEQPACK_Connector::complete(), ACE_SOCK_Connector::complete(), and ACE_SOCK_Connector::shared_connect_finish().

02510 {
02511   ACE_TRACE ("ACE::handle_timed_complete");
02512 
02513 #if !defined (ACE_WIN32) && defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02514 
02515   struct pollfd fds;
02516 
02517   fds.fd = h;
02518   fds.events = POLLIN | POLLOUT;
02519   fds.revents = 0;
02520 
02521 #else
02522   ACE_Handle_Set rd_handles;
02523   ACE_Handle_Set wr_handles;
02524 
02525   rd_handles.set_bit (h);
02526   wr_handles.set_bit (h);
02527 #endif /* !ACE_WIN32 && ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02528 
02529 #if defined (ACE_WIN32)
02530   // Winsock is different - it sets the exception bit for failed connect,
02531   // unlike other platforms, where the read bit is set.
02532   ACE_Handle_Set ex_handles;
02533   ex_handles.set_bit (h);
02534 #endif /* ACE_WIN32 */
02535 
02536   bool need_to_check = false;
02537   bool known_failure = false;
02538 
02539 #if defined (ACE_WIN32)
02540   int n = ACE_OS::select (0,    // Ignored on Windows: int (h) + 1,
02541                           0,
02542                           wr_handles,
02543                           ex_handles,
02544                           timeout);
02545 #else
02546 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02547 
02548   int n = ACE_OS::poll (&fds, 1, timeout);
02549 
02550 # else
02551   int n = ACE_OS::select (int (h) + 1,
02552                           rd_handles,
02553                           wr_handles,
02554                           0,
02555                           timeout);
02556 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02557 #endif /* ACE_WIN32 */
02558 
02559   // If we failed to connect within the time period allocated by the
02560   // caller, then we fail (e.g., the remote host might have been too
02561   // busy to accept our call).
02562   if (n <= 0)
02563     {
02564       if (n == 0 && timeout != 0)
02565         errno = ETIME;
02566       return ACE_INVALID_HANDLE;
02567     }
02568 
02569   // Usually, a ready-for-write handle is successfully connected, and
02570   // ready-for-read (exception on Win32) is a failure. On fails, we
02571   // need to grab the error code via getsockopt. On possible success for
02572   // any platform where we can't tell just from select() (e.g. AIX),
02573   // we also need to check for success/fail.
02574 #if defined (ACE_WIN32)
02575   ACE_UNUSED_ARG (is_tli);
02576 
02577   // On Win32, ex_handle set indicates a failure. We'll do the check
02578   // to try and get an errno value, but the connect failed regardless of
02579   // what getsockopt says about the error.
02580   if (ex_handles.is_set (h))
02581     {
02582       need_to_check = true;
02583       known_failure = true;
02584     }
02585 #elif defined (ACE_VXWORKS)
02586   ACE_UNUSED_ARG (is_tli);
02587 
02588   // Force the check on VxWorks.  The read handle for "h" is not set,
02589   // so "need_to_check" is false at this point.  The write handle is
02590   // set, for what it's worth.
02591   need_to_check = true;
02592 #else
02593   if (is_tli)
02594 
02595 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02596     need_to_check = (fds.revents & POLLIN) && !(fds.revents & POLLOUT);
02597 # else
02598   need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h);
02599 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02600 
02601   else
02602 #if defined(AIX)
02603     // AIX is broken... both success and failed connect will set the
02604     // write handle only, so always check.
02605     need_to_check = true;
02606 #else
02607 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02608   need_to_check = (fds.revents & POLLIN);
02609 # else
02610   need_to_check = rd_handles.is_set (h);
02611 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02612 #endif /* AIX */
02613 #endif /* ACE_WIN32 */
02614 
02615   if (need_to_check)
02616     {
02617 #if defined (SOL_SOCKET) && defined (SO_ERROR)
02618       int sock_err = 0;
02619       int sock_err_len = sizeof (sock_err);
02620       int sockopt_ret = ACE_OS::getsockopt (h, SOL_SOCKET, SO_ERROR,
02621                                             (char *)&sock_err, &sock_err_len);
02622       if (sockopt_ret < 0)
02623         {
02624           h = ACE_INVALID_HANDLE;
02625         }
02626 
02627       if (sock_err != 0 || known_failure)
02628         {
02629           h = ACE_INVALID_HANDLE;
02630           errno = sock_err;
02631         }
02632 #else
02633       char dummy;
02634 
02635       // The following recv() won't block provided that the
02636       // ACE_NONBLOCK flag has not been turned off .
02637       n = ACE::recv (h, &dummy, 1, MSG_PEEK);
02638 
02639       // If no data was read/peeked at, check to see if it's because
02640       // of a non-connected socket (and therefore an error) or there's
02641       // just no data yet.
02642       if (n <= 0)
02643         {
02644           if (n == 0)
02645             {
02646               errno = ECONNREFUSED;
02647               h = ACE_INVALID_HANDLE;
02648             }
02649           else if (errno != EWOULDBLOCK && errno != EAGAIN)
02650             h = ACE_INVALID_HANDLE;
02651         }
02652 #endif
02653     }
02654 
02655   // 1. The HANDLE is ready for writing and doesn't need to be checked or
02656   // 2. recv() returned an indication of the state of the socket - if there is
02657   // either data present, or a recv is legit but there's no data yet,
02658   // the connection was successfully established.
02659   return h;
02660 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_HANDLE ACE::handle_timed_open ACE_Time_Value timeout,
const ACE_TCHAR name,
int  flags,
int  perms,
LPSECURITY_ATTRIBUTES  sa = 0
 

Wait up to timeout> amount of time to actively open a device. This method doesn't perform the connect, it just does the timed wait.

Definition at line 17 of file Handle_Ops.cpp.

References ACE_NONBLOCK, ACE_TCHAR, ACE_TRACE, ETIMEDOUT, EWOULDBLOCK, ACE_OS::open(), ACE_Time_Value::sec(), and ACE_Time_Value::usec().

Referenced by ACE_UPIPE_Connector::connect(), ACE_SPIPE_Connector::connect(), ACE_FILE_Connector::connect(), and ACE_DEV_Connector::connect().

00022 {
00023   ACE_TRACE ("ACE::handle_timed_open");
00024 
00025   if (timeout != 0)
00026     {
00027 #if !defined (ACE_WIN32)
00028       // On Win32, ACE_NONBLOCK gets recognized as O_WRONLY so we
00029       // don't use it there
00030       flags |= ACE_NONBLOCK;
00031 #endif /* ACE_WIN32 */
00032 
00033       // Open the named pipe or file using non-blocking mode...
00034       ACE_HANDLE const handle = ACE_OS::open (name, flags, perms, sa);
00035 
00036       if (handle == ACE_INVALID_HANDLE
00037           && (errno == EWOULDBLOCK
00038               && (timeout->sec () > 0 || timeout->usec () > 0)))
00039         // This expression checks if we were polling.
00040         errno = ETIMEDOUT;
00041 
00042       return handle;
00043     }
00044   else
00045     return ACE_OS::open (name, flags, perms, sa);
00046 }

ACE_INLINE int ACE::handle_write_ready ACE_HANDLE  handle,
const ACE_Time_Value timeout
 

Timed wait for handle to get write ready.

Definition at line 252 of file ACE.inl.

References handle_ready().

Referenced by enter_send_timedwait(), send_n_i(), sendv_n_i(), and t_snd_n_i().

00254 {
00255   return ACE::handle_ready (handle,
00256                             timeout,
00257                             0,
00258                             1,
00259                             0);
00260 }

u_long ACE::hash_pjw const wchar_t *  str,
size_t  len
 

Computes the hash value of {str} using the "Hash PJW" routine.

Definition at line 347 of file ACE.cpp.

00348 {
00349   u_long hash = 0;
00350 
00351   for (size_t i = 0; i < len; i++)
00352     {
00353       // @@ UNICODE: Does this function do the correct thing with wchar's?
00354 
00355       const wchar_t temp = str[i];
00356       hash = (hash << 4) + (temp * 13);
00357 
00358       u_long g = hash & 0xf0000000;
00359 
00360       if (g)
00361         {
00362           hash ^= (g >> 24);
00363           hash ^= g;
00364         }
00365     }
00366 
00367   return hash;
00368 }

u_long ACE::hash_pjw const wchar_t *  str  ) 
 

Computes the hash value of {str} using the "Hash PJW" routine.

Definition at line 371 of file ACE.cpp.

References hash_pjw().

00372 {
00373   return ACE::hash_pjw (str, ACE_OS::strlen (str));
00374 }

u_long ACE::hash_pjw const char *  str,
size_t  len
 

Computes the hash value of {str} using the "Hash PJW" routine.

Definition at line 318 of file ACE.cpp.

00319 {
00320   u_long hash = 0;
00321 
00322   for (size_t i = 0; i < len; i++)
00323     {
00324       const char temp = str[i];
00325       hash = (hash << 4) + (temp * 13);
00326 
00327       u_long g = hash & 0xf0000000;
00328 
00329       if (g)
00330         {
00331           hash ^= (g >> 24);
00332           hash ^= g;
00333         }
00334     }
00335 
00336   return hash;
00337 }

u_long ACE::hash_pjw const char *  str  ) 
 

Computes the hash value of {str} using the "Hash PJW" routine.

Definition at line 340 of file ACE.cpp.

Referenced by ACE_Filecache::create(), ACE_Filecache::fetch(), ACE_Filecache::finish(), ACE_UNIX_Addr::hash(), ACE_String_Base< CHAR >::hash(), ACE_SString::hash(), hash_pjw(), ACE_Hash< wchar_t * >::operator()(), ACE_Hash< const wchar_t * >::operator()(), ACE_Hash< char * >::operator()(), ACE_Hash< const char * >::operator()(), and ACE_Filecache::remove().

00341 {
00342   return ACE::hash_pjw (str, ACE_OS::strlen (str));
00343 }

ACE_INLINE u_char ACE::hex2byte ACE_TCHAR  c  ) 
 

Convert a hex character to its byte representation.

Definition at line 339 of file ACE.inl.

References ACE_OS::ace_isdigit(), ACE_OS::ace_islower(), ACE_TCHAR, and ACE_TEXT.

00340 {
00341   if (ACE_OS::ace_isdigit (c))
00342     return (u_char) (c - ACE_TEXT ('0'));
00343   else if (ACE_OS::ace_islower (c))
00344     return (u_char) (10 + c - ACE_TEXT ('a'));
00345   else
00346     return (u_char) (10 + c - ACE_TEXT ('A'));
00347 }

int ACE::init void   ) 
 

This class implements the functions for the initialization and shutting down ACE. These functions are called only once per ACE invokation.

Returns:
Returns 0 on success, -1 on failure, and 1 if it had already been called.

Definition at line 15 of file Init_ACE.cpp.

References ACE_Object_Manager::init(), and ACE_Object_Manager::instance().

00016 {
00017   // Don't use ACE_TRACE, because Object_Manager might not have been
00018   // instantiated yet.
00019   // ACE_TRACE ("ACE::init");
00020 
00021   ++ACE::init_fini_count_;
00022 
00023   return ACE_Object_Manager::instance ()->init ();
00024 }

bool ACE::ipv4_enabled void   ) 
 

This is an execution-time check. If ACE has not been compiled with ACE_HAS_IPV6, it always returns true. This function tries to create a PF_INET socket, returning true if it succeeds, and false if it fails. Caches the result so it only gets checked once.

Definition at line 1617 of file Sock_Connect.cpp.

References ace_ipv4_enabled, and PF_INET.

01618 {
01619 #if defined (ACE_HAS_IPV6)
01620   return static_cast<bool> (ace_ipv4_enabled == -1 ?
01621                             ::ip_check (ace_ipv4_enabled, PF_INET) :
01622                             ace_ipv4_enabled);
01623 #else
01624  // Assume it's always enabled since ACE requires some version of
01625  // TCP/IP to exist.
01626   return true;
01627 #endif  /* ACE_HAS_IPV6*/
01628 }

int ACE::ipv6_enabled void   ) 
 

Returns 1 if IPv6 is enabled on the current host; 0 if not. This is an execution-time check. If ACE has not been compiled with ACE_HAS_IPV6, it always returns 0. If ACE_HAS_IPV6 is enabled, this function tries to create a PF_INET6 socket, returning 1 if it succeeds, and 0 if it fails. Caches the result so it only gets checked once.

Definition at line 1631 of file Sock_Connect.cpp.

References ace_ipv6_enabled.

Referenced by ACE_INET_Addr::determine_type(), ACE_SOCK_SEQPACK_Acceptor::open(), ACE_SOCK_Dgram::open(), ACE_SOCK_Acceptor::open(), and ACE_INET_Addr::set().

01632 {
01633 #if defined (ACE_HAS_IPV6)
01634   return ace_ipv6_enabled == -1 ?
01635     ::ip_check (ace_ipv6_enabled, PF_INET6) :
01636     ace_ipv6_enabled;
01637 #else /* ACE_HAS_IPV6 */
01638   return 0;
01639 #endif /* !ACE_HAS_IPV6 */
01640 }

u_long ACE::is_prime const u_long  n,
const u_long  min_factor,
const u_long  max_factor
 

Function that can burn up noticeable CPU time: brute-force determination of whether number n is prime. Returns 0 if it is prime, or the smallest factor if it is not prime. min_factor and max_factor can be used to partition the work among threads. For just one thread, typical values are 2 and n/2.

Definition at line 2991 of file ACE.cpp.

02994 {
02995   if (n > 3)
02996     for (u_long factor = min_factor;
02997          factor <= max_factor;
02998          ++factor)
02999       if (n / factor * factor == n)
03000         return factor;
03001 
03002   return 0;
03003 }

bool ACE::is_sock_error int  error  ) 
 

Determins whether the given error code corresponds to to a WinSock error. If so returns true, false otherwise.

For internal use only.

Definition at line 3158 of file ACE.cpp.

Referenced by ACE_OS::strerror().

03159 {
03160 #if defined (ACE_WIN32)
03161   switch (error)
03162     {
03163     case WSAVERNOTSUPPORTED:
03164     case WSASYSNOTREADY:
03165     case WSAEINVAL:
03166     case WSAHOST_NOT_FOUND:
03167     case WSATRY_AGAIN:
03168     case WSANO_RECOVERY:
03169     case WSANO_DATA:
03170       /*
03171         case WSANO_ADDRESS:
03172       */
03173     case WSANOTINITIALISED:
03174     case WSAENETDOWN:
03175     case WSAEINPROGRESS:
03176     case WSAEINTR:
03177     case WSAEAFNOSUPPORT:
03178     case WSAEMFILE:
03179     case WSAENOBUFS:
03180     case WSAEPROTONOSUPPORT:
03181     case WSAEPROTOTYPE:
03182     case WSAESOCKTNOSUPPORT:
03183     case WSAENOTSOCK:
03184     case WSAEWOULDBLOCK:
03185     case WSAEADDRINUSE:
03186     case WSAECONNABORTED:
03187     case WSAECONNRESET:
03188     case WSAENOTCONN:
03189     case WSAETIMEDOUT:
03190     case WSAECONNREFUSED:
03191     case WSAEHOSTDOWN:
03192     case WSAEHOSTUNREACH:
03193     case WSAEADDRNOTAVAIL:
03194     case WSAEISCONN:
03195     case WSAENETRESET:
03196     case WSAEMSGSIZE:
03197     case WSAENETUNREACH:
03198     case WSAEFAULT:
03199     case WSAEDISCON:
03200     case WSAEACCES:
03201     case WSAESHUTDOWN:
03202     case WSAEPROCLIM:
03203     case WSAEALREADY:
03204     case WSAEPFNOSUPPORT:
03205     case WSAENOPROTOOPT:
03206     case WSATYPE_NOT_FOUND:
03207     case WSAEOPNOTSUPP:
03208       return true;
03209     }
03210 #else
03211   ACE_UNUSED_ARG (error);
03212 #endif /* ACE_WIN32 */
03213   return false;
03214 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL int ACE::ldfind const ACE_TCHAR filename,
ACE_TCHAR  pathname[],
size_t  maxpathnamelen
 

Finds the file filename either using an absolute path or using a relative path in conjunction with ACE_LD_SEARCH_PATH (e.g., $LD_LIBRARY_PATH on UNIX or the directories scaned by Win32 API SearchPath on Win32). This function will add appropriate suffix (e.g., .dll on Win32 or .so on UNIX) according to the OS platform. In addition, this function will apply the appropriate prefix (e.g., "lib" on UNIX and "" on Win32) if the filename doesn't match directly.

Definition at line 121 of file Lib_Find.cpp.

References ACE_OS::access(), ACE_DIRECTORY_SEPARATOR_CHAR, ACE_DLL_PREFIX, ACE_DLL_SUFFIX, ACE_ERROR, ACE_LD_SEARCH_PATH, ACE_LD_SEARCH_PATH_SEPARATOR_STR, ACE_TCHAR, ACE_TEXT, ACE_TEXT_ALWAYS_CHAR, ACE_TEXT_ExpandEnvironmentStrings, ACE_TEXT_SearchPath, ACE_TRACE, F_OK, ACE_OS::free(), ACE_OS::getenv(), LM_WARNING, ACE_OS::malloc(), MAXPATHLEN, ACE_OS::sprintf(), ACE_OS::strcasecmp(), ACE_OS::strcat(), ACE_OS::strcmp(), ACE_OS::strcpy(), ACE_OS::strdup(), ACE_OS::strlen(), ACE_OS::strrchr(), strrepl(), and strsplit_r().

Referenced by ldopen(), and ACE_DLL_Handle::open().

00124 {
00125   ACE_TRACE ("ACE::ldfind");
00126 #if defined (ACE_OPENVMS)
00127   if (ACE_OS::strlen(filename) >= maxpathnamelen)
00128   {
00129     errno = ENOMEM;
00130     return -1;
00131   }
00132 
00133   dsc$descriptor nameDsc;
00134   nameDsc.dsc$b_class = DSC$K_CLASS_S;
00135   nameDsc.dsc$b_dtype = DSC$K_DTYPE_T;
00136   nameDsc.dsc$w_length = ACE_OS::strlen(filename);
00137   nameDsc.dsc$a_pointer = (char*)filename;
00138 
00139   char symbol[] = "NULL";
00140   dsc$descriptor symbolDsc;
00141   symbolDsc.dsc$b_class = DSC$K_CLASS_S;
00142   symbolDsc.dsc$b_dtype = DSC$K_DTYPE_T;
00143   symbolDsc.dsc$w_length = ACE_OS::strlen(symbol);
00144   symbolDsc.dsc$a_pointer = symbol;
00145 
00146   int symbolValue;
00147   int result;
00148   try
00149   {
00150     result = LIB$FIND_IMAGE_SYMBOL(&nameDsc, &symbolDsc, &symbolValue, 0, 0);
00151   }
00152   catch (chf$signal_array& sig)
00153   {
00154     result = sig.chf$l_sig_name;
00155   }
00156 
00157   int severity = result & STS$M_SEVERITY;
00158   int conditionId = result & STS$M_COND_ID;
00159   if (severity == STS$K_SUCCESS || severity == STS$K_WARNING || severity == STS$K_INFO ||
00160       (severity == STS$K_ERROR && conditionId == (LIB$_KEYNOTFOU & STS$M_COND_ID)))
00161   {
00162     ACE_OS::strcpy(pathname, filename);
00163     return 0;
00164   }
00165 
00166   if (ACE_OS::strlen(filename) + ACE_OS::strlen(ACE_DLL_PREFIX) >= maxpathnamelen)
00167   {
00168     errno = ENOMEM;
00169     return -1;
00170   }
00171 
00172 
00173   ACE_OS::strcpy(pathname, ACE_DLL_PREFIX);
00174   ACE_OS::strcat(pathname, filename);
00175   nameDsc.dsc$w_length = ACE_OS::strlen(pathname);
00176   nameDsc.dsc$a_pointer = pathname;
00177   try
00178   {
00179     result = LIB$FIND_IMAGE_SYMBOL(&nameDsc, &symbolDsc, &symbolValue, 0, 0);
00180   }
00181   catch (chf$signal_array& sig)
00182   {
00183     result = sig.chf$l_sig_name;
00184   }
00185 
00186   severity = result & STS$M_SEVERITY;
00187   conditionId = result & STS$M_COND_ID;
00188   if (severity == STS$K_SUCCESS || severity == STS$K_WARNING || severity == STS$K_INFO ||
00189       (severity == STS$K_ERROR && conditionId == (LIB$_KEYNOTFOU & STS$M_COND_ID)))
00190   {
00191     return 0;
00192   }
00193   errno = ENOENT;
00194   return -1;
00195 #endif /* ACE_OPENVMS */
00196 
00197 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && \
00198     !defined (ACE_HAS_PHARLAP)
00199   ACE_TCHAR expanded_filename[MAXPATHLEN];
00200   if (ACE_TEXT_ExpandEnvironmentStrings (filename,
00201                                          expanded_filename,
00202                                          sizeof expanded_filename
00203                                          / sizeof (ACE_TCHAR)))
00204     filename = expanded_filename;
00205 #endif /* ACE_WIN32 && !ACE_HAS_WINCE && !ACE_HAS_PHARLAP */
00206 
00207   ACE_TCHAR tempcopy[MAXPATHLEN + 1];
00208   ACE_TCHAR searchpathname[MAXPATHLEN + 1];
00209 #if defined (ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
00210   ACE_TCHAR decorator[] = ACE_LD_DECORATOR_STR;
00211   ACE_TCHAR searchfilename[MAXPATHLEN + sizeof(decorator) / sizeof (ACE_TCHAR)];
00212 #else
00213   ACE_TCHAR searchfilename[MAXPATHLEN + 1];
00214 #endif /* ACE_WIN32 && ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */
00215 
00216   // Create a copy of filename to work with.
00217   if (ACE_OS::strlen (filename) + 1
00218       > (sizeof tempcopy / sizeof (ACE_TCHAR)))
00219     {
00220       errno = ENOMEM;
00221       return -1;
00222     }
00223   else
00224     ACE_OS::strcpy (tempcopy, filename);
00225 
00226   // Insert canonical directory separators.
00227   ACE_TCHAR *separator_ptr;
00228 
00229 #if (ACE_DIRECTORY_SEPARATOR_CHAR != '/')
00230   // Make all the directory separators "canonical" to simplify
00231   // subsequent code.
00232   ACE::strrepl (tempcopy, ACE_DIRECTORY_SEPARATOR_CHAR, '/');
00233 #endif /* ACE_DIRECTORY_SEPARATOR_CHAR */
00234 
00235   // Separate filename from pathname.
00236   separator_ptr = ACE_OS::strrchr (tempcopy, '/');
00237 
00238   // This is a relative path.
00239   if (separator_ptr == 0)
00240     {
00241       searchpathname[0] = '\0';
00242       ACE_OS::strcpy (searchfilename, tempcopy);
00243     }
00244   else // This is an absolute path.
00245     {
00246       ACE_OS::strcpy (searchfilename, separator_ptr + 1);
00247       separator_ptr[1] = '\0';
00248       ACE_OS::strcpy (searchpathname, tempcopy);
00249     }
00250 
00251   bool has_suffix = false;
00252 
00253   // Check to see if this has an appropriate DLL suffix for the OS
00254   // platform.
00255   ACE_TCHAR *s = ACE_OS::strrchr (searchfilename, '.');
00256 
00257   const ACE_TCHAR *dll_suffix = ACE_DLL_SUFFIX;
00258 
00259   if (s != 0)
00260     {
00261       // If we have a dot, we have a suffix
00262       has_suffix = true;
00263 
00264       // Check whether this matches the appropriate platform-specific
00265       // suffix.
00266 #if defined (ACE_WIN32)
00267       // Use <ACE_OS::strcasecmp> on any platform with
00268       // case-insensitive filenames.
00269       if (ACE_OS::strcasecmp (s, dll_suffix) != 0)
00270 #else
00271       if (ACE_OS::strcmp (s, dll_suffix) != 0)
00272 #endif /* ACE_WIN32 */
00273         {
00274           ACE_ERROR ((LM_WARNING,
00275                       ACE_TEXT ("Warning: improper suffix for a ")
00276                       ACE_TEXT ("shared library on this platform: %s\n"),
00277                       s));
00278         }
00279     }
00280 
00281   // Make sure we've got enough space in searchfilename.
00282   if (ACE_OS::strlen (searchfilename)
00283       + ACE_OS::strlen (ACE_DLL_PREFIX)
00284       + (has_suffix ? 0 : ACE_OS::strlen (dll_suffix))
00285       >= (sizeof searchfilename / sizeof (ACE_TCHAR)))
00286     {
00287       errno = ENOMEM;
00288       return -1;
00289     }
00290 
00291 #if defined (ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
00292   size_t len_searchfilename = ACE_OS::strlen (searchfilename);
00293   if (! has_suffix)
00294     ACE_OS::strcpy (searchfilename + len_searchfilename,
00295                            decorator);
00296 
00297   for (int tag = 1; tag >= 0; tag --)
00298     {
00299       if (tag == 0)
00300         searchfilename [len_searchfilename] = 0;
00301 
00302 #endif /* ACE_WIN32 && ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */
00303       // Use absolute pathname if there is one.
00304       if (ACE_OS::strlen (searchpathname) > 0)
00305         {
00306           if (ACE_OS::strlen (searchfilename)
00307               + ACE_OS::strlen (searchpathname) >= maxpathnamelen)
00308             {
00309               errno = ENOMEM;
00310               return -1;
00311             }
00312           else
00313             {
00314 #if (ACE_DIRECTORY_SEPARATOR_CHAR != '/')
00315               // Revert to native path name separators.
00316               ACE::strrepl (searchpathname,
00317                             '/',
00318                             ACE_DIRECTORY_SEPARATOR_CHAR);
00319 #endif /* ACE_DIRECTORY_SEPARATOR_CHAR */
00320               // First, try matching the filename *without* adding a
00321               // prefix.
00322               ACE_OS::sprintf (pathname,
00323                                ACE_TEXT ("%s%s%s"),
00324                                searchpathname,
00325                                searchfilename,
00326                                has_suffix ? ACE_TEXT ("") : dll_suffix);
00327               if (ACE_OS::access (pathname, F_OK) == 0)
00328                 return 0;
00329 
00330               // Second, try matching the filename *with* adding a prefix.
00331               ACE_OS::sprintf (pathname,
00332                                ACE_TEXT ("%s%s%s%s"),
00333                                searchpathname,
00334                                ACE_DLL_PREFIX,
00335                                searchfilename,
00336                                has_suffix ? ACE_TEXT ("") : dll_suffix);
00337               if (ACE_OS::access (pathname, F_OK) == 0)
00338                 return 0;
00339             }
00340         }
00341 
00342       // Use relative filenames via LD_LIBRARY_PATH or PATH (depending on
00343       // OS platform).
00344       else
00345         {
00346 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00347           ACE_TCHAR *file_component = 0;
00348           DWORD pathlen =
00349             ACE_TEXT_SearchPath (0,
00350                                  searchfilename,
00351                                  dll_suffix,
00352                                  static_cast<DWORD> (maxpathnamelen),
00353                                  pathname,
00354                                  &file_component);
00355           if (pathlen >= maxpathnamelen)
00356           {
00357               errno = ENOMEM;
00358               return -1;
00359           }
00360           else if (pathlen > 0)
00361               return 0;
00362 
00363           // In case not found we should try again with the ACE_DLL_PREFIX
00364           // prefixed
00365           ACE_OS::strcpy (searchfilename, ACE_DLL_PREFIX);
00366           ACE_OS::strcat (searchfilename, tempcopy);
00367           pathlen =
00368             ACE_TEXT_SearchPath (0,
00369                                  searchfilename,
00370                                  dll_suffix,
00371                                  static_cast<DWORD> (maxpathnamelen),
00372                                  pathname,
00373                                  &file_component);
00374           if (pathlen >= maxpathnamelen)
00375           {
00376               errno = ENOMEM;
00377               return -1;
00378           }
00379           else if (pathlen > 0)
00380               return 0;
00381 #else
00382           ACE_TCHAR *ld_path;
00383 #  if defined ACE_DEFAULT_LD_SEARCH_PATH
00384           ld_path = ACE_DEFAULT_LD_SEARCH_PATH;
00385 #  else
00386 #    if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR)
00387           ld_path = ACE_OS::getenv (ACE_LD_SEARCH_PATH);
00388 #    else
00389           // Wide-char, non-Windows only offers char * getenv. So capture
00390           // it, translate to wide-char, and continue.
00391           ACE_Ascii_To_Wide wide_ldpath
00392             (ACE_OS::getenv (ACE_TEXT_ALWAYS_CHAR (ACE_LD_SEARCH_PATH)));
00393           ld_path = wide_ldpath.wchar_rep ();
00394 #    endif /* ACE_WIN32 || !ACE_USES_WCHAR */
00395 #  endif /* ACE_DEFAULT_LD_SEARCH_PATH */
00396 
00397 #if defined (ACE_HAS_WINCE)
00398             ACE_TCHAR *ld_path_temp = 0;
00399             if (ld_path != 0)
00400               {
00401                 ld_path_temp = (ACE_TCHAR *)
00402                   ACE_OS::malloc ((ACE_OS::strlen (ld_path) + 2)
00403                                   * sizeof (ACE_TCHAR));
00404                 if (ld_path_temp != 0)
00405                   {
00406                     ACE_OS::strcpy (ld_path_temp,
00407                                     ACE_LD_SEARCH_PATH_SEPARATOR_STR);
00408 
00409                     ACE_OS::strcat (ld_path_temp, ld_path);
00410                     ld_path = ld_path_temp;
00411                   }
00412                 else
00413                   {
00414                     ACE_OS::free ((void *) ld_path_temp);
00415                     ld_path = ld_path_temp = 0;
00416                   }
00417               }
00418 #endif /* ACE_HAS_WINCE */
00419 
00420           if (ld_path != 0
00421               && (ld_path = ACE_OS::strdup (ld_path)) != 0)
00422             {
00423               // strtok has the strange behavior of not separating the
00424               // string ":/foo:/bar" into THREE tokens.  One would expect
00425               // that the first iteration the token would be an empty
00426               // string, the second iteration would be "/foo", and the
00427               // third iteration would be "/bar".  However, this is not
00428               // the case; one only gets two iterations: "/foo" followed
00429               // by "/bar".
00430 
00431               // This is especially a problem in parsing Unix paths
00432               // because it is permissible to specify 'the current
00433               // directory' as an empty entry.  So, we introduce the
00434               // following special code to cope with this:
00435 
00436               // Look at each dynamic lib directory in the search path.
00437 
00438               ACE_TCHAR *nextholder = 0;
00439               const ACE_TCHAR *path_entry =
00440                 ACE::strsplit_r (ld_path,
00441                                  ACE_LD_SEARCH_PATH_SEPARATOR_STR,
00442                                  nextholder);
00443               int result = 0;
00444 
00445               for (;;)
00446                 {
00447                   // Check if at end of search path.
00448                   if (path_entry == 0)
00449                     {
00450                       errno = ENOENT;
00451                       result = -1;
00452                       break;
00453                     }
00454                   else if (ACE_OS::strlen (path_entry)
00455                            + 1
00456                            + ACE_OS::strlen (searchfilename)
00457                            >= maxpathnamelen)
00458                     {
00459                       errno = ENOMEM;
00460                       result = -1;
00461                       break;
00462                     }
00463                   // This works around the issue where a path might have
00464                   // an empty component indicating 'current directory'.
00465                   // We need to do it here rather than anywhere else so
00466                   // that the loop condition will still work.
00467                   else if (path_entry[0] == '\0')
00468                     path_entry = ACE_TEXT (".");
00469 
00470                   // First, try matching the filename *without* adding a
00471                   // prefix.
00472                   ACE_OS::sprintf (pathname,
00473                                    ACE_TEXT ("%s%c%s%s"),
00474                                    path_entry,
00475                                    ACE_DIRECTORY_SEPARATOR_CHAR,
00476                                    searchfilename,
00477                                    has_suffix ? ACE_TEXT ("") : dll_suffix);
00478                   if (ACE_OS::access (pathname, F_OK) == 0)
00479                     break;
00480 
00481                   // Second, try matching the filename *with* adding a
00482                   // prefix.
00483                   ACE_OS::sprintf (pathname,
00484                                    ACE_TEXT ("%s%c%s%s%s"),
00485                                    path_entry,
00486                                    ACE_DIRECTORY_SEPARATOR_CHAR,
00487                                    ACE_DLL_PREFIX,
00488                                    searchfilename,
00489                                    has_suffix ? ACE_TEXT ("") : dll_suffix);
00490                   if (ACE_OS::access (pathname, F_OK) == 0)
00491                     break;
00492 
00493                   // Fetch the next item in the path
00494                   path_entry =
00495                     ACE::strsplit_r (0,
00496                                      ACE_LD_SEARCH_PATH_SEPARATOR_STR,
00497                                      nextholder);
00498                 }
00499 
00500 #if defined (ACE_HAS_WINCE)
00501               if (ld_path_temp != 0)
00502                 ACE_OS::free (ld_path_temp);
00503 #endif /* ACE_HAS_WINCE */
00504               ACE_OS::free ((void *) ld_path);
00505 #if defined (ACE_HAS_WINCE) && defined (ACE_LD_DECORATOR_STR) && \
00506             !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
00507                if (result == 0 || tag == 0)
00508 #endif /* ACE_HAS_WINCE && ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */
00509               return result;
00510             }
00511 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */
00512         }
00513 #if defined (ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
00514     }
00515 #endif /* ACE_WIN32 && ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */
00516 
00517   errno = ENOENT;
00518   return -1;
00519 }

ACE_TCHAR * ACE::ldname const ACE_TCHAR entry_point  ) 
 

Transforms entry_point into a form that can be located in a dynamic library using . For example, with Win32/Borland extern "C" functions which use the default calling convention have a '_' prepended. Always returns a buffer that has been dynamically allocated using .

Definition at line 537 of file Lib_Find.cpp.

References ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT, ACE_TRACE, ACE_OS::strcat(), ACE_OS::strcpy(), and ACE_OS::strlen().

00538 {
00539   ACE_TRACE ("ACE::ldname");
00540 
00541 #if defined(ACE_NEEDS_DL_UNDERSCORE)
00542   size_t size =
00543     1 // leading '_'
00544     + ACE_OS::strlen (entry_point)
00545     + 1;
00546 
00547   ACE_TCHAR *new_name;
00548   ACE_NEW_RETURN (new_name,
00549                   ACE_TCHAR[size],
00550                   0);
00551 
00552   ACE_OS::strcpy (new_name, ACE_TEXT ("_"));
00553   ACE_OS::strcat (new_name, entry_point);
00554 
00555   return new_name;
00556 #else /* ACE_NEEDS_DL_UNDERSCORE */
00557   size_t size =
00558     ACE_OS::strlen (entry_point)
00559     + 1;
00560 
00561   ACE_TCHAR *new_name;
00562   ACE_NEW_RETURN (new_name,
00563                   ACE_TCHAR[size],
00564                   0);
00565 
00566   ACE_OS::strcpy (new_name, entry_point);
00567   return new_name;
00568 #endif /* ACE_NEEDS_DL_UNDERSCORE */
00569 }

FILE * ACE::ldopen const ACE_TCHAR filename,
const ACE_TCHAR type
 

Uses ldfind to locate and open the appropriate filename and returns a pointer to the file, else it returns a NULL pointer. type specifies how the file should be open.

Definition at line 522 of file Lib_Find.cpp.

References ACE_TCHAR, ACE_TRACE, ACE_OS::fopen(), ldfind(), and MAXPATHLEN.

00524 {
00525   ACE_TRACE ("ACE::ldopen");
00526 
00527   ACE_TCHAR buf[MAXPATHLEN + 1];
00528   if (ACE::ldfind (filename,
00529                    buf,
00530                    sizeof (buf) /sizeof (ACE_TCHAR)) == -1)
00531     return 0;
00532   else
00533     return ACE_OS::fopen (buf, type);
00534 }

ACE_INLINE u_long ACE::log2 u_long  num  ) 
 

Computes the base 2 logarithm of {num}.

Definition at line 296 of file ACE.inl.

Referenced by ACE_Log_Record::priority(), and ACE_Log_Record::priority_name().

00297 {
00298   u_long log = 0;
00299 
00300   for (; num > 1; ++log)
00301     num >>= 1;
00302 
00303   return log;
00304 }

u_int ACE::major_version void   ) 
 

e.g., the "5" in ACE 5.1.12.

Definition at line 107 of file ACE.cpp.

References ACE_MAJOR_VERSION.

00108 {
00109   return ACE_MAJOR_VERSION;
00110 }

ACE_INLINE int ACE::map_errno int  error  ) 
 

Map troublesome win32 errno values to values that standard C strerr function understands. Thank you Microsoft.

Definition at line 325 of file ACE.inl.

Referenced by ACE_Log_Msg::log().

00326 {
00327 #if defined (ACE_WIN32)
00328   switch (error)
00329     {
00330     case WSAEWOULDBLOCK:
00331       return EAGAIN; // Same as UNIX errno EWOULDBLOCK.
00332     }
00333 #endif /* ACE_WIN32 */
00334 
00335   return error;
00336 }

int ACE::max_handles void   ) 
 

Returns the maximum number of open handles currently permitted in this process. This maximum may be extended using ACE::set_handle_limit.

Definition at line 2843 of file ACE.cpp.

References ACE_NOTSUP_RETURN, ACE_TRACE, ACE_OS::getrlimit(), and ACE_OS::sysconf().

Referenced by daemonize(), and set_handle_limit().

02844 {
02845   ACE_TRACE ("ACE::max_handles");
02846 #if defined (RLIMIT_NOFILE) && !defined (ACE_LACKS_RLIMIT)
02847   rlimit rl;
02848   int r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
02849 # if !defined (RLIM_INFINITY)
02850   if (r == 0)
02851     return rl.rlim_cur;
02852 #else
02853   if (r == 0 && rl.rlim_cur != RLIM_INFINITY)
02854     return rl.rlim_cur;
02855   // If == RLIM_INFINITY, fall through to the ACE_LACKS_RLIMIT sections
02856 # endif /* RLIM_INFINITY */
02857 #endif /* RLIMIT_NOFILE && !ACE_LACKS_RLIMIT */
02858 
02859 #if defined (_SC_OPEN_MAX)
02860   return ACE_OS::sysconf (_SC_OPEN_MAX);
02861 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x620)
02862   return maxFiles;
02863 #elif defined (FD_SETSIZE)
02864   return FD_SETSIZE;
02865 #else
02866   ACE_NOTSUP_RETURN (-1);
02867 #endif /* _SC_OPEN_MAX */
02868 }

u_long ACE::minimum_frame_size u_long  period1,
u_long  period2
 

Calculates the minimum enclosing frame size for the given values.

Definition at line 2948 of file ACE.cpp.

References gcd().

02949 {
02950   // if one of the periods is zero, treat it as though it as
02951   // uninitialized and return the other period as the frame size
02952   if (0 == period1)
02953     {
02954       return period2;
02955     }
02956   if (0 == period2)
02957     {
02958       return period1;
02959     }
02960 
02961   // if neither is zero, find the greatest common divisor of the two periods
02962   u_long greatest_common_divisor = ACE::gcd (period1, period2);
02963 
02964   // explicitly consider cases to reduce risk of possible overflow errors
02965   if (greatest_common_divisor == 1)
02966     {
02967       // periods are relative primes: just multiply them together
02968       return period1 * period2;
02969     }
02970   else if (greatest_common_divisor == period1)
02971     {
02972       // the first period divides the second: return the second
02973       return period2;
02974     }
02975   else if (greatest_common_divisor == period2)
02976     {
02977       // the second period divides the first: return the first
02978       return period1;
02979     }
02980   else
02981     {
02982       // the current frame size and the entry's effective period
02983       // have a non-trivial greatest common divisor: return the
02984       // product of factors divided by those in their gcd.
02985       return (period1 * period2) / greatest_common_divisor;
02986     }
02987 }

u_int ACE::minor_version void   ) 
 

e.g., the "1" in ACE 5.1.12.

Definition at line 113 of file ACE.cpp.

References ACE_MINOR_VERSION.

00114 {
00115   return ACE_MINOR_VERSION;
00116 }

ACE_INLINE ACE_TCHAR ACE::nibble2hex u_int  n  ) 
 

Hex conversion utility.

Definition at line 307 of file ACE.inl.

References ACE_TCHAR, and ACE_TEXT.

00308 {
00309   // Hexadecimal characters.
00310 #if defined (ACE_VXWORKS) && !defined (__DCPLUSPLUS__)
00311   // temporary solution to prevent Windriver GNU toolchains from spewing
00312   // loads of warnings when inlining.
00313   // problem (incorrect warning leftover from older GNU) has been reported as
00314   // TSR to Windriver.
00315   const ACE_TCHAR hex_chars[] = ACE_TEXT ("0123456789abcdef");
00316 #else
00317   static const ACE_TCHAR hex_chars[] = ACE_TEXT ("0123456789abcdef");
00318 #endif
00319 
00320   // Yes, this works for UNICODE
00321   return hex_chars[n & 0x0f];
00322 }

ACE_HANDLE ACE::open_temp_file const ACE_TCHAR name,
int  mode,
int  perm = 0
 

Opening the temp file. File is automagically unlinked when it is closed. This is useful for have temp files.

Definition at line 641 of file Lib_Find.cpp.

References ACE_TCHAR, ACE_OS::open(), and ACE_OS::unlink().

00642 {
00643 #if defined (ACE_WIN32)
00644   ACE_UNUSED_ARG (perm);
00645   ACE_HANDLE handle = ACE_OS::open (name,
00646                                     mode,
00647                                     FILE_SHARE_READ
00648                                     | FILE_SHARE_WRITE
00649                                     | FILE_SHARE_DELETE);
00650 #else
00651   // Open it.
00652   ACE_HANDLE handle = ACE_OS::open (name, mode, perm);
00653 #endif /* ACE_WIN32 */
00654 
00655   if (handle == ACE_INVALID_HANDLE)
00656     return ACE_INVALID_HANDLE;
00657 
00658   // Unlink it so that the file will be removed automatically when the
00659   // process goes away.
00660   if (ACE_OS::unlink (name) == -1)
00661     return ACE_INVALID_HANDLE;
00662   else
00663     // Return the handle.
00664     return handle;
00665 }

int ACE::out_of_handles int  error  ) 
 

Check if error indicates the process being out of handles (file descriptors).

Definition at line 65 of file ACE.cpp.

References EADDRNOTAVAIL, ENFILE, ENOBUFS, ENOSYS, ENOTSUP, and EOPNOTSUPP.

Referenced by ACE_Handle_Gobbler::consume_handles().

00066 {
00067   // EMFILE is common to all platforms.
00068   if (error == EMFILE ||
00069 #if defined (ACE_WIN32)
00070       // On Win32, we need to check for ENOBUFS also.
00071       error == ENOBUFS ||
00072 #elif defined (HPUX)
00073       // On HPUX, we need to check for EADDRNOTAVAIL also.
00074       error == EADDRNOTAVAIL ||
00075 #elif defined (linux)
00076       // On linux, we need to check for ENOENT also.
00077       error == ENOENT ||
00078       // For RedHat5.2, need to check for EINVAL too.
00079       error == EINVAL ||
00080       // Without threads check for EOPNOTSUPP
00081       error == EOPNOTSUPP ||
00082 #elif defined (sun)
00083       // On sun, we need to check for ENOSR also.
00084       error == ENOSR ||
00085       // Without threads check for ENOTSUP
00086       error == ENOTSUP ||
00087 #elif defined (__FreeBSD__)
00088       // On FreeBSD we need to check for EOPNOTSUPP (LinuxThreads) or
00089       // ENOSYS (libc_r threads) also.
00090       error == EOPNOTSUPP ||
00091       error == ENOSYS ||
00092 #elif defined (__OpenBSD__)
00093       // OpenBSD appears to return EBADF.
00094       error == EBADF ||
00095 #elif defined (__sgi) // irix
00096       error == ENOTSUP ||
00097 #elif defined (DIGITAL_UNIX) // osf1
00098       error == ENOTSUP ||
00099 #endif /* ACE_WIN32 */
00100       error == ENFILE)
00101     return 1;
00102   else
00103     return 0;
00104 }

int ACE::process_active pid_t  pid  ) 
 

Checks if process with {pid} is still alive. Returns 1 if it is still alive, 0 if it isn't alive, and -1 if something weird happened.

Definition at line 253 of file ACE.cpp.

References ACE_OS::kill(), and pid_t.

00254 {
00255 #if !defined(ACE_WIN32)
00256   int retval = ACE_OS::kill (pid, 0);
00257 
00258   if (retval == 0)
00259     return 1;
00260   else if (errno == ESRCH)
00261     return 0;
00262   else
00263     return -1;
00264 #else
00265   // Create a handle for the given process id.
00266   ACE_HANDLE process_handle =
00267     ::OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid);
00268   if (process_handle == ACE_INVALID_HANDLE
00269       || process_handle == 0)
00270     return 0;
00271   else
00272     {
00273       DWORD status;
00274       int result = 1;
00275       if (::GetExitCodeProcess (process_handle,
00276                                 &status) == 0
00277           || status != STILL_ACTIVE)
00278         result = 0;
00279 
00280       ::CloseHandle (process_handle);
00281       return result;
00282     }
00283 #endif /* !ACE_WIN32 */
00284 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ssize_t ACE::read_n ACE_HANDLE  handle,
void *  buf,
size_t  len,
size_t *  bytes_transferred = 0
 

Definition at line 17 of file ACE.inl.

References ACE_OS::read_n().

Referenced by ACE_SPIPE_Stream::recv_n(), ACE_Pipe::recv_n(), ACE_FILE_IO::recv_n(), and ACE_DEV_IO::recv_n().

00021 {
00022   return ACE_OS::read_n (handle,
00023                          buf,
00024                          len,
00025                          bytes_transferred);
00026 }

ssize_t ACE::readv_n ACE_HANDLE  handle,
iovec *  iov,
int  iovcnt,
size_t *  bytes_transferred = 0
 

Definition at line 2099 of file ACE.cpp.

References ACE_OS::readv(), and ssize_t.

02103 {
02104   size_t temp;
02105   size_t &bytes_transferred = bt == 0 ? temp : *bt;
02106   bytes_transferred = 0;
02107 
02108   for (int s = 0;
02109        s < iovcnt;
02110        )
02111     {
02112       ssize_t n = ACE_OS::readv (handle,
02113                                  iov + s,
02114                                  iovcnt - s);
02115 
02116       if (n == -1 || n == 0)
02117         return n;
02118 
02119       for (bytes_transferred += n;
02120            s < iovcnt
02121              && n >= static_cast<ssize_t> (iov[s].iov_len);
02122            s++)
02123         n -= iov[s].iov_len;
02124 
02125       if (n != 0)
02126         {
02127           char *base = reinterpret_cast<char *> (iov[s].iov_base);
02128           iov[s].iov_base = base + n;
02129           iov[s].iov_len = iov[s].iov_len - n;
02130         }
02131     }
02132 
02133   return bytes_transferred;
02134 }

void ACE::record_and_set_non_blocking_mode ACE_HANDLE  handle,
int &  val
 

This makes sure that handle is set into non-blocking mode. val keeps track of whether were in non-blocking mode or not.

Definition at line 2264 of file ACE.cpp.

References ACE_BIT_DISABLED, ACE_NONBLOCK, get_flags(), and set_flags().

Referenced by enter_recv_timedwait(), enter_send_timedwait(), recv_n_i(), recvv_n_i(), send_n_i(), sendv_n_i(), t_rcv_n_i(), and t_snd_n_i().

02266 {
02267   // We need to record whether we are already *in* nonblocking mode,
02268   // so that we can correctly reset the state when we're done.
02269   val = ACE::get_flags (handle);
02270 
02271   if (ACE_BIT_DISABLED (val, ACE_NONBLOCK))
02272     // Set the handle into non-blocking mode if it's not already in
02273     // it.
02274     ACE::set_flags (handle, ACE_NONBLOCK);
02275 }

ssize_t ACE::recv ACE_HANDLE  handle,
size_t  n,
... 
 

Receive into a variable number of pieces.

Accepts a variable, caller-specified, number of pointer/length pairs. Arguments following n are char *, size_t pairs.

Parameters:
handle The I/O handle to receive on
n The total number of char *, size_t pairs following n.
Returns:
-1 on error, else total number of bytes received.

Definition at line 931 of file ACE.cpp.

References ACE_NEW_RETURN, ACE_OS::recvv(), and ssize_t.

00932 {
00933   va_list argp;
00934   int total_tuples = static_cast<int> (n / 2);
00935   iovec *iovp;
00936 #if defined (ACE_HAS_ALLOCA)
00937   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
00938 #else
00939   ACE_NEW_RETURN (iovp,
00940                   iovec[total_tuples],
00941                   -1);
00942 #endif /* !defined (ACE_HAS_ALLOCA) */
00943 
00944   va_start (argp, n);
00945 
00946   for (int i = 0; i < total_tuples; i++)
00947     {
00948       iovp[i].iov_base = va_arg (argp, char *);
00949       iovp[i].iov_len = va_arg (argp, int);
00950     }
00951 
00952   ssize_t result = ACE_OS::recvv (handle, iovp, total_tuples);
00953 #if !defined (ACE_HAS_ALLOCA)
00954   delete [] iovp;
00955 #endif /* !defined (ACE_HAS_ALLOCA) */
00956   va_end (argp);
00957   return result;
00958 }

ssize_t ACE::recv ACE_HANDLE  handle,
void *  buf,
size_t  len,
const ACE_Time_Value timeout = 0
 

Definition at line 500 of file ACE.cpp.

References enter_recv_timedwait(), recv_i(), restore_non_blocking_mode(), and ssize_t.

00504 {
00505   if (timeout == 0)
00506     return ACE::recv_i (handle, buf, n);
00507   else
00508     {
00509       int val = 0;
00510       if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
00511         return -1;
00512       else
00513         {
00514           ssize_t bytes_transferred = ACE::recv_i (handle, buf, n);
00515           ACE::restore_non_blocking_mode (handle, val);
00516           return bytes_transferred;
00517         }
00518     }
00519 }

ssize_t ACE::recv ACE_HANDLE  handle,
void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout = 0
 

Definition at line 448 of file ACE.cpp.

References enter_recv_timedwait(), ACE_OS::recv(), restore_non_blocking_mode(), and ssize_t.

Referenced by ACE_MEM_Acceptor::accept(), handle_timed_complete(), ACE_Select_Reactor_Notify::read_notify_pipe(), ACE_TLI_Stream::recv(), ACE_SOCK_IO::recv(), ACE_SOCK_Stream::recv_urg(), and ACE_SOCK_SEQPACK_Association::recv_urg().

00453 {
00454   if (timeout == 0)
00455     return ACE_OS::recv (handle, (char *) buf, len, flags);
00456   else
00457     {
00458       int val = 0;
00459       if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1)
00460         return -1;
00461       else
00462         {
00463           ssize_t bytes_transferred =
00464             ACE_OS::recv (handle, (char *) buf, len, flags);
00465           ACE::restore_non_blocking_mode (handle, val);
00466           return bytes_transferred;
00467         }
00468     }
00469 }

ACE_INLINE ssize_t ACE::recv_i ACE_HANDLE  handle,
void *  buf,
size_t  len
 

Definition at line 231 of file ACE.inl.

References ACE_OS::read(), and ACE_OS::recv().

Referenced by recv(), and recv_n_i().

00232 {
00233 #if defined (ACE_WIN32) || defined (ACE_OPENVMS) || defined (ACE_TANDEM_T1248_PTHREADS)
00234   return ACE_OS::recv (handle, (char *) buf, len);
00235 #else
00236   return ACE_OS::read (handle, (char *) buf, len);
00237 #endif /* ACE_WIN32 */
00238 }

ssize_t ACE::recv_n ACE_HANDLE  handle,
ACE_Message_Block message_block,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 1123 of file ACE.cpp.

References ACE_IOV_MAX, ACE_Message_Block::cont(), ACE_Message_Block::length(), ACE_Message_Block::next(), ACE_Message_Block::rd_ptr(), recvv_n(), and ssize_t.

01127 {
01128   size_t temp;
01129   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01130   bytes_transferred = 0;
01131 
01132   iovec iov[ACE_IOV_MAX];
01133   int iovcnt = 0;
01134 
01135   while (message_block != 0)
01136     {
01137       // Our current message block chain.
01138       const ACE_Message_Block *current_message_block = message_block;
01139 
01140       while (current_message_block != 0)
01141         {
01142           size_t current_message_block_length =
01143             current_message_block->length ();
01144           char *this_rd_ptr = current_message_block->rd_ptr ();
01145 
01146           // Check if this block has any space for incoming data.
01147           while (current_message_block_length > 0)
01148             {
01149               u_long this_chunk_length;
01150               if (current_message_block_length > ULONG_MAX)
01151                 this_chunk_length = ULONG_MAX;
01152               else
01153                 this_chunk_length =
01154                   static_cast<u_long> (current_message_block_length);
01155               // Collect the data in the iovec.
01156               iov[iovcnt].iov_base = this_rd_ptr;
01157               iov[iovcnt].iov_len  = this_chunk_length;
01158               current_message_block_length -= this_chunk_length;
01159               this_rd_ptr += this_chunk_length;
01160 
01161               // Increment iovec counter.
01162               ++iovcnt;
01163 
01164               // The buffer is full make a OS call.  @@ TODO find a way to
01165               // find ACE_IOV_MAX for platforms that do not define it rather
01166               // than simply setting ACE_IOV_MAX to some arbitrary value such
01167               // as 16.
01168               if (iovcnt == ACE_IOV_MAX)
01169                 {
01170                   size_t current_transfer = 0;
01171 
01172                   ssize_t result = ACE::recvv_n (handle,
01173                                                  iov,
01174                                                  iovcnt,
01175                                                  timeout,
01176                                                  &current_transfer);
01177 
01178                   // Add to total bytes transferred.
01179                   bytes_transferred += current_transfer;
01180 
01181                   // Errors.
01182                   if (result == -1 || result == 0)
01183                     return result;
01184 
01185                   // Reset iovec counter.
01186                   iovcnt = 0;
01187                 }
01188             }
01189 
01190           // Select the next message block in the chain.
01191           current_message_block = current_message_block->cont ();
01192         }
01193 
01194       // Selection of the next message block chain.
01195       message_block = message_block->next ();
01196     }
01197 
01198   // Check for remaining buffers to be sent.  This will happen when
01199   // ACE_IOV_MAX is not a multiple of the number of message blocks.
01200   if (iovcnt != 0)
01201     {
01202       size_t current_transfer = 0;
01203 
01204       ssize_t result = ACE::recvv_n (handle,
01205                                      iov,
01206                                      iovcnt,
01207                                      timeout,
01208                                      &current_transfer);
01209 
01210       // Add to total bytes transferred.
01211       bytes_transferred += current_transfer;
01212 
01213       // Errors.
01214       if (result == -1 || result == 0)
01215         return result;
01216     }
01217 
01218   // Return total bytes transferred.
01219   return bytes_transferred;
01220 }

ACE_INLINE ssize_t ACE::recv_n ACE_HANDLE  handle,
void *  buf,
size_t  len,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 91 of file ACE.inl.

References recv_n_i().

00096 {
00097   if (timeout == 0)
00098     return ACE::recv_n_i (handle,
00099                           buf,
00100                           len,
00101                           bytes_transferred);
00102   else
00103     return ACE::recv_n_i (handle,
00104                           buf,
00105                           len,
00106                           timeout,
00107                           bytes_transferred);
00108 }

ACE_INLINE ssize_t ACE::recv_n ACE_HANDLE  handle,
void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 41 of file ACE.inl.

References recv_n_i().

Referenced by ACE_TLI_Stream::recv_n(), ACE_SOCK_Stream::recv_n(), ACE_SOCK_SEQPACK_Association::recv_n(), ACE_Pipe::recv_n(), ACE_FIFO_Recv::recv_n(), and ACE_DEV_IO::recv_n().

00047 {
00048   if (timeout == 0)
00049     return ACE::recv_n_i (handle,
00050                           buf,
00051                           len,
00052                           flags,
00053                           bytes_transferred);
00054   else
00055     return ACE::recv_n_i (handle,
00056                           buf,
00057                           len,
00058                           flags,
00059                           timeout,
00060                           bytes_transferred);
00061 }

ssize_t ACE::recv_n_i ACE_HANDLE  handle,
void *  buf,
size_t  len,
const ACE_Time_Value timeout,
size_t *  bytes_transferred
 

Definition at line 860 of file ACE.cpp.

References EWOULDBLOCK, handle_read_ready(), record_and_set_non_blocking_mode(), recv_i(), restore_non_blocking_mode(), and ssize_t.

00865 {
00866   size_t temp;
00867   size_t &bytes_transferred = bt == 0 ? temp : *bt;
00868   ssize_t n;
00869   ssize_t result = 0;
00870   int error = 0;
00871 
00872   int val = 0;
00873   ACE::record_and_set_non_blocking_mode (handle, val);
00874 
00875   for (bytes_transferred = 0;
00876        bytes_transferred < len;
00877        bytes_transferred += n)
00878     {
00879       // Try to transfer as much of the remaining data as possible.
00880       // Since the socket is in non-blocking mode, this call will not
00881       // block.
00882       n = ACE::recv_i (handle,
00883                        static_cast <char *> (buf) + bytes_transferred,
00884                        len - bytes_transferred);
00885 
00886       // Check for errors.
00887       if (n == 0 ||
00888           n == -1)
00889         {
00890           // Check for possible blocking.
00891           if (n == -1 &&
00892               errno == EWOULDBLOCK)
00893             {
00894               // Wait upto <timeout> for the blocking to subside.
00895               int rtn = ACE::handle_read_ready (handle,
00896                                                 timeout);
00897 
00898               // Did select() succeed?
00899               if (rtn != -1)
00900                 {
00901                   // Blocking subsided in <timeout> period.  Continue
00902                   // data transfer.
00903                   n = 0;
00904                   continue;
00905                 }
00906             }
00907 
00908           // Wait in select() timed out or other data transfer or
00909           // select() failures.
00910           error = 1;
00911           result = n;
00912           break;
00913         }
00914     }
00915 
00916   ACE::restore_non_blocking_mode (handle, val);
00917 
00918   if (error)
00919     return result;
00920   else
00921     return static_cast<ssize_t> (bytes_transferred);
00922 }

ssize_t ACE::recv_n_i ACE_HANDLE  handle,
void *  buf,
size_t  len,
size_t *  bytes_transferred
 

Definition at line 810 of file ACE.cpp.

References EWOULDBLOCK, handle_read_ready(), recv_i(), and ssize_t.

00814 {
00815   size_t temp;
00816   size_t &bytes_transferred = bt == 0 ? temp : *bt;
00817   ssize_t n;
00818 
00819   for (bytes_transferred = 0;
00820        bytes_transferred < len;
00821        bytes_transferred += n)
00822     {
00823       // Try to transfer as much of the remaining data as possible.
00824       n = ACE::recv_i (handle,
00825                        static_cast <char *> (buf) + bytes_transferred,
00826                        len - bytes_transferred);
00827       // Check EOF.
00828       if (n == 0)
00829         {
00830           return 0;
00831         }
00832       // Check for other errors.
00833       if (n == -1)
00834         {
00835           // Check for possible blocking.
00836           if (errno == EWOULDBLOCK)
00837             {
00838               // Wait for the blocking to subside.
00839               int result = ACE::handle_read_ready (handle,
00840                                                    0);
00841 
00842               // Did select() succeed?
00843               if (result != -1)
00844                 {
00845                   // Blocking subsided.  Continue data transfer.
00846                   n = 0;
00847                   continue;
00848                 }
00849             }
00850 
00851           // Other data transfer or select() failures.
00852           return -1;
00853         }
00854     }
00855 
00856   return static_cast<ssize_t> (bytes_transferred);
00857 }

ssize_t ACE::recv_n_i ACE_HANDLE  handle,
void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout,
size_t *  bytes_transferred
 

Definition at line 621 of file ACE.cpp.

References EWOULDBLOCK, handle_read_ready(), record_and_set_non_blocking_mode(), ACE_OS::recv(), restore_non_blocking_mode(), and ssize_t.

00627 {
00628   size_t temp;
00629   size_t &bytes_transferred = bt == 0 ? temp : *bt;
00630   ssize_t n;
00631   ssize_t result = 0;
00632   int error = 0;
00633 
00634   int val = 0;
00635   ACE::record_and_set_non_blocking_mode (handle, val);
00636 
00637   for (bytes_transferred = 0;
00638        bytes_transferred < len;
00639        bytes_transferred += n)
00640     {
00641       // Try to transfer as much of the remaining data as possible.
00642       // Since the socket is in non-blocking mode, this call will not
00643       // block.
00644       n = ACE_OS::recv (handle,
00645                         static_cast <char *> (buf) + bytes_transferred,
00646                         len - bytes_transferred,
00647                         flags);
00648 
00649       // Check for errors.
00650       if (n == 0 ||
00651           n == -1)
00652         {
00653           // Check for possible blocking.
00654           if (n == -1 &&
00655               errno == EWOULDBLOCK)
00656             {
00657               // Wait upto <timeout> for the blocking to subside.
00658               int rtn = ACE::handle_read_ready (handle,
00659                                                 timeout);
00660 
00661               // Did select() succeed?
00662               if (rtn != -1)
00663                 {
00664                   // Blocking subsided in <timeout> period.  Continue
00665                   // data transfer.
00666                   n = 0;
00667                   continue;
00668                 }
00669             }
00670 
00671           // Wait in select() timed out or other data transfer or
00672           // select() failures.
00673           error = 1;
00674           result = n;
00675           break;
00676         }
00677     }
00678 
00679   ACE::restore_non_blocking_mode (handle, val);
00680 
00681   if (error)
00682     return result;
00683   else
00684     return static_cast<ssize_t> (bytes_transferred);
00685 }

ssize_t ACE::recv_n_i ACE_HANDLE  handle,
void *  buf,
size_t  len,
int  flags,
size_t *  bytes_transferred
 

Definition at line 570 of file ACE.cpp.

References EWOULDBLOCK, handle_read_ready(), ACE_OS::recv(), and ssize_t.

Referenced by recv_n().

00575 {
00576   size_t temp;
00577   size_t &bytes_transferred = bt == 0 ? temp : *bt;
00578   ssize_t n;
00579 
00580   for (bytes_transferred = 0;
00581        bytes_transferred < len;
00582        bytes_transferred += n)
00583     {
00584       // Try to transfer as much of the remaining data as possible.
00585       n = ACE_OS::recv (handle,
00586                         static_cast <char *> (buf) + bytes_transferred,
00587                         len - bytes_transferred,
00588                         flags);
00589       // Check EOF.
00590       if (n == 0)
00591         return 0;
00592 
00593       // Check for other errors.
00594       if (n == -1)
00595         {
00596           // Check for possible blocking.
00597           if (errno == EWOULDBLOCK)
00598             {
00599               // Wait for the blocking to subside.
00600               int result = ACE::handle_read_ready (handle,
00601                                                    0);
00602 
00603               // Did select() succeed?
00604               if (result != -1)
00605                 {
00606                   // Blocking subsided.  Continue data transfer.
00607                   n = 0;
00608                   continue;
00609                 }
00610             }
00611 
00612           // Other data transfer or select() failures.
00613           return -1;
00614         }
00615     }
00616 
00617   return static_cast<ssize_t> (bytes_transferred);
00618 }

ssize_t ACE::recvfrom ACE_HANDLE  handle,
char *  buf,
int  len,
int  flags,
struct sockaddr *  addr,
int *  addrlen,
const ACE_Time_Value timeout = 0
 

Definition at line 544 of file ACE.cpp.

References enter_recv_timedwait(), ACE_OS::recvfrom(), restore_non_blocking_mode(), and ssize_t.

00551 {
00552   if (timeout == 0)
00553     return ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen);
00554   else
00555     {
00556       int val = 0;
00557       if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
00558         return -1;
00559       else
00560         {
00561           ssize_t bytes_transferred =
00562             ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen);
00563           ACE::restore_non_blocking_mode (handle, val);
00564           return bytes_transferred;
00565         }
00566     }
00567 }

ssize_t ACE::recvmsg ACE_HANDLE  handle,
struct msghdr msg,
int  flags,
const ACE_Time_Value timeout = 0
 

Definition at line 522 of file ACE.cpp.

References enter_recv_timedwait(), ACE_OS::recvmsg(), restore_non_blocking_mode(), and ssize_t.

00526 {
00527   if (timeout == 0)
00528     return ACE_OS::recvmsg (handle, msg, flags);
00529   else
00530     {
00531       int val = 0;
00532       if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
00533         return -1;
00534       else
00535         {
00536           ssize_t bytes_transferred = ACE_OS::recvmsg (handle, msg, flags);
00537           ACE::restore_non_blocking_mode (handle, val);
00538           return bytes_transferred;
00539         }
00540     }
00541 }

ssize_t ACE::recvv ACE_HANDLE  handle,
iovec *  iov,
int  iovcnt,
const ACE_Time_Value timeout = 0
 

Definition at line 961 of file ACE.cpp.

References enter_recv_timedwait(), ACE_OS::recvv(), restore_non_blocking_mode(), and ssize_t.

Referenced by ACE_Pipe::recv(), and ACE_SOCK_IO::recvv().

00965 {
00966   if (timeout == 0)
00967     return ACE_OS::recvv (handle, iov, iovcnt);
00968   else
00969     {
00970       int val = 0;
00971       if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
00972         return -1;
00973       else
00974         {
00975           ssize_t bytes_transferred = ACE_OS::recvv (handle, iov, iovcnt);
00976           ACE::restore_non_blocking_mode (handle, val);
00977           return bytes_transferred;
00978         }
00979     }
00980 }

ACE_INLINE ssize_t ACE::recvv_n ACE_HANDLE  handle,
iovec *  iov,
int  iovcnt,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 111 of file ACE.inl.

References recvv_n_i().

Referenced by recv_n(), ACE_SOCK_Stream::recvv_n(), and ACE_SOCK_SEQPACK_Association::recvv_n().

00116 {
00117   if (timeout == 0)
00118     return ACE::recvv_n_i (handle,
00119                            iov,
00120                            iovcnt,
00121                            bytes_transferred);
00122   else
00123     return ACE::recvv_n_i (handle,
00124                            iov,
00125                            iovcnt,
00126                            timeout,
00127                            bytes_transferred);
00128 }

ssize_t ACE::recvv_n_i ACE_HANDLE  handle,
iovec *  iov,
int  iovcnt,
const ACE_Time_Value timeout,
size_t *  bytes_transferred
 

Definition at line 1045 of file ACE.cpp.

References EWOULDBLOCK, handle_read_ready(), record_and_set_non_blocking_mode(), ACE_OS::recvv(), restore_non_blocking_mode(), and ssize_t.

01050 {
01051   size_t temp;
01052   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01053   bytes_transferred = 0;
01054   ssize_t result = 0;
01055   int error = 0;
01056 
01057   int val = 0;
01058   ACE::record_and_set_non_blocking_mode (handle, val);
01059 
01060   for (int s = 0;
01061        s < iovcnt;
01062        )
01063     {
01064       // Try to transfer as much of the remaining data as possible.
01065       // Since the socket is in non-blocking mode, this call will not
01066       // block.
01067       ssize_t n = ACE_OS::recvv (handle,
01068                                  iov + s,
01069                                  iovcnt - s);
01070 
01071       // Check for errors.
01072       if (n == 0 ||
01073           n == -1)
01074         {
01075           // Check for possible blocking.
01076           if (n == -1 &&
01077               errno == EWOULDBLOCK)
01078             {
01079               // Wait upto <timeout> for the blocking to subside.
01080               int rtn = ACE::handle_read_ready (handle,
01081                                                 timeout);
01082 
01083               // Did select() succeed?
01084               if (rtn != -1)
01085                 {
01086                   // Blocking subsided in <timeout> period.  Continue
01087                   // data transfer.
01088                   n = 0;
01089                   continue;
01090                 }
01091             }
01092 
01093           // Wait in select() timed out or other data transfer or
01094           // select() failures.
01095           error = 1;
01096           result = n;
01097           break;
01098         }
01099 
01100       for (bytes_transferred += n;
01101            s < iovcnt
01102              && n >= static_cast<ssize_t> (iov[s].iov_len);
01103            s++)
01104         n -= iov[s].iov_len;
01105 
01106       if (n != 0)
01107         {
01108           char *base = reinterpret_cast<char *> (iov[s].iov_base);
01109           iov[s].iov_base = base + n;
01110           iov[s].iov_len = iov[s].iov_len - n;
01111         }
01112     }
01113 
01114   ACE::restore_non_blocking_mode (handle, val);
01115 
01116   if (error)
01117     return result;
01118   else
01119     return bytes_transferred;
01120 }

ssize_t ACE::recvv_n_i ACE_HANDLE  handle,
iovec *  iov,
int  iovcnt,
size_t *  bytes_transferred
 

Definition at line 983 of file ACE.cpp.

References EWOULDBLOCK, handle_read_ready(), ACE_OS::recvv(), and ssize_t.

Referenced by recvv_n().

00987 {
00988   size_t temp;
00989   size_t &bytes_transferred = bt == 0 ? temp : *bt;
00990   bytes_transferred = 0;
00991 
00992   for (int s = 0;
00993        s < iovcnt;
00994        )
00995     {
00996       // Try to transfer as much of the remaining data as possible.
00997       ssize_t n = ACE_OS::recvv (handle,
00998                                  iov + s,
00999                                  iovcnt - s);
01000       // Check EOF.
01001       if (n == 0)
01002         return 0;
01003 
01004       // Check for other errors.
01005       if (n == -1)
01006         {
01007           // Check for possible blocking.
01008           if (errno == EWOULDBLOCK)
01009             {
01010               // Wait for the blocking to subside.
01011               int result = ACE::handle_read_ready (handle,
01012                                                    0);
01013 
01014               // Did select() succeed?
01015               if (result != -1)
01016                 {
01017                   // Blocking subsided.  Continue data transfer.
01018                   n = 0;
01019                   continue;
01020                 }
01021             }
01022 
01023           // Other data transfer or select() failures.
01024           return -1;
01025         }
01026 
01027       for (bytes_transferred += n;
01028            s < iovcnt
01029              && n >= static_cast<ssize_t> (iov[s].iov_len);
01030            s++)
01031         n -= iov[s].iov_len;
01032 
01033       if (n != 0)
01034         {
01035           char *base = static_cast<char *> (iov[s].iov_base);
01036           iov[s].iov_base = base + n;
01037           iov[s].iov_len = iov[s].iov_len - n;
01038         }
01039     }
01040 
01041   return bytes_transferred;
01042 }

void ACE::restore_non_blocking_mode ACE_HANDLE  handle,
int  val
 

Cleanup after a timed operation, restore the appropriate non-blocking status of handle.

Definition at line 2278 of file ACE.cpp.

References ACE_BIT_DISABLED, ACE_NONBLOCK, and clr_flags().

Referenced by recv(), recv_n_i(), recvfrom(), recvmsg(), recvv(), recvv_n_i(), send(), send_n_i(), sendmsg(), sendto(), sendv(), sendv_n_i(), t_rcv(), t_rcv_n_i(), t_snd(), and t_snd_n_i().

02280 {
02281   if (ACE_BIT_DISABLED (val,
02282                         ACE_NONBLOCK))
02283     {
02284       // Save/restore errno.
02285       ACE_Errno_Guard error (errno);
02286       // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
02287       // originally.
02288       ACE::clr_flags (handle, ACE_NONBLOCK);
02289     }
02290 }

size_t ACE::round_to_allocation_granularity size_t  len  ) 
 

Rounds the request to a multiple of the allocation granularity.

Definition at line 2496 of file ACE.cpp.

References ACE_TRACE, and ACE_OS::allocation_granularity().

02497 {
02498   ACE_TRACE ("ACE::round_to_allocation_granularity");
02499 
02500   if (ACE::allocation_granularity_ == 0)
02501     ACE::allocation_granularity_ = ACE_OS::allocation_granularity ();
02502 
02503   return (len + (ACE::allocation_granularity_ - 1)) & ~(ACE::allocation_granularity_ - 1);
02504 }

size_t ACE::round_to_pagesize size_t  len  ) 
 

Rounds the request to a multiple of the page size.

Definition at line 2485 of file ACE.cpp.

References ACE_TRACE, and ACE_OS::getpagesize().

Referenced by ACE_Shared_Memory_Pool::init_acquire(), ACE_Shared_Memory_Pool::round_up(), ACE_Sbrk_Memory_Pool::round_up(), ACE_MMAP_Memory_Pool::round_up(), and ACE_Local_Memory_Pool::round_up().

02486 {
02487   ACE_TRACE ("ACE::round_to_pagesize");
02488 
02489   if (ACE::pagesize_ == 0)
02490     ACE::pagesize_ = ACE_OS::getpagesize ();
02491 
02492   return (len + (ACE::pagesize_ - 1)) & ~(ACE::pagesize_ - 1);
02493 }

int ACE::select int  width,
ACE_Handle_Set readfds,
const ACE_Time_Value timeout = 0
 

Wrapper facade for the most common use of select that uses ACE_Handle_Sets.

Definition at line 205 of file ACE.cpp.

References ACE_Handle_Set::fdset(), ACE_OS::select(), and ACE_Handle_Set::sync().

00208 {
00209   int result = ACE_OS::select (width,
00210                                readfds.fdset (),
00211                                0,
00212                                0,
00213                                timeout);
00214 
00215 #if !defined (ACE_WIN32)
00216   if (result > 0)
00217     readfds.sync ((ACE_HANDLE) width);
00218 #endif /* ACE_WIN32 */
00219   return result;
00220 }

int ACE::select int  width,
ACE_Handle_Set readfds,
ACE_Handle_Set writefds = 0,
ACE_Handle_Set exceptfds = 0,
const ACE_Time_Value timeout = 0
 

Wrapper facade for select that uses ACE_Handle_Sets.

Definition at line 178 of file ACE.cpp.

References ACE_Handle_Set::fdset(), ACE_OS::select(), and ACE_Handle_Set::sync().

00183 {
00184   int result = ACE_OS::select (width,
00185                                readfds ? readfds->fdset () : 0,
00186                                writefds ? writefds->fdset () : 0,
00187                                exceptfds ? exceptfds->fdset () : 0,
00188                                timeout);
00189   if (result > 0)
00190     {
00191 # if !defined (ACE_WIN32)
00192       // This isn't needed for Windows... it's a no-op anyway.
00193       if (readfds)
00194         readfds->sync ((ACE_HANDLE) width);
00195       if (writefds)
00196         writefds->sync ((ACE_HANDLE) width);
00197       if (exceptfds)
00198         exceptfds->sync ((ACE_HANDLE) width);
00199 #endif /* ACE_WIN32 */
00200     }
00201   return result;
00202 }

ssize_t ACE::send ACE_HANDLE  handle,
size_t  n,
... 
 

Varargs variant.

Definition at line 1706 of file ACE.cpp.

References ACE_NEW_RETURN, ACE_OS::sendv(), and ssize_t.

01707 {
01708   va_list argp;
01709   int total_tuples = static_cast<int> (n / 2);
01710   iovec *iovp;
01711 #if defined (ACE_HAS_ALLOCA)
01712   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
01713 #else
01714   ACE_NEW_RETURN (iovp,
01715                   iovec[total_tuples],
01716                   -1);
01717 #endif /* !defined (ACE_HAS_ALLOCA) */
01718 
01719   va_start (argp, n);
01720 
01721   for (int i = 0; i < total_tuples; i++)
01722     {
01723       iovp[i].iov_base = va_arg (argp, char *);
01724       iovp[i].iov_len = va_arg (argp, int);
01725     }
01726 
01727   ssize_t result = ACE_OS::sendv (handle, iovp, total_tuples);
01728 #if !defined (ACE_HAS_ALLOCA)
01729   delete [] iovp;
01730 #endif /* !defined (ACE_HAS_ALLOCA) */
01731   va_end (argp);
01732   return result;
01733 }

ssize_t ACE::send ACE_HANDLE  handle,
const void *  buf,
size_t  len,
const ACE_Time_Value timeout = 0
 

Definition at line 1273 of file ACE.cpp.

References enter_send_timedwait(), restore_non_blocking_mode(), send_i(), and ssize_t.

01277 {
01278   if (timeout == 0)
01279     return ACE::send_i (handle, buf, n);
01280   else
01281     {
01282       int val = 0;
01283       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01284         return -1;
01285       else
01286         {
01287           ssize_t bytes_transferred = ACE::send_i (handle, buf, n);
01288           ACE::restore_non_blocking_mode (handle, val);
01289           return bytes_transferred;
01290         }
01291     }
01292 }

ssize_t ACE::send ACE_HANDLE  handle,
const void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout = 0
 

Definition at line 1223 of file ACE.cpp.

References enter_send_timedwait(), restore_non_blocking_mode(), ACE_OS::send(), and ssize_t.

Referenced by ACE_MEM_Acceptor::accept(), ACE_Select_Reactor_Notify::dispatch_notify(), ACE_Select_Reactor_Notify::notify(), ACE_TLI_Stream::send(), ACE_SOCK_IO::send(), ACE_SOCK_Stream::send_urg(), and ACE_SOCK_SEQPACK_Association::send_urg().

01228 {
01229   if (timeout == 0)
01230     return ACE_OS::send (handle, (const char *) buf, n, flags);
01231   else
01232     {
01233       int val = 0;
01234       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01235         return -1;
01236       else
01237         {
01238           ssize_t bytes_transferred = ACE_OS::send (handle, (const char *) buf, n, flags);
01239           ACE::restore_non_blocking_mode (handle, val);
01240           return bytes_transferred;
01241         }
01242     }
01243 }

ACE_INLINE ssize_t ACE::send_i ACE_HANDLE  handle,
const void *  buf,
size_t  len
 

Definition at line 221 of file ACE.inl.

References ACE_OS::send(), and ACE_OS::write().

Referenced by send(), and send_n_i().

00222 {
00223 #if defined (ACE_WIN32) || defined (HPUX)
00224   return ACE_OS::send (handle, (const char *) buf, len);
00225 #else
00226   return ACE_OS::write (handle, (const char *) buf, len);
00227 #endif /* ACE_WIN32 */
00228 }

ssize_t ACE::send_n ACE_HANDLE  handle,
const ACE_Message_Block message_block,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Send all the message_blocks chained through their next and cont pointers. This call uses the underlying OS gather-write operation to reduce the domain-crossing penalty.

Definition at line 1999 of file ACE.cpp.

References ACE_IOV_MAX, ACE_Message_Block::cont(), ACE_Message_Block::length(), ACE_Message_Block::next(), ACE_Message_Block::rd_ptr(), sendv_n(), and ssize_t.

02003 {
02004   size_t temp;
02005   size_t &bytes_transferred = bt == 0 ? temp : *bt;
02006   bytes_transferred = 0;
02007 
02008   iovec iov[ACE_IOV_MAX];
02009   int iovcnt = 0;
02010 
02011   while (message_block != 0)
02012     {
02013       // Our current message block chain.
02014       const ACE_Message_Block *current_message_block = message_block;
02015 
02016       while (current_message_block != 0)
02017         {
02018           char *this_block_ptr = current_message_block->rd_ptr ();
02019           size_t current_message_block_length =
02020             current_message_block->length ();
02021 
02022           // Check if this block has any data to be sent.
02023           while (current_message_block_length > 0)
02024             {
02025               u_long this_chunk_length;
02026               if (current_message_block_length > ULONG_MAX)
02027                 this_chunk_length = ULONG_MAX;
02028               else
02029                 this_chunk_length =
02030                   static_cast<u_long> (current_message_block_length);
02031               // Collect the data in the iovec.
02032               iov[iovcnt].iov_base = this_block_ptr;
02033               iov[iovcnt].iov_len  = this_chunk_length;
02034               current_message_block_length -= this_chunk_length;
02035               this_block_ptr += this_chunk_length;
02036 
02037               // Increment iovec counter.
02038               ++iovcnt;
02039 
02040               // The buffer is full make a OS call.  @@ TODO find a way to
02041               // find ACE_IOV_MAX for platforms that do not define it rather
02042               // than simply setting ACE_IOV_MAX to some arbitrary value such
02043               // as 16.
02044               if (iovcnt == ACE_IOV_MAX)
02045                 {
02046                   size_t current_transfer = 0;
02047 
02048                   ssize_t result = ACE::sendv_n (handle,
02049                                                  iov,
02050                                                  iovcnt,
02051                                                  timeout,
02052                                                  &current_transfer);
02053 
02054                   // Add to total bytes transferred.
02055                   bytes_transferred += current_transfer;
02056 
02057                   // Errors.
02058                   if (result == -1 || result == 0)
02059                     return result;
02060 
02061                   // Reset iovec counter.
02062                   iovcnt = 0;
02063                 }
02064             }
02065 
02066           // Select the next message block in the chain.
02067           current_message_block = current_message_block->cont ();
02068         }
02069 
02070       // Selection of the next message block chain.
02071       message_block = message_block->next ();
02072     }
02073 
02074   // Check for remaining buffers to be sent.  This will happen when
02075   // ACE_IOV_MAX is not a multiple of the number of message blocks.
02076   if (iovcnt != 0)
02077     {
02078       size_t current_transfer = 0;
02079 
02080       ssize_t result = ACE::sendv_n (handle,
02081                                      iov,
02082                                      iovcnt,
02083                                      timeout,
02084                                      &current_transfer);
02085 
02086       // Add to total bytes transferred.
02087       bytes_transferred += current_transfer;
02088 
02089       // Errors.
02090       if (result == -1 || result == 0)
02091         return result;
02092     }
02093 
02094   // Return total bytes transferred.
02095   return bytes_transferred;
02096 }

ACE_INLINE ssize_t ACE::send_n ACE_HANDLE  handle,
const void *  buf,
size_t  len,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 181 of file ACE.inl.

References send_n_i().

00186 {
00187   if (timeout == 0)
00188     return ACE::send_n_i (handle,
00189                           buf,
00190                           len,
00191                           bytes_transferred);
00192   else
00193     return ACE::send_n_i (handle,
00194                           buf,
00195                           len,
00196                           timeout,
00197                           bytes_transferred);
00198 }

ACE_INLINE ssize_t ACE::send_n ACE_HANDLE  handle,
const void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 131 of file ACE.inl.

References send_n_i().

Referenced by ACE_TLI_Stream::send_n(), ACE_SOCK_Stream::send_n(), ACE_SOCK_SEQPACK_Association::send_n(), ACE_Pipe::send_n(), and ACE_FIFO_Send::send_n().

00137 {
00138   if (timeout == 0)
00139     return ACE::send_n_i (handle,
00140                           buf,
00141                           len,
00142                           flags,
00143                           bytes_transferred);
00144   else
00145     return ACE::send_n_i (handle,
00146                           buf,
00147                           len,
00148                           flags,
00149                           timeout,
00150                           bytes_transferred);
00151 }

ssize_t ACE::send_n_i ACE_HANDLE  handle,
const void *  buf,
size_t  len,
const ACE_Time_Value timeout,
size_t *  bytes_transferred
 

Definition at line 1636 of file ACE.cpp.

References ENOBUFS, EWOULDBLOCK, handle_write_ready(), record_and_set_non_blocking_mode(), restore_non_blocking_mode(), send_i(), and ssize_t.

01641 {
01642   size_t temp;
01643   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01644   ssize_t n;
01645   ssize_t result = 0;
01646   int error = 0;
01647 
01648   int val = 0;
01649   ACE::record_and_set_non_blocking_mode (handle, val);
01650 
01651   for (bytes_transferred = 0;
01652        bytes_transferred < len;
01653        bytes_transferred += n)
01654     {
01655       // Try to transfer as much of the remaining data as possible.
01656       // Since the socket is in non-blocking mode, this call will not
01657       // block.
01658       n = ACE::send_i (handle,
01659                        (char *) buf + bytes_transferred,
01660                        len - bytes_transferred);
01661 
01662       // Check for errors.
01663       if (n == 0 ||
01664           n == -1)
01665         {
01666           // Check for possible blocking.
01667           if (n == -1 &&
01668               errno == EWOULDBLOCK || errno == ENOBUFS)
01669             {
01670               // Wait upto <timeout> for the blocking to subside.
01671               int rtn = ACE::handle_write_ready (handle,
01672                                                  timeout);
01673 
01674               // Did select() succeed?
01675               if (rtn != -1)
01676                 {
01677                   // Blocking subsided in <timeout> period.  Continue
01678                   // data transfer.
01679                   n = 0;
01680                   continue;
01681                 }
01682             }
01683 
01684           // Wait in select() timed out or other data transfer or
01685           // select() failures.
01686           error = 1;
01687           result = n;
01688           break;
01689         }
01690     }
01691 
01692   ACE::restore_non_blocking_mode (handle, val);
01693 
01694   if (error)
01695     return result;
01696   else
01697     return bytes_transferred;
01698 }

ssize_t ACE::send_n_i ACE_HANDLE  handle,
const void *  buf,
size_t  len,
size_t *  bytes_transferred
 

Definition at line 1587 of file ACE.cpp.

References ENOBUFS, EWOULDBLOCK, handle_write_ready(), send_i(), and ssize_t.

01591 {
01592   size_t temp;
01593   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01594   ssize_t n;
01595 
01596   for (bytes_transferred = 0;
01597        bytes_transferred < len;
01598        bytes_transferred += n)
01599     {
01600       // Try to transfer as much of the remaining data as possible.
01601       n = ACE::send_i (handle,
01602                        (char *) buf + bytes_transferred,
01603                        len - bytes_transferred);
01604       // Check EOF.
01605       if (n == 0)
01606         return 0;
01607 
01608       // Check for other errors.
01609       if (n == -1)
01610         {
01611           // Check for possible blocking.
01612           if (errno == EWOULDBLOCK || errno == ENOBUFS)
01613             {
01614               // Wait for the blocking to subside.
01615               int result = ACE::handle_write_ready (handle,
01616                                                     0);
01617 
01618               // Did select() succeed?
01619               if (result != -1)
01620                 {
01621                   // Blocking subsided.  Continue data transfer.
01622                   n = 0;
01623                   continue;
01624                 }
01625             }
01626 
01627           // Other data transfer or select() failures.
01628           return -1;
01629         }
01630     }
01631 
01632   return bytes_transferred;
01633 }

ssize_t ACE::send_n_i ACE_HANDLE  handle,
const void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout,
size_t *  bytes_transferred
 

Definition at line 1398 of file ACE.cpp.

References ENOBUFS, EWOULDBLOCK, handle_write_ready(), record_and_set_non_blocking_mode(), restore_non_blocking_mode(), ACE_OS::send(), and ssize_t.

01404 {
01405   size_t temp;
01406   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01407   ssize_t n;
01408   ssize_t result = 0;
01409   int error = 0;
01410 
01411   int val = 0;
01412   ACE::record_and_set_non_blocking_mode (handle, val);
01413 
01414   for (bytes_transferred = 0;
01415        bytes_transferred < len;
01416        bytes_transferred += n)
01417     {
01418       // Try to transfer as much of the remaining data as possible.
01419       // Since the socket is in non-blocking mode, this call will not
01420       // block.
01421       n = ACE_OS::send (handle,
01422                         (char *) buf + bytes_transferred,
01423                         len - bytes_transferred,
01424                         flags);
01425 
01426       // Check for errors.
01427       if (n == 0 ||
01428           n == -1)
01429         {
01430           // Check for possible blocking.
01431           if (n == -1 &&
01432               errno == EWOULDBLOCK || errno == ENOBUFS)
01433             {
01434               // Wait upto <timeout> for the blocking to subside.
01435               int rtn = ACE::handle_write_ready (handle,
01436                                                  timeout);
01437 
01438               // Did select() succeed?
01439               if (rtn != -1)
01440                 {
01441                   // Blocking subsided in <timeout> period.  Continue
01442                   // data transfer.
01443                   n = 0;
01444                   continue;
01445                 }
01446             }
01447 
01448           // Wait in select() timed out or other data transfer or
01449           // select() failures.
01450           error = 1;
01451           result = n;
01452           break;
01453         }
01454     }
01455 
01456   ACE::restore_non_blocking_mode (handle, val);
01457 
01458   if (error)
01459     return result;
01460   else
01461     return bytes_transferred;
01462 }

ssize_t ACE::send_n_i ACE_HANDLE  handle,
const void *  buf,
size_t  len,
int  flags,
size_t *  bytes_transferred
 

Definition at line 1343 of file ACE.cpp.

References ENOBUFS, EWOULDBLOCK, handle_write_ready(), ACE_OS::send(), and ssize_t.

Referenced by send_n().

01348 {
01349   size_t temp;
01350   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01351   ssize_t n;
01352 
01353   for (bytes_transferred = 0;
01354        bytes_transferred < len;
01355        bytes_transferred += n)
01356     {
01357       // Try to transfer as much of the remaining data as possible.
01358       n = ACE_OS::send (handle,
01359                         (char *) buf + bytes_transferred,
01360                         len - bytes_transferred,
01361                         flags);
01362       // Check EOF.
01363       if (n == 0)
01364         return 0;
01365 
01366       // Check for other errors.
01367       if (n == -1)
01368         {
01369           // Check for possible blocking.
01370 #if defined (ACE_WIN32)
01371           if (errno == EWOULDBLOCK) // If enobufs no need to loop
01372 #else
01373           if (errno == EWOULDBLOCK || errno == ENOBUFS)
01374 #endif /* ACE_WIN32 */
01375             {
01376               // Wait for the blocking to subside.
01377               int result = ACE::handle_write_ready (handle,
01378                                                     0);
01379 
01380               // Did select() succeed?
01381               if (result != -1)
01382                 {
01383                   // Blocking subsided.  Continue data transfer.
01384                   n = 0;
01385                   continue;
01386                 }
01387             }
01388 
01389           // Other data transfer or select() failures.
01390           return -1;
01391         }
01392     }
01393 
01394   return bytes_transferred;
01395 }

ssize_t ACE::sendmsg ACE_HANDLE  handle,
const struct msghdr msg,
int  flags,
const ACE_Time_Value timeout = 0
 

Definition at line 1295 of file ACE.cpp.

References enter_send_timedwait(), restore_non_blocking_mode(), ACE_OS::sendmsg(), and ssize_t.

01299 {
01300   if (timeout == 0)
01301     return ACE_OS::sendmsg (handle, msg, flags);
01302   else
01303     {
01304       int val = 0;
01305       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01306         return -1;
01307       else
01308         {
01309           ssize_t bytes_transferred = ACE_OS::sendmsg (handle, msg, flags);
01310           ACE::restore_non_blocking_mode (handle, val);
01311           return bytes_transferred;
01312         }
01313     }
01314 }

ssize_t ACE::sendto ACE_HANDLE  handle,
const char *  buf,
int  len,
int  flags,
const struct sockaddr *  addr,
int  addrlen,
const ACE_Time_Value timeout = 0
 

Definition at line 1317 of file ACE.cpp.

References enter_send_timedwait(), restore_non_blocking_mode(), ACE_OS::sendto(), and ssize_t.

01324 {
01325   if (timeout == 0)
01326     return ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
01327   else
01328     {
01329       int val = 0;
01330       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01331         return -1;
01332       else
01333         {
01334           ssize_t bytes_transferred =
01335             ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
01336           ACE::restore_non_blocking_mode (handle, val);
01337           return bytes_transferred;
01338         }
01339     }
01340 }

ssize_t ACE::sendv ACE_HANDLE  handle,
const iovec *  iov,
int  iovcnt,
const ACE_Time_Value timeout = 0
 

Definition at line 1736 of file ACE.cpp.

References enter_send_timedwait(), restore_non_blocking_mode(), ACE_OS::sendv(), and ssize_t.

Referenced by ACE_Pipe::send(), and ACE_SOCK_IO::sendv().

01740 {
01741   if (timeout == 0)
01742     return ACE_OS::sendv (handle, iov, iovcnt);
01743   else
01744     {
01745       int val = 0;
01746       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01747         return -1;
01748       else
01749         {
01750           ssize_t bytes_transferred = ACE_OS::sendv (handle, iov, iovcnt);
01751           ACE::restore_non_blocking_mode (handle, val);
01752           return bytes_transferred;
01753         }
01754     }
01755 }

ACE_INLINE ssize_t ACE::sendv_n ACE_HANDLE  handle,
const iovec *  iov,
int  iovcnt,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 201 of file ACE.inl.

References sendv_n_i().

Referenced by send_n(), ACE_SOCK_Stream::sendv_n(), ACE_SOCK_SEQPACK_Association::sendv_n(), and ACE_Pipe::sendv_n().

00206 {
00207   if (timeout == 0)
00208     return ACE::sendv_n_i (handle,
00209                            iov,
00210                            iovcnt,
00211                            bytes_transferred);
00212   else
00213     return ACE::sendv_n_i (handle,
00214                            iov,
00215                            iovcnt,
00216                            timeout,
00217                            bytes_transferred);
00218 }

ssize_t ACE::sendv_n_i ACE_HANDLE  handle,
const iovec *  iov,
int  iovcnt,
const ACE_Time_Value timeout,
size_t *  bytes_transferred
 

Definition at line 1822 of file ACE.cpp.

References ENOBUFS, EWOULDBLOCK, handle_write_ready(), record_and_set_non_blocking_mode(), restore_non_blocking_mode(), ACE_OS::sendv(), and ssize_t.

01827 {
01828   size_t temp;
01829   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01830   bytes_transferred = 0;
01831   ssize_t result = 0;
01832   int error = 0;
01833 
01834   int val = 0;
01835   ACE::record_and_set_non_blocking_mode (handle, val);
01836 
01837   iovec *iov = const_cast<iovec *> (i);
01838 
01839   for (int s = 0;
01840        s < iovcnt;
01841        )
01842     {
01843       // Try to transfer as much of the remaining data as possible.
01844       // Since the socket is in non-blocking mode, this call will not
01845       // block.
01846       ssize_t n = ACE_OS::sendv (handle,
01847                                  iov + s,
01848                                  iovcnt - s);
01849 
01850       // Check for errors.
01851       if (n == 0 ||
01852           n == -1)
01853         {
01854           // Check for possible blocking.
01855           if (n == -1 &&
01856               errno == EWOULDBLOCK || errno == ENOBUFS)
01857             {
01858               // Wait upto <timeout> for the blocking to subside.
01859               int rtn = ACE::handle_write_ready (handle,
01860                                                  timeout);
01861 
01862               // Did select() succeed?
01863               if (rtn != -1)
01864                 {
01865                   // Blocking subsided in <timeout> period.  Continue
01866                   // data transfer.
01867                   n = 0;
01868                   continue;
01869                 }
01870             }
01871 
01872           // Wait in select() timed out or other data transfer or
01873           // select() failures.
01874           error = 1;
01875           result = n;
01876           break;
01877         }
01878 
01879       for (bytes_transferred += n;
01880            s < iovcnt
01881              && n >= static_cast<ssize_t> (iov[s].iov_len);
01882            s++)
01883         n -= iov[s].iov_len;
01884 
01885       if (n != 0)
01886         {
01887           char *base = reinterpret_cast<char *> (iov[s].iov_base);
01888           iov[s].iov_base = base + n;
01889           iov[s].iov_len = iov[s].iov_len - n;
01890         }
01891     }
01892 
01893   ACE::restore_non_blocking_mode (handle, val);
01894 
01895   if (error)
01896     return result;
01897   else
01898     return bytes_transferred;
01899 }

ssize_t ACE::sendv_n_i ACE_HANDLE  handle,
const iovec *  iov,
int  iovcnt,
size_t *  bytes_transferred
 

Definition at line 1758 of file ACE.cpp.

References ENOBUFS, EWOULDBLOCK, handle_write_ready(), ACE_OS::sendv(), and ssize_t.

Referenced by sendv_n().

01762 {
01763   size_t temp;
01764   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01765   bytes_transferred = 0;
01766 
01767   iovec *iov = const_cast<iovec *> (i);
01768 
01769   for (int s = 0;
01770        s < iovcnt;
01771        )
01772     {
01773       // Try to transfer as much of the remaining data as possible.
01774       ssize_t n = ACE_OS::sendv (handle,
01775                                  iov + s,
01776                                  iovcnt - s);
01777       // Check EOF.
01778       if (n == 0)
01779         return 0;
01780 
01781       // Check for other errors.
01782       if (n == -1)
01783         {
01784           // Check for possible blocking.
01785           if (errno == EWOULDBLOCK || errno == ENOBUFS)
01786             {
01787               // Wait for the blocking to subside.
01788               int result = ACE::handle_write_ready (handle,
01789                                                     0);
01790 
01791               // Did select() succeed?
01792               if (result != -1)
01793                 {
01794                   // Blocking subsided.  Continue data transfer.
01795                   n = 0;
01796                   continue;
01797                 }
01798             }
01799 
01800           // Other data transfer or select() failures.
01801           return -1;
01802         }
01803 
01804       for (bytes_transferred += n;
01805            s < iovcnt
01806              && n >= static_cast<ssize_t> (iov[s].iov_len);
01807            s++)
01808         n -= iov[s].iov_len;
01809 
01810       if (n != 0)
01811         {
01812           char *base = reinterpret_cast<char *> (iov[s].iov_base);
01813           iov[s].iov_base = base + n;
01814           iov[s].iov_len = iov[s].iov_len - n;
01815         }
01816     }
01817 
01818   return bytes_transferred;
01819 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL int ACE::set_flags ACE_HANDLE  handle,
int  flags
 

Set flags associated with handle.

Definition at line 27 of file Flag_Manip.cpp.

References ACE_NONBLOCK, ACE_NOTSUP_RETURN, ACE_SET_BITS, ACE_TRACE, F_GETFL, ACE_OS::fcntl(), and ACE_OS::ioctl().

Referenced by ACE_IPC_SAP::enable(), ACE_IO_SAP::enable(), ACE_Select_Reactor_Notify::open(), record_and_set_non_blocking_mode(), ACE_SOCK_SEQPACK_Acceptor::shared_accept_start(), and ACE_SOCK_Acceptor::shared_accept_start().

00028 {
00029   ACE_TRACE ("ACE::set_flags");
00030 #if defined (ACE_LACKS_FCNTL)
00031   switch (flags)
00032     {
00033     case ACE_NONBLOCK:
00034       // nonblocking argument (1)
00035       // blocking:            (0)
00036       {
00037         int nonblock = 1;
00038         return ACE_OS::ioctl (handle, FIONBIO, &nonblock);
00039       }
00040     default:
00041       ACE_NOTSUP_RETURN (-1);
00042     }
00043 #else
00044   int val = ACE_OS::fcntl (handle, F_GETFL, 0);
00045 
00046   if (val == -1)
00047     return -1;
00048 
00049   // Turn on flags.
00050   ACE_SET_BITS (val, flags);
00051 
00052   if (ACE_OS::fcntl (handle, F_SETFL, val) == -1)
00053     return -1;
00054   else
00055     return 0;
00056 #endif /* ACE_LACKS_FCNTL */
00057 }

int ACE::set_handle_limit int  new_limit = -1,
int  increase_limit_only = 0
 

Reset the limit on the number of open handles. If new_limit == -1 set the limit to the maximum allowable. Otherwise, set the limit value to new_limit. If increase_limit_only is non-0 then only allow increases to the limit.

Definition at line 2876 of file ACE.cpp.

References ACE_NOTSUP_RETURN, ACE_TRACE, ACE_OS::getrlimit(), max_handles(), ACE_OS::memset(), and ACE_OS::setrlimit().

02878 {
02879   ACE_TRACE ("ACE::set_handle_limit");
02880   int cur_limit = ACE::max_handles ();
02881   int max_limit = cur_limit;
02882 
02883   if (cur_limit == -1)
02884     return -1;
02885 
02886 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
02887   struct rlimit rl;
02888 
02889   ACE_OS::memset ((void *) &rl, 0, sizeof rl);
02890   int r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
02891   if (r == 0)
02892     max_limit = rl.rlim_max;
02893 #endif /* ACE_LACKS_RLIMIT */
02894 
02895   if (new_limit == -1)
02896     new_limit = max_limit;
02897 
02898   if (new_limit < 0)
02899     {
02900       errno = EINVAL;
02901       return -1;
02902     }
02903   else if (new_limit > cur_limit)
02904     {
02905       // Increase the limit.
02906 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
02907       rl.rlim_cur = new_limit;
02908       return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl);
02909 #else
02910       // Must return EINVAL errno.
02911       ACE_NOTSUP_RETURN (-1);
02912 #endif /* ACE_LACKS_RLIMIT */
02913     }
02914   else if (increase_limit_only == 0)
02915     {
02916       // Decrease the limit.
02917 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
02918       rl.rlim_cur = new_limit;
02919       return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl);
02920 #else
02921       // We give a chance to platforms without RLIMIT to work.
02922       // Instead of ACE_NOTSUP_RETURN (0), just return 0 because
02923       // new_limit is <= cur_limit, so it's a no-op.
02924       return 0;
02925 #endif /* ACE_LACKS_RLIMIT */
02926     }
02927 
02928   return 0;
02929 }

const ACE_TCHAR * ACE::sock_error int  error  ) 
 

Returns a string containing the error message corresponding to a WinSock error. This works around an omission in the Win32 API.

For internal use only.

Definition at line 3006 of file ACE.cpp.

References ACE_NOTSUP_RETURN, ACE_TCHAR, ACE_TEXT, and ACE_OS::sprintf().

Referenced by ACE_Log_Msg::log(), and ACE_OS::strerror().

03007 {
03008 #if defined (ACE_WIN32)
03009   static ACE_TCHAR unknown_msg[64];
03010 
03011   switch (error)
03012     {
03013     case WSAVERNOTSUPPORTED:
03014       return ACE_TEXT ("version of WinSock not supported");
03015       /* NOTREACHED */
03016     case WSASYSNOTREADY:
03017       return ACE_TEXT ("WinSock not present or not responding");
03018       /* NOTREACHED */
03019     case WSAEINVAL:
03020       return ACE_TEXT ("app version not supported by DLL");
03021       /* NOTREACHED */
03022     case WSAHOST_NOT_FOUND:
03023       return ACE_TEXT ("Authoritive: Host not found");
03024       /* NOTREACHED */
03025     case WSATRY_AGAIN:
03026       return ACE_TEXT ("Non-authoritive: host not found or server failure");
03027       /* NOTREACHED */
03028     case WSANO_RECOVERY:
03029       return ACE_TEXT ("Non-recoverable: refused or not implemented");
03030       /* NOTREACHED */
03031     case WSANO_DATA:
03032       return ACE_TEXT ("Valid name, no data record for type");
03033       /* NOTREACHED */
03034       /*
03035         case WSANO_ADDRESS:
03036         return "Valid name, no MX record";
03037       */
03038     case WSANOTINITIALISED:
03039       return ACE_TEXT ("WSA Startup not initialized");
03040       /* NOTREACHED */
03041     case WSAENETDOWN:
03042       return ACE_TEXT ("Network subsystem failed");
03043       /* NOTREACHED */
03044     case WSAEINPROGRESS:
03045       return ACE_TEXT ("Blocking operation in progress");
03046       /* NOTREACHED */
03047     case WSAEINTR:
03048       return ACE_TEXT ("Blocking call cancelled");
03049       /* NOTREACHED */
03050     case WSAEAFNOSUPPORT:
03051       return ACE_TEXT ("address family not supported");
03052       /* NOTREACHED */
03053     case WSAEMFILE:
03054       return ACE_TEXT ("no file handles available");
03055       /* NOTREACHED */
03056     case WSAENOBUFS:
03057       return ACE_TEXT ("no buffer space available");
03058       /* NOTREACHED */
03059     case WSAEPROTONOSUPPORT:
03060       return ACE_TEXT ("specified protocol not supported");
03061       /* NOTREACHED */
03062     case WSAEPROTOTYPE:
03063       return ACE_TEXT ("protocol wrong type for this socket");
03064       /* NOTREACHED */
03065     case WSAESOCKTNOSUPPORT:
03066       return ACE_TEXT ("socket type not supported for address family");
03067       /* NOTREACHED */
03068     case WSAENOTSOCK:
03069       return ACE_TEXT ("handle is not a socket");
03070       /* NOTREACHED */
03071     case WSAEWOULDBLOCK:
03072       return ACE_TEXT ("resource temporarily unavailable");
03073       /* NOTREACHED */
03074     case WSAEADDRINUSE:
03075       return ACE_TEXT ("address already in use");
03076       /* NOTREACHED */
03077     case WSAECONNABORTED:
03078       return ACE_TEXT ("connection aborted");
03079       /* NOTREACHED */
03080     case WSAECONNRESET:
03081       return ACE_TEXT ("connection reset");
03082       /* NOTREACHED */
03083     case WSAENOTCONN:
03084       return ACE_TEXT ("not connected");
03085       /* NOTREACHED */
03086     case WSAETIMEDOUT:
03087       return ACE_TEXT ("connection timed out");
03088       /* NOTREACHED */
03089     case WSAECONNREFUSED:
03090       return ACE_TEXT ("connection refused");
03091       /* NOTREACHED */
03092     case WSAEHOSTDOWN:
03093       return ACE_TEXT ("host down");
03094       /* NOTREACHED */
03095     case WSAEHOSTUNREACH:
03096       return ACE_TEXT ("host unreachable");
03097       /* NOTREACHED */
03098     case WSAEADDRNOTAVAIL:
03099       return ACE_TEXT ("address not available");
03100       /* NOTREACHED */
03101     case WSAEISCONN:
03102       return ACE_TEXT ("socket is already connected");
03103       /* NOTREACHED */
03104     case WSAENETRESET:
03105       return ACE_TEXT ("network dropped connection on reset");
03106       /* NOTREACHED */
03107     case WSAEMSGSIZE:
03108       return ACE_TEXT ("message too long");
03109       /* NOTREACHED */
03110     case WSAENETUNREACH:
03111       return ACE_TEXT ("network is unreachable");
03112       /* NOTREACHED */
03113     case WSAEFAULT:
03114       return ACE_TEXT ("bad address");
03115       /* NOTREACHED */
03116     case WSAEDISCON:
03117       return ACE_TEXT ("graceful shutdown in progress");
03118       /* NOTREACHED */
03119     case WSAEACCES:
03120       return ACE_TEXT ("permission denied");
03121       /* NOTREACHED */
03122     case WSAESHUTDOWN:
03123       return ACE_TEXT ("cannot send after socket shutdown");
03124       /* NOTREACHED */
03125     case WSAEPROCLIM:
03126       return ACE_TEXT ("too many processes");
03127       /* NOTREACHED */
03128     case WSAEALREADY:
03129       return ACE_TEXT ("operation already in progress");
03130       /* NOTREACHED */
03131     case WSAEPFNOSUPPORT:
03132       return ACE_TEXT ("protocol family not supported");
03133       /* NOTREACHED */
03134     case WSAENOPROTOOPT:
03135       return ACE_TEXT ("bad protocol option");
03136       /* NOTREACHED */
03137     case WSATYPE_NOT_FOUND:
03138       return ACE_TEXT ("class type not found");
03139       /* NOTREACHED */
03140     case WSAEOPNOTSUPP:
03141       return ACE_TEXT ("operation not supported");
03142       /* NOTREACHED */
03143     case WSAEDESTADDRREQ:
03144       return ACE_TEXT ("destination address required");
03145       /* NOTREACHED */
03146     default:
03147       ACE_OS::sprintf (unknown_msg, ACE_TEXT ("unknown error: %d"), error);
03148       return unknown_msg;
03149       /* NOTREACHED */
03150     }
03151 #else
03152   ACE_UNUSED_ARG (error);
03153   ACE_NOTSUP_RETURN (0);
03154 #endif /* ACE_WIN32 */
03155 }

ACE_INLINE void ACE::strdelete wchar_t *  s  ) 
 

Definition at line 281 of file ACE.inl.

00282 {
00283   delete [] s;
00284 }

ACE_INLINE void ACE::strdelete char *  s  ) 
 

Delete the memory allocated by strnew.

Definition at line 274 of file ACE.inl.

Referenced by ACE_Process_Options::command_line_argv(), ACE_Service_Type_Impl::name(), ACE_Framework_Component::~ACE_Framework_Component(), and ACE_Process_Options::~ACE_Process_Options().

00275 {
00276   delete [] s;
00277 }

const wchar_t * ACE::strend const wchar_t *  s  ) 
 

Definition at line 3316 of file ACE.cpp.

References ACE_TEXT_WIDE.

03317 {
03318   while (*s++ != ACE_TEXT_WIDE ('\0'))
03319     continue;
03320 
03321   return s;
03322 }

const char * ACE::strend const char *  s  ) 
 

Returns a pointer to the "end" of the string, i.e., the character past the ''.

Definition at line 3306 of file ACE.cpp.

03307 {
03308   while (*s++ != '\0')
03309     continue;
03310 
03311   return s;
03312 }

ACE_TCHAR * ACE::strenvdup const ACE_TCHAR str  ) 
 

Return a dynamically allocated duplicate of str, substituting the environment variable if str[0] == '$'. Note that the pointer is allocated with ACE_OS::malloc and must be freed by ACE_OS::free.

Definition at line 379 of file ACE.cpp.

References ACE_TCHAR, ACE_TRACE, and ACE_OS::strenvdup().

00380 {
00381   ACE_TRACE ("ACE::strenvdup");
00382 
00383   return ACE_OS::strenvdup (str);
00384 }

wchar_t * ACE::strndup const wchar_t *  str,
size_t  n
 

Definition at line 3239 of file ACE.cpp.

References ACE_ALLOCATOR_RETURN, and ACE_OS::strsncpy().

03240 {
03241   const wchar_t *t = str;
03242   size_t len;
03243 
03244   // Figure out how long this string is (remember, it might not be
03245   // NUL-terminated).
03246 
03247   for (len = 0;
03248        len < n && *t++ != '\0';
03249        len++)
03250     continue;
03251 
03252   wchar_t *s;
03253   ACE_ALLOCATOR_RETURN (s,
03254                         static_cast<wchar_t *> (
03255             ACE_OS::malloc ((len + 1) * sizeof (wchar_t))),
03256                         0);
03257   return ACE_OS::strsncpy (s, str, len + 1);
03258 }

char * ACE::strndup const char *  str,
size_t  n
 

Create a fresh new copy of str, up to n chars long. Uses ACE_OS::malloc to allocate the new string.

Definition at line 3217 of file ACE.cpp.

References ACE_ALLOCATOR_RETURN, and ACE_OS::strsncpy().

03218 {
03219   const char *t = str;
03220   size_t len;
03221 
03222   // Figure out how long this string is (remember, it might not be
03223   // NUL-terminated).
03224 
03225   for (len = 0;
03226        len < n && *t++ != '\0';
03227        len++)
03228     continue;
03229 
03230   char *s;
03231   ACE_ALLOCATOR_RETURN (s,
03232                         (char *) ACE_OS::malloc (len + 1),
03233                         0);
03234   return ACE_OS::strsncpy (s, str, len + 1);
03235 }

wchar_t * ACE::strnew const wchar_t *  s  ) 
 

Definition at line 3342 of file ACE.cpp.

References ACE_NEW_RETURN, and ACE_OS::strcpy().

03343 {
03344   if (s == 0)
03345     return 0;
03346   wchar_t *t = 0;
03347   ACE_NEW_RETURN (t,
03348                   wchar_t[ACE_OS::strlen (s) + 1],
03349                   0);
03350   if (t == 0)
03351     return 0;
03352   else
03353     return ACE_OS::strcpy (t, s);
03354 }

char * ACE::strnew const char *  s  ) 
 

This method is just like strdup, except that it uses operator new rather than malloc. If s is NULL returns NULL rather than segfaulting.

Definition at line 3326 of file ACE.cpp.

References ACE_NEW_RETURN, and ACE_OS::strcpy().

Referenced by ACE_Logging_Strategy::ACE_Logging_Strategy(), ACE_Process_Options::command_line_argv(), ACE_MEM_Acceptor::mmap_prefix(), ACE_Service_Type_Impl::name(), ACE_Service_Type::name(), ACE_DLL_Handle::open(), ACE_DLL::open_i(), and ACE_Logging_Strategy::parse_args().

03327 {
03328   if (s == 0)
03329     return 0;
03330   char *t = 0;
03331   ACE_NEW_RETURN (t,
03332                   char [ACE_OS::strlen (s) + 1],
03333                   0);
03334   if (t == 0)
03335     return 0;
03336   else
03337     return ACE_OS::strcpy (t, s);
03338 }

wchar_t * ACE::strnnew const wchar_t *  str,
size_t  n
 

Definition at line 3284 of file ACE.cpp.

References ACE_NEW_RETURN, ACE_TEXT_WIDE, and ACE_OS::strsncpy().

03285 {
03286   const wchar_t *t = str;
03287   size_t len;
03288 
03289   // Figure out how long this string is (remember, it might not be
03290   // NUL-terminated).
03291 
03292   for (len = 0;
03293        len < n && *t++ != ACE_TEXT_WIDE ('\0');
03294        len++)
03295     continue;
03296 
03297   wchar_t *s;
03298   ACE_NEW_RETURN (s,
03299                   wchar_t[len + 1],
03300                   0);
03301   return ACE_OS::strsncpy (s, str, len + 1);
03302 }

char * ACE::strnnew const char *  str,
size_t  n
 

Create a fresh new copy of str, up to n chars long. Uses ACE_OS::malloc to allocate the new string.

Definition at line 3262 of file ACE.cpp.

References ACE_NEW_RETURN, and ACE_OS::strsncpy().

03263 {
03264   const char *t = str;
03265   size_t len;
03266 
03267   // Figure out how long this string is (remember, it might not be
03268   // NUL-terminated).
03269 
03270   for (len = 0;
03271        len < n && *t++ != L'\0';
03272        len++)
03273     continue;
03274 
03275   char *s;
03276   ACE_NEW_RETURN (s,
03277                   char[len + 1],
03278                   0);
03279   return ACE_OS::strsncpy (s, str, len + 1);
03280 }

size_t ACE::strrepl wchar_t *  s,
wchar_t  search,
wchar_t  replace
 

As strrepl, but for wide characters.

Definition at line 756 of file Lib_Find.cpp.

References ACE_TRACE.

00757 {
00758   ACE_TRACE ("ACE::strrepl");
00759 
00760   size_t replaced = 0;
00761 
00762   for (size_t i = 0; s[i] != '\0'; i++)
00763     if (s[i] == search)
00764       {
00765         s[i] = replace;
00766         replaced++;
00767       }
00768 
00769   return replaced;
00770 }

size_t ACE::strrepl char *  s,
char  search,
char  replace
 

Replace all instances of search in s with replace. Returns the number of replacements made.

Definition at line 668 of file Lib_Find.cpp.

References ACE_TRACE.

Referenced by ldfind().

00669 {
00670   ACE_TRACE ("ACE::strrepl");
00671 
00672   size_t replaced = 0;
00673 
00674   for (size_t i = 0; s[i] != '\0'; i++)
00675     if (s[i] == search)
00676       {
00677         s[i] = replace;
00678         replaced++;
00679       }
00680 
00681   return replaced;
00682 }

wchar_t * ACE::strsplit_r wchar_t *  s,
const wchar_t *  token,
wchar_t *&  next_start
 

As strsplit_r, but for wide characters.

Definition at line 723 of file Lib_Find.cpp.

References ACE_OS::strlen(), and ACE_OS::strstr().

00726 {
00727   wchar_t *result = 0;
00728 
00729   if (str != 0)
00730     next_start = str;
00731 
00732   if (next_start != 0)
00733     {
00734       wchar_t *tok_loc = ACE_OS::strstr (next_start, token);
00735 
00736       if (tok_loc != 0)
00737         {
00738           // Return the beginning of the string.
00739           result = next_start;
00740 
00741           // Insure it's terminated.
00742           *tok_loc = '\0';
00743           next_start = tok_loc + ACE_OS::strlen (token);
00744         }
00745       else
00746         {
00747           result = next_start;
00748           next_start = (wchar_t *) 0;
00749         }
00750     }
00751 
00752   return result;
00753 }

char * ACE::strsplit_r char *  s,
const char *  token,
char *&  next_start
 

Splits string into pieces separated by the string . is an opaque cookie handed back by the call to store its state for the next invocation, thus making it re-entrant. This operates very similar to Perl's function except that it returns pieces one at a time instead of into an array.

Definition at line 689 of file Lib_Find.cpp.

References ACE_OS::strlen(), and ACE_OS::strstr().

Referenced by ldfind().

00692 {
00693   char *result = 0;
00694 
00695   if (str != 0)
00696     next_start = str;
00697 
00698   if (next_start != 0)
00699     {
00700       char *tok_loc = ACE_OS::strstr (next_start, token);
00701 
00702       if (tok_loc != 0)
00703         {
00704           // Return the beginning of the string.
00705           result = next_start;
00706 
00707           // Insure it's terminated.
00708           *tok_loc = '\0';
00709           next_start = tok_loc + ACE_OS::strlen (token);
00710         }
00711       else
00712         {
00713           result = next_start;
00714           next_start = (char *) 0;
00715         }
00716     }
00717 
00718   return result;
00719 }

ssize_t ACE::t_rcv ACE_HANDLE  handle,
void *  buf,
size_t  len,
int *  flags,
const ACE_Time_Value timeout = 0
 

Definition at line 474 of file ACE.cpp.

References enter_recv_timedwait(), restore_non_blocking_mode(), ssize_t, and ACE_OS::t_rcv().

Referenced by ACE_TLI_Stream::recv().

00479 {
00480   if (timeout == 0)
00481     return ACE_OS::t_rcv (handle, (char *) buf, len, flags);
00482   else
00483     {
00484       int val = 0;
00485       if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1)
00486         return -1;
00487       else
00488         {
00489           ssize_t bytes_transferred =
00490             ACE_OS::t_rcv (handle, (char *) buf, len, flags);
00491           ACE::restore_non_blocking_mode (handle, val);
00492           return bytes_transferred;
00493         }
00494     }
00495 }

ACE_INLINE ssize_t ACE::t_rcv_n ACE_HANDLE  handle,
void *  buf,
size_t  len,
int *  flags,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 66 of file ACE.inl.

References t_rcv_n_i().

Referenced by ACE_TLI_Stream::recv_n().

00072 {
00073   if (timeout == 0)
00074     return ACE::t_rcv_n_i (handle,
00075                            buf,
00076                            len,
00077                            flags,
00078                            bytes_transferred);
00079   else
00080     return ACE::t_rcv_n_i (handle,
00081                            buf,
00082                            len,
00083                            flags,
00084                            timeout,
00085                            bytes_transferred);
00086 }

ssize_t ACE::t_rcv_n_i ACE_HANDLE  handle,
void *  buf,
size_t  len,
int *  flags,
const ACE_Time_Value timeout,
size_t *  bytes_transferred
 

Definition at line 741 of file ACE.cpp.

References EWOULDBLOCK, handle_read_ready(), record_and_set_non_blocking_mode(), restore_non_blocking_mode(), ssize_t, and ACE_OS::t_rcv().

00747 {
00748   size_t temp;
00749   size_t &bytes_transferred = bt == 0 ? temp : *bt;
00750   ssize_t n;
00751   ssize_t result = 0;
00752   int error = 0;
00753 
00754   int val = 0;
00755   ACE::record_and_set_non_blocking_mode (handle, val);
00756 
00757   for (bytes_transferred = 0;
00758        bytes_transferred < len;
00759        bytes_transferred += n)
00760     {
00761       // Try to transfer as much of the remaining data as possible.
00762       // Since the socket is in non-blocking mode, this call will not
00763       // block.
00764       n = ACE_OS::t_rcv (handle,
00765                          (char *) buf + bytes_transferred,
00766                          len - bytes_transferred,
00767                          flags);
00768 
00769       // Check for errors.
00770       if (n == 0 ||
00771           n == -1)
00772         {
00773           // Check for possible blocking.
00774           if (n == -1 &&
00775               errno == EWOULDBLOCK)
00776             {
00777               // Wait upto <timeout> for the blocking to subside.
00778               int rtn = ACE::handle_read_ready (handle,
00779                                                 timeout);
00780 
00781               // Did select() succeed?
00782               if (rtn != -1)
00783                 {
00784                   // Blocking subsided in <timeout> period.  Continue
00785                   // data transfer.
00786                   n = 0;
00787                   continue;
00788                 }
00789             }
00790 
00791           // Wait in select() timed out or other data transfer or
00792           // select() failures.
00793           error = 1;
00794           result = n;
00795           break;
00796         }
00797     }
00798 
00799   ACE::restore_non_blocking_mode (handle, val);
00800 
00801   if (error)
00802     return result;
00803   else
00804     return bytes_transferred;
00805 }

ssize_t ACE::t_rcv_n_i ACE_HANDLE  handle,
void *  buf,
size_t  len,
int *  flags,
size_t *  bytes_transferred
 

Definition at line 690 of file ACE.cpp.

References EWOULDBLOCK, handle_read_ready(), ssize_t, and ACE_OS::t_rcv().

Referenced by t_rcv_n().

00695 {
00696   size_t temp;
00697   size_t &bytes_transferred = bt == 0 ? temp : *bt;
00698   ssize_t n;
00699 
00700   for (bytes_transferred = 0;
00701        bytes_transferred < len;
00702        bytes_transferred += n)
00703     {
00704       // Try to transfer as much of the remaining data as possible.
00705       n = ACE_OS::t_rcv (handle,
00706                          (char *) buf + bytes_transferred,
00707                          len - bytes_transferred,
00708                          flags);
00709       // Check EOF.
00710       if (n == 0)
00711         return 0;
00712 
00713       // Check for other errors.
00714       if (n == -1)
00715         {
00716           // Check for possible blocking.
00717           if (errno == EWOULDBLOCK)
00718             {
00719               // Wait for the blocking to subside.
00720               int result = ACE::handle_read_ready (handle,
00721                                                    0);
00722 
00723               // Did select() succeed?
00724               if (result != -1)
00725                 {
00726                   // Blocking subsided.  Continue data transfer.
00727                   n = 0;
00728                   continue;
00729                 }
00730             }
00731 
00732           // Other data transfer or select() failures.
00733           return -1;
00734         }
00735     }
00736 
00737   return bytes_transferred;
00738 }

ssize_t ACE::t_snd ACE_HANDLE  handle,
const void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout = 0
 

Definition at line 1248 of file ACE.cpp.

References enter_send_timedwait(), restore_non_blocking_mode(), ssize_t, and ACE_OS::t_snd().

Referenced by ACE_TLI_Stream::send().

01253 {
01254   if (timeout == 0)
01255     return ACE_OS::t_snd (handle, (const char *) buf, n, flags);
01256   else
01257     {
01258       int val = 0;
01259       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01260         return -1;
01261       else
01262         {
01263           ssize_t bytes_transferred = ACE_OS::t_snd (handle, (const char *) buf, n, flags);
01264           ACE::restore_non_blocking_mode (handle, val);
01265           return bytes_transferred;
01266         }
01267     }
01268 }

ACE_INLINE ssize_t ACE::t_snd_n ACE_HANDLE  handle,
const void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0
 

Definition at line 156 of file ACE.inl.

References t_snd_n_i().

Referenced by ACE_TLI_Stream::send_n().

00162 {
00163   if (timeout == 0)
00164     return ACE::t_snd_n_i (handle,
00165                            buf,
00166                            len,
00167                            flags,
00168                            bytes_transferred);
00169   else
00170     return ACE::t_snd_n_i (handle,
00171                            buf,
00172                            len,
00173                            flags,
00174                            timeout,
00175                            bytes_transferred);
00176 }

ssize_t ACE::t_snd_n_i ACE_HANDLE  handle,
const void *  buf,
size_t  len,
int  flags,
const ACE_Time_Value timeout,
size_t *  bytes_transferred
 

Definition at line 1518 of file ACE.cpp.

References ENOBUFS, EWOULDBLOCK, handle_write_ready(), record_and_set_non_blocking_mode(), restore_non_blocking_mode(), ssize_t, and ACE_OS::t_snd().

01524 {
01525   size_t temp;
01526   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01527   ssize_t n;
01528   ssize_t result = 0;
01529   int error = 0;
01530 
01531   int val = 0;
01532   ACE::record_and_set_non_blocking_mode (handle, val);
01533 
01534   for (bytes_transferred = 0;
01535        bytes_transferred < len;
01536        bytes_transferred += n)
01537     {
01538       // Try to transfer as much of the remaining data as possible.
01539       // Since the socket is in non-blocking mode, this call will not
01540       // block.
01541       n = ACE_OS::t_snd (handle,
01542                          (char *) buf + bytes_transferred,
01543                          len - bytes_transferred,
01544                          flags);
01545 
01546       // Check for errors.
01547       if (n == 0 ||
01548           n == -1)
01549         {
01550           // Check for possible blocking.
01551           if (n == -1 &&
01552               errno == EWOULDBLOCK || errno == ENOBUFS)
01553             {
01554               // Wait upto <timeout> for the blocking to subside.
01555               int rtn = ACE::handle_write_ready (handle,
01556                                                  timeout);
01557 
01558               // Did select() succeed?
01559               if (rtn != -1)
01560                 {
01561                   // Blocking subsided in <timeout> period.  Continue
01562                   // data transfer.
01563                   n = 0;
01564                   continue;
01565                 }
01566             }
01567 
01568           // Wait in select() timed out or other data transfer or
01569           // select() failures.
01570           error = 1;
01571           result = n;
01572           break;
01573         }
01574     }
01575 
01576   ACE::restore_non_blocking_mode (handle, val);
01577 
01578   if (error)
01579     return result;
01580   else
01581     return bytes_transferred;
01582 }

ssize_t ACE::t_snd_n_i ACE_HANDLE  handle,
const void *  buf,
size_t  len,
int  flags,
size_t *  bytes_transferred
 

Definition at line 1467 of file ACE.cpp.

References ENOBUFS, EWOULDBLOCK, handle_write_ready(), ssize_t, and ACE_OS::t_snd().

Referenced by t_snd_n().

01472 {
01473   size_t temp;
01474   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01475   ssize_t n;
01476 
01477   for (bytes_transferred = 0;
01478        bytes_transferred < len;
01479        bytes_transferred += n)
01480     {
01481       // Try to transfer as much of the remaining data as possible.
01482       n = ACE_OS::t_snd (handle,
01483                          (char *) buf + bytes_transferred,
01484                          len - bytes_transferred,
01485                          flags);
01486       // Check EOF.
01487       if (n == 0)
01488         return 0;
01489 
01490       // Check for other errors.
01491       if (n == -1)
01492         {
01493           // Check for possible blocking.
01494           if (errno == EWOULDBLOCK || errno == ENOBUFS)
01495             {
01496               // Wait for the blocking to subside.
01497               int result = ACE::handle_write_ready (handle,
01498                                                     0);
01499 
01500               // Did select() succeed?
01501               if (result != -1)
01502                 {
01503                   // Blocking subsided.  Continue data transfer.
01504                   n = 0;
01505                   continue;
01506                 }
01507             }
01508 
01509           // Other data transfer or select() failures.
01510           return -1;
01511         }
01512     }
01513 
01514   return bytes_transferred;
01515 }

int ACE::terminate_process pid_t  pid  ) 
 

Terminate the process abruptly with id pid. On Win32 platforms this uses {TerminateProcess} and on POSIX platforms is uses {kill} with the -9 (SIGKILL) signal, which cannot be caught or ignored. Note that this call is potentially dangerous to use since the process being terminated may not have a chance to cleanup before it shuts down.

Definition at line 223 of file ACE.cpp.

References ACE_NOTSUP_RETURN, ACE_OS::close(), ACE_OS::kill(), and pid_t.

Referenced by ACE_Process_Manager::terminate(), and ACE_Process::terminate().

00224 {
00225 #if defined (ACE_HAS_PHARLAP)
00226   ACE_UNUSED_ARG (pid);
00227   ACE_NOTSUP_RETURN (-1);
00228 #elif defined (ACE_WIN32)
00229   // Create a handle for the given process id.
00230   ACE_HANDLE process_handle =
00231     ::OpenProcess (PROCESS_TERMINATE,
00232                    FALSE, // New handle is not inheritable.
00233                    pid);
00234 
00235   if (process_handle == ACE_INVALID_HANDLE
00236       || process_handle == 0)
00237     return -1;
00238   else
00239     {
00240       // Kill the process associated with process_handle.
00241       BOOL terminate_result =
00242         ::TerminateProcess (process_handle, 0);
00243       // Free up the kernel resources.
00244       ACE_OS::close (process_handle);
00245       return terminate_result ? 0 : -1;
00246     }
00247 #else
00248   return ACE_OS::kill (pid, 9);
00249 #endif /* ACE_HAS_PHARLAP */
00250 }

ACE_TCHAR * ACE::timestamp ACE_TCHAR  date_and_time[],
int  time_len,
int  return_pointer_to_first_digit = 0
 

Returns the current timestamp in the form "hour:minute:second:microsecond." The month, day, and year are also stored in the beginning of the date_and_time array, which is a user-supplied array of size time_len> ACE_TCHARs. Returns 0 if unsuccessful, else returns pointer to beginning of the "time" portion of date_and_time. If return_pointer_to_first_digit is 0 then return a pointer to the space before the time, else return a pointer to the beginning of the time portion.

Definition at line 2392 of file ACE.cpp.

References ACE_TCHAR, ACE_TEXT, ACE_OS::ctime_r(), ACE_OS::gettimeofday(), ACE_Time_Value::sec(), ACE_OS::sprintf(), ACE_OS::strsncpy(), and ACE_Time_Value::usec().

Referenced by ACE_Log_Msg_UNIX_Syslog::log(), and ACE_Log_Msg::log().

02395 {
02396   //ACE_TRACE ("ACE::timestamp");
02397 
02398   if (date_and_timelen < 35)
02399     {
02400       errno = EINVAL;
02401       return 0;
02402     }
02403 
02404 #if defined (WIN32)
02405   // Emulate Unix.  Win32 does NOT support all the UNIX versions
02406   // below, so DO we need this ifdef.
02407   static const ACE_TCHAR *day_of_week_name[] =
02408     {
02409       ACE_TEXT ("Sun"),
02410       ACE_TEXT ("Mon"),
02411       ACE_TEXT ("Tue"),
02412       ACE_TEXT ("Wed"),
02413       ACE_TEXT ("Thu"),
02414       ACE_TEXT ("Fri"),
02415       ACE_TEXT ("Sat")
02416     };
02417 
02418   static const ACE_TCHAR *month_name[] =
02419     {
02420       ACE_TEXT ("Jan"),
02421       ACE_TEXT ("Feb"),
02422       ACE_TEXT ("Mar"),
02423       ACE_TEXT ("Apr"),
02424       ACE_TEXT ("May"),
02425       ACE_TEXT ("Jun"),
02426       ACE_TEXT ("Jul"),
02427       ACE_TEXT ("Aug"),
02428       ACE_TEXT ("Sep"),
02429       ACE_TEXT ("Oct"),
02430       ACE_TEXT ("Nov"),
02431       ACE_TEXT ("Dec")
02432     };
02433 
02434   SYSTEMTIME local;
02435   ::GetLocalTime (&local);
02436 
02437   ACE_OS::sprintf (date_and_time,
02438                    ACE_TEXT ("%3s %3s %2d %04d %02d:%02d:%02d.%06d"),
02439                    day_of_week_name[local.wDayOfWeek],
02440                    month_name[local.wMonth - 1],
02441                    (int) local.wDay,
02442                    (int) local.wYear,
02443                    (int) local.wHour,
02444                    (int) local.wMinute,
02445                    (int) local.wSecond,
02446                    (int) (local.wMilliseconds * 1000));
02447   return &date_and_time[15 + (return_pointer_to_first_digit != 0)];
02448 #else  /* UNIX */
02449   ACE_TCHAR timebuf[26]; // This magic number is based on the ctime(3c) man page.
02450   ACE_Time_Value cur_time = ACE_OS::gettimeofday ();
02451   time_t secs = cur_time.sec ();
02452 
02453   ACE_OS::ctime_r (&secs,
02454                    timebuf,
02455                    sizeof timebuf);
02456   // date_and_timelen > sizeof timebuf!
02457   ACE_OS::strsncpy (date_and_time,
02458                     timebuf,
02459                     date_and_timelen);
02460   ACE_TCHAR yeartmp[5];
02461   ACE_OS::strsncpy (yeartmp,
02462                     &date_and_time[20],
02463                     5);
02464   ACE_TCHAR timetmp[9];
02465   ACE_OS::strsncpy (timetmp,
02466                     &date_and_time[11],
02467                     9);
02468   ACE_OS::sprintf (&date_and_time[11],
02469 #  if defined (ACE_USES_WCHAR)
02470                    ACE_TEXT ("%ls %ls.%06ld"),
02471 #  else
02472                    ACE_TEXT ("%s %s.%06ld"),
02473 #  endif /* ACE_USES_WCHAR */
02474                    yeartmp,
02475                    timetmp,
02476                    cur_time.usec ());
02477   date_and_time[33] = '\0';
02478   return &date_and_time[15 + (return_pointer_to_first_digit != 0)];
02479 #endif /* WIN32 */
02480 }

ACE_INLINE void ACE::unique_name const void *  object,
ACE_TCHAR name,
size_t  length
 

This method uses process id and object pointer to come up with a machine wide unique name. The process ID will provide uniqueness between processes on the same machine. The "this" pointer of the {object} will provide uniqueness between other "live" objects in the same process. The uniqueness of this name is therefore only valid for the life of {object}.

Definition at line 288 of file ACE.inl.

References ACE_TCHAR, and ACE_OS::unique_name().

Referenced by ACE_Semaphore::ACE_Semaphore(), ACE_RW_Process_Mutex::unique_name(), and ACE_Process_Mutex::unique_name().

00291 {
00292   ACE_OS::unique_name (object, name, length);
00293 }

bool ACE::wild_match const char *  s,
const char *  pattern,
bool  case_sensitive = true
 

Simple wildcard matching function supporting '*' and '?' return true if string s matches pattern.

Definition at line 3365 of file ACE.cpp.

References equal_char().

03366 {
03367   if (str == pat)
03368     return true;
03369   if (pat == 0 || str == 0)
03370     return false;
03371 
03372   bool star = false;
03373   const char* s = str;
03374   const char* p = pat;
03375   while (*s != '\0')
03376     {
03377       if (*p == '*')
03378   {
03379     star = true;
03380     pat = p;
03381     while (*++pat == '*');
03382 
03383     if (*pat == '\0')
03384       return true;
03385     p = pat;
03386   }
03387       else if (*p == '?')
03388   {
03389     ++s;
03390     ++p;
03391   }
03392       else if (! equal_char(*s, *p, case_sensitive))
03393   {
03394     if (!star)
03395       return false;
03396     s = ++str;
03397     p = pat;
03398   }
03399       else
03400   {
03401     ++s;
03402     ++p;
03403   }
03404     }
03405   if (*p == '*')
03406     while (*++p == '*');
03407 
03408   return *p == '\0';
03409 }

ssize_t ACE::write_n ACE_HANDLE  handle,
const ACE_Message_Block message_block,
size_t *  bytes_transferred = 0
 

Write all the message_blocks chained through their next and cont pointers. This call uses the underlying OS gather-write operation to reduce the domain-crossing penalty.

Definition at line 1902 of file ACE.cpp.

References ACE_IOV_MAX, ACE_Message_Block::cont(), ACE_Message_Block::length(), ACE_Message_Block::next(), ACE_Message_Block::rd_ptr(), ssize_t, and writev_n().

01905 {
01906   size_t temp;
01907   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01908   bytes_transferred = 0;
01909 
01910   iovec iov[ACE_IOV_MAX];
01911   int iovcnt = 0;
01912 
01913   while (message_block != 0)
01914     {
01915       // Our current message block chain.
01916       const ACE_Message_Block *current_message_block = message_block;
01917 
01918       while (current_message_block != 0)
01919         {
01920           size_t current_message_block_length =
01921             current_message_block->length ();
01922           char *this_block_ptr = current_message_block->rd_ptr ();
01923 
01924           // Check if this block has any data to be sent.
01925           while (current_message_block_length > 0)
01926             {
01927               u_long this_chunk_length;
01928               if (current_message_block_length > ULONG_MAX)
01929                 this_chunk_length = ULONG_MAX;
01930               else
01931                 this_chunk_length =
01932                   static_cast<u_long> (current_message_block_length);
01933               // Collect the data in the iovec.
01934               iov[iovcnt].iov_base = this_block_ptr;
01935               iov[iovcnt].iov_len  = this_chunk_length;
01936               current_message_block_length -= this_chunk_length;
01937               this_block_ptr += this_chunk_length;
01938 
01939               // Increment iovec counter.
01940               ++iovcnt;
01941 
01942               // The buffer is full make a OS call.  @@ TODO find a way to
01943               // find ACE_IOV_MAX for platforms that do not define it rather
01944               // than simply setting ACE_IOV_MAX to some arbitrary value such
01945               // as 16.
01946               if (iovcnt == ACE_IOV_MAX)
01947                 {
01948                   size_t current_transfer = 0;
01949 
01950                   ssize_t result = ACE::writev_n (handle,
01951                                                   iov,
01952                                                   iovcnt,
01953                                                   &current_transfer);
01954 
01955                   // Add to total bytes transferred.
01956                   bytes_transferred += current_transfer;
01957 
01958                   // Errors.
01959                   if (result == -1 || result == 0)
01960                     return result;
01961 
01962                   // Reset iovec counter.
01963                   iovcnt = 0;
01964                 }
01965             }
01966 
01967           // Select the next message block in the chain.
01968           current_message_block = current_message_block->cont ();
01969         }
01970 
01971       // Selection of the next message block chain.
01972       message_block = message_block->next ();
01973     }
01974 
01975   // Check for remaining buffers to be sent.  This will happen when
01976   // ACE_IOV_MAX is not a multiple of the number of message blocks.
01977   if (iovcnt != 0)
01978     {
01979       size_t current_transfer = 0;
01980 
01981       ssize_t result = ACE::writev_n (handle,
01982                                       iov,
01983                                       iovcnt,
01984                                       &current_transfer);
01985 
01986       // Add to total bytes transferred.
01987       bytes_transferred += current_transfer;
01988 
01989       // Errors.
01990       if (result == -1 || result == 0)
01991         return result;
01992     }
01993 
01994   // Return total bytes transferred.
01995   return bytes_transferred;
01996 }

ACE_INLINE ssize_t ACE::write_n ACE_HANDLE  handle,
const void *  buf,
size_t  len,
size_t *  bytes_transferred = 0
 

Definition at line 29 of file ACE.inl.

References ACE_OS::write_n().

Referenced by ACE_SPIPE_Stream::send_n(), ACE_Pipe::send_n(), ACE_FILE_IO::send_n(), and ACE_DEV_IO::send_n().

00033 {
00034   return ACE_OS::write_n (handle,
00035                           buf,
00036                           len,
00037                           bytes_transferred);
00038 }

ssize_t ACE::writev_n ACE_HANDLE  handle,
const iovec *  iov,
int  iovcnt,
size_t *  bytes_transferred = 0
 

Definition at line 2137 of file ACE.cpp.

References ssize_t, and ACE_OS::writev().

Referenced by ACE_SPIPE_Stream::sendv_n(), ACE_Pipe::sendv_n(), ACE_FILE_IO::sendv_n(), and write_n().

02141 {
02142   size_t temp;
02143   size_t &bytes_transferred = bt == 0 ? temp : *bt;
02144   bytes_transferred = 0;
02145 
02146   iovec *iov = const_cast<iovec *> (i);
02147 
02148   for (int s = 0;
02149        s < iovcnt;
02150        )
02151     {
02152       ssize_t n = ACE_OS::writev (handle,
02153                                   iov + s,
02154                                   iovcnt - s);
02155       if (n == -1 || n == 0)
02156         return n;
02157 
02158       for (bytes_transferred += n;
02159            s < iovcnt
02160              && n >= static_cast<ssize_t> (iov[s].iov_len);
02161            s++)
02162         n -= iov[s].iov_len;
02163 
02164       if (n != 0)
02165         {
02166           char *base = reinterpret_cast<char *> (iov[s].iov_base);
02167           iov[s].iov_base = base + n;
02168           iov[s].iov_len = iov[s].iov_len - n;
02169         }
02170     }
02171 
02172   return bytes_transferred;
02173 }


Variable Documentation

size_t ACE::allocation_granularity_ = 0
 

Definition at line 53 of file ACE.cpp.

char ACE::debug_
 

Definition at line 60 of file ACE.cpp.

ACE_BEGIN_VERSIONED_NAMESPACE_DECL unsigned int ACE::init_fini_count_ = 0
 

Counter to match <init()>/<fini()> calls. <init()> must increment it; <fini()> must decrement it. <fini()> then does nothing until it reaches 0.

Definition at line 12 of file Init_ACE.cpp.

size_t ACE::pagesize_ = 0
 

Definition at line 56 of file ACE.cpp.


Generated on Sun Jan 27 12:59:35 2008 for ACE by doxygen 1.3.6