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)
ACE_NAMESPACE_INLINE_FUNCTION void strdelete (char *s)
 Delete the memory allocated by strnew.
ACE_Export char * strndup (const char *str, size_t n)
ACE_Export char * strnnew (const char *str, size_t n)
ACE_NAMESPACE_INLINE_FUNCTION 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 (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)
ACE_NAMESPACE_INLINE_FUNCTION void unique_name (const void *object, ACE_TCHAR *name, size_t length)
ACE_NAMESPACE_INLINE_FUNCTION
u_long 
log2 (u_long num)
 Computes the base 2 logarithm of {num}.
ACE_Export ACE_TCHAR nibble2hex (u_int n)
 Hex conversion utility.
ACE_NAMESPACE_INLINE_FUNCTION
u_char 
hex2byte (ACE_TCHAR c)
 Convert a hex character to its byte representation.
ACE_Export bool debug (void)
ACE_Export void debug (bool onoff)
ACE_Export int select (int width, ACE_Handle_Set *readfds, ACE_Handle_Set *writefds=0, ACE_Handle_Set *exceptfds=0, const ACE_Time_Value *timeout=0)
 Wrapper facade for select that uses ACE_Handle_Sets.
ACE_Export int select (int width, ACE_Handle_Set &readfds, const ACE_Time_Value *timeout=0)
ACE_NAMESPACE_INLINE_FUNCTION int handle_read_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout)
 Timed wait for handle to get read ready.
ACE_NAMESPACE_INLINE_FUNCTION int handle_write_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout)
 Timed wait for handle to get write ready.
ACE_NAMESPACE_INLINE_FUNCTION int handle_exception_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout)
 Timed wait for handle to get exception ready.
ACE_Export int handle_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout, int read_ready, int write_ready, int exception_ready)
 Timed wait for handle to get read, write, or exception ready.
ACE_Export int enter_recv_timedwait (ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val)
ACE_Export int enter_send_timedwait (ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val)
ACE_Export void record_and_set_non_blocking_mode (ACE_HANDLE handle, int &val)
ACE_Export void restore_non_blocking_mode (ACE_HANDLE handle, int val)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
recv_i (ACE_HANDLE handle, void *buf, size_t len)
ACE_Export ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, size_t *bytes_transferred)
ACE_Export ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, size_t *bytes_transferred)
ACE_Export ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, size_t *bytes_transferred)
ACE_Export ssize_t recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
send_i (ACE_HANDLE handle, const void *buf, size_t len)
ACE_Export ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, size_t *bytes_transferred)
ACE_Export ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, size_t *bytes_transferred)
ACE_Export ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export ssize_t sendv_n_i (ACE_HANDLE handle, const iovec *iov, int iovcnt, size_t *bytes_transferred)
ACE_Export ssize_t sendv_n_i (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bytes_transferred)
ACE_Export int set_flags (ACE_HANDLE handle, int flags)
 Set flags associated with handle.
ACE_Export int clr_flags (ACE_HANDLE handle, int flags)
 Clear flags associated with handle.
ACE_NAMESPACE_INLINE_FUNCTION int get_flags (ACE_HANDLE handle)
 Return the current setting of flags associated with handle.
ACE_Export ACE_HANDLE handle_timed_open (ACE_Time_Value *timeout, const ACE_TCHAR *name, int flags, int perms, LPSECURITY_ATTRIBUTES sa=0)
ACE_Export int init (void)
ACE_Export int fini (void)
ACE_Export int ldfind (const ACE_TCHAR *filename, ACE_TCHAR pathname[], size_t maxpathnamelen)
ACE_Export FILE * ldopen (const ACE_TCHAR *filename, const ACE_TCHAR *type)
ACE_Export ACE_TCHARldname (const ACE_TCHAR *entry_point)
ACE_Export void ldregister (const ACE_TCHAR *entry_point, void *entry_addr)
ACE_Export void * ldsymbol (ACE_SHLIB_HANDLE sh, const ACE_TCHAR *entry_point)
ACE_Export int get_temp_dir (ACE_TCHAR *buffer, size_t buffer_len)
ACE_Export ACE_HANDLE open_temp_file (const ACE_TCHAR *name, int mode, int perm=0)
ACE_Export size_t strrepl (char *s, char search, char replace)
ACE_Export char * strsplit_r (char *s, const char *token, char *&next_start)
ACE_Export size_t strrepl (wchar_t *s, wchar_t search, wchar_t replace)
 As strrepl, but for wide characters.
ACE_Export wchar_t * strsplit_r (wchar_t *s, const wchar_t *token, wchar_t *&next_start)
 As strsplit_r, but for wide characters.
ACE_Export int bind_port (ACE_HANDLE handle, ACE_UINT32 ip_addr=INADDR_ANY, int address_family=AF_UNSPEC)
 Bind a new unused port to handle.
ACE_Export int get_bcast_addr (ACE_UINT32 &bcast_addr, const ACE_TCHAR *hostname=0, ACE_UINT32 host_addr=0, ACE_HANDLE handle=ACE_INVALID_HANDLE)
ACE_Export int get_fqdn (ACE_INET_Addr const &addr, char hostname[], size_t len)
 Get fully qualified host/domain name.
ACE_Export int get_ip_interfaces (size_t &count, ACE_INET_Addr *&addr_array)
ACE_Export int count_interfaces (ACE_HANDLE handle, size_t &how_many)
ACE_Export ACE_HANDLE get_handle (void)
ACE_Export bool ipv4_enabled (void)
ACE_Export int ipv6_enabled (void)
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.
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
recv_n (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
recv_n (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 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.
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
recvv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 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.
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
send_n (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
send_n (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 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.
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
sendv_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0)
 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)
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t 
read_n (ACE_HANDLE handle, void *buf, size_t len, size_t *bytes_transferred=0)
 Receive into a variable number of pieces.
ACE_NAMESPACE_INLINE_FUNCTION
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.

00411 {
00412   ACE_TRACE ("ACE::basename");
00413   const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);
00414 
00415   if (temp == 0)
00416     return pathname;
00417   else
00418     return temp + 1;
00419 }

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.

00122 {
00123   return ACE_BETA_VERSION;
00124 }

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.

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

u_int ACE::compiler_beta_version ( void   ) 

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

Definition at line 157 of file ACE.cpp.

00158 {
00159 #ifdef ACE_CC_BETA_VERSION
00160   return ACE_CC_BETA_VERSION;
00161 #else
00162   return 0;
00163 #endif
00164 }

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.

00138 {
00139 #ifdef ACE_CC_MAJOR_VERSION
00140   return ACE_CC_MAJOR_VERSION;
00141 #else
00142   return 0;
00143 #endif
00144 }

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.

00148 {
00149 #ifdef ACE_CC_MINOR_VERSION
00150   return ACE_CC_MINOR_VERSION;
00151 #else
00152   return 0;
00153 #endif
00154 }

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.

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

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

01407 {
01408 #if defined (SIOCGIFNUM)
01409 # if defined (SIOCGLIFNUM) && !defined (ACE_LACKS_STRUCT_LIFNUM)
01410   int cmd = SIOCGLIFNUM;
01411   struct lifnum if_num = {AF_UNSPEC,0,0};
01412 # else
01413   int cmd = SIOCGIFNUM;
01414   int if_num = 0;
01415 # endif /* SIOCGLIFNUM */
01416   if (ACE_OS::ioctl (handle, cmd, (caddr_t)&if_num) == -1)
01417     ACE_ERROR_RETURN ((LM_ERROR,
01418                        ACE_TEXT ("%p\n"),
01419                        ACE_TEXT ("ACE::count_interfaces:")
01420                        ACE_TEXT ("ioctl - SIOCGLIFNUM failed")),
01421                       -1);
01422 # if defined (SIOCGLIFNUM) && !defined (ACE_LACKS_STRUCT_LIFNUM)
01423   how_many = if_num.lifn_count;
01424 # else
01425   how_many = if_num;
01426 # endif /* SIOCGLIFNUM */
01427 return 0;
01428 
01429 #elif (defined (__unix) || defined (__unix__) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS) || (defined (ACE_VXWORKS) && !defined (ACE_HAS_GETIFADDRS))) && !defined (ACE_LACKS_NETWORKING)
01430   // Note: DEC CXX doesn't define "unix".  BSD compatible OS: HP UX,
01431   // AIX, SunOS 4.x perform some ioctls to retrieve ifconf list of
01432   // ifreq structs no SIOCGIFNUM on SunOS 4.x, so use guess and scan
01433   // algorithm
01434 
01435   // Probably hard to put this many ifs in a unix box..
01436   int const MAX_IF = 50;
01437 
01438   // HACK - set to an unreasonable number
01439   int const num_ifs = MAX_IF;
01440 
01441   struct ifconf ifcfg;
01442   size_t ifreq_size = num_ifs * sizeof (struct ifreq);
01443   struct ifreq *p_ifs = (struct ifreq *) ACE_OS::malloc (ifreq_size);
01444 
01445   if (!p_ifs)
01446     {
01447       errno = ENOMEM;
01448       return -1;
01449     }
01450 
01451   ACE_OS::memset (p_ifs, 0, ifreq_size);
01452   ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf));
01453 
01454   ifcfg.ifc_req = p_ifs;
01455   ifcfg.ifc_len = ifreq_size;
01456 
01457   if (ACE_OS::ioctl (handle,
01458                      SIOCGIFCONF_CMD,
01459                      (caddr_t) &ifcfg) == -1)
01460     {
01461       ACE_OS::free (ifcfg.ifc_req);
01462       ACE_ERROR_RETURN ((LM_ERROR,
01463                          ACE_TEXT ("%p\n"),
01464                          ACE_TEXT ("ACE::count_interfaces:")
01465                          ACE_TEXT ("ioctl - SIOCGIFCONF failed")),
01466                         -1);
01467     }
01468 
01469   int if_count = 0;
01470   int i = 0;
01471 
01472   // get if address out of ifreq buffers.  ioctl puts a blank-named
01473   // interface to mark the end of the returned interfaces.
01474   for (i = 0;
01475        i < num_ifs;
01476        i++)
01477     {
01478       /* In OpenBSD, the length of the list is returned. */
01479       ifcfg.ifc_len -= sizeof (struct ifreq);
01480       if (ifcfg.ifc_len < 0)
01481         break;
01482 
01483       ++if_count;
01484 #if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__)
01485       ++p_ifs;
01486 #else
01487      if (p_ifs->ifr_addr.sa_len <= sizeof (struct sockaddr))
01488        {
01489           ++p_ifs;
01490        }
01491        else
01492        {
01493           p_ifs = (struct ifreq *)
01494               (p_ifs->ifr_addr.sa_len + (caddr_t) &p_ifs->ifr_addr);
01495        }
01496 #endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__)*/
01497     }
01498 
01499   ACE_OS::free (ifcfg.ifc_req);
01500 
01501 # if defined (ACE_HAS_IPV6)
01502   FILE* fp = 0;
01503 
01504   if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0)
01505     {
01506       // Scan the lines according to the expected format but don't really read any input
01507       while (fscanf (fp, "%*32s %*02x %*02x %*02x %*02x %*8s\n") != EOF)
01508         {
01509           ++if_count;
01510         }
01511       ACE_OS::fclose (fp);
01512     }
01513 # endif /* ACE_HAS_IPV6 */
01514 
01515   how_many = if_count;
01516   return 0;
01517 #else
01518   ACE_UNUSED_ARG (handle);
01519   ACE_UNUSED_ARG (how_many);
01520   ACE_NOTSUP_RETURN (-1); // no implementation
01521 #endif /* sparc && SIOCGIFNUM */
01522 }

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.

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

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

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

Definition at line 126 of file ACE_crc32.cpp.

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

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

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

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

Computes CRC-CCITT for the @ len iovec buffers.

Definition at line 109 of file ACE_crc_ccitt.cpp.

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

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

Computes CRC-CCITT for the buffer.

Definition at line 93 of file ACE_crc_ccitt.cpp.

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

ACE_UINT16 ACE::crc_ccitt ( const char *  str  ) 

Computes CRC-CCITT for the string.

Definition at line 78 of file ACE_crc_ccitt.cpp.

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

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

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

Definition at line 2767 of file ACE.cpp.

02770 {
02771   ACE_TRACE ("ACE::daemonize");
02772 #if !defined (ACE_LACKS_FORK)
02773   pid_t pid = ACE_OS::fork ();
02774 
02775   if (pid == -1)
02776     return -1;
02777   else if (pid != 0)
02778     ACE_OS::exit (0); // Parent exits.
02779 
02780   // 1st child continues.
02781   ACE_OS::setsid (); // Become session leader.
02782 
02783   ACE_OS::signal (SIGHUP, SIG_IGN);
02784 
02785   pid = ACE_OS::fork (program_name);
02786 
02787   if (pid != 0)
02788     ACE_OS::exit (0); // First child terminates.
02789 
02790   // Second child continues.
02791 
02792   if (pathname != 0)
02793     // change working directory.
02794     ACE_OS::chdir (pathname);
02795 
02796   ACE_OS::umask (0); // clear our file mode creation mask.
02797 
02798   // Close down the I/O handles.
02799   if (close_all_handles)
02800     {
02801       for (int i = ACE::max_handles () - 1; i >= 0; i--)
02802         ACE_OS::close (i);
02803 
02804       int fd = ACE_OS::open ("/dev/null", O_RDWR, 0);
02805       if (fd != -1)
02806         {
02807           ACE_OS::dup2 (fd, ACE_STDIN);
02808           ACE_OS::dup2 (fd, ACE_STDOUT);
02809           ACE_OS::dup2 (fd, ACE_STDERR);
02810 
02811           if (fd > ACE_STDERR)
02812             ACE_OS::close (fd);
02813         }
02814     }
02815 
02816   return 0;
02817 #else
02818   ACE_UNUSED_ARG (pathname);
02819   ACE_UNUSED_ARG (close_all_handles);
02820   ACE_UNUSED_ARG (program_name);
02821 
02822   ACE_NOTSUP_RETURN (-1);
02823 #endif /* ACE_LACKS_FORK */
02824 }

void ACE::debug ( bool  onoff  ) 

Definition at line 181 of file ACE.cpp.

00182 {
00183   ACE::debug_ = onoff;
00184 }

bool ACE::debug ( void   ) 

Definition at line 174 of file ACE.cpp.

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

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.

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

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

02255 {
02256   int result = ACE::handle_read_ready (handle,
02257                                        timeout);
02258 
02259   if (result == -1)
02260     return -1;
02261 
02262   ACE::record_and_set_non_blocking_mode (handle,
02263                                          val);
02264 
02265   return result;
02266 }

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

02272 {
02273   int result = ACE::handle_write_ready (handle,
02274                                         timeout);
02275 
02276   if (result == -1)
02277     return -1;
02278 
02279   ACE::record_and_set_non_blocking_mode (handle,
02280                                          val);
02281 
02282   return result;
02283 }

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.

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

int ACE::fini ( void   ) 

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

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

Definition at line 27 of file Init_ACE.cpp.

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

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

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

Definition at line 2827 of file ACE.cpp.

02829 {
02830   if (avoid_zombies == 0)
02831     return ACE_OS::fork (program_name);
02832   else
02833     {
02834       // This algorithm is adapted from an example in the Stevens book
02835       // "Advanced Programming in the Unix Environment" and an item in
02836       // Andrew Gierth's Unix Programming FAQ.  It creates an orphan
02837       // process that's inherited by the init process; init cleans up
02838       // when the orphan process terminates.
02839       //
02840       // Another way to avoid zombies is to ignore or catch the
02841       // SIGCHLD signal; we don't use that approach here.
02842 
02843       pid_t pid = ACE_OS::fork ();
02844       if (pid == 0)
02845         {
02846           // The child process forks again to create a grandchild.
02847           switch (ACE_OS::fork (program_name))
02848             {
02849             case 0: // grandchild returns 0.
02850               return 0;
02851             case -1: // assumes all errnos are < 256
02852               ACE_OS::_exit (errno);
02853             default:  // child terminates, orphaning grandchild
02854               ACE_OS::_exit (0);
02855             }
02856         }
02857 
02858       // Parent process waits for child to terminate.
02859       ACE_exitcode status;
02860       if (pid < 0 || ACE_OS::waitpid (pid, &status, 0) < 0)
02861         return -1;
02862 
02863       // child terminated by calling exit()?
02864       if (WIFEXITED ((status)))
02865         {
02866           // child terminated normally?
02867           if (WEXITSTATUS ((status)) == 0)
02868             return 1;
02869           else
02870             errno = WEXITSTATUS ((status));
02871         }
02872       else
02873         // child didn't call exit(); perhaps it received a signal?
02874         errno = EINTR;
02875 
02876       return -1;
02877     }
02878 }

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

02324 {
02325   ACE_TRACE ("ACE::format_hexdump");
02326 
02327   u_char c;
02328   ACE_TCHAR textver[16 + 1];
02329 
02330   // We can fit 16 bytes output in text mode per line, 4 chars per byte.
02331   size_t maxlen = (obuf_sz / 68) * 16;
02332 
02333   if (size > maxlen)
02334     size = maxlen;
02335 
02336   size_t i;
02337 
02338   size_t const lines = size / 16;
02339   for (i = 0; i < lines; i++)
02340     {
02341       size_t j;
02342 
02343       for (j = 0 ; j < 16; j++)
02344         {
02345           c = (u_char) buffer[(i << 4) + j];    // or, buffer[i*16+j]
02346           ACE_OS::sprintf (obuf,
02347                            ACE_TEXT ("%02x "),
02348                            c);
02349           obuf += 3;
02350           if (j == 7)
02351             {
02352               ACE_OS::sprintf (obuf,
02353                                ACE_TEXT (" "));
02354               ++obuf;
02355             }
02356           textver[j] = ACE_OS::ace_isprint (c) ? c : '.';
02357         }
02358 
02359       textver[j] = 0;
02360 
02361       ACE_OS::sprintf (obuf,
02362 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
02363                        ACE_TEXT ("  %ls\n"),
02364 #else
02365                        ACE_TEXT ("  %s\n"),
02366 #endif
02367                        textver);
02368 
02369       while (*obuf != '\0')
02370         ++obuf;
02371     }
02372 
02373   if (size % 16)
02374     {
02375       for (i = 0 ; i < size % 16; i++)
02376         {
02377           c = (u_char) buffer[size - size % 16 + i];
02378           ACE_OS::sprintf (obuf,
02379                            ACE_TEXT ("%02x "),
02380                            c);
02381           obuf += 3;
02382           if (i == 7)
02383             {
02384               ACE_OS::sprintf (obuf,
02385                                ACE_TEXT (" "));
02386               ++obuf;
02387             }
02388           textver[i] = ACE_OS::ace_isprint (c) ? c : '.';
02389         }
02390 
02391       for (i = size % 16; i < 16; i++)
02392         {
02393           ACE_OS::sprintf (obuf,
02394                            ACE_TEXT ("   "));
02395           obuf += 3;
02396           if (i == 7)
02397             {
02398               ACE_OS::sprintf (obuf,
02399                                ACE_TEXT (" "));
02400               ++obuf;
02401             }
02402           textver[i] = ' ';
02403         }
02404 
02405       textver[i] = 0;
02406       ACE_OS::sprintf (obuf,
02407 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
02408                        ACE_TEXT ("  %ls\n"),
02409 #else
02410                        ACE_TEXT ("  %s\n"),
02411 #endif
02412                        textver);
02413     }
02414   return size;
02415 }

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

Euclid's greatest common divisor algorithm.

Definition at line 2973 of file ACE.cpp.

02974 {
02975   while (y != 0)
02976     {
02977       u_long r = x % y;
02978       x = y;
02979       y = r;
02980     }
02981 
02982   return x;
02983 }

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

00205 {
00206   ACE_TRACE ("ACE::get_bcast_addr");
00207 
00208 #if defined (ACE_LACKS_GET_BCAST_ADDR)
00209   ACE_UNUSED_ARG (bcast_addr);
00210   ACE_UNUSED_ARG (host_name);
00211   ACE_UNUSED_ARG (host_addr);
00212   ACE_UNUSED_ARG (handle);
00213   ACE_NOTSUP_RETURN (-1);
00214 #elif !defined(ACE_WIN32) && !defined(__INTERIX)
00215   ACE_HANDLE s = handle;
00216 
00217   if (s == ACE_INVALID_HANDLE)
00218     s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0);
00219 
00220   if (s == ACE_INVALID_HANDLE)
00221     ACE_ERROR_RETURN ((LM_ERROR,
00222                        ACE_TEXT ("%p\n"),
00223                        ACE_TEXT ("ACE_OS::socket")),
00224                       -1);
00225 
00226   struct ifconf ifc;
00227   char buf[BUFSIZ];
00228 
00229   ifc.ifc_len = sizeof buf;
00230   ifc.ifc_buf = buf;
00231 
00232   // Get interface structure and initialize the addresses using UNIX
00233   // techniques
00234   if (ACE_OS::ioctl (s, SIOCGIFCONF_CMD, (char *) &ifc) == -1)
00235     ACE_ERROR_RETURN ((LM_ERROR,
00236                        ACE_TEXT ("%p\n"),
00237                        ACE_TEXT ("ACE::get_bcast_addr:")
00238                        ACE_TEXT ("ioctl (get interface configuration)")),
00239                       -1);
00240 
00241   struct ifreq *ifr = ifc.ifc_req;
00242 
00243   struct sockaddr_in ip_addr;
00244 
00245   // Get host ip address if necessary.
00246   if (host_name)
00247     {
00248       hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name));
00249 
00250       if (hp == 0)
00251         return -1;
00252       else
00253 #if !defined(_UNICOS)
00254         ACE_OS::memcpy ((char *) &ip_addr.sin_addr.s_addr,
00255                         (char *) hp->h_addr,
00256                         hp->h_length);
00257 #else /* _UNICOS */
00258       {
00259         ACE_UINT64 haddr;  // a place to put the address
00260         char * haddrp = (char *) &haddr;  // convert to char pointer
00261         ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length);
00262         ip_addr.sin_addr.s_addr = haddr;
00263       }
00264 #endif /* ! _UNICOS */
00265     }
00266   else
00267     {
00268       ACE_OS::memset ((void *) &ip_addr, 0, sizeof ip_addr);
00269 #if !defined(_UNICOS)
00270       ACE_OS::memcpy ((void *) &ip_addr.sin_addr,
00271                       (void*) &host_addr,
00272                       sizeof ip_addr.sin_addr);
00273 #else /* _UNICOS */
00274       ip_addr.sin_addr.s_addr = host_addr;   // just copy to the bitfield
00275 #endif /* ! _UNICOS */
00276     }
00277 
00278 #if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (__Lynx__)
00279   for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0;
00280        n--, ifr++)
00281 #else
00282   // see mk_broadcast@SOCK_Dgram_Bcast.cpp
00283   for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) &&
00284         ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
00285           (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1);
00286         ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
00287           (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len,
00288             ifr = (struct ifreq *)
00289               ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) :
00290           (nbytes -= sizeof (struct ifreq), ifr++)))
00291 #endif /* !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (__Lynx__) */
00292     {
00293       struct sockaddr_in if_addr;
00294 
00295       // Compare host ip address with interface ip address.
00296       ACE_OS::memcpy (&if_addr,
00297                       &ifr->ifr_addr,
00298                       sizeof if_addr);
00299 
00300       if (ip_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr)
00301         continue;
00302 
00303       if (ifr->ifr_addr.sa_family != AF_INET)
00304         {
00305           ACE_ERROR ((LM_ERROR,
00306                       ACE_TEXT ("%p\n"),
00307                       ACE_TEXT ("ACE::get_bcast_addr:")
00308                       ACE_TEXT ("Not AF_INET")));
00309           continue;
00310         }
00311 
00312       struct ifreq flags = *ifr;
00313       struct ifreq if_req = *ifr;
00314 
00315       if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1)
00316         {
00317           ACE_ERROR ((LM_ERROR,
00318                       ACE_TEXT ("%p\n"),
00319                       ACE_TEXT ("ACE::get_bcast_addr:")
00320                       ACE_TEXT (" ioctl (get interface flags)")));
00321           continue;
00322         }
00323 
00324       if (ACE_BIT_DISABLED (flags.ifr_flags, IFF_UP))
00325         {
00326           ACE_ERROR ((LM_ERROR,
00327                       ACE_TEXT ("%p\n"),
00328                       ACE_TEXT ("ACE::get_bcast_addr:")
00329                       ACE_TEXT ("Network interface is not up")));
00330           continue;
00331         }
00332 
00333       if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_LOOPBACK))
00334         continue;
00335 
00336       if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_BROADCAST))
00337         {
00338           if (ACE_OS::ioctl (s,
00339                              SIOCGIFBRDADDR,
00340                              (char *) &if_req) == -1)
00341             ACE_ERROR ((LM_ERROR,
00342                         ACE_TEXT ("%p\n"),
00343                         ACE_TEXT ("ACE::get_bcast_addr:")
00344                         ACE_TEXT ("ioctl (get broadaddr)")));
00345           else
00346             {
00347               ACE_OS::memcpy (&ip_addr,
00348                               &if_req.ifr_broadaddr,
00349                               sizeof if_req.ifr_broadaddr);
00350 
00351               ACE_OS::memcpy ((void *) &host_addr,
00352                               (void *) &ip_addr.sin_addr,
00353                               sizeof host_addr);
00354 
00355               if (handle == ACE_INVALID_HANDLE)
00356                 ACE_OS::close (s);
00357 
00358               bcast_addr = host_addr;
00359               return 0;
00360             }
00361         }
00362       else
00363         ACE_ERROR ((LM_ERROR,
00364                     ACE_TEXT ("%p\n"),
00365                     ACE_TEXT ("ACE::get_bcast_addr:")
00366                     ACE_TEXT ("Broadcast is not enable for this interface.")));
00367 
00368       if (handle == ACE_INVALID_HANDLE)
00369         ACE_OS::close (s);
00370 
00371       bcast_addr = host_addr;
00372       return 0;
00373     }
00374 
00375   return 0;
00376 #else
00377   ACE_UNUSED_ARG (handle);
00378   ACE_UNUSED_ARG (host_addr);
00379   ACE_UNUSED_ARG (host_name);
00380   bcast_addr = (ACE_UINT32 (INADDR_BROADCAST));
00381   return 0;
00382 #endif /* !ACE_WIN32 && !__INTERIX */
00383 }

int ACE::get_flags ( ACE_HANDLE  handle  ) 

Return the current setting of flags associated with handle.

Definition at line 11 of file Flag_Manip.inl.

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

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

Get fully qualified host/domain name.

Definition at line 386 of file Sock_Connect.cpp.

00389 {
00390   int h_error;  // Not the same as errno!
00391   hostent hentry;
00392   ACE_HOSTENT_DATA buf;
00393 
00394   char * ip_addr = 0;
00395   int ip_addr_size = 0;
00396   if (addr.get_type () == AF_INET)
00397     {
00398       sockaddr_in * const sock_addr =
00399         reinterpret_cast<sockaddr_in *> (addr.get_addr ());
00400       ip_addr_size = sizeof sock_addr->sin_addr;
00401       ip_addr = (char*) &sock_addr->sin_addr;
00402     }
00403 #ifdef ACE_HAS_IPV6
00404   else
00405     {
00406       sockaddr_in6 * sock_addr =
00407         reinterpret_cast<sockaddr_in6 *> (addr.get_addr ());
00408 
00409       ip_addr_size = sizeof sock_addr->sin6_addr;
00410       ip_addr = (char*) &sock_addr->sin6_addr;
00411     }
00412 #endif  /* ACE_HAS_IPV6 */
00413 
00414    // get the host entry for the address in question
00415    hostent * const hp = ACE_OS::gethostbyaddr_r (ip_addr,
00416                                                  ip_addr_size,
00417                                                  addr.get_type (),
00418                                                  &hentry,
00419                                                  buf,
00420                                                  &h_error);
00421 
00422    // if it's not found in the host file or the DNS datase, there is nothing
00423    // much we can do. embed the IP address
00424    if (hp == 0 || hp->h_name == 0)
00425      return -1;
00426 
00427    if (ACE::debug())
00428      ACE_DEBUG ((LM_DEBUG,
00429                  ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ")
00430                  ACE_TEXT ("canonical host name is %C\n"),
00431                  hp->h_name));
00432 
00433    // check if the canonical name is the FQDN
00434    if (!ACE_OS::strchr(hp->h_name, '.'))
00435      {
00436        // list of address
00437        char** p;
00438        // list of aliases
00439        char** q;
00440 
00441        // for every address and for every alias within the address, check and
00442        // see if we can locate a FQDN
00443        for (p = hp->h_addr_list; *p != 0; ++p)
00444          {
00445            for (q = hp->h_aliases; *q != 0; ++q)
00446              {
00447                if (ACE_OS::strchr(*q, '.'))
00448                  {
00449                    // we got an FQDN from an alias. use this
00450                    if (ACE_OS::strlen (*q) >= len)
00451                      // the hostname is too huge to fit into a
00452                      // buffer of size MAXHOSTNAMELEN
00453                      // should we check other aliases as well
00454                      // before bailing out prematurely?
00455                      // for right now, let's do it. this (short name)
00456                      // is atleast better than embedding the IP
00457                      // address in the profile
00458                      continue;
00459 
00460                    if (ACE::debug ())
00461                      ACE_DEBUG ((LM_DEBUG,
00462                                  ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ")
00463                                  ACE_TEXT ("found fqdn within alias as %C\n"),
00464                                  *q));
00465                    ACE_OS::strcpy (hostname, *q);
00466 
00467                    return 0;
00468                  }
00469              }
00470          }
00471      }
00472 
00473    // The canonical name may be an FQDN when we reach here.
00474    // Alternatively, the canonical name (a non FQDN) may be the best
00475    // we can do.
00476    if (ACE_OS::strlen (hp->h_name) >= len)
00477      {
00478        // The hostname is too large to fit into a buffer of size
00479        // MAXHOSTNAMELEN.
00480        return -2;
00481      }
00482    else
00483      {
00484        ACE_OS::strcpy (hostname, hp->h_name);
00485      }
00486 
00487    return 0;
00488 }

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

01528 {
01529   // Solaris 2.x
01530   ACE_HANDLE handle = ACE_INVALID_HANDLE;
01531 #if defined (sparc)
01532   handle = ACE_OS::open ("/dev/udp", O_RDONLY);
01533 #elif defined (__unix) || defined (__unix__) || defined (_AIX) || defined (__hpux) || (defined (ACE_VXWORKS) && (ACE_VXWORKS >= 0x600)) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS)
01534   // Note: DEC CXX doesn't define "unix" BSD compatible OS: HP UX,
01535   // AIX, SunOS 4.x
01536 
01537   handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, 0);
01538 #endif /* sparc */
01539   return handle;
01540 }

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

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

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.

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

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

Timed wait for handle to get exception ready.

Definition at line 263 of file ACE.inl.

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

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

Timed wait for handle to get read ready.

Definition at line 241 of file ACE.inl.

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

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

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

Definition at line 2198 of file ACE.cpp.

02203 {
02204 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02205   ACE_UNUSED_ARG (write_ready);
02206   ACE_UNUSED_ARG (exception_ready);
02207 
02208   struct pollfd fds;
02209 
02210   fds.fd = handle;
02211   fds.events = read_ready ? POLLIN : POLLOUT;
02212   fds.revents = 0;
02213 
02214   int result = ACE_OS::poll (&fds, 1, timeout);
02215 #else
02216   ACE_Handle_Set handle_set;
02217   handle_set.set_bit (handle);
02218 
02219   // Wait for data or for the timeout to elapse.
02220   int select_width;
02221 #  if defined (ACE_WIN32)
02222   // This arg is ignored on Windows and causes pointer truncation
02223   // warnings on 64-bit compiles.
02224   select_width = 0;
02225 #  else
02226   select_width = int (handle) + 1;
02227 #  endif /* ACE_WIN64 */
02228   int result = ACE_OS::select (select_width,
02229                                read_ready ? handle_set.fdset () : 0, // read_fds.
02230                                write_ready ? handle_set.fdset () : 0, // write_fds.
02231                                exception_ready ? handle_set.fdset () : 0, // exception_fds.
02232                                timeout);
02233 
02234 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02235 
02236   switch (result)
02237     {
02238     case 0:  // Timer expired.
02239       errno = ETIME;
02240       /* FALLTHRU */
02241     case -1: // we got here directly - select() returned -1.
02242       return -1;
02243     case 1: // Handle has data.
02244       /* FALLTHRU */
02245     default: // default is case result > 0; return a
02246       // ACE_ASSERT (result == 1);
02247       return result;
02248     }
02249 }

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

02695 {
02696   ACE_TRACE ("ACE::handle_timed_accept");
02697   // Make sure we don't bomb out on erroneous values.
02698   if (listener == ACE_INVALID_HANDLE)
02699     return -1;
02700 
02701 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02702 
02703   struct pollfd fds;
02704 
02705   fds.fd = listener;
02706   fds.events = POLLIN;
02707   fds.revents = 0;
02708 
02709 #else
02710   // Use the select() implementation rather than poll().
02711   ACE_Handle_Set rd_handle;
02712   rd_handle.set_bit (listener);
02713 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02714 
02715   // We need a loop here if <restart> is enabled.
02716 
02717   for (;;)
02718     {
02719 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02720 
02721       int n = ACE_OS::poll (&fds, 1, timeout);
02722 
02723 #else
02724       int select_width;
02725 #  if defined (ACE_WIN32)
02726       // This arg is ignored on Windows and causes pointer truncation
02727       // warnings on 64-bit compiles.
02728       select_width = 0;
02729 #  else
02730       select_width = int (listener) + 1;
02731 #  endif /* ACE_WIN32 */
02732       int n = ACE_OS::select (select_width,
02733                               rd_handle, 0, 0,
02734                               timeout);
02735 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02736 
02737       switch (n)
02738         {
02739         case -1:
02740           if (errno == EINTR && restart)
02741             continue;
02742           else
02743             return -1;
02744           /* NOTREACHED */
02745         case 0:
02746           if (timeout != 0 && *timeout == ACE_Time_Value::zero)
02747             errno = EWOULDBLOCK;
02748           else
02749             errno = ETIMEDOUT;
02750           return -1;
02751           /* NOTREACHED */
02752         case 1:
02753           return 0;
02754           /* NOTREACHED */
02755         default:
02756           errno = EINVAL;
02757           return -1;
02758           /* NOTREACHED */
02759         }
02760     }
02761 }

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

02540 {
02541   ACE_TRACE ("ACE::handle_timed_complete");
02542 
02543 #if !defined (ACE_WIN32) && defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02544 
02545   struct pollfd fds;
02546 
02547   fds.fd = h;
02548   fds.events = POLLIN | POLLOUT;
02549   fds.revents = 0;
02550 
02551 #else
02552   ACE_Handle_Set rd_handles;
02553   ACE_Handle_Set wr_handles;
02554   rd_handles.set_bit (h);
02555   wr_handles.set_bit (h);
02556 #endif /* !ACE_WIN32 && ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02557 
02558 #if defined (ACE_WIN32)
02559   // Winsock is different - it sets the exception bit for failed connect,
02560   // unlike other platforms, where the write bit is set for both success
02561   // and fail.
02562   ACE_Handle_Set ex_handles;
02563   ex_handles.set_bit (h);
02564 #endif /* ACE_WIN32 */
02565 
02566   bool need_to_check = false;
02567   bool known_failure = false;
02568 
02569 #if defined (ACE_WIN32)
02570   int n = ACE_OS::select (0,    // Ignored on Windows: int (h) + 1,
02571                           0,
02572                           wr_handles,
02573                           ex_handles,
02574                           timeout);
02575 #else
02576 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02577 
02578   int n = ACE_OS::poll (&fds, 1, timeout);
02579 
02580 # else
02581   int n = 0;
02582   if (is_tli)
02583     n = ACE_OS::select (int (h) + 1,
02584                         rd_handles,
02585                         wr_handles,
02586                         0,
02587                         timeout);
02588   else
02589     n = ACE_OS::select (int (h) + 1,
02590                         0,
02591                         wr_handles,
02592                         0,
02593                         timeout);
02594 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02595 #endif /* ACE_WIN32 */
02596 
02597   // If we failed to connect within the time period allocated by the
02598   // caller, then we fail (e.g., the remote host might have been too
02599   // busy to accept our call).
02600   if (n <= 0)
02601     {
02602       if (n == 0 && timeout != 0)
02603         errno = ETIME;
02604       return ACE_INVALID_HANDLE;
02605     }
02606 
02607   // On Windows, a ready-for-write handle is successfully connected, and
02608   // ready-for-exception is a failure. On fails, we need to grab the error
02609   // code via getsockopt.
02610   // On BSD sockets using select(), the handle becomes writable on
02611   // completion either success or fail, so if the select() does not time
02612   // out, we need to check for success/fail.
02613   // It is believed that TLI sockets use the readable=fail, writeable=success
02614   // but that hasn't been as well tested.
02615 #if defined (ACE_WIN32)
02616   ACE_UNUSED_ARG (is_tli);
02617 
02618   // On Win32, ex_handle set indicates a failure. We'll do the check
02619   // to try and get an errno value, but the connect failed regardless of
02620   // what getsockopt says about the error.
02621   if (ex_handles.is_set (h))
02622     {
02623       need_to_check = true;
02624       known_failure = true;
02625     }
02626 #else
02627   if (is_tli)
02628 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02629     need_to_check = (fds.revents & POLLIN) && !(fds.revents & POLLOUT);
02630 # else
02631     need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h);
02632 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02633 
02634   else
02635 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
02636     need_to_check = (fds.revents & POLLIN);
02637 # else
02638     need_to_check = true;
02639 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
02640 #endif /* ACE_WIN32 */
02641 
02642   if (need_to_check)
02643     {
02644 #if defined (SOL_SOCKET) && defined (SO_ERROR)
02645       int sock_err = 0;
02646       int sock_err_len = sizeof (sock_err);
02647       int sockopt_ret = ACE_OS::getsockopt (h, SOL_SOCKET, SO_ERROR,
02648                                             (char *)&sock_err, &sock_err_len);
02649       if (sockopt_ret < 0)
02650         {
02651           h = ACE_INVALID_HANDLE;
02652         }
02653 
02654       if (sock_err != 0 || known_failure)
02655         {
02656           h = ACE_INVALID_HANDLE;
02657           errno = sock_err;
02658         }
02659 #else
02660       char dummy;
02661 
02662       // The following recv() won't block provided that the
02663       // ACE_NONBLOCK flag has not been turned off .
02664       n = ACE::recv (h, &dummy, 1, MSG_PEEK);
02665 
02666       // If no data was read/peeked at, check to see if it's because
02667       // of a non-connected socket (and therefore an error) or there's
02668       // just no data yet.
02669       if (n <= 0)
02670         {
02671           if (n == 0)
02672             {
02673               errno = ECONNREFUSED;
02674               h = ACE_INVALID_HANDLE;
02675             }
02676           else if (errno != EWOULDBLOCK && errno != EAGAIN)
02677             h = ACE_INVALID_HANDLE;
02678         }
02679 #endif
02680     }
02681 
02682   // 1. The HANDLE is ready for writing and doesn't need to be checked or
02683   // 2. recv() returned an indication of the state of the socket - if there is
02684   // either data present, or a recv is legit but there's no data yet,
02685   // the connection was successfully established.
02686   return h;
02687 }

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 
)

Timed wait for handle to get write ready.

Definition at line 252 of file ACE.inl.

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

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.

00325 {
00326   u_long hash = 0;
00327 
00328   for (size_t i = 0; i < len; i++)
00329     {
00330       const char temp = str[i];
00331       hash = (hash << 4) + (temp * 13);
00332 
00333       u_long g = hash & 0xf0000000;
00334 
00335       if (g)
00336         {
00337           hash ^= (g >> 24);
00338           hash ^= g;
00339         }
00340     }
00341 
00342   return hash;
00343 }

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.

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

u_char ACE::hex2byte ( ACE_TCHAR  c  ) 

Convert a hex character to its byte representation.

Definition at line 337 of file ACE.inl.

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

ACE_Export int ACE::init ( void   ) 

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

Returns:
Returns 0 on success, -1 on failure, and 1 if it had already been called.
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 1572 of file Sock_Connect.cpp.

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

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

01587 {
01588 #if defined (ACE_HAS_IPV6)
01589   return ace_ipv6_enabled == -1 ?
01590     ::ip_check (ace_ipv6_enabled, PF_INET6) :
01591     ace_ipv6_enabled;
01592 #else /* ACE_HAS_IPV6 */
01593   return 0;
01594 #endif /* !ACE_HAS_IPV6 */
01595 }

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

03034 {
03035   if (n > 3)
03036     for (u_long factor = min_factor;
03037          factor <= max_factor;
03038          ++factor)
03039       if (n / factor * factor == n)
03040         return factor;
03041 
03042   return 0;
03043 }

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

03199 {
03200 #if defined (ACE_WIN32)
03201   switch (error)
03202     {
03203     case WSAVERNOTSUPPORTED:
03204     case WSASYSNOTREADY:
03205     case WSAEINVAL:
03206     case WSAHOST_NOT_FOUND:
03207     case WSATRY_AGAIN:
03208     case WSANO_RECOVERY:
03209     case WSANO_DATA:
03210       /*
03211         case WSANO_ADDRESS:
03212       */
03213     case WSANOTINITIALISED:
03214     case WSAENETDOWN:
03215     case WSAEINPROGRESS:
03216     case WSAEINTR:
03217     case WSAEAFNOSUPPORT:
03218     case WSAEMFILE:
03219     case WSAENOBUFS:
03220     case WSAEPROTONOSUPPORT:
03221     case WSAEPROTOTYPE:
03222     case WSAESOCKTNOSUPPORT:
03223     case WSAENOTSOCK:
03224     case WSAEWOULDBLOCK:
03225     case WSAEADDRINUSE:
03226     case WSAECONNABORTED:
03227     case WSAECONNRESET:
03228     case WSAENOTCONN:
03229     case WSAETIMEDOUT:
03230     case WSAECONNREFUSED:
03231     case WSAEHOSTDOWN:
03232     case WSAEHOSTUNREACH:
03233     case WSAEADDRNOTAVAIL:
03234     case WSAEISCONN:
03235     case WSAENETRESET:
03236     case WSAEMSGSIZE:
03237     case WSAENETUNREACH:
03238     case WSAEFAULT:
03239     case WSAEDISCON:
03240     case WSAEACCES:
03241     case WSAESHUTDOWN:
03242     case WSAEPROCLIM:
03243     case WSAEALREADY:
03244     case WSAEPFNOSUPPORT:
03245     case WSAENOPROTOOPT:
03246     case WSATYPE_NOT_FOUND:
03247     case WSAEOPNOTSUPP:
03248       return true;
03249     }
03250 #else
03251   ACE_UNUSED_ARG (error);
03252 #endif /* ACE_WIN32 */
03253   return false;
03254 }

bool ACE::isdotdir ( const char *  s  ) 

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

Definition at line 288 of file ACE.inl.

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

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.

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

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.

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

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.

00519 {
00520   ACE_TRACE ("ACE::ldopen");
00521 
00522   ACE_TCHAR buf[MAXPATHLEN + 1];
00523   if (ACE::ldfind (filename,
00524                    buf,
00525                    sizeof (buf) /sizeof (ACE_TCHAR)) == -1)
00526     return 0;
00527   else
00528     return ACE_OS::fopen (buf, type);
00529 }

ACE_Export void ACE::ldregister ( const ACE_TCHAR entry_point,
void *  entry_addr 
)

Registers an entry_point and its address for later retrieval through the ACE::ldsymbol () method. For use in cases where the OS compiler encodes long symbolnames.

ACE_Export void* ACE::ldsymbol ( ACE_SHLIB_HANDLE  sh,
const ACE_TCHAR entry_point 
)

Looks up an entry_point address either from previously registered symbols or through ACE_OS::dlsym (). Returns 0 in case the entry_point is not found, otherwise nonzero. For use in cases where the OS compiler encodes long symbolnames.

u_long ACE::log2 ( u_long  num  ) 

Computes the base 2 logarithm of {num}.

Definition at line 312 of file ACE.inl.

00313 {
00314   u_long log = 0;
00315 
00316   for (; num > 1; ++log)
00317     num >>= 1;
00318 
00319   return log;
00320 }

u_int ACE::major_version ( void   ) 

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

Definition at line 109 of file ACE.cpp.

00110 {
00111   return ACE_MAJOR_VERSION;
00112 }

int ACE::map_errno ( int  error  ) 

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

Definition at line 323 of file ACE.inl.

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

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

02882 {
02883   ACE_TRACE ("ACE::max_handles");
02884 #if defined (RLIMIT_NOFILE) && !defined (ACE_LACKS_RLIMIT)
02885   rlimit rl;
02886   int const r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
02887 # if !defined (RLIM_INFINITY)
02888   if (r == 0)
02889     return rl.rlim_cur;
02890 # else
02891   if (r == 0 && rl.rlim_cur != RLIM_INFINITY)
02892     return rl.rlim_cur;
02893   // If == RLIM_INFINITY, fall through to the ACE_LACKS_RLIMIT sections
02894 # endif /* RLIM_INFINITY */
02895 #endif /* RLIMIT_NOFILE && !ACE_LACKS_RLIMIT */
02896 
02897 #if defined (_SC_OPEN_MAX)
02898   return ACE_OS::sysconf (_SC_OPEN_MAX);
02899 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x620)
02900   return maxFiles;
02901 #elif defined (FD_SETSIZE)
02902   return FD_SETSIZE;
02903 #else
02904   ACE_NOTSUP_RETURN (-1);
02905 #endif /* _SC_OPEN_MAX */
02906 }

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

02989 {
02990   // if one of the periods is zero, treat it as though it as
02991   // uninitialized and return the other period as the frame size
02992   if (0 == period1)
02993     {
02994       return period2;
02995     }
02996   if (0 == period2)
02997     {
02998       return period1;
02999     }
03000 
03001   // if neither is zero, find the greatest common divisor of the two periods
03002   u_long greatest_common_divisor = ACE::gcd (period1, period2);
03003 
03004   // explicitly consider cases to reduce risk of possible overflow errors
03005   if (greatest_common_divisor == 1)
03006     {
03007       // periods are relative primes: just multiply them together
03008       return period1 * period2;
03009     }
03010   else if (greatest_common_divisor == period1)
03011     {
03012       // the first period divides the second: return the second
03013       return period2;
03014     }
03015   else if (greatest_common_divisor == period2)
03016     {
03017       // the second period divides the first: return the first
03018       return period1;
03019     }
03020   else
03021     {
03022       // the current frame size and the entry's effective period
03023       // have a non-trivial greatest common divisor: return the
03024       // product of factors divided by those in their gcd.
03025       return (period1 * period2) / greatest_common_divisor;
03026     }
03027 }

u_int ACE::minor_version ( void   ) 

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

Definition at line 115 of file ACE.cpp.

00116 {
00117   return ACE_MINOR_VERSION;
00118 }

ACE_TCHAR ACE::nibble2hex ( u_int  n  ) 

Hex conversion utility.

Definition at line 167 of file ACE.cpp.

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

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.

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

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.

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

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.

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

ssize_t ACE::read_n ( ACE_HANDLE  handle,
void *  buf,
size_t  len,
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 17 of file ACE.inl.

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

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

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

02122 {
02123   size_t temp;
02124   size_t &bytes_transferred = bt == 0 ? temp : *bt;
02125   bytes_transferred = 0;
02126 
02127   for (int s = 0;
02128        s < iovcnt;
02129        )
02130     {
02131       ssize_t n = ACE_OS::readv (handle,
02132                                  iov + s,
02133                                  iovcnt - s);
02134 
02135       if (n == -1 || n == 0)
02136         return n;
02137 
02138       for (bytes_transferred += n;
02139            s < iovcnt
02140              && n >= static_cast<ssize_t> (iov[s].iov_len);
02141            s++)
02142         n -= iov[s].iov_len;
02143 
02144       if (n != 0)
02145         {
02146           char *base = reinterpret_cast<char *> (iov[s].iov_base);
02147           iov[s].iov_base = base + n;
02148           iov[s].iov_len = iov[s].iov_len - n;
02149         }
02150     }
02151 
02152   return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
02153 }

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

02288 {
02289   // We need to record whether we are already *in* nonblocking mode,
02290   // so that we can correctly reset the state when we're done.
02291   val = ACE::get_flags (handle);
02292 
02293   if (ACE_BIT_DISABLED (val, ACE_NONBLOCK))
02294     // Set the handle into non-blocking mode if it's not already in
02295     // it.
02296     ACE::set_flags (handle, ACE_NONBLOCK);
02297 }

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

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

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.

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

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.

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

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

Definition at line 231 of file ACE.inl.

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

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

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

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

ssize_t ACE::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.

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.

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

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 
)

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.

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

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

Definition at line 863 of file ACE.cpp.

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

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

Definition at line 813 of file ACE.cpp.

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

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.

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

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.

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

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.

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

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.

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

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

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

ssize_t ACE::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.

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.

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

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

Definition at line 1048 of file ACE.cpp.

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

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

Definition at line 986 of file ACE.cpp.

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

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

02302 {
02303   if (ACE_BIT_DISABLED (val,
02304                         ACE_NONBLOCK))
02305     {
02306       // Save/restore errno.
02307       ACE_Errno_Guard error (errno);
02308       // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
02309       // originally.
02310       ACE::clr_flags (handle, ACE_NONBLOCK);
02311     }
02312 }

size_t ACE::round_to_allocation_granularity ( size_t  len  ) 

Rounds the request to a multiple of the allocation granularity.

Definition at line 2526 of file ACE.cpp.

02527 {
02528   ACE_TRACE ("ACE::round_to_allocation_granularity");
02529 
02530   if (ACE::allocation_granularity_ == 0)
02531     ACE::allocation_granularity_ = ACE_OS::allocation_granularity ();
02532 
02533   return (len + (ACE::allocation_granularity_ - 1)) & ~(ACE::allocation_granularity_ - 1);
02534 }

size_t ACE::round_to_pagesize ( size_t  len  ) 

Rounds the request to a multiple of the page size.

Definition at line 2515 of file ACE.cpp.

02516 {
02517   ACE_TRACE ("ACE::round_to_pagesize");
02518 
02519   if (ACE::pagesize_ == 0)
02520     ACE::pagesize_ = ACE_OS::getpagesize ();
02521 
02522   return (len + (ACE::pagesize_ - 1)) & ~(ACE::pagesize_ - 1);
02523 }

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.

00217 {
00218   int result = ACE_OS::select (width,
00219                                readfds.fdset (),
00220                                0,
00221                                0,
00222                                timeout);
00223 
00224 #if !defined (ACE_WIN32)
00225   if (result > 0)
00226     readfds.sync ((ACE_HANDLE) width);
00227 #endif /* ACE_WIN32 */
00228   return result;
00229 }

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.

00192 {
00193   int result = ACE_OS::select (width,
00194                                readfds ? readfds->fdset () : 0,
00195                                writefds ? writefds->fdset () : 0,
00196                                exceptfds ? exceptfds->fdset () : 0,
00197                                timeout);
00198   if (result > 0)
00199     {
00200 # if !defined (ACE_WIN32)
00201       // This isn't needed for Windows... it's a no-op anyway.
00202       if (readfds)
00203         readfds->sync ((ACE_HANDLE) width);
00204       if (writefds)
00205         writefds->sync ((ACE_HANDLE) width);
00206       if (exceptfds)
00207         exceptfds->sync ((ACE_HANDLE) width);
00208 #endif /* ACE_WIN32 */
00209     }
00210   return result;
00211 }

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

Varargs variant.

Definition at line 1723 of file ACE.cpp.

01724 {
01725   va_list argp;
01726   int total_tuples = static_cast<int> (n / 2);
01727   iovec *iovp;
01728 #if defined (ACE_HAS_ALLOCA)
01729   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
01730 #else
01731   ACE_NEW_RETURN (iovp,
01732                   iovec[total_tuples],
01733                   -1);
01734 #endif /* !defined (ACE_HAS_ALLOCA) */
01735 
01736   va_start (argp, n);
01737 
01738   for (int i = 0; i < total_tuples; i++)
01739     {
01740       iovp[i].iov_base = va_arg (argp, char *);
01741       iovp[i].iov_len = va_arg (argp, int);
01742     }
01743 
01744   ssize_t result = ACE_OS::sendv (handle, iovp, total_tuples);
01745 #if !defined (ACE_HAS_ALLOCA)
01746   delete [] iovp;
01747 #endif /* !defined (ACE_HAS_ALLOCA) */
01748   va_end (argp);
01749   return result;
01750 }

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

01284 {
01285   if (timeout == 0)
01286     return ACE::send_i (handle, buf, n);
01287   else
01288     {
01289       int val = 0;
01290       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01291         return -1;
01292       else
01293         {
01294           ssize_t bytes_transferred = ACE::send_i (handle, buf, n);
01295           ACE::restore_non_blocking_mode (handle, val);
01296           return bytes_transferred;
01297         }
01298     }
01299 }

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

01235 {
01236   if (timeout == 0)
01237     return ACE_OS::send (handle, (const char *) buf, n, flags);
01238   else
01239     {
01240       int val = 0;
01241       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01242         return -1;
01243       else
01244         {
01245           ssize_t bytes_transferred = ACE_OS::send (handle, (const char *) buf, n, flags);
01246           ACE::restore_non_blocking_mode (handle, val);
01247           return bytes_transferred;
01248         }
01249     }
01250 }

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

Definition at line 221 of file ACE.inl.

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

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

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

Definition at line 2018 of file ACE.cpp.

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

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 
)

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.

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

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 
)

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.

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

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

Definition at line 1649 of file ACE.cpp.

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

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

Definition at line 1598 of file ACE.cpp.

01602 {
01603   size_t temp;
01604   size_t &bytes_transferred = bt == 0 ? temp : *bt;
01605   ssize_t n;
01606 
01607   for (bytes_transferred = 0;
01608        bytes_transferred < len;
01609        bytes_transferred += n)
01610     {
01611       // Try to transfer as much of the remaining data as possible.
01612       n = ACE::send_i (handle,
01613                        (char *) buf + bytes_transferred,
01614                        len - bytes_transferred);
01615       // Check EOF.
01616       if (n == 0)
01617         {
01618           return 0;
01619         }
01620 
01621       // Check for other errors.
01622       if (n == -1)
01623         {
01624           // Check for possible blocking.
01625           if (errno == EWOULDBLOCK || errno == ENOBUFS)
01626             {
01627               // Wait for the blocking to subside.
01628               int result = ACE::handle_write_ready (handle,
01629                                                     0);
01630 
01631               // Did select() succeed?
01632               if (result != -1)
01633                 {
01634                   // Blocking subsided.  Continue data transfer.
01635                   n = 0;
01636                   continue;
01637                 }
01638             }
01639 
01640           // Other data transfer or select() failures.
01641           return -1;
01642         }
01643     }
01644 
01645   return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
01646 }

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

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

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

Definition at line 1350 of file ACE.cpp.

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

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

01306 {
01307   if (timeout == 0)
01308     return ACE_OS::sendmsg (handle, msg, flags);
01309   else
01310     {
01311       int val = 0;
01312       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01313         return -1;
01314       else
01315         {
01316           ssize_t bytes_transferred = ACE_OS::sendmsg (handle, msg, flags);
01317           ACE::restore_non_blocking_mode (handle, val);
01318           return bytes_transferred;
01319         }
01320     }
01321 }

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

01331 {
01332   if (timeout == 0)
01333     return ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
01334   else
01335     {
01336       int val = 0;
01337       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01338         return -1;
01339       else
01340         {
01341           ssize_t bytes_transferred =
01342             ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
01343           ACE::restore_non_blocking_mode (handle, val);
01344           return bytes_transferred;
01345         }
01346     }
01347 }

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

01757 {
01758   if (timeout == 0)
01759     return ACE_OS::sendv (handle, iov, iovcnt);
01760   else
01761     {
01762       int val = 0;
01763       if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
01764         return -1;
01765       else
01766         {
01767           ssize_t bytes_transferred = ACE_OS::sendv (handle, iov, iovcnt);
01768           ACE::restore_non_blocking_mode (handle, val);
01769           return bytes_transferred;
01770         }
01771     }
01772 }

ssize_t ACE::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.

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.

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

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

Definition at line 1839 of file ACE.cpp.

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