Namespaces | Classes | Functions | Variables

ACE Namespace Reference

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

Namespaces

namespace  Monitor_Control

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...

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, bool character_classes=false)
ACE_Export int handle_timed_accept (ACE_HANDLE listener, ACE_Time_Value *timeout, bool 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)
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)
bool isdotdir (const char *s)
 Determine if a specified pathname is "dot dir" (ie. "." or "..").
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 (const ACE_Time_Value &time_value, ACE_TCHAR date_and_time[], size_t time_len, bool return_pointer_to_first_digit=false)
ACE_Export ACE_TCHARtimestamp (ACE_TCHAR date_and_time[], size_t time_len, bool return_pointer_to_first_digit=false)
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 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)
void unique_name (const void *object, ACE_TCHAR *name, size_t length)
u_long log2 (u_long num)
 Computes the base 2 logarithm of {num}.
ACE_Export ACE_TCHAR nibble2hex (u_int n)
 Hex conversion utility.
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)
int handle_read_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout)
 Timed wait for handle to get read ready.
int handle_write_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout)
 Timed wait for handle to get write ready.
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)
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 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)
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 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.
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 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)
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)
 Receive into a variable number of pieces.
ACE_Export ssize_t recv (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout=0)
 Receive into a variable number of pieces.
ACE_Export ssize_t recvmsg (ACE_HANDLE handle, struct msghdr *msg, int flags, const ACE_Time_Value *timeout=0)
 Receive into a variable number of pieces.
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)
 Receive into a variable number of pieces.
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)
 Receive into a variable number of pieces.
ssize_t recv_n (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
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)
 Receive into a variable number of pieces.
ssize_t recvv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
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)
 Receive into a variable number of pieces.
ACE_Export ssize_t send (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0)
 Receive into a variable number of pieces.
ACE_Export ssize_t send (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout=0)
 Receive into a variable number of pieces.
ACE_Export ssize_t sendmsg (ACE_HANDLE handle, const struct msghdr *msg, int flags, const ACE_Time_Value *timeout=0)
 Receive into a variable number of pieces.
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)
 Receive into a variable number of pieces.
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)
 Receive into a variable number of pieces.
ssize_t send_n (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
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)
 Receive into a variable number of pieces.
ssize_t sendv_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
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)
ssize_t read_n (ACE_HANDLE handle, void *buf, size_t len, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
ssize_t write_n (ACE_HANDLE handle, const void *buf, size_t len, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
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)
 Receive into a variable number of pieces.
ACE_Export ssize_t writev_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.

Variables

unsigned int init_fini_count_

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 410 of file ACE.cpp.

{
  ACE_TRACE ("ACE::basename");
  const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);

  if (temp == 0)
    return pathname;
  else
    return temp + 1;
}

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 121 of file ACE.cpp.

{
  return ACE_BETA_VERSION;
}

ACE_Export 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.

int ACE::clr_flags ( ACE_HANDLE  handle,
int  flags 
)

Clear flags associated with handle.

Definition at line 62 of file Flag_Manip.cpp.

{
  ACE_TRACE ("ACE::clr_flags");

#if defined (ACE_LACKS_FCNTL)
  switch (flags)
    {
    case ACE_NONBLOCK:
      // nonblocking argument (1)
      // blocking:            (0)
      {
        int nonblock = 0;
        return ACE_OS::ioctl (handle, FIONBIO, &nonblock);
      }
    default:
      ACE_NOTSUP_RETURN (-1);
    }
#else
  int val = ACE_OS::fcntl (handle, F_GETFL, 0);

  if (val == -1)
    return -1;

  // Turn flags off.
  ACE_CLR_BITS (val, flags);

  if (ACE_OS::fcntl (handle, F_SETFL, val) == -1)
    return -1;
  else
    return 0;
#endif /* ACE_LACKS_FCNTL */
}

u_int ACE::compiler_beta_version ( void   ) 

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

Definition at line 157 of file ACE.cpp.

{
#ifdef ACE_CC_BETA_VERSION
  return ACE_CC_BETA_VERSION;
#else
  return 0;
#endif
}

u_int ACE::compiler_major_version ( void   ) 

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

Definition at line 137 of file ACE.cpp.

{
#ifdef ACE_CC_MAJOR_VERSION
  return ACE_CC_MAJOR_VERSION;
#else
  return 0;
#endif
}

u_int ACE::compiler_minor_version ( void   ) 

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

Definition at line 147 of file ACE.cpp.

{
#ifdef ACE_CC_MINOR_VERSION
  return ACE_CC_MINOR_VERSION;
#else
  return 0;
#endif
}

const ACE_TCHAR * ACE::compiler_name ( void   ) 

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

Definition at line 127 of file ACE.cpp.

{
#ifdef ACE_CC_NAME
  return ACE_CC_NAME;
#else
  return ACE_TEXT ("");
#endif
}

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 1403 of file Sock_Connect.cpp.

{
#if defined (SIOCGIFNUM)
# if defined (SIOCGLIFNUM) && !defined (ACE_LACKS_STRUCT_LIFNUM)
  int cmd = SIOCGLIFNUM;
  struct lifnum if_num = {AF_UNSPEC,0,0};
# else
  int cmd = SIOCGIFNUM;
  int if_num = 0;
# endif /* SIOCGLIFNUM */
  if (ACE_OS::ioctl (handle, cmd, (caddr_t)&if_num) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("ACE::count_interfaces:")
                       ACE_TEXT ("ioctl - SIOCGLIFNUM failed")),
                      -1);
# if defined (SIOCGLIFNUM) && !defined (ACE_LACKS_STRUCT_LIFNUM)
  how_many = if_num.lifn_count;
# else
  how_many = if_num;
# endif /* SIOCGLIFNUM */
return 0;

#elif (defined (__unix) || defined (__unix__) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS) || (defined (ACE_VXWORKS) && !defined (ACE_HAS_GETIFADDRS))) && !defined (ACE_LACKS_NETWORKING)
  // Note: DEC CXX doesn't define "unix".  BSD compatible OS: HP UX,
  // AIX, SunOS 4.x perform some ioctls to retrieve ifconf list of
  // ifreq structs no SIOCGIFNUM on SunOS 4.x, so use guess and scan
  // algorithm

  // Probably hard to put this many ifs in a unix box..
  int const MAX_IF = 50;

  // HACK - set to an unreasonable number
  int const num_ifs = MAX_IF;

  struct ifconf ifcfg;
  size_t ifreq_size = num_ifs * sizeof (struct ifreq);
  struct ifreq *p_ifs = (struct ifreq *) ACE_OS::malloc (ifreq_size);

  if (!p_ifs)
    {
      errno = ENOMEM;
      return -1;
    }

  ACE_OS::memset (p_ifs, 0, ifreq_size);
  ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf));

  ifcfg.ifc_req = p_ifs;
  ifcfg.ifc_len = ifreq_size;

  if (ACE_OS::ioctl (handle,
                     SIOCGIFCONF_CMD,
                     (caddr_t) &ifcfg) == -1)
    {
      ACE_OS::free (ifcfg.ifc_req);
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("ACE::count_interfaces:")
                         ACE_TEXT ("ioctl - SIOCGIFCONF failed")),
                        -1);
    }

  int if_count = 0;
  int i = 0;

  // get if address out of ifreq buffers.  ioctl puts a blank-named
  // interface to mark the end of the returned interfaces.
  for (i = 0;
       i < num_ifs;
       i++)
    {
      /* In OpenBSD, the length of the list is returned. */
      ifcfg.ifc_len -= sizeof (struct ifreq);
      if (ifcfg.ifc_len < 0)
        break;

      ++if_count;
#if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__)
      ++p_ifs;
#else
     if (p_ifs->ifr_addr.sa_len <= sizeof (struct sockaddr))
       {
          ++p_ifs;
       }
       else
       {
          p_ifs = (struct ifreq *)
              (p_ifs->ifr_addr.sa_len + (caddr_t) &p_ifs->ifr_addr);
       }
#endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__)*/
    }

  ACE_OS::free (ifcfg.ifc_req);

# if defined (ACE_HAS_IPV6)
  FILE* fp = 0;

  if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0)
    {
      // Scan the lines according to the expected format but don't really read any input
      while (fscanf (fp, "%*32s %*02x %*02x %*02x %*02x %*8s\n") != EOF)
        {
          ++if_count;
        }
      ACE_OS::fclose (fp);
    }
# endif /* ACE_HAS_IPV6 */

  how_many = if_count;
  return 0;
#else
  ACE_UNUSED_ARG (handle);
  ACE_UNUSED_ARG (how_many);
  ACE_NOTSUP_RETURN (-1); // no implementation
#endif /* sparc && SIOCGIFNUM */
}

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.

{
  ACE_UINT32 crc = 0xFFFFFFFF;

  for (const char *p = string;
       *p != 0;
       ++p)
    {
      COMPUTE (crc, *p);
    }

  return ~crc;
}

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.

{
  crc = ~crc;

  for (const char *p = (const char *) buffer,
                  *e = (const char *) buffer + len;
       p != e;
       ++p)
    {
      COMPUTE (crc, *p);
    }

  return ~crc;
}

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.

{
  crc = ~crc;

  for (int i = 0; i < len; ++i)
    {
      for (const char *p = (const char *) iov[i].iov_base,
                      *e = (const char *) iov[i].iov_base + iov[i].iov_len;
           p != e;
           ++p)
        COMPUTE (crc, *p);
    }

  return ~crc;
}

ACE_UINT16 ACE::crc_ccitt ( const char *  str  ) 

Computes CRC-CCITT for the string.

Definition at line 78 of file ACE_crc_ccitt.cpp.

{
  ACE_UINT16 crc = 0xFFFF;

  for (const char *p = string;
       *p != 0;
       ++p)
    {
      COMPUTE (crc, *p);
    }

  return ~crc;
}

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.

{
  crc = ~crc;

  for (const char *p = (const char *) buffer,
                  *e = (const char *) buffer + len;
       p != e;
       ++p)
    {
      COMPUTE (crc, *p);
    }

  return ~crc;
}

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.

{
  crc = ~crc;

  for (int i = 0; i < len; ++i)
    {
      for (const char *p = (const char *) iov[i].iov_base,
                      *e = (const char *) iov[i].iov_base + iov[i].iov_len;
           p != e;
           ++p)
        COMPUTE (crc, *p);
    }

  return ~crc;
}

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 2761 of file ACE.cpp.

{
  ACE_TRACE ("ACE::daemonize");
#if !defined (ACE_LACKS_FORK)
  pid_t pid = ACE_OS::fork ();

  if (pid == -1)
    return -1;
  else if (pid != 0)
    ACE_OS::exit (0); // Parent exits.

  // 1st child continues.
  ACE_OS::setsid (); // Become session leader.

  ACE_OS::signal (SIGHUP, SIG_IGN);

  pid = ACE_OS::fork (program_name);

  if (pid != 0)
    ACE_OS::exit (0); // First child terminates.

  // Second child continues.

  if (pathname != 0)
    // change working directory.
    ACE_OS::chdir (pathname);

  ACE_OS::umask (0); // clear our file mode creation mask.

  // Close down the I/O handles.
  if (close_all_handles)
    {
      for (int i = ACE::max_handles () - 1; i >= 0; i--)
        ACE_OS::close (i);

      int fd = ACE_OS::open ("/dev/null", O_RDWR, 0);
      if (fd != -1)
        {
          ACE_OS::dup2 (fd, ACE_STDIN);
          ACE_OS::dup2 (fd, ACE_STDOUT);
          ACE_OS::dup2 (fd, ACE_STDERR);

          if (fd > ACE_STDERR)
            ACE_OS::close (fd);
        }
    }

  return 0;
#else
  ACE_UNUSED_ARG (pathname);
  ACE_UNUSED_ARG (close_all_handles);
  ACE_UNUSED_ARG (program_name);

  ACE_NOTSUP_RETURN (-1);
#endif /* ACE_LACKS_FORK */
}

bool ACE::debug ( void   ) 

Definition at line 174 of file ACE.cpp.

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

void ACE::debug ( bool  onoff  ) 

Definition at line 181 of file ACE.cpp.

{
  ACE::debug_ = onoff;
}

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 422 of file ACE.cpp.

{
  ACE_TRACE ("ACE::dirname");
  static ACE_TCHAR return_dirname[MAXPATHLEN + 1];

  const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);

  if (temp == 0)
    {
      return_dirname[0] = '.';
      return_dirname[1] = '\0';

      return return_dirname;
    }
  else
    {
      // When the len is truncated, there are problems!  This should
      // not happen in normal circomstances
      size_t len = temp - pathname + 1;
      if (len > (sizeof return_dirname / sizeof (ACE_TCHAR)))
        len = sizeof return_dirname / sizeof (ACE_TCHAR);

      ACE_OS::strsncpy (return_dirname,
                        pathname,
                        len);
      return return_dirname;
    }
}

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 2226 of file ACE.cpp.

{
  int result = ACE::handle_read_ready (handle,
                                       timeout);

  if (result == -1)
    return -1;

  ACE::record_and_set_non_blocking_mode (handle,
                                         val);

  return result;
}

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 2243 of file ACE.cpp.

{
  int result = ACE::handle_write_ready (handle,
                                        timeout);

  if (result == -1)
    return -1;

  ACE::record_and_set_non_blocking_mode (handle,
                                         val);

  return result;
}

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 293 of file ACE.cpp.

{
#if defined (ACE_WIN32)
  const ACE_TCHAR *suffix = ACE_OS::strrchr (old_name, ACE_TEXT ('.'));
  if (suffix == 0 || ACE_OS::strcasecmp (suffix, ACE_TEXT (".exe")) != 0)
    {
      ACE_TCHAR *new_name = 0;

      size_t size =
        ACE_OS::strlen (old_name)
        + ACE_OS::strlen (ACE_TEXT (".exe"))
        + 1;

      ACE_NEW_RETURN (new_name,
                      ACE_TCHAR[size],
                      0);
      ACE_TCHAR *end = new_name;

      end = ACE_OS::strecpy (new_name, old_name);

      // Concatenate the .exe suffix onto the end of the executable.
      // end points _after_ the terminating nul.
      ACE_OS::strcpy (end - 1, ACE_TEXT (".exe"));

      return new_name;
    }
#endif /* ACE_WIN32 */
  return old_name;
}

int ACE::fini ( void   ) 

Finalize the ACE library services and releases ACE's internal resources. In general, do not instantiate ACE classes or call methods on objects of these classes after ACE::fini() has been called.

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.

{
  ACE_TRACE ("ACE::fini");

  if (ACE::init_fini_count_ > 0)
    {
      if (--ACE::init_fini_count_ == 0)
        return ACE_Object_Manager::instance ()->fini ();
      else
        // Wait for remaining fini () calls.
        return 1;
    }
  else
    // More ACE::fini () calls than ACE::init () calls.  Bad
    // application!
    return -1;
}

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 2821 of file ACE.cpp.

{
  if (avoid_zombies == 0)
    return ACE_OS::fork (program_name);
  else
    {
      // This algorithm is adapted from an example in the Stevens book
      // "Advanced Programming in the Unix Environment" and an item in
      // Andrew Gierth's Unix Programming FAQ.  It creates an orphan
      // process that's inherited by the init process; init cleans up
      // when the orphan process terminates.
      //
      // Another way to avoid zombies is to ignore or catch the
      // SIGCHLD signal; we don't use that approach here.

      pid_t pid = ACE_OS::fork ();
      if (pid == 0)
        {
          // The child process forks again to create a grandchild.
          switch (ACE_OS::fork (program_name))
            {
            case 0: // grandchild returns 0.
              return 0;
            case -1: // assumes all errnos are < 256
              ACE_OS::_exit (errno);
            default:  // child terminates, orphaning grandchild
              ACE_OS::_exit (0);
            }
        }

      // Parent process waits for child to terminate.
      ACE_exitcode status;
      if (pid < 0 || ACE_OS::waitpid (pid, &status, 0) < 0)
        return -1;

      // child terminated by calling exit()?
      if (WIFEXITED ((status)))
        {
          // child terminated normally?
          if (WEXITSTATUS ((status)) == 0)
            return 1;
          else
            errno = WEXITSTATUS ((status));
        }
      else
        // child didn't call exit(); perhaps it received a signal?
        errno = EINTR;

      return -1;
    }
}

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 2294 of file ACE.cpp.

{
  ACE_TRACE ("ACE::format_hexdump");

  u_char c;
  ACE_TCHAR textver[16 + 1];

  // We can fit 16 bytes output in text mode per line, 4 chars per byte.
  size_t maxlen = (obuf_sz / 68) * 16;

  if (size > maxlen)
    size = maxlen;

  size_t i;

  size_t const lines = size / 16;
  for (i = 0; i < lines; i++)
    {
      size_t j;

      for (j = 0 ; j < 16; j++)
        {
          c = (u_char) buffer[(i << 4) + j];    // or, buffer[i*16+j]
          ACE_OS::sprintf (obuf,
                           ACE_TEXT ("%02x "),
                           c);
          obuf += 3;
          if (j == 7)
            {
              ACE_OS::sprintf (obuf,
                               ACE_TEXT (" "));
              ++obuf;
            }
          textver[j] = ACE_OS::ace_isprint (c) ? c : '.';
        }

      textver[j] = 0;

      ACE_OS::sprintf (obuf,
#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
                       ACE_TEXT ("  %ls\n"),
#else
                       ACE_TEXT ("  %s\n"),
#endif
                       textver);

      while (*obuf != '\0')
        ++obuf;
    }

  if (size % 16)
    {
      for (i = 0 ; i < size % 16; i++)
        {
          c = (u_char) buffer[size - size % 16 + i];
          ACE_OS::sprintf (obuf,
                           ACE_TEXT ("%02x "),
                           c);
          obuf += 3;
          if (i == 7)
            {
              ACE_OS::sprintf (obuf,
                               ACE_TEXT (" "));
              ++obuf;
            }
          textver[i] = ACE_OS::ace_isprint (c) ? c : '.';
        }

      for (i = size % 16; i < 16; i++)
        {
          ACE_OS::sprintf (obuf,
                           ACE_TEXT ("   "));
          obuf += 3;
          if (i == 7)
            {
              ACE_OS::sprintf (obuf,
                               ACE_TEXT (" "));
              ++obuf;
            }
          textver[i] = ' ';
        }

      textver[i] = 0;
      ACE_OS::sprintf (obuf,
#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
                       ACE_TEXT ("  %ls\n"),
#else
                       ACE_TEXT ("  %s\n"),
#endif
                       textver);
    }
  return size;
}

u_long ACE::gcd ( u_long  x,
u_long  y 
)

Euclid's greatest common divisor algorithm.

Definition at line 2967 of file ACE.cpp.

{
  while (y != 0)
    {
      u_long r = x % y;
      x = y;
      y = r;
    }

  return x;
}

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 198 of file Sock_Connect.cpp.

{
  ACE_TRACE ("ACE::get_bcast_addr");

#if defined (ACE_LACKS_GET_BCAST_ADDR)
  ACE_UNUSED_ARG (bcast_addr);
  ACE_UNUSED_ARG (host_name);
  ACE_UNUSED_ARG (host_addr);
  ACE_UNUSED_ARG (handle);
  ACE_NOTSUP_RETURN (-1);
#elif !defined(ACE_WIN32) && !defined(__INTERIX)
  ACE_HANDLE s = handle;

  if (s == ACE_INVALID_HANDLE)
    s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0);

  if (s == ACE_INVALID_HANDLE)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("ACE_OS::socket")),
                      -1);

  struct ifconf ifc;
  char buf[BUFSIZ];

  ifc.ifc_len = sizeof buf;
  ifc.ifc_buf = buf;

  // Get interface structure and initialize the addresses using UNIX
  // techniques
  if (ACE_OS::ioctl (s, SIOCGIFCONF_CMD, (char *) &ifc) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("ACE::get_bcast_addr:")
                       ACE_TEXT ("ioctl (get interface configuration)")),
                      -1);

  struct ifreq *ifr = ifc.ifc_req;

  struct sockaddr_in ip_addr;

  // Get host ip address if necessary.
  if (host_name)
    {
      hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name));

      if (hp == 0)
        return -1;
      else
#if !defined(_UNICOS)
        ACE_OS::memcpy ((char *) &ip_addr.sin_addr.s_addr,
                        (char *) hp->h_addr,
                        hp->h_length);
#else /* _UNICOS */
      {
        ACE_UINT64 haddr;  // a place to put the address
        char * haddrp = (char *) &haddr;  // convert to char pointer
        ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length);
        ip_addr.sin_addr.s_addr = haddr;
      }
#endif /* ! _UNICOS */
    }
  else
    {
      ACE_OS::memset ((void *) &ip_addr, 0, sizeof ip_addr);
#if !defined(_UNICOS)
      ACE_OS::memcpy ((void *) &ip_addr.sin_addr,
                      (void*) &host_addr,
                      sizeof ip_addr.sin_addr);
#else /* _UNICOS */
      ip_addr.sin_addr.s_addr = host_addr;   // just copy to the bitfield
#endif /* ! _UNICOS */
    }

#if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (__Lynx__)
  for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0;
       n--, ifr++)
#else
  // see mk_broadcast@SOCK_Dgram_Bcast.cpp
  for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) &&
        ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
          (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1);
        ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
          (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len,
            ifr = (struct ifreq *)
              ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) :
          (nbytes -= sizeof (struct ifreq), ifr++)))
#endif /* !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (__Lynx__) */
    {
      struct sockaddr_in if_addr;

      // Compare host ip address with interface ip address.
      ACE_OS::memcpy (&if_addr,
                      &ifr->ifr_addr,
                      sizeof if_addr);

      if (ip_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr)
        continue;

      if (ifr->ifr_addr.sa_family != AF_INET)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("ACE::get_bcast_addr:")
                      ACE_TEXT ("Not AF_INET")));
          continue;
        }

      struct ifreq flags = *ifr;
      struct ifreq if_req = *ifr;

      if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("ACE::get_bcast_addr:")
                      ACE_TEXT (" ioctl (get interface flags)")));
          continue;
        }

      if (ACE_BIT_DISABLED (flags.ifr_flags, IFF_UP))
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("ACE::get_bcast_addr:")
                      ACE_TEXT ("Network interface is not up")));
          continue;
        }

      if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_LOOPBACK))
        continue;

      if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_BROADCAST))
        {
          if (ACE_OS::ioctl (s,
                             SIOCGIFBRDADDR,
                             (char *) &if_req) == -1)
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("%p\n"),
                        ACE_TEXT ("ACE::get_bcast_addr:")
                        ACE_TEXT ("ioctl (get broadaddr)")));
          else
            {
              ACE_OS::memcpy (&ip_addr,
                              &if_req.ifr_broadaddr,
                              sizeof if_req.ifr_broadaddr);

              ACE_OS::memcpy ((void *) &host_addr,
                              (void *) &ip_addr.sin_addr,
                              sizeof host_addr);

              if (handle == ACE_INVALID_HANDLE)
                ACE_OS::close (s);

              bcast_addr = host_addr;
              return 0;
            }
        }
      else
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%p\n"),
                    ACE_TEXT ("ACE::get_bcast_addr:")
                    ACE_TEXT ("Broadcast is not enable for this interface.")));

      if (handle == ACE_INVALID_HANDLE)
        ACE_OS::close (s);

      bcast_addr = host_addr;
      return 0;
    }

  return 0;
#else
  ACE_UNUSED_ARG (handle);
  ACE_UNUSED_ARG (host_addr);
  ACE_UNUSED_ARG (host_name);
  bcast_addr = (ACE_UINT32 (INADDR_BROADCAST));
  return 0;
#endif /* !ACE_WIN32 && !__INTERIX */
}

int ACE::get_flags ( ACE_HANDLE  handle  )  [inline]

Return the current setting of flags associated with handle.

Definition at line 11 of file Flag_Manip.inl.

{
  ACE_TRACE ("ACE::get_flags");

#if defined (ACE_LACKS_FCNTL)
  // ACE_OS::fcntl is not supported.  It
  // would be better to store ACE's notion of the flags
  // associated with the handle, but this works for now.
  ACE_UNUSED_ARG (handle);
  return 0;
#else
  return ACE_OS::fcntl (handle, F_GETFL, 0);
#endif /* ACE_LACKS_FCNTL */
}

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

Get fully qualified host/domain name.

Definition at line 383 of file Sock_Connect.cpp.

{
  int h_error;  // Not the same as errno!
  hostent hentry;
  ACE_HOSTENT_DATA buf;

  char * ip_addr = 0;
  int ip_addr_size = 0;
  if (addr.get_type () == AF_INET)
    {
      sockaddr_in * const sock_addr =
        reinterpret_cast<sockaddr_in *> (addr.get_addr ());
      ip_addr_size = sizeof sock_addr->sin_addr;
      ip_addr = (char*) &sock_addr->sin_addr;
    }
#ifdef ACE_HAS_IPV6
  else
    {
      sockaddr_in6 * sock_addr =
        reinterpret_cast<sockaddr_in6 *> (addr.get_addr ());

      ip_addr_size = sizeof sock_addr->sin6_addr;
      ip_addr = (char*) &sock_addr->sin6_addr;
    }
#endif  /* ACE_HAS_IPV6 */

   // get the host entry for the address in question
   hostent * const hp = ACE_OS::gethostbyaddr_r (ip_addr,
                                                 ip_addr_size,
                                                 addr.get_type (),
                                                 &hentry,
                                                 buf,
                                                 &h_error);

   // if it's not found in the host file or the DNS datase, there is nothing
   // much we can do. embed the IP address
   if (hp == 0 || hp->h_name == 0)
     return -1;

   if (ACE::debug())
     ACE_DEBUG ((LM_DEBUG,
                 ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ")
                 ACE_TEXT ("canonical host name is %C\n"),
                 hp->h_name));

   // check if the canonical name is the FQDN
   if (!ACE_OS::strchr(hp->h_name, '.'))
     {
       // list of address
       char** p;
       // list of aliases
       char** q;

       // for every address and for every alias within the address, check and
       // see if we can locate a FQDN
       for (p = hp->h_addr_list; *p != 0; ++p)
         {
           for (q = hp->h_aliases; *q != 0; ++q)
             {
               if (ACE_OS::strchr(*q, '.'))
                 {
                   // we got an FQDN from an alias. use this
                   if (ACE_OS::strlen (*q) >= len)
                     // the hostname is too huge to fit into a
                     // buffer of size MAXHOSTNAMELEN
                     // should we check other aliases as well
                     // before bailing out prematurely?
                     // for right now, let's do it. this (short name)
                     // is atleast better than embedding the IP
                     // address in the profile
                     continue;

                   if (ACE::debug ())
                     ACE_DEBUG ((LM_DEBUG,
                                 ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ")
                                 ACE_TEXT ("found fqdn within alias as %C\n"),
                                 *q));
                   ACE_OS::strcpy (hostname, *q);

                   return 0;
                 }
             }
         }
     }

   // The canonical name may be an FQDN when we reach here.
   // Alternatively, the canonical name (a non FQDN) may be the best
   // we can do.
   if (ACE_OS::strlen (hp->h_name) >= len)
     {
       // The hostname is too large to fit into a buffer of size
       // MAXHOSTNAMELEN.
       return -2;
     }
   else
     {
       ACE_OS::strcpy (hostname, hp->h_name);
     }

   return 0;
}

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 1524 of file Sock_Connect.cpp.

{
  // Solaris 2.x
  ACE_HANDLE handle = ACE_INVALID_HANDLE;
#if defined (sparc)
  handle = ACE_OS::open ("/dev/udp", O_RDONLY);
#elif defined (__unix) || defined (__unix__) || defined (_AIX) || defined (__hpux) || (defined (ACE_VXWORKS) && (ACE_VXWORKS >= 0x600)) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS)
  // Note: DEC CXX doesn't define "unix" BSD compatible OS: HP UX,
  // AIX, SunOS 4.x

  handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, 0);
#endif /* sparc */
  return handle;
}

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 1180 of file Sock_Connect.cpp.

{
  ACE_TRACE ("ACE::get_ip_interfaces");

  count = 0;
  addrs = 0;

#if defined (ACE_WIN32)
  return get_ip_interfaces_win32 (count, addrs);
#elif defined (ACE_HAS_GETIFADDRS)
  return get_ip_interfaces_getifaddrs (count, addrs);
#elif defined (__hpux)
  return get_ip_interfaces_hpux (count, addrs);
#elif defined (_AIX)
  return get_ip_interfaces_aix (count, addrs);
#elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x600) && !defined (ACE_HAS_VXWORKS551_MEDUSA)
  return get_ip_interfaces_vxworks_lt600 (count, addrs);
#elif (defined (__unix) || defined (__unix__) || defined (ACE_OPENVMS) || (defined (ACE_VXWORKS) && !defined (ACE_HAS_GETIFADDRS)) || defined (ACE_HAS_RTEMS)) && !defined (ACE_LACKS_NETWORKING)
  // COMMON (SVR4 and BSD) UNIX CODE

  // Call specific routine as necessary.
  ACE_HANDLE handle = ACE::get_handle();

  if (handle == ACE_INVALID_HANDLE)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("ACE::get_ip_interfaces:open")),
                      -1);

  size_t num_ifs = 0;

  if (ACE::count_interfaces (handle, num_ifs))
    {
      ACE_OS::close (handle);
      return -1;
    }

  // ioctl likes to have an extra ifreq structure to mark the end of
  // what it returned, so increase the num_ifs by one.
  ++num_ifs;

  struct IFREQ *ifs = 0;
  ACE_NEW_RETURN (ifs,
                  struct IFREQ[num_ifs],
                  -1);
  ACE_OS::memset (ifs, 0, num_ifs * sizeof (struct IFREQ));

  ACE_Auto_Array_Ptr<struct IFREQ> p_ifs (ifs);

  if (p_ifs.get() == 0)
    {
      ACE_OS::close (handle);
      errno = ENOMEM;
      return -1;
    }

  struct IFCONF ifcfg;
  ACE_OS::memset (&ifcfg, 0, sizeof (struct IFCONF));

# ifdef SETFAMILY
  ifcfg.IFC_FAMILY = AF_UNSPEC;  // request all families be returned
  ifcfg.IFC_FLAGS = 0;
# endif

  ifcfg.IFC_REQ = p_ifs.get ();
  ifcfg.IFC_LEN = num_ifs * sizeof (struct IFREQ);

  if (ACE_OS::ioctl (handle,
                     SIOCGIFCONF_CMD,
                     (caddr_t) &ifcfg) == -1)
    {
      ACE_OS::close (handle);
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%p\n"),
                         ACE_TEXT ("ACE::get_ip_interfaces:")
                         ACE_TEXT ("ioctl - SIOCGIFCONF failed")),
                        -1);
    }

  ACE_OS::close (handle);

  // Now create and initialize output array.

  ACE_NEW_RETURN (addrs,
                  ACE_INET_Addr[num_ifs],
                  -1); // caller must free

  struct IFREQ *pcur = p_ifs.get ();
  size_t num_ifs_found = ifcfg.IFC_LEN / sizeof (struct IFREQ); // get the number of returned ifs

  // Pull the address out of each INET interface.  Not every interface
  // is for IP, so be careful to count properly.  When setting the
  // INET_Addr, note that the 3rd arg (0) says to leave the byte order
  // (already in net byte order from the interface structure) as is.
  count = 0;

  for (size_t i = 0;
       i < num_ifs_found;
       i++)
    {
      if (pcur->IFR_ADDR.SA_FAMILY == AF_INET
#  if defined (ACE_HAS_IPV6)
          || pcur->IFR_ADDR.SA_FAMILY == AF_INET6
#  endif
          )

        {
# if !defined(_UNICOS)
          struct sockaddr_in *addr =
            reinterpret_cast<sockaddr_in *> (&pcur->IFR_ADDR);

          // Sometimes the kernel returns 0.0.0.0 as an IPv4 interface
          // address; skip those...
          if (addr->sin_addr.s_addr != 0
#  if defined (ACE_HAS_IPV6)
              || (addr->sin_family == AF_INET6 &&
                  !IN6_IS_ADDR_UNSPECIFIED(&reinterpret_cast<sockaddr_in6 *>(addr)->sin6_addr))
#  endif
              )
            {
              int addrlen = static_cast<int> (sizeof (struct sockaddr_in));
#  if defined (ACE_HAS_IPV6)
              if (addr->sin_family == AF_INET6)
                addrlen = static_cast<int> (sizeof (struct sockaddr_in6));
#  endif
              addrs[count].set (addr, addrlen);
              ++count;
            }
# else /* ! _UNICOS */
          // need to explicitly copy on the Cray, since the bitfields kinda
          // screw things up here
          struct sockaddr_in inAddr;

          inAddr.sin_len = pcur->IFR_ADDR.sa_len;
          inAddr.sin_family = pcur->IFR_ADDR.sa_family;
          memcpy((void *)&(inAddr.sin_addr),
                 (const void *)&(pcur->IFR_ADDR.sa_data[8]),
                 sizeof(struct in_addr));

          if (inAddr.sin_addr.s_addr != 0)
            {
              addrs[count].set(&inAddr, sizeof(struct sockaddr_in));
              ++count;
            }
# endif /* ! _UNICOS */
        }

#if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__)
      ++pcur;
#else
      if (pcur->ifr_addr.sa_len <= sizeof (struct sockaddr))
        {
           ++pcur;
        }
      else
        {
           pcur = (struct ifreq *)
               (pcur->ifr_addr.sa_len + (caddr_t) &pcur->ifr_addr);
        }
#endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__) */
    }

# if defined (ACE_HAS_IPV6)
  // Retrieve IPv6 local interfaces by scanning /proc/net/if_inet6 if
  // it exists.  If we cannot open it then ignore possible IPv6
  // interfaces, we did our best;-)
  FILE* fp = 0;
  char addr_p[8][5];
  char s_ipaddr[64];
  int scopeid;
  struct addrinfo hints, *res0;
  int error;

  ACE_OS::memset (&hints, 0, sizeof (hints));
  hints.ai_flags = AI_NUMERICHOST;
  hints.ai_family = AF_INET6;

  if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0)
    {
      while (fscanf (fp,
                     "%4s%4s%4s%4s%4s%4s%4s%4s %02x %*02x %*02x %*02x %*8s\n",
                     addr_p[0], addr_p[1], addr_p[2], addr_p[3],
                     addr_p[4], addr_p[5], addr_p[6], addr_p[7], &scopeid) != EOF)
        {
          // Format the address intoa proper IPv6 decimal address specification and
          // resolve the resulting text using getaddrinfo().

          const char* ip_fmt = "%s:%s:%s:%s:%s:%s:%s:%s%%%d";
          ACE_OS::sprintf (s_ipaddr,
                           ip_fmt,
                           addr_p[0], addr_p[1], addr_p[2], addr_p[3],
                           addr_p[4], addr_p[5], addr_p[6], addr_p[7], scopeid);

          error = getaddrinfo (s_ipaddr, 0, &hints, &res0);
          if (error)
            continue;

          if (res0->ai_family == AF_INET6 &&
                !IN6_IS_ADDR_UNSPECIFIED (&reinterpret_cast<sockaddr_in6 *> (res0->ai_addr)->sin6_addr))
            {
              addrs[count].set(reinterpret_cast<sockaddr_in *> (res0->ai_addr), res0->ai_addrlen);
              ++count;
            }
          freeaddrinfo (res0);

        }
      ACE_OS::fclose (fp);
    }
# endif /* ACE_HAS_IPV6 */

  return 0;
#else
  ACE_UNUSED_ARG (count);
  ACE_UNUSED_ARG (addrs);
  ACE_NOTSUP_RETURN (-1);                      // no implementation
#endif /* ACE_WIN32 */
}

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 588 of file Lib_Find.cpp.

{
  int result;
#if defined (ACE_WIN32)
  result = ACE_TEXT_GetTempPath (static_cast<DWORD> (buffer_len),
                                 buffer);

  // Make sure to return -1 if there is an error
  if ((result == 0 && ::GetLastError () != ERROR_SUCCESS)
      || (result > static_cast<int> (buffer_len)))
    result = -1;

#else /* ACE_WIN32 */

  // NOTE! Non-Windows platforms don't deal with wide chars for env.
  // variables, so do this narrow-char and convert to wide for the
  // caller if necessary.

  // On non-win32 platforms, check to see what the TMPDIR environment
  // variable is defined to be.  If it doesn't exist, just use /tmp
  const char *tmpdir = ACE_OS::getenv ("TMPDIR");

  if (tmpdir == 0)
    tmpdir = "/tmp";

  size_t len = ACE_OS::strlen (tmpdir);

  // Check to see if the buffer is large enough for the string,
  // another /, and its null character (hence the + 2)
  if ((len + 2) > buffer_len)
    {
      result = -1;
    }
  else
    {
      ACE_OS::strcpy (buffer, ACE_TEXT_CHAR_TO_TCHAR (tmpdir));

      // Add a trailing slash because we cannot assume there is already one
      // at the end.  And having an extra one should not cause problems.
      buffer[len] = ACE_TEXT ('/');
      buffer[len + 1] = 0;
      result = 0;
    }
#endif /* ACE_WIN32 */
  return result;
}

int ACE::handle_exception_ready ( ACE_HANDLE  handle,
const ACE_Time_Value timeout 
) [inline]

Timed wait for handle to get exception ready.

Definition at line 263 of file ACE.inl.

{
  return ACE::handle_ready (handle,
                            timeout,
                            0,
                            0,
                            1);
}

int ACE::handle_read_ready ( ACE_HANDLE  handle,
const ACE_Time_Value timeout 
) [inline]

Timed wait for handle to get read ready.

Definition at line 241 of file ACE.inl.

{
  return ACE::handle_ready (handle,
                            timeout,
                            1,
                            0,
                            0);
}

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 2172 of file ACE.cpp.

{
#if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
  ACE_UNUSED_ARG (write_ready);
  ACE_UNUSED_ARG (exception_ready);

  struct pollfd fds;

  fds.fd = handle;
  fds.events = read_ready ? POLLIN : POLLOUT;
  fds.revents = 0;

  int result = ACE_OS::poll (&fds, 1, timeout);
#else
  ACE_Handle_Set handle_set;
  handle_set.set_bit (handle);

  // Wait for data or for the timeout to elapse.
  int select_width;
#  if defined (ACE_WIN32)
  // This arg is ignored on Windows and causes pointer truncation
  // warnings on 64-bit compiles.
  select_width = 0;
#  else
  select_width = int (handle) + 1;
#  endif /* ACE_WIN64 */
  int result = ACE_OS::select (select_width,
                               read_ready ? handle_set.fdset () : 0, // read_fds.
                               write_ready ? handle_set.fdset () : 0, // write_fds.
                               exception_ready ? handle_set.fdset () : 0, // exception_fds.
                               timeout);

#endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */

  switch (result)
    {
    case 0:  // Timer expired.
      errno = ETIME;
      /* FALLTHRU */
    case -1: // we got here directly - select() returned -1.
      return -1;
    case 1: // Handle has data.
      /* FALLTHRU */
    default: // default is case result > 0; return a
      // ACE_ASSERT (result == 1);
      return result;
    }
}

int ACE::handle_timed_accept ( ACE_HANDLE  listener,
ACE_Time_Value timeout,
bool  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 2686 of file ACE.cpp.

{
  ACE_TRACE ("ACE::handle_timed_accept");
  // Make sure we don't bomb out on erroneous values.
  if (listener == ACE_INVALID_HANDLE)
    return -1;

#if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)

  struct pollfd fds;

  fds.fd = listener;
  fds.events = POLLIN;
  fds.revents = 0;

#else
  // Use the select() implementation rather than poll().
  ACE_Handle_Set rd_handle;
  rd_handle.set_bit (listener);
#endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */

  // We need a loop here if <restart> is enabled.

  for (;;)
    {
#if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)

      int n = ACE_OS::poll (&fds, 1, timeout);

#else
      int select_width;
#  if defined (ACE_WIN32)
      // This arg is ignored on Windows and causes pointer truncation
      // warnings on 64-bit compiles.
      select_width = 0;
#  else
      select_width = int (listener) + 1;
#  endif /* ACE_WIN32 */
      int n = ACE_OS::select (select_width,
                              rd_handle, 0, 0,
                              timeout);
#endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */

      switch (n)
        {
        case -1:
          if (errno == EINTR && restart)
            continue;
          else
            return -1;
          /* NOTREACHED */
        case 0:
          if (timeout != 0 && *timeout == ACE_Time_Value::zero)
            errno = EWOULDBLOCK;
          else
            errno = ETIMEDOUT;
          return -1;
          /* NOTREACHED */
        case 1:
          return 0;
          /* NOTREACHED */
        default:
          errno = EINVAL;
          return -1;
          /* NOTREACHED */
        }
    }
}

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 2531 of file ACE.cpp.

{
  ACE_TRACE ("ACE::handle_timed_complete");

#if !defined (ACE_WIN32) && defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)

  struct pollfd fds;

  fds.fd = h;
  fds.events = POLLIN | POLLOUT;
  fds.revents = 0;

#else
  ACE_Handle_Set rd_handles;
  ACE_Handle_Set wr_handles;
  rd_handles.set_bit (h);
  wr_handles.set_bit (h);
#endif /* !ACE_WIN32 && ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */

#if defined (ACE_WIN32)
  // Winsock is different - it sets the exception bit for failed connect,
  // unlike other platforms, where the write bit is set for both success
  // and fail.
  ACE_Handle_Set ex_handles;
  ex_handles.set_bit (h);
#endif /* ACE_WIN32 */

  bool need_to_check = false;
  bool known_failure = false;

#if defined (ACE_WIN32)
  int n = ACE_OS::select (0,    // Ignored on Windows: int (h) + 1,
                          0,
                          wr_handles,
                          ex_handles,
                          timeout);
#else
# if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)

  int n = ACE_OS::poll (&fds, 1, timeout);

# else
  int n = 0;
  if (is_tli)
    n = ACE_OS::select (int (h) + 1,
                        rd_handles,
                        wr_handles,
                        0,
                        timeout);
  else
    n = ACE_OS::select (int (h) + 1,
                        0,
                        wr_handles,
                        0,
                        timeout);
# endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
#endif /* ACE_WIN32 */

  // If we failed to connect within the time period allocated by the
  // caller, then we fail (e.g., the remote host might have been too
  // busy to accept our call).
  if (n <= 0)
    {
      if (n == 0 && timeout != 0)
        errno = ETIME;
      return ACE_INVALID_HANDLE;
    }

  // On Windows, a ready-for-write handle is successfully connected, and
  // ready-for-exception is a failure. On fails, we need to grab the error
  // code via getsockopt.
  // On BSD sockets using select(), the handle becomes writable on
  // completion either success or fail, so if the select() does not time
  // out, we need to check for success/fail.
  // It is believed that TLI sockets use the readable=fail, writeable=success
  // but that hasn't been as well tested.
#if defined (ACE_WIN32)
  ACE_UNUSED_ARG (is_tli);

  // On Win32, ex_handle set indicates a failure. We'll do the check
  // to try and get an errno value, but the connect failed regardless of
  // what getsockopt says about the error.
  if (ex_handles.is_set (h))
    {
      need_to_check = true;
      known_failure = true;
    }
#else
  if (is_tli)
# if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
    need_to_check = (fds.revents & POLLIN) && !(fds.revents & POLLOUT);
# else
    need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h);
# endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */

  else
# if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
    need_to_check = (fds.revents & POLLIN);
# else
    need_to_check = true;
# endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
#endif /* ACE_WIN32 */

  if (need_to_check)
    {
#if defined (SOL_SOCKET) && defined (SO_ERROR)
      int sock_err = 0;
      int sock_err_len = sizeof (sock_err);
      int sockopt_ret = ACE_OS::getsockopt (h, SOL_SOCKET, SO_ERROR,
                                            (char *)&sock_err, &sock_err_len);
      if (sockopt_ret < 0)
        {
          h = ACE_INVALID_HANDLE;
        }

      if (sock_err != 0 || known_failure)
        {
          h = ACE_INVALID_HANDLE;
          errno = sock_err;
        }
#else
      char dummy;

      // The following recv() won't block provided that the
      // ACE_NONBLOCK flag has not been turned off .
      n = ACE::recv (h, &dummy, 1, MSG_PEEK);

      // If no data was read/peeked at, check to see if it's because
      // of a non-connected socket (and therefore an error) or there's
      // just no data yet.
      if (n <= 0)
        {
          if (n == 0)
            {
              errno = ECONNREFUSED;
              h = ACE_INVALID_HANDLE;
            }
          else if (errno != EWOULDBLOCK && errno != EAGAIN)
            h = ACE_INVALID_HANDLE;
        }
#endif
    }

  // 1. The HANDLE is ready for writing and doesn't need to be checked or
  // 2. recv() returned an indication of the state of the socket - if there is
  // either data present, or a recv is legit but there's no data yet,
  // the connection was successfully established.
  return h;
}

ACE_Export 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.

int ACE::handle_write_ready ( ACE_HANDLE  handle,
const ACE_Time_Value timeout 
) [inline]

Timed wait for handle to get write ready.

Definition at line 252 of file ACE.inl.

{
  return ACE::handle_ready (handle,
                            timeout,
                            0,
                            1,
                            0);
}

u_long ACE::hash_pjw ( const char *  str  ) 

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

Definition at line 346 of file ACE.cpp.

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

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 324 of file ACE.cpp.

{
  u_long hash = 0;

  for (size_t i = 0; i < len; i++)
    {
      const char temp = str[i];
      hash = (hash << 4) + (temp * 13);

      u_long g = hash & 0xf0000000;

      if (g)
        {
          hash ^= (g >> 24);
          hash ^= g;
        }
    }

  return hash;
}

u_char ACE::hex2byte ( ACE_TCHAR  c  )  [inline]

Convert a hex character to its byte representation.

Definition at line 337 of file ACE.inl.

{
  if (ACE_OS::ace_isdigit (c))
    return (u_char) (c - ACE_TEXT ('0'));
  else if (ACE_OS::ace_islower (c))
    return (u_char) (10 + c - ACE_TEXT ('a'));
  else
    return (u_char) (10 + c - ACE_TEXT ('A'));
}

ACE_Export int ACE::init ( void   ) 

This method initializes the ACE library services and initializes ACE's internal resources. Applications should not instantiate ACE classes or call methods on objects of these classes until ACE::init() returns successfully.

Returns:
Returns 0 on success, -1 on failure, and 1 if it had already been called.
bool ACE::ipv4_enabled ( void   ) 

Returns true if IPv4 is enabled on the current host; false if not. 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 1569 of file Sock_Connect.cpp.

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

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 1583 of file Sock_Connect.cpp.

{
#if defined (ACE_HAS_IPV6)
  return ace_ipv6_enabled == -1 ?
    ::ip_check (ace_ipv6_enabled, PF_INET6) :
    ace_ipv6_enabled;
#else /* ACE_HAS_IPV6 */
  return 0;
#endif /* !ACE_HAS_IPV6 */
}

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 3025 of file ACE.cpp.

{
  if (n > 3)
    for (u_long factor = min_factor;
         factor <= max_factor;
         ++factor)
      if (n / factor * factor == n)
        return factor;

  return 0;
}

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 3192 of file ACE.cpp.

{
#if defined (ACE_WIN32)
  switch (error)
    {
    case WSAVERNOTSUPPORTED:
    case WSASYSNOTREADY:
    case WSAEINVAL:
    case WSAHOST_NOT_FOUND:
    case WSATRY_AGAIN:
    case WSANO_RECOVERY:
    case WSANO_DATA:
      /*
        case WSANO_ADDRESS:
      */
    case WSANOTINITIALISED:
    case WSAENETDOWN:
    case WSAEINPROGRESS:
    case WSAEINTR:
    case WSAEAFNOSUPPORT:
    case WSAEMFILE:
    case WSAENOBUFS:
    case WSAEPROTONOSUPPORT:
    case WSAEPROTOTYPE:
    case WSAESOCKTNOSUPPORT:
    case WSAENOTSOCK:
    case WSAEWOULDBLOCK:
    case WSAEADDRINUSE:
    case WSAECONNABORTED:
    case WSAECONNRESET:
    case WSAENOTCONN:
    case WSAETIMEDOUT:
    case WSAECONNREFUSED:
    case WSAEHOSTDOWN:
    case WSAEHOSTUNREACH:
    case WSAEADDRNOTAVAIL:
    case WSAEISCONN:
    case WSAENETRESET:
    case WSAEMSGSIZE:
    case WSAENETUNREACH:
    case WSAEFAULT:
    case WSAEDISCON:
    case WSAEACCES:
    case WSAESHUTDOWN:
    case WSAEPROCLIM:
    case WSAEALREADY:
    case WSAEPFNOSUPPORT:
    case WSAENOPROTOOPT:
    case WSATYPE_NOT_FOUND:
    case WSAEOPNOTSUPP:
      return true;
    }
#else
  ACE_UNUSED_ARG (error);
#endif /* ACE_WIN32 */
  return false;
}

bool ACE::isdotdir ( const char *  s  )  [inline]

Determine if a specified pathname is "dot dir" (ie. "." or "..").

Definition at line 288 of file ACE.inl.

{
  return (s[0] == '.' && 
          ((s[1] == 0) || (s[1] == '.' && s[2] == 0)));
}

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 118 of file Lib_Find.cpp.

{
  ACE_TRACE ("ACE::ldfind");
#if defined (ACE_OPENVMS)
  if (ACE_OS::strlen(filename) >= maxpathnamelen)
  {
    errno = ENOMEM;
    return -1;
  }

  dsc$descriptor nameDsc;
  nameDsc.dsc$b_class = DSC$K_CLASS_S;
  nameDsc.dsc$b_dtype = DSC$K_DTYPE_T;
  nameDsc.dsc$w_length = ACE_OS::strlen(filename);
  nameDsc.dsc$a_pointer = (char*)filename;

  char symbol[] = "NULL";
  dsc$descriptor symbolDsc;
  symbolDsc.dsc$b_class = DSC$K_CLASS_S;
  symbolDsc.dsc$b_dtype = DSC$K_DTYPE_T;
  symbolDsc.dsc$w_length = ACE_OS::strlen(symbol);
  symbolDsc.dsc$a_pointer = symbol;

  int symbolValue;
  int result;
  try
  {
    result = LIB$FIND_IMAGE_SYMBOL(&nameDsc, &symbolDsc, &symbolValue, 0, 0);
  }
  catch (chf$signal_array& sig)
  {
    result = sig.chf$l_sig_name;
  }

  int severity = result & STS$M_SEVERITY;
  int conditionId = result & STS$M_COND_ID;
  if (severity == STS$K_SUCCESS || severity == STS$K_WARNING || severity == STS$K_INFO ||
      (severity == STS$K_ERROR && conditionId == (LIB$_KEYNOTFOU & STS$M_COND_ID)))
  {
    ACE_OS::strcpy(pathname, filename);
    return 0;
  }

  if (ACE_OS::strlen(filename) + ACE_OS::strlen(ACE_DLL_PREFIX) >= maxpathnamelen)
  {
    errno = ENOMEM;
    return -1;
  }


  ACE_OS::strcpy(pathname, ACE_DLL_PREFIX);
  ACE_OS::strcat(pathname, filename);
  nameDsc.dsc$w_length = ACE_OS::strlen(pathname);
  nameDsc.dsc$a_pointer = pathname;
  try
  {
    result = LIB$FIND_IMAGE_SYMBOL(&nameDsc, &symbolDsc, &symbolValue, 0, 0);
  }
  catch (chf$signal_array& sig)
  {
    result = sig.chf$l_sig_name;
  }

  severity = result & STS$M_SEVERITY;
  conditionId = result & STS$M_COND_ID;
  if (severity == STS$K_SUCCESS || severity == STS$K_WARNING || severity == STS$K_INFO ||
      (severity == STS$K_ERROR && conditionId == (LIB$_KEYNOTFOU & STS$M_COND_ID)))
  {
    return 0;
  }
  errno = ENOENT;
  return -1;
#endif /* ACE_OPENVMS */

#if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && \
    !defined (ACE_HAS_PHARLAP)
  ACE_TCHAR expanded_filename[MAXPATHLEN];
  if (ACE_TEXT_ExpandEnvironmentStrings (filename,
                                         expanded_filename,
                                         sizeof expanded_filename
                                         / sizeof (ACE_TCHAR)))
    filename = expanded_filename;
#endif /* ACE_WIN32 && !ACE_HAS_WINCE && !ACE_HAS_PHARLAP */

  ACE_TCHAR tempcopy[MAXPATHLEN + 1];
  ACE_TCHAR searchpathname[MAXPATHLEN + 1];
#if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
  ACE_TCHAR decorator[] = ACE_LD_DECORATOR_STR;
  ACE_TCHAR searchfilename[MAXPATHLEN + sizeof(decorator) / sizeof (ACE_TCHAR)];
#else
  ACE_TCHAR searchfilename[MAXPATHLEN + 1];
#endif /* ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */

  // Create a copy of filename to work with.
  if (ACE_OS::strlen (filename) + 1
      > (sizeof tempcopy / sizeof (ACE_TCHAR)))
    {
      errno = ENOMEM;
      return -1;
    }
  else
    ACE_OS::strcpy (tempcopy, filename);

  // Insert canonical directory separators.
  ACE_TCHAR *separator_ptr;

#if (ACE_DIRECTORY_SEPARATOR_CHAR != '/')
  // Make all the directory separators "canonical" to simplify
  // subsequent code.
  ACE::strrepl (tempcopy, ACE_DIRECTORY_SEPARATOR_CHAR, '/');
#endif /* ACE_DIRECTORY_SEPARATOR_CHAR */

  // Separate filename from pathname.
  separator_ptr = ACE_OS::strrchr (tempcopy, '/');

  // This is a relative path.
  if (separator_ptr == 0)
    {
      searchpathname[0] = '\0';
      ACE_OS::strcpy (searchfilename, tempcopy);
    }
  else // This is an absolute path.
    {
      ACE_OS::strcpy (searchfilename, separator_ptr + 1);
      separator_ptr[1] = '\0';
      ACE_OS::strcpy (searchpathname, tempcopy);
    }

  bool has_suffix = false;

  // Check to see if this has an appropriate DLL suffix for the OS
  // platform.
  ACE_TCHAR *s = ACE_OS::strrchr (searchfilename, '.');

  const ACE_TCHAR *dll_suffix = ACE_DLL_SUFFIX;

  if (s != 0)
    {
      // If we have a dot, we have a suffix
      has_suffix = true;

      // Check whether this matches the appropriate platform-specific
      // suffix.
#if defined (ACE_WIN32)
      // Use <ACE_OS::strcasecmp> on any platform with
      // case-insensitive filenames.
      if (ACE_OS::strcasecmp (s, dll_suffix) != 0)
#else
      if (ACE_OS::strcmp (s, dll_suffix) != 0)
#endif /* ACE_WIN32 */
        {
          ACE_ERROR ((LM_WARNING,
                      ACE_TEXT ("Warning: improper suffix for a ")
                      ACE_TEXT ("shared library on this platform: %s\n"),
                      s));
        }
    }

  // Make sure we've got enough space in searchfilename.
  if (ACE_OS::strlen (searchfilename)
      + ACE_OS::strlen (ACE_DLL_PREFIX)
      + (has_suffix ? 0 : ACE_OS::strlen (dll_suffix))
      >= (sizeof searchfilename / sizeof (ACE_TCHAR)))
    {
      errno = ENOMEM;
      return -1;
    }

#if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
  size_t const len_searchfilename = ACE_OS::strlen (searchfilename);
  if (!has_suffix)
    ACE_OS::strcpy (searchfilename + len_searchfilename, decorator);

  for (int tag = 1; tag >= 0; tag --)
    {
      if (tag == 0)
        searchfilename [len_searchfilename] = 0;

#endif /* ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */
      // Use absolute pathname if there is one.
      if (ACE_OS::strlen (searchpathname) > 0)
        {
          if (ACE_OS::strlen (searchfilename)
              + ACE_OS::strlen (searchpathname) >= maxpathnamelen)
            {
              errno = ENOMEM;
              return -1;
            }
          else
            {
#if (ACE_DIRECTORY_SEPARATOR_CHAR != '/')
              // Revert to native path name separators.
              ACE::strrepl (searchpathname,
                            '/',
                            ACE_DIRECTORY_SEPARATOR_CHAR);
#endif /* ACE_DIRECTORY_SEPARATOR_CHAR */
              // First, try matching the filename *without* adding a
              // prefix.
              ACE_OS::sprintf (pathname,
                               ACE_TEXT ("%s%s%s"),
                               searchpathname,
                               searchfilename,
                               has_suffix ? ACE_TEXT ("") : dll_suffix);
              if (ACE_OS::access (pathname, F_OK) == 0)
                return 0;

              // Second, try matching the filename *with* adding a prefix.
              ACE_OS::sprintf (pathname,
                               ACE_TEXT ("%s%s%s%s"),
                               searchpathname,
                               ACE_DLL_PREFIX,
                               searchfilename,
                               has_suffix ? ACE_TEXT ("") : dll_suffix);
              if (ACE_OS::access (pathname, F_OK) == 0)
                return 0;
            }
        }

      // Use relative filenames via LD_LIBRARY_PATH or PATH (depending on
      // OS platform).
      else
        {
#if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
          ACE_TCHAR *file_component = 0;
          DWORD pathlen =
            ACE_TEXT_SearchPath (0,
                                 searchfilename,
                                 dll_suffix,
                                 static_cast<DWORD> (maxpathnamelen),
                                 pathname,
                                 &file_component);
          if (pathlen >= maxpathnamelen)
          {
              errno = ENOMEM;
              return -1;
          }
          else if (pathlen > 0)
              return 0;

          // In case not found we should try again with the ACE_DLL_PREFIX
          // prefixed
          ACE_OS::strcpy (searchfilename, ACE_DLL_PREFIX);
          ACE_OS::strcat (searchfilename, tempcopy);
          pathlen =
            ACE_TEXT_SearchPath (0,
                                 searchfilename,
                                 dll_suffix,
                                 static_cast<DWORD> (maxpathnamelen),
                                 pathname,
                                 &file_component);
          if (pathlen >= maxpathnamelen)
          {
              errno = ENOMEM;
              return -1;
          }
          else if (pathlen > 0)
              return 0;
#else
          ACE_TCHAR *ld_path = 0;
#  if defined ACE_DEFAULT_LD_SEARCH_PATH
          ld_path = const_cast <ACE_TCHAR*> (ACE_DEFAULT_LD_SEARCH_PATH);
#  else
#    if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR)
          ld_path = ACE_OS::getenv (ACE_LD_SEARCH_PATH);
#    else
          // Wide-char, non-Windows only offers char * getenv. So capture
          // it, translate to wide-char, and continue.
          ACE_Ascii_To_Wide wide_ldpath
            (ACE_OS::getenv (ACE_TEXT_ALWAYS_CHAR (ACE_LD_SEARCH_PATH)));
          ld_path = wide_ldpath.wchar_rep ();
#    endif /* ACE_WIN32 || !ACE_USES_WCHAR */
#  endif /* ACE_DEFAULT_LD_SEARCH_PATH */

#if defined (ACE_HAS_WINCE)
            ACE_TCHAR *ld_path_temp = 0;
            if (ld_path != 0)
              {
                ld_path_temp = (ACE_TCHAR *)
                  ACE_OS::malloc ((ACE_OS::strlen (ld_path) + 2)
                                  * sizeof (ACE_TCHAR));
                if (ld_path_temp != 0)
                  {
                    ACE_OS::strcpy (ld_path_temp,
                                    ACE_LD_SEARCH_PATH_SEPARATOR_STR);

                    ACE_OS::strcat (ld_path_temp, ld_path);
                    ld_path = ld_path_temp;
                  }
                else
                  {
                    ACE_OS::free ((void *) ld_path_temp);
                    ld_path = ld_path_temp = 0;
                  }
              }
#endif /* ACE_HAS_WINCE */

          if (ld_path != 0
              && (ld_path = ACE_OS::strdup (ld_path)) != 0)
            {
              // strtok has the strange behavior of not separating the
              // string ":/foo:/bar" into THREE tokens.  One would expect
              // that the first iteration the token would be an empty
              // string, the second iteration would be "/foo", and the
              // third iteration would be "/bar".  However, this is not
              // the case; one only gets two iterations: "/foo" followed
              // by "/bar".

              // This is especially a problem in parsing Unix paths
              // because it is permissible to specify 'the current
              // directory' as an empty entry.  So, we introduce the
              // following special code to cope with this:

              // Look at each dynamic lib directory in the search path.

              ACE_TCHAR *nextholder = 0;
              const ACE_TCHAR *path_entry =
                ACE::strsplit_r (ld_path,
                                 ACE_LD_SEARCH_PATH_SEPARATOR_STR,
                                 nextholder);
              int result = 0;

              for (;;)
                {
                  // Check if at end of search path.
                  if (path_entry == 0)
                    {
                      errno = ENOENT;
                      result = -1;
                      break;
                    }
                  else if (ACE_OS::strlen (path_entry)
                           + 1
                           + ACE_OS::strlen (searchfilename)
                           >= maxpathnamelen)
                    {
                      errno = ENOMEM;
                      result = -1;
                      break;
                    }
                  // This works around the issue where a path might have
                  // an empty component indicating 'current directory'.
                  // We need to do it here rather than anywhere else so
                  // that the loop condition will still work.
                  else if (path_entry[0] == '\0')
                    path_entry = ACE_TEXT (".");

                  // First, try matching the filename *without* adding a
                  // prefix.
                  ACE_OS::sprintf (pathname,
                                   ACE_TEXT ("%s%c%s%s"),
                                   path_entry,
                                   ACE_DIRECTORY_SEPARATOR_CHAR,
                                   searchfilename,
                                   has_suffix ? ACE_TEXT ("") : dll_suffix);
                  if (ACE_OS::access (pathname, F_OK) == 0)
                    break;

                  // Second, try matching the filename *with* adding a
                  // prefix.
                  ACE_OS::sprintf (pathname,
                                   ACE_TEXT ("%s%c%s%s%s"),
                                   path_entry,
                                   ACE_DIRECTORY_SEPARATOR_CHAR,
                                   ACE_DLL_PREFIX,
                                   searchfilename,
                                   has_suffix ? ACE_TEXT ("") : dll_suffix);
                  if (ACE_OS::access (pathname, F_OK) == 0)
                    break;

                  // Fetch the next item in the path
                  path_entry =
                    ACE::strsplit_r (0,
                                     ACE_LD_SEARCH_PATH_SEPARATOR_STR,
                                     nextholder);
                }

#if defined (ACE_HAS_WINCE)
              if (ld_path_temp != 0)
                ACE_OS::free (ld_path_temp);
#endif /* ACE_HAS_WINCE */
              ACE_OS::free ((void *) ld_path);
#if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
               if (result == 0 || tag == 0)
#endif /* ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */
              return result;
            }
#endif /* ACE_WIN32 && !ACE_HAS_WINCE */
        }
#if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK)
    }
#endif /* ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */

  errno = ENOENT;
  return -1;
}

ACE_TCHAR * ACE::ldname ( const ACE_TCHAR entry_point  ) 

Transforms entry_point into a form that can be located in a dynamic library using <dlsym>. 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 <operator new>="">.

Definition at line 532 of file Lib_Find.cpp.

{
  ACE_TRACE ("ACE::ldname");

#if defined(ACE_NEEDS_DL_UNDERSCORE)
  size_t size =
    1 // leading '_'
    + ACE_OS::strlen (entry_point)
    + 1;

  ACE_TCHAR *new_name;
  ACE_NEW_RETURN (new_name,
                  ACE_TCHAR[size],
                  0);

  ACE_OS::strcpy (new_name, ACE_TEXT ("_"));
  ACE_OS::strcat (new_name, entry_point);

  return new_name;
#else /* ACE_NEEDS_DL_UNDERSCORE */
  size_t size =
    ACE_OS::strlen (entry_point)
    + 1;

  ACE_TCHAR *new_name;
  ACE_NEW_RETURN (new_name,
                  ACE_TCHAR[size],
                  0);

  ACE_OS::strcpy (new_name, entry_point);
  return new_name;
#endif /* ACE_NEEDS_DL_UNDERSCORE */
}

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 517 of file Lib_Find.cpp.

{
  ACE_TRACE ("ACE::ldopen");

  ACE_TCHAR buf[MAXPATHLEN + 1];
  if (ACE::ldfind (filename,
                   buf,
                   sizeof (buf) /sizeof (ACE_TCHAR)) == -1)
    return 0;
  else
    return ACE_OS::fopen (buf, type);
}

u_long ACE::log2 ( u_long  num  )  [inline]

Computes the base 2 logarithm of {num}.

Definition at line 312 of file ACE.inl.

{
  u_long log = 0;

  for (; num > 1; ++log)
    num >>= 1;

  return log;
}

u_int ACE::major_version ( void   ) 

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

Definition at line 109 of file ACE.cpp.

{
  return ACE_MAJOR_VERSION;
}

int ACE::map_errno ( int  error  )  [inline]

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

Definition at line 323 of file ACE.inl.

{
#if defined (ACE_WIN32)
  switch (error)
    {
    case WSAEWOULDBLOCK:
      return EAGAIN; // Same as UNIX errno EWOULDBLOCK.
    }
#endif /* ACE_WIN32 */

  return error;
}

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 2875 of file ACE.cpp.

{
  ACE_TRACE ("ACE::max_handles");
#if defined (RLIMIT_NOFILE) && !defined (ACE_LACKS_RLIMIT)
  rlimit rl;
  int const r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
# if !defined (RLIM_INFINITY)
  if (r == 0)
    return rl.rlim_cur;
# else
  if (r == 0 && rl.rlim_cur != RLIM_INFINITY)
    return rl.rlim_cur;
  // If == RLIM_INFINITY, fall through to the ACE_LACKS_RLIMIT sections
# endif /* RLIM_INFINITY */
#endif /* RLIMIT_NOFILE && !ACE_LACKS_RLIMIT */

#if defined (_SC_OPEN_MAX)
  return ACE_OS::sysconf (_SC_OPEN_MAX);
#elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x620)
  return maxFiles;
#elif defined (FD_SETSIZE)
  return FD_SETSIZE;
#else
  ACE_NOTSUP_RETURN (-1);
#endif /* _SC_OPEN_MAX */
}

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 2982 of file ACE.cpp.

{
  // if one of the periods is zero, treat it as though it as
  // uninitialized and return the other period as the frame size
  if (0 == period1)
    {
      return period2;
    }
  if (0 == period2)
    {
      return period1;
    }

  // if neither is zero, find the greatest common divisor of the two periods
  u_long greatest_common_divisor = ACE::gcd (period1, period2);

  // explicitly consider cases to reduce risk of possible overflow errors
  if (greatest_common_divisor == 1)
    {
      // periods are relative primes: just multiply them together
      return period1 * period2;
    }
  else if (greatest_common_divisor == period1)
    {
      // the first period divides the second: return the second
      return period2;
    }
  else if (greatest_common_divisor == period2)
    {
      // the second period divides the first: return the first
      return period1;
    }
  else
    {
      // the current frame size and the entry's effective period
      // have a non-trivial greatest common divisor: return the
      // product of factors divided by those in their gcd.
      return (period1 * period2) / greatest_common_divisor;
    }
}

u_int ACE::minor_version ( void   ) 

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

Definition at line 115 of file ACE.cpp.

{
  return ACE_MINOR_VERSION;
}

ACE_TCHAR ACE::nibble2hex ( u_int  n  ) 

Hex conversion utility.

Definition at line 167 of file ACE.cpp.

{
  // Yes, this works for UNICODE
  return ACE_TEXT ("0123456789abcdef")[n & 0x0f];
}

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 636 of file Lib_Find.cpp.

{
#if defined (ACE_WIN32)
  ACE_UNUSED_ARG (perm);
  ACE_HANDLE handle = ACE_OS::open (name,
                                    mode,
                                    FILE_SHARE_READ
                                    | FILE_SHARE_WRITE
                                    | FILE_SHARE_DELETE);
#else
  // Open it.
  ACE_HANDLE handle = ACE_OS::open (name, mode, perm);
#endif /* ACE_WIN32 */

  if (handle == ACE_INVALID_HANDLE)
    return ACE_INVALID_HANDLE;

  // Unlink it so that the file will be removed automatically when the
  // process goes away.
  if (ACE_OS::unlink (name) == -1)
    return ACE_INVALID_HANDLE;
  else
    // Return the handle.
    return handle;
}

int ACE::out_of_handles ( int  error  ) 

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

Definition at line 67 of file ACE.cpp.

{
  // EMFILE is common to all platforms.
  if (error == EMFILE ||
#if defined (ACE_WIN32)
      // On Win32, we need to check for ENOBUFS also.
      error == ENOBUFS ||
#elif defined (HPUX)
      // On HPUX, we need to check for EADDRNOTAVAIL also.
      error == EADDRNOTAVAIL ||
#elif defined (linux)
      // On linux, we need to check for ENOENT also.
      error == ENOENT ||
      // For RedHat5.2, need to check for EINVAL too.
      error == EINVAL ||
      // Without threads check for EOPNOTSUPP
      error == EOPNOTSUPP ||
#elif defined (sun)
      // On sun, we need to check for ENOSR also.
      error == ENOSR ||
      // Without threads check for ENOTSUP
      error == ENOTSUP ||
#elif defined (__FreeBSD__)
      // On FreeBSD we need to check for EOPNOTSUPP (LinuxThreads) or
      // ENOSYS (libc_r threads) also.
      error == EOPNOTSUPP ||
      error == ENOSYS ||
#elif defined (__OpenBSD__)
      // OpenBSD appears to return EBADF.
      error == EBADF ||
#elif defined (__sgi) // irix
      error == ENOTSUP ||
#elif defined (DIGITAL_UNIX) // osf1
      error == ENOTSUP ||
#endif /* ACE_WIN32 */
      error == ENFILE)
    return 1;
  else
    return 0;
}

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 262 of file ACE.cpp.

{
#if !defined(ACE_WIN32)
  if (ACE_OS::kill (pid, 0) == 0)
    return 1;
  else if (errno == ESRCH)
    return 0;
  else
    return -1;
#else
  // Create a handle for the given process id.
  ACE_HANDLE process_handle =
    ::OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid);
  if (process_handle == ACE_INVALID_HANDLE || process_handle == 0)
    return 0;
  else
    {
      DWORD status;
      int result = 1;
      if (::GetExitCodeProcess (process_handle,
                                &status) == 0
          || status != STILL_ACTIVE)
        result = 0;

      ::CloseHandle (process_handle);
      return result;
    }
#endif /* !ACE_WIN32 */
}

ssize_t ACE::read_n ( ACE_HANDLE  handle,
void *  buf,
size_t  len,
size_t *  bytes_transferred = 0 
) [inline]

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 17 of file ACE.inl.

{
  return ACE_OS::read_n (handle,
                         buf,
                         len,
                         bytes_transferred);
}

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

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 2092 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;

  for (int s = 0;
       s < iovcnt;
       )
    {
      ssize_t n = ACE_OS::readv (handle,
                                 iov + s,
                                 iovcnt - s);

      if (n == -1 || n == 0)
        return n;

      for (bytes_transferred += n;
           s < iovcnt
             && n >= static_cast<ssize_t> (iov[s].iov_len);
           s++)
        n -= iov[s].iov_len;

      if (n != 0)
        {
          char *base = reinterpret_cast<char *> (iov[s].iov_base);
          iov[s].iov_base = base + n;
          iov[s].iov_len = iov[s].iov_len - n;
        }
    }

  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}

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 2260 of file ACE.cpp.

{
  // We need to record whether we are already *in* nonblocking mode,
  // so that we can correctly reset the state when we're done.
  val = ACE::get_flags (handle);

  if (ACE_BIT_DISABLED (val, ACE_NONBLOCK))
    // Set the handle into non-blocking mode if it's not already in
    // it.
    ACE::set_flags (handle, ACE_NONBLOCK);
}

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 929 of file ACE.cpp.

{
  va_list argp;
  int const total_tuples = static_cast<int> (n / 2);
  iovec *iovp = 0;
#if defined (ACE_HAS_ALLOCA)
  iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
#else
  ACE_NEW_RETURN (iovp,
                  iovec[total_tuples],
                  -1);
#endif /* !defined (ACE_HAS_ALLOCA) */

  va_start (argp, n);

  for (int i = 0; i < total_tuples; i++)
    {
      iovp[i].iov_base = va_arg (argp, char *);
      iovp[i].iov_len = va_arg (argp, int);
    }

  ssize_t const result = ACE_OS::recvv (handle, iovp, total_tuples);
#if !defined (ACE_HAS_ALLOCA)
  delete [] iovp;
#endif /* !defined (ACE_HAS_ALLOCA) */
  va_end (argp);
  return result;
}

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

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 452 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE_OS::recv (handle, (char *) buf, len, flags);
  else
    {
      int val = 0;
      if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1)
        return -1;
      else
        {
          ssize_t bytes_transferred =
            ACE_OS::recv (handle, (char *) buf, len, flags);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

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

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 504 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE::recv_i (handle, buf, n);
  else
    {
      int val = 0;
      if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t bytes_transferred = ACE::recv_i (handle, buf, n);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

ssize_t ACE::recv_i ( ACE_HANDLE  handle,
void *  buf,
size_t  len 
) [inline]

Definition at line 231 of file ACE.inl.

{
#if defined (ACE_WIN32) || defined (ACE_OPENVMS) || defined (ACE_TANDEM_T1248_PTHREADS)
  return ACE_OS::recv (handle, (char *) buf, len);
#else
  return ACE_OS::read (handle, (char *) buf, len);
#endif /* ACE_WIN32 */
}

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

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 1113 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;

  iovec iov[ACE_IOV_MAX];
  int iovcnt = 0;

  while (message_block != 0)
    {
      // Our current message block chain.
      const ACE_Message_Block *current_message_block = message_block;

      while (current_message_block != 0)
        {
          size_t current_message_block_length =
            current_message_block->length ();
          char *this_rd_ptr = current_message_block->rd_ptr ();

          // Check if this block has any space for incoming data.
          while (current_message_block_length > 0)
            {
              u_long const this_chunk_length =
                ACE_Utils::truncate_cast<u_long> (
                  current_message_block_length);

              // Collect the data in the iovec.
              iov[iovcnt].iov_base = this_rd_ptr;
              iov[iovcnt].iov_len  = this_chunk_length;
              current_message_block_length -= this_chunk_length;
              this_rd_ptr += this_chunk_length;

              // Increment iovec counter.
              ++iovcnt;

              // The buffer is full make a OS call.  @@ TODO find a way to
              // find ACE_IOV_MAX for platforms that do not define it rather
              // than simply setting ACE_IOV_MAX to some arbitrary value such
              // as 16.
              if (iovcnt == ACE_IOV_MAX)
                {
                  size_t current_transfer = 0;

                  ssize_t const result = ACE::recvv_n (handle,
                                                       iov,
                                                       iovcnt,
                                                       timeout,
                                                       &current_transfer);

                  // Add to total bytes transferred.
                  bytes_transferred += current_transfer;

                  // Errors.
                  if (result == -1 || result == 0)
                    return result;

                  // Reset iovec counter.
                  iovcnt = 0;
                }
            }

          // Select the next message block in the chain.
          current_message_block = current_message_block->cont ();
        }

      // Selection of the next message block chain.
      message_block = message_block->next ();
    }

  // Check for remaining buffers to be sent.  This will happen when
  // ACE_IOV_MAX is not a multiple of the number of message blocks.
  if (iovcnt != 0)
    {
      size_t current_transfer = 0;

      ssize_t const result = ACE::recvv_n (handle,
                                           iov,
                                           iovcnt,
                                           timeout,
                                           &current_transfer);

      // Add to total bytes transferred.
      bytes_transferred += current_transfer;

      // Errors.
      if (result == -1 || result == 0)
        {
          return result;
        }
    }

  // Return total bytes transferred.
  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}

ssize_t ACE::recv_n ( ACE_HANDLE  handle,
void *  buf,
size_t  len,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0 
) [inline]

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 91 of file ACE.inl.

{
  if (timeout == 0)
    return ACE::recv_n_i (handle,
                          buf,
                          len,
                          bytes_transferred);
  else
    return ACE::recv_n_i (handle,
                          buf,
                          len,
                          timeout,
                          bytes_transferred);
}

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 
) [inline]

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 41 of file ACE.inl.

{
  if (timeout == 0)
    return ACE::recv_n_i (handle,
                          buf,
                          len,
                          flags,
                          bytes_transferred);
  else
    return ACE::recv_n_i (handle,
                          buf,
                          len,
                          flags,
                          timeout,
                          bytes_transferred);
}

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

Definition at line 574 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  ssize_t n;

  for (bytes_transferred = 0;
       bytes_transferred < len;
       bytes_transferred += n)
    {
      // Try to transfer as much of the remaining data as possible.
      n = ACE_OS::recv (handle,
                        static_cast <char *> (buf) + bytes_transferred,
                        len - bytes_transferred,
                        flags);
      // Check EOF.
      if (n == 0)
        return 0;

      // Check for other errors.
      if (n == -1)
        {
          // Check for possible blocking.
          if (errno == EWOULDBLOCK)
            {
              // Wait for the blocking to subside.
              int const result = ACE::handle_read_ready (handle, 0);

              // Did select() succeed?
              if (result != -1)
                {
                  // Blocking subsided.  Continue data transfer.
                  n = 0;
                  continue;
                }
            }

          // Other data transfer or select() failures.
          return -1;
        }
    }

  return static_cast<ssize_t> (bytes_transferred);
}

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.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  ssize_t n;

  for (bytes_transferred = 0;
       bytes_transferred < len;
       bytes_transferred += n)
    {
      // Try to transfer as much of the remaining data as possible.
      n = ACE::recv_i (handle,
                       static_cast <char *> (buf) + bytes_transferred,
                       len - bytes_transferred);
      // Check EOF.
      if (n == 0)
        {
          return 0;
        }
      // Check for other errors.
      if (n == -1)
        {
          // Check for possible blocking.
          if (errno == EWOULDBLOCK)
            {
              // Wait for the blocking to subside.
              int const result = ACE::handle_read_ready (handle, 0);

              // Did select() succeed?
              if (result != -1)
                {
                  // Blocking subsided.  Continue data transfer.
                  n = 0;
                  continue;
                }
            }

          // Other data transfer or select() failures.
          return -1;
        }
    }

  return static_cast<ssize_t> (bytes_transferred);
}

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 624 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  ssize_t n;
  ssize_t result = 0;
  int error = 0;

  int val = 0;
  ACE::record_and_set_non_blocking_mode (handle, val);

  for (bytes_transferred = 0;
       bytes_transferred < len;
       bytes_transferred += n)
    {
      // Try to transfer as much of the remaining data as possible.
      // Since the socket is in non-blocking mode, this call will not
      // block.
      n = ACE_OS::recv (handle,
                        static_cast <char *> (buf) + bytes_transferred,
                        len - bytes_transferred,
                        flags);

      // Check for errors.
      if (n == 0 ||
          n == -1)
        {
          // Check for possible blocking.
          if (n == -1 &&
              errno == EWOULDBLOCK)
            {
              // Wait upto <timeout> for the blocking to subside.
              int const rtn = ACE::handle_read_ready (handle, timeout);

              // Did select() succeed?
              if (rtn != -1)
                {
                  // Blocking subsided in <timeout> period.  Continue
                  // data transfer.
                  n = 0;
                  continue;
                }
            }

          // Wait in select() timed out or other data transfer or
          // select() failures.
          error = 1;
          result = n;
          break;
        }
    }

  ACE::restore_non_blocking_mode (handle, val);

  if (error)
    return result;
  else
    return static_cast<ssize_t> (bytes_transferred);
}

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 859 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  ssize_t n;
  ssize_t result = 0;
  int error = 0;

  int val = 0;
  ACE::record_and_set_non_blocking_mode (handle, val);

  for (bytes_transferred = 0;
       bytes_transferred < len;
       bytes_transferred += n)
    {
      // Try to transfer as much of the remaining data as possible.
      // Since the socket is in non-blocking mode, this call will not
      // block.
      n = ACE::recv_i (handle,
                       static_cast <char *> (buf) + bytes_transferred,
                       len - bytes_transferred);

      // Check for errors.
      if (n == 0 ||
          n == -1)
        {
          // Check for possible blocking.
          if (n == -1 &&
              errno == EWOULDBLOCK)
            {
              // Wait upto <timeout> for the blocking to subside.
              int const rtn = ACE::handle_read_ready (handle, timeout);

              // Did select() succeed?
              if (rtn != -1)
                {
                  // Blocking subsided in <timeout> period.  Continue
                  // data transfer.
                  n = 0;
                  continue;
                }
            }

          // Wait in select() timed out or other data transfer or
          // select() failures.
          error = 1;
          result = n;
          break;
        }
    }

  ACE::restore_non_blocking_mode (handle, val);

  if (error)
    return result;
  else
    return static_cast<ssize_t> (bytes_transferred);
}

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

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 548 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen);
  else
    {
      int val = 0;
      if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t bytes_transferred =
            ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

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

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 526 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE_OS::recvmsg (handle, msg, flags);
  else
    {
      int val = 0;
      if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t bytes_transferred = ACE_OS::recvmsg (handle, msg, flags);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

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

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 959 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE_OS::recvv (handle, iov, iovcnt);
  else
    {
      int val = 0;
      if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t bytes_transferred = ACE_OS::recvv (handle, iov, iovcnt);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

ssize_t ACE::recvv_n ( ACE_HANDLE  handle,
iovec *  iov,
int  iovcnt,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0 
) [inline]

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 111 of file ACE.inl.

{
  if (timeout == 0)
    return ACE::recvv_n_i (handle,
                           iov,
                           iovcnt,
                           bytes_transferred);
  else
    return ACE::recvv_n_i (handle,
                           iov,
                           iovcnt,
                           timeout,
                           bytes_transferred);
}

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 1038 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;
  ssize_t result = 0;
  int error = 0;

  int val = 0;
  ACE::record_and_set_non_blocking_mode (handle, val);

  for (int s = 0; s < iovcnt; )
    {
      // Try to transfer as much of the remaining data as possible.
      // Since the socket is in non-blocking mode, this call will not
      // block.
      ssize_t n = ACE_OS::recvv (handle, iov + s, iovcnt - s);

      // Check for errors.
      if (n == 0 || n == -1)
        {
          // Check for possible blocking.
          if (n == -1 && errno == EWOULDBLOCK)
            {
              // Wait upto <timeout> for the blocking to subside.
              int const rtn = ACE::handle_read_ready (handle, timeout);

              // Did select() succeed?
              if (rtn != -1)
                {
                  // Blocking subsided in <timeout> period.  Continue
                  // data transfer.
                  n = 0;
                  continue;
                }
            }

          // Wait in select() timed out or other data transfer or
          // select() failures.
          error = 1;
          result = n;
          break;
        }

      for (bytes_transferred += n;
           s < iovcnt
             && n >= static_cast<ssize_t> (iov[s].iov_len);
           s++)
        n -= iov[s].iov_len;

      if (n != 0)
        {
          char *base = reinterpret_cast<char *> (iov[s].iov_base);
          iov[s].iov_base = base + n;
          iov[s].iov_len = iov[s].iov_len - n;
        }
    }

  ACE::restore_non_blocking_mode (handle, val);

  if (error)
    {
      return result;
    }
  else
    {
      return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
    }
}

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

Definition at line 981 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;

  for (int s = 0; s < iovcnt; )
    {
      // Try to transfer as much of the remaining data as possible.
      ssize_t n = ACE_OS::recvv (handle, iov + s, iovcnt - s);
      // Check EOF.
      if (n == 0)
        return 0;

      // Check for other errors.
      if (n == -1)
        {
          // Check for possible blocking.
          if (errno == EWOULDBLOCK)
            {
              // Wait for the blocking to subside.
              int const result = ACE::handle_read_ready (handle, 0);

              // Did select() succeed?
              if (result != -1)
                {
                  // Blocking subsided.  Continue data transfer.
                  n = 0;
                  continue;
                }
            }

          // Other data transfer or select() failures.
          return -1;
        }

      for (bytes_transferred += n;
           s < iovcnt
             && n >= static_cast<ssize_t> (iov[s].iov_len);
           s++)
        n -= iov[s].iov_len;

      if (n != 0)
        {
          char *base = static_cast<char *> (iov[s].iov_base);
          iov[s].iov_base = base + n;
          iov[s].iov_len = iov[s].iov_len - n;
        }
    }

  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}

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 2274 of file ACE.cpp.

{
  if (ACE_BIT_DISABLED (val,
                        ACE_NONBLOCK))
    {
      // Save/restore errno.
      ACE_Errno_Guard error (errno);
      // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
      // originally.
      ACE::clr_flags (handle, ACE_NONBLOCK);
    }
}

size_t ACE::round_to_allocation_granularity ( size_t  len  ) 

Rounds the request to a multiple of the allocation granularity.

Definition at line 2520 of file ACE.cpp.

{
  ACE_TRACE ("ACE::round_to_allocation_granularity");

  if (ACE::allocation_granularity_ == 0)
    ACE::allocation_granularity_ = ACE_OS::allocation_granularity ();

  return (len + (ACE::allocation_granularity_ - 1)) & ~(ACE::allocation_granularity_ - 1);
}

size_t ACE::round_to_pagesize ( size_t  len  ) 

Rounds the request to a multiple of the page size.

Definition at line 2509 of file ACE.cpp.

{
  ACE_TRACE ("ACE::round_to_pagesize");

  if (ACE::pagesize_ == 0)
    ACE::pagesize_ = ACE_OS::getpagesize ();

  return (len + (ACE::pagesize_ - 1)) & ~(ACE::pagesize_ - 1);
}

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 187 of file ACE.cpp.

{
  int result = ACE_OS::select (width,
                               readfds ? readfds->fdset () : 0,
                               writefds ? writefds->fdset () : 0,
                               exceptfds ? exceptfds->fdset () : 0,
                               timeout);
  if (result > 0)
    {
# if !defined (ACE_WIN32)
      // This isn't needed for Windows... it's a no-op anyway.
      if (readfds)
        readfds->sync ((ACE_HANDLE) width);
      if (writefds)
        writefds->sync ((ACE_HANDLE) width);
      if (exceptfds)
        exceptfds->sync ((ACE_HANDLE) width);
#endif /* ACE_WIN32 */
    }
  return result;
}

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 214 of file ACE.cpp.

{
  int result = ACE_OS::select (width,
                               readfds.fdset (),
                               0,
                               0,
                               timeout);

#if !defined (ACE_WIN32)
  if (result > 0)
    readfds.sync ((ACE_HANDLE) width);
#endif /* ACE_WIN32 */
  return result;
}

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

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 1265 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE::send_i (handle, buf, n);
  else
    {
      int val = 0;
      if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t const bytes_transferred = ACE::send_i (handle, buf, n);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

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

Varargs variant.

Definition at line 1702 of file ACE.cpp.

{
  va_list argp;
  int total_tuples = static_cast<int> (n / 2);
  iovec *iovp;
#if defined (ACE_HAS_ALLOCA)
  iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
#else
  ACE_NEW_RETURN (iovp,
                  iovec[total_tuples],
                  -1);
#endif /* !defined (ACE_HAS_ALLOCA) */

  va_start (argp, n);

  for (int i = 0; i < total_tuples; i++)
    {
      iovp[i].iov_base = va_arg (argp, char *);
      iovp[i].iov_len = va_arg (argp, int);
    }

  ssize_t result = ACE_OS::sendv (handle, iovp, total_tuples);
#if !defined (ACE_HAS_ALLOCA)
  delete [] iovp;
#endif /* !defined (ACE_HAS_ALLOCA) */
  va_end (argp);
  return result;
}

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

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 1213 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE_OS::send (handle, (const char *) buf, n, flags);
  else
    {
      int val = 0;
      if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t const bytes_transferred =
            ACE_OS::send (handle, (const char *) buf, n, flags);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

ssize_t ACE::send_i ( ACE_HANDLE  handle,
const void *  buf,
size_t  len 
) [inline]

Definition at line 221 of file ACE.inl.

{
#if defined (ACE_WIN32) || defined (HPUX)
  return ACE_OS::send (handle, (const char *) buf, len);
#else
  return ACE_OS::write (handle, (const char *) buf, len);
#endif /* ACE_WIN32 */
}

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 
) [inline]

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 181 of file ACE.inl.

{
  if (timeout == 0)
    return ACE::send_n_i (handle,
                          buf,
                          len,
                          bytes_transferred);
  else
    return ACE::send_n_i (handle,
                          buf,
                          len,
                          timeout,
                          bytes_transferred);
}

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 1992 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;

  iovec iov[ACE_IOV_MAX];
  int iovcnt = 0;

  while (message_block != 0)
    {
      // Our current message block chain.
      const ACE_Message_Block *current_message_block = message_block;

      while (current_message_block != 0)
        {
          char *this_block_ptr = current_message_block->rd_ptr ();
          size_t current_message_block_length =
            current_message_block->length ();

          // Check if this block has any data to be sent.
          while (current_message_block_length > 0)
            {
              u_long const this_chunk_length =
                ACE_Utils::truncate_cast<u_long> (
                  current_message_block_length);

              // Collect the data in the iovec.
              iov[iovcnt].iov_base = this_block_ptr;
              iov[iovcnt].iov_len  = this_chunk_length;
              current_message_block_length -= this_chunk_length;
              this_block_ptr += this_chunk_length;

              // Increment iovec counter.
              ++iovcnt;

              // The buffer is full make a OS call.  @@ TODO find a way to
              // find ACE_IOV_MAX for platforms that do not define it rather
              // than simply setting ACE_IOV_MAX to some arbitrary value such
              // as 16.
              if (iovcnt == ACE_IOV_MAX)
                {
                  size_t current_transfer = 0;

                  ssize_t const result = ACE::sendv_n (handle,
                                                       iov,
                                                       iovcnt,
                                                       timeout,
                                                       &current_transfer);

                  // Add to total bytes transferred.
                  bytes_transferred += current_transfer;

                  // Errors.
                  if (result == -1 || result == 0)
                    return result;

                  // Reset iovec counter.
                  iovcnt = 0;
                }
            }

          // Select the next message block in the chain.
          current_message_block = current_message_block->cont ();
        }

      // Selection of the next message block chain.
      message_block = message_block->next ();
    }

  // Check for remaining buffers to be sent.  This will happen when
  // ACE_IOV_MAX is not a multiple of the number of message blocks.
  if (iovcnt != 0)
    {
      size_t current_transfer = 0;

      ssize_t const result = ACE::sendv_n (handle,
                                           iov,
                                           iovcnt,
                                           timeout,
                                           &current_transfer);

      // Add to total bytes transferred.
      bytes_transferred += current_transfer;

      // Errors.
      if (result == -1 || result == 0)
        {
          return result;
        }
    }

  // Return total bytes transferred.
  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}

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 
) [inline]

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 131 of file ACE.inl.

{
  if (timeout == 0)
    return ACE::send_n_i (handle,
                          buf,
                          len,
                          flags,
                          bytes_transferred);
  else
    return ACE::send_n_i (handle,
                          buf,
                          len,
                          flags,
                          timeout,
                          bytes_transferred);
}

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

Definition at line 1579 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  ssize_t n;

  for (bytes_transferred = 0;
       bytes_transferred < len;
       bytes_transferred += n)
    {
      // Try to transfer as much of the remaining data as possible.
      n = ACE::send_i (handle,
                       (char *) buf + bytes_transferred,
                       len - bytes_transferred);
      // Check EOF.
      if (n == 0)
        {
          return 0;
        }

      // Check for other errors.
      if (n == -1)
        {
          // Check for possible blocking.
          if (errno == EWOULDBLOCK || errno == ENOBUFS)
            {
              // Wait for the blocking to subside.
              int const result = ACE::handle_write_ready (handle, 0);

              // Did select() succeed?
              if (result != -1)
                {
                  // Blocking subsided.  Continue data transfer.
                  n = 0;
                  continue;
                }
            }

          // Other data transfer or select() failures.
          return -1;
        }
    }

  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}

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 1629 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  ssize_t n;
  ssize_t result = 0;
  int error = 0;

  int val = 0;
  ACE::record_and_set_non_blocking_mode (handle, val);

  for (bytes_transferred = 0;
       bytes_transferred < len;
       bytes_transferred += n)
    {
      // Try to transfer as much of the remaining data as possible.
      // Since the socket is in non-blocking mode, this call will not
      // block.
      n = ACE::send_i (handle,
                       (char *) buf + bytes_transferred,
                       len - bytes_transferred);

      // Check for errors.
      if (n == 0 ||
          n == -1)
        {
          // Check for possible blocking.
          if (n == -1 &&
              (errno == EWOULDBLOCK || errno == ENOBUFS))
            {
              // Wait upto <timeout> for the blocking to subside.
              int const rtn = ACE::handle_write_ready (handle, timeout);

              // Did select() succeed?
              if (rtn != -1)
                {
                  // Blocking subsided in <timeout> period.  Continue
                  // data transfer.
                  n = 0;
                  continue;
                }
            }

          // Wait in select() timed out or other data transfer or
          // select() failures.
          error = 1;
          result = n;
          break;
        }
    }

  ACE::restore_non_blocking_mode (handle, val);

  if (error)
    {
      return result;
    }
  else
    {
      return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
    }
}

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 1390 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  ssize_t n;
  ssize_t result = 0;
  int error = 0;

  int val = 0;
  ACE::record_and_set_non_blocking_mode (handle, val);

  for (bytes_transferred = 0;
       bytes_transferred < len;
       bytes_transferred += n)
    {
      // Try to transfer as much of the remaining data as possible.
      // Since the socket is in non-blocking mode, this call will not
      // block.
      n = ACE_OS::send (handle,
                        (char *) buf + bytes_transferred,
                        len - bytes_transferred,
                        flags);

      // Check for errors.
      if (n == 0 ||
          n == -1)
        {
          // Check for possible blocking.
          if (n == -1 && (errno == EWOULDBLOCK || errno == ENOBUFS))
            {
              // Wait upto <timeout> for the blocking to subside.
              int const rtn = ACE::handle_write_ready (handle, timeout);

              // Did select() succeed?
              if (rtn != -1)
                {
                  // Blocking subsided in <timeout> period.  Continue
                  // data transfer.
                  n = 0;
                  continue;
                }
            }

          // Wait in select() timed out or other data transfer or
          // select() failures.
          error = 1;
          result = n;
          break;
        }
    }

  ACE::restore_non_blocking_mode (handle, val);

  if (error)
    {
      return result;
    }
  else
    {
      return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
    }
}

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

Definition at line 1336 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  ssize_t n;

  for (bytes_transferred = 0;
       bytes_transferred < len;
       bytes_transferred += n)
    {
      // Try to transfer as much of the remaining data as possible.
      n = ACE_OS::send (handle,
                        (char *) buf + bytes_transferred,
                        len - bytes_transferred,
                        flags);
      // Check EOF.
      if (n == 0)
        return 0;

      // Check for other errors.
      if (n == -1)
        {
          // Check for possible blocking.
#if defined (ACE_WIN32)
          if (errno == EWOULDBLOCK) // If enobufs no need to loop
#else
          if (errno == EWOULDBLOCK || errno == ENOBUFS)
#endif /* ACE_WIN32 */
            {
              // Wait for the blocking to subside.
              int const result = ACE::handle_write_ready (handle, 0);

              // Did select() succeed?
              if (result != -1)
                {
                  // Blocking subsided.  Continue data transfer.
                  n = 0;
                  continue;
                }
            }

          // Other data transfer or select() failures.
          return -1;
        }
    }

  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}

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

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 1287 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE_OS::sendmsg (handle, msg, flags);
  else
    {
      int val = 0;
      if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t const bytes_transferred =
            ACE_OS::sendmsg (handle, msg, flags);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

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 
)

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 1310 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
  else
    {
      int val = 0;
      if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t const bytes_transferred =
            ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

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

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 1732 of file ACE.cpp.

{
  if (timeout == 0)
    return ACE_OS::sendv (handle, iov, iovcnt);
  else
    {
      int val = 0;
      if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
        return -1;
      else
        {
          ssize_t bytes_transferred = ACE_OS::sendv (handle, iov, iovcnt);
          ACE::restore_non_blocking_mode (handle, val);
          return bytes_transferred;
        }
    }
}

ssize_t ACE::sendv_n ( ACE_HANDLE  handle,
const iovec *  iov,
int  iovcnt,
const ACE_Time_Value timeout = 0,
size_t *  bytes_transferred = 0 
) [inline]

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 201 of file ACE.inl.

{
  if (timeout == 0)
    return ACE::sendv_n_i (handle,
                           iov,
                           iovcnt,
                           bytes_transferred);
  else
    return ACE::sendv_n_i (handle,
                           iov,
                           iovcnt,
                           timeout,
                           bytes_transferred);
}

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 1816 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;
  ssize_t result = 0;
  int error = 0;

  int val = 0;
  ACE::record_and_set_non_blocking_mode (handle, val);

  iovec *iov = const_cast<iovec *> (i);

  for (int s = 0;
       s < iovcnt;
       )
    {
      // Try to transfer as much of the remaining data as possible.
      // Since the socket is in non-blocking mode, this call will not
      // block.
      ssize_t n = ACE_OS::sendv (handle, iov + s, iovcnt - s);

      // Check for errors.
      if (n == 0 ||
          n == -1)
        {
          // Check for possible blocking.
          if (n == -1 &&
              (errno == EWOULDBLOCK || errno == ENOBUFS))
            {
              // Wait upto <timeout> for the blocking to subside.
              int const rtn = ACE::handle_write_ready (handle, timeout);

              // Did select() succeed?
              if (rtn != -1)
                {
                  // Blocking subsided in <timeout> period.  Continue
                  // data transfer.
                  n = 0;
                  continue;
                }
            }

          // Wait in select() timed out or other data transfer or
          // select() failures.
          error = 1;
          result = n;
          break;
        }

      for (bytes_transferred += n;
           s < iovcnt
             && n >= static_cast<ssize_t> (iov[s].iov_len);
           s++)
        n -= iov[s].iov_len;

      if (n != 0)
        {
          char *base = reinterpret_cast<char *> (iov[s].iov_base);
          iov[s].iov_base = base + n;
          iov[s].iov_len = iov[s].iov_len - n;
        }
    }

  ACE::restore_non_blocking_mode (handle, val);

  if (error)
    {
      return result;
    }
  else
    {
      return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
    }
}

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

Definition at line 1754 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;

  iovec *iov = const_cast<iovec *> (i);

  for (int s = 0;
       s < iovcnt;
       )
    {
      // Try to transfer as much of the remaining data as possible.
      ssize_t n = ACE_OS::sendv (handle, iov + s, iovcnt - s);
      
      // Check EOF.
      if (n == 0)
        return 0;

      // Check for other errors.
      if (n == -1)
        {
          // Check for possible blocking.
          if (errno == EWOULDBLOCK || errno == ENOBUFS)
            {
              // Wait for the blocking to subside.
              int const result = ACE::handle_write_ready (handle, 0);

              // Did select() succeed?
              if (result != -1)
                {
                  // Blocking subsided.  Continue data transfer.
                  n = 0;
                  continue;
                }
            }

          // Other data transfer or select() failures.
          return -1;
        }

      for (bytes_transferred += n;
           s < iovcnt
             && n >= static_cast<ssize_t> (iov[s].iov_len);
           s++)
        n -= iov[s].iov_len;

      if (n != 0)
        {
          char *base = reinterpret_cast<char *> (iov[s].iov_base);
          iov[s].iov_base = base + n;
          iov[s].iov_len = iov[s].iov_len - n;
        }
    }

  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}

ACE_Export int ACE::set_flags ( ACE_HANDLE  handle,
int  flags 
)

Set flags associated with handle.

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 2908 of file ACE.cpp.

{
  ACE_TRACE ("ACE::set_handle_limit");
  int cur_limit = ACE::max_handles ();
  int max_limit = cur_limit;

  if (cur_limit == -1)
    return -1;

#if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
  struct rlimit rl;

  ACE_OS::memset ((void *) &rl, 0, sizeof rl);
  int r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
  if (r == 0)
    max_limit = rl.rlim_max;
#endif /* ACE_LACKS_RLIMIT */

  if (new_limit == -1)
    new_limit = max_limit;

  if (new_limit < 0)
    {
      errno = EINVAL;
      return -1;
    }
  else if (new_limit > cur_limit)
    {
      // Increase the limit.
#if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
      rl.rlim_cur = new_limit;
      return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl);
#elif defined (ACE_LACKS_RLIMIT_NOFILE)
      return 0;
#else
      // Must return EINVAL errno.
      ACE_NOTSUP_RETURN (-1);
#endif /* ACE_LACKS_RLIMIT */
    }
  else if (increase_limit_only == 0)
    {
      // Decrease the limit.
#if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
      rl.rlim_cur = new_limit;
      return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl);
#else
      // We give a chance to platforms without RLIMIT to work.
      // Instead of ACE_NOTSUP_RETURN (0), just return 0 because
      // new_limit is <= cur_limit, so it's a no-op.
      return 0;
#endif /* ACE_LACKS_RLIMIT */
    }

  return 0;
}

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 3040 of file ACE.cpp.

{
#if defined (ACE_WIN32)
  static ACE_TCHAR unknown_msg[64];

  switch (error)
    {
    case WSAVERNOTSUPPORTED:
      return ACE_TEXT ("version of WinSock not supported");
      /* NOTREACHED */
    case WSASYSNOTREADY:
      return ACE_TEXT ("WinSock not present or not responding");
      /* NOTREACHED */
    case WSAEINVAL:
      return ACE_TEXT ("app version not supported by DLL");
      /* NOTREACHED */
    case WSAHOST_NOT_FOUND:
      return ACE_TEXT ("Authoritive: Host not found");
      /* NOTREACHED */
    case WSATRY_AGAIN:
      return ACE_TEXT ("Non-authoritive: host not found or server failure");
      /* NOTREACHED */
    case WSANO_RECOVERY:
      return ACE_TEXT ("Non-recoverable: refused or not implemented");
      /* NOTREACHED */
    case WSANO_DATA:
      return ACE_TEXT ("Valid name, no data record for type");
      /* NOTREACHED */
      /*
        case WSANO_ADDRESS:
        return "Valid name, no MX record";
      */
    case WSANOTINITIALISED:
      return ACE_TEXT ("WSA Startup not initialized");
      /* NOTREACHED */
    case WSAENETDOWN:
      return ACE_TEXT ("Network subsystem failed");
      /* NOTREACHED */
    case WSAEINPROGRESS:
      return ACE_TEXT ("Blocking operation in progress");
      /* NOTREACHED */
    case WSAEINTR:
      return ACE_TEXT ("Blocking call cancelled");
      /* NOTREACHED */
    case WSAEAFNOSUPPORT:
      return ACE_TEXT ("address family not supported");
      /* NOTREACHED */
    case WSAEMFILE:
      return ACE_TEXT ("no file handles available");
      /* NOTREACHED */
    case WSAENOBUFS:
      return ACE_TEXT ("no buffer space available");
      /* NOTREACHED */
    case WSAEPROTONOSUPPORT:
      return ACE_TEXT ("specified protocol not supported");
      /* NOTREACHED */
    case WSAEPROTOTYPE:
      return ACE_TEXT ("protocol wrong type for this socket");
      /* NOTREACHED */
    case WSAESOCKTNOSUPPORT:
      return ACE_TEXT ("socket type not supported for address family");
      /* NOTREACHED */
    case WSAENOTSOCK:
      return ACE_TEXT ("handle is not a socket");
      /* NOTREACHED */
    case WSAEWOULDBLOCK:
      return ACE_TEXT ("resource temporarily unavailable");
      /* NOTREACHED */
    case WSAEADDRINUSE:
      return ACE_TEXT ("address already in use");
      /* NOTREACHED */
    case WSAECONNABORTED:
      return ACE_TEXT ("connection aborted");
      /* NOTREACHED */
    case WSAECONNRESET:
      return ACE_TEXT ("connection reset");
      /* NOTREACHED */
    case WSAENOTCONN:
      return ACE_TEXT ("not connected");
      /* NOTREACHED */
    case WSAETIMEDOUT:
      return ACE_TEXT ("connection timed out");
      /* NOTREACHED */
    case WSAECONNREFUSED:
      return ACE_TEXT ("connection refused");
      /* NOTREACHED */
    case WSAEHOSTDOWN:
      return ACE_TEXT ("host down");
      /* NOTREACHED */
    case WSAEHOSTUNREACH:
      return ACE_TEXT ("host unreachable");
      /* NOTREACHED */
    case WSAEADDRNOTAVAIL:
      return ACE_TEXT ("address not available");
      /* NOTREACHED */
    case WSAEISCONN:
      return ACE_TEXT ("socket is already connected");
      /* NOTREACHED */
    case WSAENETRESET:
      return ACE_TEXT ("network dropped connection on reset");
      /* NOTREACHED */
    case WSAEMSGSIZE:
      return ACE_TEXT ("message too long");
      /* NOTREACHED */
    case WSAENETUNREACH:
      return ACE_TEXT ("network is unreachable");
      /* NOTREACHED */
    case WSAEFAULT:
      return ACE_TEXT ("bad address");
      /* NOTREACHED */
    case WSAEDISCON:
      return ACE_TEXT ("graceful shutdown in progress");
      /* NOTREACHED */
    case WSAEACCES:
      return ACE_TEXT ("permission denied");
      /* NOTREACHED */
    case WSAESHUTDOWN:
      return ACE_TEXT ("cannot send after socket shutdown");
      /* NOTREACHED */
    case WSAEPROCLIM:
      return ACE_TEXT ("too many processes");
      /* NOTREACHED */
    case WSAEALREADY:
      return ACE_TEXT ("operation already in progress");
      /* NOTREACHED */
    case WSAEPFNOSUPPORT:
      return ACE_TEXT ("protocol family not supported");
      /* NOTREACHED */
    case WSAENOPROTOOPT:
      return ACE_TEXT ("bad protocol option");
      /* NOTREACHED */
    case WSATYPE_NOT_FOUND:
      return ACE_TEXT ("class type not found");
      /* NOTREACHED */
    case WSAEOPNOTSUPP:
      return ACE_TEXT ("operation not supported");
      /* NOTREACHED */
    case WSAEDESTADDRREQ:
      return ACE_TEXT ("destination address required");
      /* NOTREACHED */
    default:
      ACE_OS::sprintf (unknown_msg, ACE_TEXT ("unknown error: %d"), error);
      return unknown_msg;
      /* NOTREACHED */
    }
#else
  ACE_UNUSED_ARG (error);
  ACE_NOTSUP_RETURN (0);
#endif /* ACE_WIN32 */
}

void ACE::strdelete ( char *  s  )  [inline]

Delete the memory allocated by strnew.

Definition at line 274 of file ACE.inl.

{
  delete [] s;
}

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 3340 of file ACE.cpp.

{
  while (*s++ != '\0')
    continue;

  return s;
}

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 384 of file ACE.cpp.

{
  ACE_TRACE ("ACE::strenvdup");

  return ACE_OS::strenvdup (str);
}

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 3251 of file ACE.cpp.

{
  const char *t = str;
  size_t len;

  // Figure out how long this string is (remember, it might not be
  // NUL-terminated).

  for (len = 0;
       len < n && *t++ != '\0';
       len++)
    continue;

  char *s;
  ACE_ALLOCATOR_RETURN (s,
                        (char *) ACE_OS::malloc (len + 1),
                        0);
  return ACE_OS::strsncpy (s, str, len + 1);
}

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 3360 of file ACE.cpp.

{
  if (s == 0)
    return 0;
  char *t = 0;
  ACE_NEW_RETURN (t,
                  char [ACE_OS::strlen (s) + 1],
                  0);
  if (t == 0)
    return 0;
  else
    return ACE_OS::strcpy (t, s);
}

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 3296 of file ACE.cpp.

{
  const char *t = str;
  size_t len;

  // Figure out how long this string is (remember, it might not be
  // NUL-terminated).

  for (len = 0;
       len < n && *t++ != L'\0';
       len++)
    continue;

  char *s;
  ACE_NEW_RETURN (s,
                  char[len + 1],
                  0);
  return ACE_OS::strsncpy (s, str, len + 1);
}

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 663 of file Lib_Find.cpp.

{
  ACE_TRACE ("ACE::strrepl");

  size_t replaced = 0;

  for (size_t i = 0; s[i] != '\0'; i++)
    if (s[i] == search)
      {
        s[i] = replace;
        ++replaced;
      }

  return replaced;
}

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

Splits string <s> into pieces separated by the string <token>. <next_start> 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 <split> function except that it returns pieces one at a time instead of into an array.

Definition at line 684 of file Lib_Find.cpp.

{
  char *result = 0;

  if (str != 0)
    next_start = str;

  if (next_start != 0)
    {
      char *tok_loc = ACE_OS::strstr (next_start, token);

      if (tok_loc != 0)
        {
          // Return the beginning of the string.
          result = next_start;

          // Insure it's terminated.
          *tok_loc = '\0';
          next_start = tok_loc + ACE_OS::strlen (token);
        }
      else
        {
          result = next_start;
          next_start = (char *) 0;
        }
    }

  return result;
}

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 232 of file ACE.cpp.

{
#if defined (ACE_HAS_PHARLAP)
  ACE_UNUSED_ARG (pid);
  ACE_NOTSUP_RETURN (-1);
#elif defined (ACE_WIN32)
  // Create a handle for the given process id.
  ACE_HANDLE process_handle =
    ::OpenProcess (PROCESS_TERMINATE,
                   FALSE, // New handle is not inheritable.
                   pid);

  if (process_handle == ACE_INVALID_HANDLE
      || process_handle == 0)
    return -1;
  else
    {
      // Kill the process associated with process_handle.
      BOOL terminate_result =
        ::TerminateProcess (process_handle, 0);
      // Free up the kernel resources.
      ACE_OS::close (process_handle);
      return terminate_result ? 0 : -1;
    }
#else
  return ACE_OS::kill (pid, 9);
#endif /* ACE_HAS_PHARLAP */
}

ACE_TCHAR * ACE::timestamp ( const ACE_Time_Value time_value,
ACE_TCHAR  date_and_time[],
size_t  time_len,
bool  return_pointer_to_first_digit = false 
)

Returns the given 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 2411 of file ACE.cpp.

{
  //ACE_TRACE ("ACE::timestamp");

  if (date_and_timelen < 35)
    {
      errno = EINVAL;
      return 0;
    }

#if defined (WIN32)
  if (time_value == ACE_Time_Value::zero)
  {
    // Emulate Unix.  Win32 does NOT support all the UNIX versions
    // below, so DO we need this ifdef.
    static const ACE_TCHAR *day_of_week_name[] =
      {
        ACE_TEXT ("Sun"),
        ACE_TEXT ("Mon"),
        ACE_TEXT ("Tue"),
        ACE_TEXT ("Wed"),
        ACE_TEXT ("Thu"),
        ACE_TEXT ("Fri"),
        ACE_TEXT ("Sat")
      };
  
    static const ACE_TCHAR *month_name[] =
      {
        ACE_TEXT ("Jan"),
        ACE_TEXT ("Feb"),
        ACE_TEXT ("Mar"),
        ACE_TEXT ("Apr"),
        ACE_TEXT ("May"),
        ACE_TEXT ("Jun"),
        ACE_TEXT ("Jul"),
        ACE_TEXT ("Aug"),
        ACE_TEXT ("Sep"),
        ACE_TEXT ("Oct"),
        ACE_TEXT ("Nov"),
        ACE_TEXT ("Dec")
      };
  
    SYSTEMTIME local;
    ::GetLocalTime (&local);
  
    ACE_OS::sprintf (date_and_time,
                    ACE_TEXT ("%3s %3s %2d %04d %02d:%02d:%02d.%06d"),
                    day_of_week_name[local.wDayOfWeek],
                    month_name[local.wMonth - 1],
                    (int) local.wDay,
                    (int) local.wYear,
                    (int) local.wHour,
                    (int) local.wMinute,
                    (int) local.wSecond,
                    (int) (local.wMilliseconds * 1000));
    return &date_and_time[15 + (return_pointer_to_first_digit != 0)];
  }
#endif  /* WIN32 */
  ACE_TCHAR timebuf[26]; // This magic number is based on the ctime(3c) man page.
  ACE_Time_Value cur_time = 
    (time_value == ACE_Time_Value::zero) ? 
        ACE_Time_Value (ACE_OS::gettimeofday ()) : time_value;
  time_t secs = cur_time.sec ();

  ACE_OS::ctime_r (&secs,
                   timebuf,
                   sizeof timebuf / sizeof (ACE_TCHAR));
  // date_and_timelen > sizeof timebuf!
  ACE_OS::strsncpy (date_and_time,
                    timebuf,
                    date_and_timelen);
  ACE_TCHAR yeartmp[5];
  ACE_OS::strsncpy (yeartmp,
                    &date_and_time[20],
                    5);
  ACE_TCHAR timetmp[9];
  ACE_OS::strsncpy (timetmp,
                    &date_and_time[11],
                    9);
  ACE_OS::sprintf (&date_and_time[11],
#  if defined (ACE_USES_WCHAR)
                   ACE_TEXT ("%ls %ls.%06ld"),
#  else
                   ACE_TEXT ("%s %s.%06ld"),
#  endif /* ACE_USES_WCHAR */
                   yeartmp,
                   timetmp,
                   cur_time.usec ());
  date_and_time[33] = '\0';
  return &date_and_time[15 + (return_pointer_to_first_digit != 0)];
}

ACE_TCHAR * ACE::timestamp ( ACE_TCHAR  date_and_time[],
size_t  time_len,
bool  return_pointer_to_first_digit = false 
)

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 2396 of file ACE.cpp.

{
  return ACE::timestamp (ACE_Time_Value::zero,
                         date_and_time,
                         date_and_timelen,
                         return_pointer_to_first_digit);
}

void ACE::unique_name ( const void *  object,
ACE_TCHAR name,
size_t  length 
) [inline]

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 304 of file ACE.inl.

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

bool ACE::wild_match ( const char *  s,
const char *  pattern,
bool  case_sensitive = true,
bool  character_classes = false 
)

Simple wildcard matching function supporting '*' and '?' return true if string s matches pattern. If character_classes is true, '[' is treated as a wildcard character as described in the fnmatch() POSIX API. The following POSIX "bracket expression" features are not implemented: collating symbols, equivalence class expressions, and character class expressions. The POSIX locale is assumed.

Definition at line 3448 of file ACE.cpp.

{
  if (str == pat)
    return true;
  if (pat == 0 || str == 0)
    return false;

  bool star = false, escape = false;
  const char *s = str;
  const char *p = pat;
  while (*s != '\0')
    {
      if (!escape && *p == '\\')
        {
          ++p;
          escape = true;
        }
      else if (!escape && *p == '*')
        {
          star = true;
          pat = p;
          while (*++pat == '*') {}

          if (*pat == '\0')
            return true;
          p = pat;
        }
      else if (!escape && *p == '?')
        {
          ++s;
          ++p;
        }
      else if (!escape && character_classes && *p == '[')
        {
          if (equal_class (*s, p, case_sensitive))
            {
              ++p;
            }
           else
            {
              if (!star)
                return false;
              p = pat;
            }
          ++s;
        }
      else if (!equal_char (*s, *p, case_sensitive))
        {
          if (!star)
            return false;
          ++s;
          p = pat;
          escape = false;
        }
      else
        {
          ++s;
          ++p;
          escape = false;
        }
    }
  if (*p == '*')
    while (*++p == '*') {}

  return *p == '\0';
}

ssize_t ACE::write_n ( ACE_HANDLE  handle,
const void *  buf,
size_t  len,
size_t *  bytes_transferred = 0 
) [inline]

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 29 of file ACE.inl.

{
  return ACE_OS::write_n (handle,
                          buf,
                          len,
                          bytes_transferred);
}

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 1897 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;

  iovec iov[ACE_IOV_MAX];
  int iovcnt = 0;

  while (message_block != 0)
    {
      // Our current message block chain.
      const ACE_Message_Block *current_message_block = message_block;

      while (current_message_block != 0)
        {
          size_t current_message_block_length =
            current_message_block->length ();
          char *this_block_ptr = current_message_block->rd_ptr ();

          // Check if this block has any data to be sent.
          while (current_message_block_length > 0)
            {
              u_long const this_chunk_length =
                ACE_Utils::truncate_cast<u_long> (
                  current_message_block_length);

              // Collect the data in the iovec.
              iov[iovcnt].iov_base = this_block_ptr;
              iov[iovcnt].iov_len  = this_chunk_length;
              current_message_block_length -= this_chunk_length;
              this_block_ptr += this_chunk_length;

              // Increment iovec counter.
              ++iovcnt;

              // The buffer is full make a OS call.  @@ TODO find a way to
              // find ACE_IOV_MAX for platforms that do not define it rather
              // than simply setting ACE_IOV_MAX to some arbitrary value such
              // as 16.
              if (iovcnt == ACE_IOV_MAX)
                {
                  size_t current_transfer = 0;

                  ssize_t const result = ACE::writev_n (handle,
                                                        iov,
                                                        iovcnt,
                                                        &current_transfer);

                  // Add to total bytes transferred.
                  bytes_transferred += current_transfer;

                  // Errors.
                  if (result == -1 || result == 0)
                    return result;

                  // Reset iovec counter.
                  iovcnt = 0;
                }
            }

          // Select the next message block in the chain.
          current_message_block = current_message_block->cont ();
        }

      // Selection of the next message block chain.
      message_block = message_block->next ();
    }

  // Check for remaining buffers to be sent.  This will happen when
  // ACE_IOV_MAX is not a multiple of the number of message blocks.
  if (iovcnt != 0)
    {
      size_t current_transfer = 0;

      ssize_t const result = ACE::writev_n (handle,
                                            iov,
                                            iovcnt,
                                            &current_transfer);

      // Add to total bytes transferred.
      bytes_transferred += current_transfer;

      // Errors.
      if (result == -1 || result == 0)
        return result;
    }

  // Return total bytes transferred.
  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}

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

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 2130 of file ACE.cpp.

{
  size_t temp;
  size_t &bytes_transferred = bt == 0 ? temp : *bt;
  bytes_transferred = 0;

  iovec *iov = const_cast<iovec *> (i);

  for (int s = 0;
       s < iovcnt;
       )
    {
      ssize_t n = ACE_OS::writev (handle,
                                  iov + s,
                                  iovcnt - s);

      if (n == -1 || n == 0)
        {
          return n;
        }

      for (bytes_transferred += n;
           s < iovcnt
             && n >= static_cast<ssize_t> (iov[s].iov_len);
           s++)
        n -= iov[s].iov_len;

      if (n != 0)
        {
          char *base = reinterpret_cast<char *> (iov[s].iov_base);
          iov[s].iov_base = base + n;
          iov[s].iov_len = iov[s].iov_len - n;
        }
    }

  return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
}


Variable Documentation

unsigned int ACE::init_fini_count_

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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines