1 // $Id: ACE.cpp 82581 2008-08-11 08:58:24Z johnnyw $
5 #include "ace/Basic_Types.h"
6 #include "ace/Handle_Set.h"
7 #include "ace/Auto_Ptr.h"
8 #include "ace/SString.h"
9 #include "ace/Version.h"
10 #include "ace/Message_Block.h"
11 #include "ace/Log_Msg.h"
12 #include "ace/OS_NS_sys_select.h"
13 #include "ace/OS_NS_string.h"
14 #include "ace/OS_NS_strings.h"
15 #include "ace/OS_NS_signal.h"
16 #include "ace/OS_NS_stdio.h"
17 #include "ace/OS_NS_sys_resource.h"
18 #include "ace/OS_NS_sys_wait.h"
19 #include "ace/OS_NS_sys_time.h"
20 #include "ace/OS_NS_time.h"
21 #include "ace/OS_NS_sys_uio.h"
22 #include "ace/OS_NS_sys_stat.h"
23 #include "ace/OS_NS_ctype.h"
24 #include "ace/OS_NS_fcntl.h"
25 #include "ace/OS_TLI.h"
26 #include "ace/Truncate.h"
28 #if defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x620)
29 extern "C" int maxFiles
;
30 #endif /* ACE_VXWORKS */
32 #if !defined (__ACE_INLINE__)
33 #include "ace/ACE.inl"
34 #endif /* __ACE_INLINE__ */
36 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
37 # include "ace/OS_NS_poll.h"
38 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
43 "$Id: ACE.cpp 82581 2008-08-11 08:58:24Z johnnyw $")
46 // Open versioned namespace, if enabled by the user.
47 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
52 // Used internally so not exported.
54 // Size of allocation granularity.
55 size_t allocation_granularity_
= 0;
60 // Are we debugging ACE?
61 // Keeps track of whether we're in some global debug mode.
67 ACE::out_of_handles (int error
)
69 // EMFILE is common to all platforms.
70 if (error
== EMFILE
||
71 #if defined (ACE_WIN32)
72 // On Win32, we need to check for ENOBUFS also.
75 // On HPUX, we need to check for EADDRNOTAVAIL also.
76 error
== EADDRNOTAVAIL
||
78 // On linux, we need to check for ENOENT also.
80 // For RedHat5.2, need to check for EINVAL too.
82 // Without threads check for EOPNOTSUPP
83 error
== EOPNOTSUPP
||
85 // On sun, we need to check for ENOSR also.
87 // Without threads check for ENOTSUP
89 #elif defined (__FreeBSD__)
90 // On FreeBSD we need to check for EOPNOTSUPP (LinuxThreads) or
91 // ENOSYS (libc_r threads) also.
92 error
== EOPNOTSUPP
||
94 #elif defined (__OpenBSD__)
95 // OpenBSD appears to return EBADF.
97 #elif defined (__sgi) // irix
99 #elif defined (DIGITAL_UNIX) // osf1
101 #endif /* ACE_WIN32 */
109 ACE::major_version (void)
111 return ACE_MAJOR_VERSION
;
115 ACE::minor_version (void)
117 return ACE_MINOR_VERSION
;
121 ACE::beta_version (void)
123 return ACE_BETA_VERSION
;
127 ACE::compiler_name (void)
132 return ACE_TEXT ("");
137 ACE::compiler_major_version (void)
139 #ifdef ACE_CC_MAJOR_VERSION
140 return ACE_CC_MAJOR_VERSION
;
147 ACE::compiler_minor_version (void)
149 #ifdef ACE_CC_MINOR_VERSION
150 return ACE_CC_MINOR_VERSION
;
157 ACE::compiler_beta_version (void)
159 #ifdef ACE_CC_BETA_VERSION
160 return ACE_CC_BETA_VERSION
;
169 static const char* debug
= ACE_OS::getenv ("ACE_DEBUG");
170 return (ACE::debug_
!= 0) ? ACE::debug_
: (debug
!= 0 ? (*debug
!= '0'): false);
174 ACE::debug (bool onoff
)
180 ACE::select (int width
,
181 ACE_Handle_Set
*readfds
,
182 ACE_Handle_Set
*writefds
,
183 ACE_Handle_Set
*exceptfds
,
184 const ACE_Time_Value
*timeout
)
186 int result
= ACE_OS::select (width
,
187 readfds
? readfds
->fdset () : 0,
188 writefds
? writefds
->fdset () : 0,
189 exceptfds
? exceptfds
->fdset () : 0,
193 # if !defined (ACE_WIN32)
194 // This isn't needed for Windows... it's a no-op anyway.
196 readfds
->sync ((ACE_HANDLE
) width
);
198 writefds
->sync ((ACE_HANDLE
) width
);
200 exceptfds
->sync ((ACE_HANDLE
) width
);
201 #endif /* ACE_WIN32 */
207 ACE::select (int width
,
208 ACE_Handle_Set
&readfds
,
209 const ACE_Time_Value
*timeout
)
211 int result
= ACE_OS::select (width
,
217 #if !defined (ACE_WIN32)
219 readfds
.sync ((ACE_HANDLE
) width
);
220 #endif /* ACE_WIN32 */
225 ACE::terminate_process (pid_t pid
)
227 #if defined (ACE_HAS_PHARLAP)
228 ACE_UNUSED_ARG (pid
);
229 ACE_NOTSUP_RETURN (-1);
230 #elif defined (ACE_WIN32)
231 // Create a handle for the given process id.
232 ACE_HANDLE process_handle
=
233 ::OpenProcess (PROCESS_TERMINATE
,
234 FALSE
, // New handle is not inheritable.
237 if (process_handle
== ACE_INVALID_HANDLE
238 || process_handle
== 0)
242 // Kill the process associated with process_handle.
243 BOOL terminate_result
=
244 ::TerminateProcess (process_handle
, 0);
245 // Free up the kernel resources.
246 ACE_OS::close (process_handle
);
247 return terminate_result
? 0 : -1;
250 return ACE_OS::kill (pid
, 9);
251 #endif /* ACE_HAS_PHARLAP */
255 ACE::process_active (pid_t pid
)
257 #if !defined(ACE_WIN32)
258 if (ACE_OS::kill (pid
, 0) == 0)
260 else if (errno
== ESRCH
)
265 // Create a handle for the given process id.
266 ACE_HANDLE process_handle
=
267 ::OpenProcess (PROCESS_QUERY_INFORMATION
, FALSE
, pid
);
268 if (process_handle
== ACE_INVALID_HANDLE
|| process_handle
== 0)
274 if (::GetExitCodeProcess (process_handle
,
276 || status
!= STILL_ACTIVE
)
279 ::CloseHandle (process_handle
);
282 #endif /* !ACE_WIN32 */
286 ACE::execname (const ACE_TCHAR
*old_name
)
288 #if defined (ACE_WIN32)
289 const ACE_TCHAR
*suffix
= ACE_OS::strrchr (old_name
, ACE_TEXT ('.'));
290 if (suffix
== 0 || ACE_OS::strcasecmp (suffix
, ACE_TEXT (".exe")) != 0)
292 ACE_TCHAR
*new_name
= 0;
295 ACE_OS::strlen (old_name
)
296 + ACE_OS::strlen (ACE_TEXT (".exe"))
299 ACE_NEW_RETURN (new_name
,
302 ACE_TCHAR
*end
= new_name
;
304 end
= ACE_OS::strecpy (new_name
, old_name
);
306 // Concatenate the .exe suffix onto the end of the executable.
307 // end points _after_ the terminating nul.
308 ACE_OS::strcpy (end
- 1, ACE_TEXT (".exe"));
312 #endif /* ACE_WIN32 */
317 ACE::hash_pjw (const char *str
, size_t len
)
321 for (size_t i
= 0; i
< len
; i
++)
323 const char temp
= str
[i
];
324 hash
= (hash
<< 4) + (temp
* 13);
326 u_long g
= hash
& 0xf0000000;
339 ACE::hash_pjw (const char *str
)
341 return ACE::hash_pjw (str
, ACE_OS::strlen (str
));
344 #if defined (ACE_HAS_WCHAR)
346 ACE::hash_pjw (const wchar_t *str
, size_t len
)
350 for (size_t i
= 0; i
< len
; i
++)
352 // @@ UNICODE: Does this function do the correct thing with wchar's?
354 const wchar_t temp
= str
[i
];
355 hash
= (hash
<< 4) + (temp
* 13);
357 u_long g
= hash
& 0xf0000000;
370 ACE::hash_pjw (const wchar_t *str
)
372 return ACE::hash_pjw (str
, ACE_OS::strlen (str
));
374 #endif /* ACE_HAS_WCHAR */
376 #if !defined (ACE_HAS_WINCE)
378 ACE::strenvdup (const ACE_TCHAR
*str
)
380 ACE_TRACE ("ACE::strenvdup");
382 return ACE_OS::strenvdup (str
);
384 #endif /* ACE_HAS_WINCE */
391 ==================================================================
392 netsvc netsvc.dll libnetsvc.so
393 (PATH will be (LD_LIBRARY_PATH
394 evaluated) evaluated)
396 libnetsvc.dll libnetsvc.dll libnetsvc.dll + warning
397 netsvc.so netsvc.so + warning libnetsvc.so
399 ..\../libs/netsvc ..\..\libs\netsvc.dll ../../libs/netsvc.so
400 (absolute path used) (absolute path used)
405 ACE::basename (const ACE_TCHAR
*pathname
, ACE_TCHAR delim
)
407 ACE_TRACE ("ACE::basename");
408 const ACE_TCHAR
*temp
= ACE_OS::strrchr (pathname
, delim
);
417 ACE::dirname (const ACE_TCHAR
*pathname
, ACE_TCHAR delim
)
419 ACE_TRACE ("ACE::dirname");
420 static ACE_TCHAR return_dirname
[MAXPATHLEN
+ 1];
422 const ACE_TCHAR
*temp
= ACE_OS::strrchr (pathname
, delim
);
426 return_dirname
[0] = '.';
427 return_dirname
[1] = '\0';
429 return return_dirname
;
433 // When the len is truncated, there are problems! This should
434 // not happen in normal circomstances
435 size_t len
= temp
- pathname
+ 1;
436 if (len
> (sizeof return_dirname
/ sizeof (ACE_TCHAR
)))
437 len
= sizeof return_dirname
/ sizeof (ACE_TCHAR
);
439 ACE_OS::strsncpy (return_dirname
,
442 return return_dirname
;
447 ACE::recv (ACE_HANDLE handle
,
451 const ACE_Time_Value
*timeout
)
454 return ACE_OS::recv (handle
, (char *) buf
, len
, flags
);
458 if (ACE::enter_recv_timedwait (handle
, timeout
, val
) ==-1)
462 ssize_t bytes_transferred
=
463 ACE_OS::recv (handle
, (char *) buf
, len
, flags
);
464 ACE::restore_non_blocking_mode (handle
, val
);
465 return bytes_transferred
;
470 #if defined (ACE_HAS_TLI)
473 ACE::t_rcv (ACE_HANDLE handle
,
477 const ACE_Time_Value
*timeout
)
480 return ACE_OS::t_rcv (handle
, (char *) buf
, len
, flags
);
484 if (ACE::enter_recv_timedwait (handle
, timeout
, val
) ==-1)
488 ssize_t bytes_transferred
=
489 ACE_OS::t_rcv (handle
, (char *) buf
, len
, flags
);
490 ACE::restore_non_blocking_mode (handle
, val
);
491 return bytes_transferred
;
496 #endif /* ACE_HAS_TLI */
499 ACE::recv (ACE_HANDLE handle
,
502 const ACE_Time_Value
*timeout
)
505 return ACE::recv_i (handle
, buf
, n
);
509 if (ACE::enter_recv_timedwait (handle
, timeout
, val
) == -1)
513 ssize_t bytes_transferred
= ACE::recv_i (handle
, buf
, n
);
514 ACE::restore_non_blocking_mode (handle
, val
);
515 return bytes_transferred
;
521 ACE::recvmsg (ACE_HANDLE handle
,
524 const ACE_Time_Value
*timeout
)
527 return ACE_OS::recvmsg (handle
, msg
, flags
);
531 if (ACE::enter_recv_timedwait (handle
, timeout
, val
) == -1)
535 ssize_t bytes_transferred
= ACE_OS::recvmsg (handle
, msg
, flags
);
536 ACE::restore_non_blocking_mode (handle
, val
);
537 return bytes_transferred
;
543 ACE::recvfrom (ACE_HANDLE handle
,
547 struct sockaddr
*addr
,
549 const ACE_Time_Value
*timeout
)
552 return ACE_OS::recvfrom (handle
, buf
, len
, flags
, addr
, addrlen
);
556 if (ACE::enter_recv_timedwait (handle
, timeout
, val
) == -1)
560 ssize_t bytes_transferred
=
561 ACE_OS::recvfrom (handle
, buf
, len
, flags
, addr
, addrlen
);
562 ACE::restore_non_blocking_mode (handle
, val
);
563 return bytes_transferred
;
569 ACE::recv_n_i (ACE_HANDLE handle
,
576 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
579 for (bytes_transferred
= 0;
580 bytes_transferred
< len
;
581 bytes_transferred
+= n
)
583 // Try to transfer as much of the remaining data as possible.
584 n
= ACE_OS::recv (handle
,
585 static_cast <char *> (buf
) + bytes_transferred
,
586 len
- bytes_transferred
,
592 // Check for other errors.
595 // Check for possible blocking.
596 if (errno
== EWOULDBLOCK
)
598 // Wait for the blocking to subside.
599 int const result
= ACE::handle_read_ready (handle
, 0);
601 // Did select() succeed?
604 // Blocking subsided. Continue data transfer.
610 // Other data transfer or select() failures.
615 return static_cast<ssize_t
> (bytes_transferred
);
619 ACE::recv_n_i (ACE_HANDLE handle
,
623 const ACE_Time_Value
*timeout
,
627 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
633 ACE::record_and_set_non_blocking_mode (handle
, val
);
635 for (bytes_transferred
= 0;
636 bytes_transferred
< len
;
637 bytes_transferred
+= n
)
639 // Try to transfer as much of the remaining data as possible.
640 // Since the socket is in non-blocking mode, this call will not
642 n
= ACE_OS::recv (handle
,
643 static_cast <char *> (buf
) + bytes_transferred
,
644 len
- bytes_transferred
,
651 // Check for possible blocking.
653 errno
== EWOULDBLOCK
)
655 // Wait upto <timeout> for the blocking to subside.
656 int rtn
= ACE::handle_read_ready (handle
,
659 // Did select() succeed?
662 // Blocking subsided in <timeout> period. Continue
669 // Wait in select() timed out or other data transfer or
670 // select() failures.
677 ACE::restore_non_blocking_mode (handle
, val
);
682 return static_cast<ssize_t
> (bytes_transferred
);
685 #if defined (ACE_HAS_TLI)
688 ACE::t_rcv_n_i (ACE_HANDLE handle
,
695 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
698 for (bytes_transferred
= 0;
699 bytes_transferred
< len
;
700 bytes_transferred
+= n
)
702 // Try to transfer as much of the remaining data as possible.
703 n
= ACE_OS::t_rcv (handle
,
704 (char *) buf
+ bytes_transferred
,
705 len
- bytes_transferred
,
711 // Check for other errors.
714 // Check for possible blocking.
715 if (errno
== EWOULDBLOCK
)
717 // Wait for the blocking to subside.
718 int result
= ACE::handle_read_ready (handle
,
721 // Did select() succeed?
724 // Blocking subsided. Continue data transfer.
730 // Other data transfer or select() failures.
735 return bytes_transferred
;
739 ACE::t_rcv_n_i (ACE_HANDLE handle
,
743 const ACE_Time_Value
*timeout
,
747 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
753 ACE::record_and_set_non_blocking_mode (handle
, val
);
755 for (bytes_transferred
= 0;
756 bytes_transferred
< len
;
757 bytes_transferred
+= n
)
759 // Try to transfer as much of the remaining data as possible.
760 // Since the socket is in non-blocking mode, this call will not
762 n
= ACE_OS::t_rcv (handle
,
763 (char *) buf
+ bytes_transferred
,
764 len
- bytes_transferred
,
771 // Check for possible blocking.
773 errno
== EWOULDBLOCK
)
775 // Wait upto <timeout> for the blocking to subside.
776 int rtn
= ACE::handle_read_ready (handle
,
779 // Did select() succeed?
782 // Blocking subsided in <timeout> period. Continue
789 // Wait in select() timed out or other data transfer or
790 // select() failures.
797 ACE::restore_non_blocking_mode (handle
, val
);
802 return bytes_transferred
;
805 #endif /* ACE_HAS_TLI */
808 ACE::recv_n_i (ACE_HANDLE handle
,
814 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
817 for (bytes_transferred
= 0;
818 bytes_transferred
< len
;
819 bytes_transferred
+= n
)
821 // Try to transfer as much of the remaining data as possible.
822 n
= ACE::recv_i (handle
,
823 static_cast <char *> (buf
) + bytes_transferred
,
824 len
- bytes_transferred
);
830 // Check for other errors.
833 // Check for possible blocking.
834 if (errno
== EWOULDBLOCK
)
836 // Wait for the blocking to subside.
837 int result
= ACE::handle_read_ready (handle
,
840 // Did select() succeed?
843 // Blocking subsided. Continue data transfer.
849 // Other data transfer or select() failures.
854 return static_cast<ssize_t
> (bytes_transferred
);
858 ACE::recv_n_i (ACE_HANDLE handle
,
861 const ACE_Time_Value
*timeout
,
865 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
871 ACE::record_and_set_non_blocking_mode (handle
, val
);
873 for (bytes_transferred
= 0;
874 bytes_transferred
< len
;
875 bytes_transferred
+= n
)
877 // Try to transfer as much of the remaining data as possible.
878 // Since the socket is in non-blocking mode, this call will not
880 n
= ACE::recv_i (handle
,
881 static_cast <char *> (buf
) + bytes_transferred
,
882 len
- bytes_transferred
);
888 // Check for possible blocking.
890 errno
== EWOULDBLOCK
)
892 // Wait upto <timeout> for the blocking to subside.
893 int rtn
= ACE::handle_read_ready (handle
,
896 // Did select() succeed?
899 // Blocking subsided in <timeout> period. Continue
906 // Wait in select() timed out or other data transfer or
907 // select() failures.
914 ACE::restore_non_blocking_mode (handle
, val
);
919 return static_cast<ssize_t
> (bytes_transferred
);
922 // This is basically an interface to ACE_OS::readv, that doesn't use
923 // the struct iovec explicitly. The ... can be passed as an arbitrary
924 // number of (char *ptr, int len) tuples. However, the count N is the
925 // *total* number of trailing arguments, *not* a couple of the number
929 ACE::recv (ACE_HANDLE handle
, size_t n
, ...)
932 int total_tuples
= static_cast<int> (n
/ 2);
934 #if defined (ACE_HAS_ALLOCA)
935 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
937 ACE_NEW_RETURN (iovp
,
940 #endif /* !defined (ACE_HAS_ALLOCA) */
944 for (int i
= 0; i
< total_tuples
; i
++)
946 iovp
[i
].iov_base
= va_arg (argp
, char *);
947 iovp
[i
].iov_len
= va_arg (argp
, int);
950 ssize_t result
= ACE_OS::recvv (handle
, iovp
, total_tuples
);
951 #if !defined (ACE_HAS_ALLOCA)
953 #endif /* !defined (ACE_HAS_ALLOCA) */
959 ACE::recvv (ACE_HANDLE handle
,
962 const ACE_Time_Value
*timeout
)
965 return ACE_OS::recvv (handle
, iov
, iovcnt
);
969 if (ACE::enter_recv_timedwait (handle
, timeout
, val
) == -1)
973 ssize_t bytes_transferred
= ACE_OS::recvv (handle
, iov
, iovcnt
);
974 ACE::restore_non_blocking_mode (handle
, val
);
975 return bytes_transferred
;
981 ACE::recvv_n_i (ACE_HANDLE handle
,
987 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
988 bytes_transferred
= 0;
994 // Try to transfer as much of the remaining data as possible.
995 ssize_t n
= ACE_OS::recvv (handle
,
1002 // Check for other errors.
1005 // Check for possible blocking.
1006 if (errno
== EWOULDBLOCK
)
1008 // Wait for the blocking to subside.
1009 int result
= ACE::handle_read_ready (handle
,
1012 // Did select() succeed?
1015 // Blocking subsided. Continue data transfer.
1021 // Other data transfer or select() failures.
1025 for (bytes_transferred
+= n
;
1027 && n
>= static_cast<ssize_t
> (iov
[s
].iov_len
);
1029 n
-= iov
[s
].iov_len
;
1033 char *base
= static_cast<char *> (iov
[s
].iov_base
);
1034 iov
[s
].iov_base
= base
+ n
;
1035 iov
[s
].iov_len
= iov
[s
].iov_len
- n
;
1039 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1043 ACE::recvv_n_i (ACE_HANDLE handle
,
1046 const ACE_Time_Value
*timeout
,
1050 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1051 bytes_transferred
= 0;
1056 ACE::record_and_set_non_blocking_mode (handle
, val
);
1062 // Try to transfer as much of the remaining data as possible.
1063 // Since the socket is in non-blocking mode, this call will not
1065 ssize_t n
= ACE_OS::recvv (handle
,
1069 // Check for errors.
1073 // Check for possible blocking.
1075 errno
== EWOULDBLOCK
)
1077 // Wait upto <timeout> for the blocking to subside.
1078 int rtn
= ACE::handle_read_ready (handle
,
1081 // Did select() succeed?
1084 // Blocking subsided in <timeout> period. Continue
1091 // Wait in select() timed out or other data transfer or
1092 // select() failures.
1098 for (bytes_transferred
+= n
;
1100 && n
>= static_cast<ssize_t
> (iov
[s
].iov_len
);
1102 n
-= iov
[s
].iov_len
;
1106 char *base
= reinterpret_cast<char *> (iov
[s
].iov_base
);
1107 iov
[s
].iov_base
= base
+ n
;
1108 iov
[s
].iov_len
= iov
[s
].iov_len
- n
;
1112 ACE::restore_non_blocking_mode (handle
, val
);
1120 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1125 ACE::recv_n (ACE_HANDLE handle
,
1126 ACE_Message_Block
*message_block
,
1127 const ACE_Time_Value
*timeout
,
1131 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1132 bytes_transferred
= 0;
1134 iovec iov
[ACE_IOV_MAX
];
1137 while (message_block
!= 0)
1139 // Our current message block chain.
1140 const ACE_Message_Block
*current_message_block
= message_block
;
1142 while (current_message_block
!= 0)
1144 size_t current_message_block_length
=
1145 current_message_block
->length ();
1146 char *this_rd_ptr
= current_message_block
->rd_ptr ();
1148 // Check if this block has any space for incoming data.
1149 while (current_message_block_length
> 0)
1151 u_long
const this_chunk_length
=
1152 ACE_Utils::truncate_cast
<u_long
> (
1153 current_message_block_length
);
1155 // Collect the data in the iovec.
1156 iov
[iovcnt
].iov_base
= this_rd_ptr
;
1157 iov
[iovcnt
].iov_len
= this_chunk_length
;
1158 current_message_block_length
-= this_chunk_length
;
1159 this_rd_ptr
+= this_chunk_length
;
1161 // Increment iovec counter.
1164 // The buffer is full make a OS call. @@ TODO find a way to
1165 // find ACE_IOV_MAX for platforms that do not define it rather
1166 // than simply setting ACE_IOV_MAX to some arbitrary value such
1168 if (iovcnt
== ACE_IOV_MAX
)
1170 size_t current_transfer
= 0;
1172 ssize_t
const result
= ACE::recvv_n (handle
,
1178 // Add to total bytes transferred.
1179 bytes_transferred
+= current_transfer
;
1182 if (result
== -1 || result
== 0)
1185 // Reset iovec counter.
1190 // Select the next message block in the chain.
1191 current_message_block
= current_message_block
->cont ();
1194 // Selection of the next message block chain.
1195 message_block
= message_block
->next ();
1198 // Check for remaining buffers to be sent. This will happen when
1199 // ACE_IOV_MAX is not a multiple of the number of message blocks.
1202 size_t current_transfer
= 0;
1204 ssize_t
const result
= ACE::recvv_n (handle
,
1210 // Add to total bytes transferred.
1211 bytes_transferred
+= current_transfer
;
1214 if (result
== -1 || result
== 0)
1220 // Return total bytes transferred.
1221 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1225 ACE::send (ACE_HANDLE handle
,
1229 const ACE_Time_Value
*timeout
)
1232 return ACE_OS::send (handle
, (const char *) buf
, n
, flags
);
1236 if (ACE::enter_send_timedwait (handle
, timeout
, val
) == -1)
1240 ssize_t bytes_transferred
= ACE_OS::send (handle
, (const char *) buf
, n
, flags
);
1241 ACE::restore_non_blocking_mode (handle
, val
);
1242 return bytes_transferred
;
1247 #if defined (ACE_HAS_TLI)
1250 ACE::t_snd (ACE_HANDLE handle
,
1254 const ACE_Time_Value
*timeout
)
1257 return ACE_OS::t_snd (handle
, (const char *) buf
, n
, flags
);
1261 if (ACE::enter_send_timedwait (handle
, timeout
, val
) == -1)
1265 ssize_t bytes_transferred
= ACE_OS::t_snd (handle
, (const char *) buf
, n
, flags
);
1266 ACE::restore_non_blocking_mode (handle
, val
);
1267 return bytes_transferred
;
1272 #endif /* ACE_HAS_TLI */
1275 ACE::send (ACE_HANDLE handle
,
1278 const ACE_Time_Value
*timeout
)
1281 return ACE::send_i (handle
, buf
, n
);
1285 if (ACE::enter_send_timedwait (handle
, timeout
, val
) == -1)
1289 ssize_t bytes_transferred
= ACE::send_i (handle
, buf
, n
);
1290 ACE::restore_non_blocking_mode (handle
, val
);
1291 return bytes_transferred
;
1297 ACE::sendmsg (ACE_HANDLE handle
,
1298 const struct msghdr
*msg
,
1300 const ACE_Time_Value
*timeout
)
1303 return ACE_OS::sendmsg (handle
, msg
, flags
);
1307 if (ACE::enter_send_timedwait (handle
, timeout
, val
) == -1)
1311 ssize_t bytes_transferred
= ACE_OS::sendmsg (handle
, msg
, flags
);
1312 ACE::restore_non_blocking_mode (handle
, val
);
1313 return bytes_transferred
;
1319 ACE::sendto (ACE_HANDLE handle
,
1323 const struct sockaddr
*addr
,
1325 const ACE_Time_Value
*timeout
)
1328 return ACE_OS::sendto (handle
, buf
, len
, flags
, addr
, addrlen
);
1332 if (ACE::enter_send_timedwait (handle
, timeout
, val
) == -1)
1336 ssize_t bytes_transferred
=
1337 ACE_OS::sendto (handle
, buf
, len
, flags
, addr
, addrlen
);
1338 ACE::restore_non_blocking_mode (handle
, val
);
1339 return bytes_transferred
;
1345 ACE::send_n_i (ACE_HANDLE handle
,
1352 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1355 for (bytes_transferred
= 0;
1356 bytes_transferred
< len
;
1357 bytes_transferred
+= n
)
1359 // Try to transfer as much of the remaining data as possible.
1360 n
= ACE_OS::send (handle
,
1361 (char *) buf
+ bytes_transferred
,
1362 len
- bytes_transferred
,
1368 // Check for other errors.
1371 // Check for possible blocking.
1372 #if defined (ACE_WIN32)
1373 if (errno
== EWOULDBLOCK
) // If enobufs no need to loop
1375 if (errno
== EWOULDBLOCK
|| errno
== ENOBUFS
)
1376 #endif /* ACE_WIN32 */
1378 // Wait for the blocking to subside.
1379 int result
= ACE::handle_write_ready (handle
,
1382 // Did select() succeed?
1385 // Blocking subsided. Continue data transfer.
1391 // Other data transfer or select() failures.
1396 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1400 ACE::send_n_i (ACE_HANDLE handle
,
1404 const ACE_Time_Value
*timeout
,
1408 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1414 ACE::record_and_set_non_blocking_mode (handle
, val
);
1416 for (bytes_transferred
= 0;
1417 bytes_transferred
< len
;
1418 bytes_transferred
+= n
)
1420 // Try to transfer as much of the remaining data as possible.
1421 // Since the socket is in non-blocking mode, this call will not
1423 n
= ACE_OS::send (handle
,
1424 (char *) buf
+ bytes_transferred
,
1425 len
- bytes_transferred
,
1428 // Check for errors.
1432 // Check for possible blocking.
1434 (errno
== EWOULDBLOCK
|| errno
== ENOBUFS
))
1436 // Wait upto <timeout> for the blocking to subside.
1437 int rtn
= ACE::handle_write_ready (handle
,
1440 // Did select() succeed?
1443 // Blocking subsided in <timeout> period. Continue
1450 // Wait in select() timed out or other data transfer or
1451 // select() failures.
1458 ACE::restore_non_blocking_mode (handle
, val
);
1466 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1470 #if defined (ACE_HAS_TLI)
1473 ACE::t_snd_n_i (ACE_HANDLE handle
,
1480 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1483 for (bytes_transferred
= 0;
1484 bytes_transferred
< len
;
1485 bytes_transferred
+= n
)
1487 // Try to transfer as much of the remaining data as possible.
1488 n
= ACE_OS::t_snd (handle
,
1489 (char *) buf
+ bytes_transferred
,
1490 len
- bytes_transferred
,
1496 // Check for other errors.
1499 // Check for possible blocking.
1500 if (errno
== EWOULDBLOCK
|| errno
== ENOBUFS
)
1502 // Wait for the blocking to subside.
1503 int result
= ACE::handle_write_ready (handle
,
1506 // Did select() succeed?
1509 // Blocking subsided. Continue data transfer.
1515 // Other data transfer or select() failures.
1520 return bytes_transferred
;
1524 ACE::t_snd_n_i (ACE_HANDLE handle
,
1528 const ACE_Time_Value
*timeout
,
1532 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1538 ACE::record_and_set_non_blocking_mode (handle
, val
);
1540 for (bytes_transferred
= 0;
1541 bytes_transferred
< len
;
1542 bytes_transferred
+= n
)
1544 // Try to transfer as much of the remaining data as possible.
1545 // Since the socket is in non-blocking mode, this call will not
1547 n
= ACE_OS::t_snd (handle
,
1548 (char *) buf
+ bytes_transferred
,
1549 len
- bytes_transferred
,
1552 // Check for errors.
1556 // Check for possible blocking.
1558 errno
== EWOULDBLOCK
|| errno
== ENOBUFS
)
1560 // Wait upto <timeout> for the blocking to subside.
1561 int rtn
= ACE::handle_write_ready (handle
,
1564 // Did select() succeed?
1567 // Blocking subsided in <timeout> period. Continue
1574 // Wait in select() timed out or other data transfer or
1575 // select() failures.
1582 ACE::restore_non_blocking_mode (handle
, val
);
1587 return bytes_transferred
;
1590 #endif /* ACE_HAS_TLI */
1593 ACE::send_n_i (ACE_HANDLE handle
,
1599 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1602 for (bytes_transferred
= 0;
1603 bytes_transferred
< len
;
1604 bytes_transferred
+= n
)
1606 // Try to transfer as much of the remaining data as possible.
1607 n
= ACE::send_i (handle
,
1608 (char *) buf
+ bytes_transferred
,
1609 len
- bytes_transferred
);
1616 // Check for other errors.
1619 // Check for possible blocking.
1620 if (errno
== EWOULDBLOCK
|| errno
== ENOBUFS
)
1622 // Wait for the blocking to subside.
1623 int result
= ACE::handle_write_ready (handle
,
1626 // Did select() succeed?
1629 // Blocking subsided. Continue data transfer.
1635 // Other data transfer or select() failures.
1640 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1644 ACE::send_n_i (ACE_HANDLE handle
,
1647 const ACE_Time_Value
*timeout
,
1651 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1657 ACE::record_and_set_non_blocking_mode (handle
, val
);
1659 for (bytes_transferred
= 0;
1660 bytes_transferred
< len
;
1661 bytes_transferred
+= n
)
1663 // Try to transfer as much of the remaining data as possible.
1664 // Since the socket is in non-blocking mode, this call will not
1666 n
= ACE::send_i (handle
,
1667 (char *) buf
+ bytes_transferred
,
1668 len
- bytes_transferred
);
1670 // Check for errors.
1674 // Check for possible blocking.
1676 (errno
== EWOULDBLOCK
|| errno
== ENOBUFS
))
1678 // Wait upto <timeout> for the blocking to subside.
1679 int rtn
= ACE::handle_write_ready (handle
,
1682 // Did select() succeed?
1685 // Blocking subsided in <timeout> period. Continue
1692 // Wait in select() timed out or other data transfer or
1693 // select() failures.
1700 ACE::restore_non_blocking_mode (handle
, val
);
1708 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1712 // Send N char *ptrs and int lengths. Note that the char *'s precede
1713 // the ints (basically, an varargs version of writev). The count N is
1714 // the *total* number of trailing arguments, *not* a couple of the
1715 // number of tuple pairs!
1718 ACE::send (ACE_HANDLE handle
, size_t n
, ...)
1721 int total_tuples
= static_cast<int> (n
/ 2);
1723 #if defined (ACE_HAS_ALLOCA)
1724 iovp
= (iovec
*) alloca (total_tuples
* sizeof (iovec
));
1726 ACE_NEW_RETURN (iovp
,
1727 iovec
[total_tuples
],
1729 #endif /* !defined (ACE_HAS_ALLOCA) */
1733 for (int i
= 0; i
< total_tuples
; i
++)
1735 iovp
[i
].iov_base
= va_arg (argp
, char *);
1736 iovp
[i
].iov_len
= va_arg (argp
, int);
1739 ssize_t result
= ACE_OS::sendv (handle
, iovp
, total_tuples
);
1740 #if !defined (ACE_HAS_ALLOCA)
1742 #endif /* !defined (ACE_HAS_ALLOCA) */
1748 ACE::sendv (ACE_HANDLE handle
,
1751 const ACE_Time_Value
*timeout
)
1754 return ACE_OS::sendv (handle
, iov
, iovcnt
);
1758 if (ACE::enter_send_timedwait (handle
, timeout
, val
) == -1)
1762 ssize_t bytes_transferred
= ACE_OS::sendv (handle
, iov
, iovcnt
);
1763 ACE::restore_non_blocking_mode (handle
, val
);
1764 return bytes_transferred
;
1770 ACE::sendv_n_i (ACE_HANDLE handle
,
1776 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1777 bytes_transferred
= 0;
1779 iovec
*iov
= const_cast<iovec
*> (i
);
1785 // Try to transfer as much of the remaining data as possible.
1786 ssize_t n
= ACE_OS::sendv (handle
,
1793 // Check for other errors.
1796 // Check for possible blocking.
1797 if (errno
== EWOULDBLOCK
|| errno
== ENOBUFS
)
1799 // Wait for the blocking to subside.
1800 int result
= ACE::handle_write_ready (handle
,
1803 // Did select() succeed?
1806 // Blocking subsided. Continue data transfer.
1812 // Other data transfer or select() failures.
1816 for (bytes_transferred
+= n
;
1818 && n
>= static_cast<ssize_t
> (iov
[s
].iov_len
);
1820 n
-= iov
[s
].iov_len
;
1824 char *base
= reinterpret_cast<char *> (iov
[s
].iov_base
);
1825 iov
[s
].iov_base
= base
+ n
;
1826 iov
[s
].iov_len
= iov
[s
].iov_len
- n
;
1830 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1834 ACE::sendv_n_i (ACE_HANDLE handle
,
1837 const ACE_Time_Value
*timeout
,
1841 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1842 bytes_transferred
= 0;
1847 ACE::record_and_set_non_blocking_mode (handle
, val
);
1849 iovec
*iov
= const_cast<iovec
*> (i
);
1855 // Try to transfer as much of the remaining data as possible.
1856 // Since the socket is in non-blocking mode, this call will not
1858 ssize_t n
= ACE_OS::sendv (handle
,
1862 // Check for errors.
1866 // Check for possible blocking.
1868 (errno
== EWOULDBLOCK
|| errno
== ENOBUFS
))
1870 // Wait upto <timeout> for the blocking to subside.
1871 int rtn
= ACE::handle_write_ready (handle
,
1874 // Did select() succeed?
1877 // Blocking subsided in <timeout> period. Continue
1884 // Wait in select() timed out or other data transfer or
1885 // select() failures.
1891 for (bytes_transferred
+= n
;
1893 && n
>= static_cast<ssize_t
> (iov
[s
].iov_len
);
1895 n
-= iov
[s
].iov_len
;
1899 char *base
= reinterpret_cast<char *> (iov
[s
].iov_base
);
1900 iov
[s
].iov_base
= base
+ n
;
1901 iov
[s
].iov_len
= iov
[s
].iov_len
- n
;
1905 ACE::restore_non_blocking_mode (handle
, val
);
1913 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
1918 ACE::write_n (ACE_HANDLE handle
,
1919 const ACE_Message_Block
*message_block
,
1923 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
1924 bytes_transferred
= 0;
1926 iovec iov
[ACE_IOV_MAX
];
1929 while (message_block
!= 0)
1931 // Our current message block chain.
1932 const ACE_Message_Block
*current_message_block
= message_block
;
1934 while (current_message_block
!= 0)
1936 size_t current_message_block_length
=
1937 current_message_block
->length ();
1938 char *this_block_ptr
= current_message_block
->rd_ptr ();
1940 // Check if this block has any data to be sent.
1941 while (current_message_block_length
> 0)
1943 u_long
const this_chunk_length
=
1944 ACE_Utils::truncate_cast
<u_long
> (
1945 current_message_block_length
);
1947 // Collect the data in the iovec.
1948 iov
[iovcnt
].iov_base
= this_block_ptr
;
1949 iov
[iovcnt
].iov_len
= this_chunk_length
;
1950 current_message_block_length
-= this_chunk_length
;
1951 this_block_ptr
+= this_chunk_length
;
1953 // Increment iovec counter.
1956 // The buffer is full make a OS call. @@ TODO find a way to
1957 // find ACE_IOV_MAX for platforms that do not define it rather
1958 // than simply setting ACE_IOV_MAX to some arbitrary value such
1960 if (iovcnt
== ACE_IOV_MAX
)
1962 size_t current_transfer
= 0;
1964 ssize_t
const result
= ACE::writev_n (handle
,
1969 // Add to total bytes transferred.
1970 bytes_transferred
+= current_transfer
;
1973 if (result
== -1 || result
== 0)
1976 // Reset iovec counter.
1981 // Select the next message block in the chain.
1982 current_message_block
= current_message_block
->cont ();
1985 // Selection of the next message block chain.
1986 message_block
= message_block
->next ();
1989 // Check for remaining buffers to be sent. This will happen when
1990 // ACE_IOV_MAX is not a multiple of the number of message blocks.
1993 size_t current_transfer
= 0;
1995 ssize_t
const result
= ACE::writev_n (handle
,
2000 // Add to total bytes transferred.
2001 bytes_transferred
+= current_transfer
;
2004 if (result
== -1 || result
== 0)
2008 // Return total bytes transferred.
2009 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
2013 ACE::send_n (ACE_HANDLE handle
,
2014 const ACE_Message_Block
*message_block
,
2015 const ACE_Time_Value
*timeout
,
2019 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
2020 bytes_transferred
= 0;
2022 iovec iov
[ACE_IOV_MAX
];
2025 while (message_block
!= 0)
2027 // Our current message block chain.
2028 const ACE_Message_Block
*current_message_block
= message_block
;
2030 while (current_message_block
!= 0)
2032 char *this_block_ptr
= current_message_block
->rd_ptr ();
2033 size_t current_message_block_length
=
2034 current_message_block
->length ();
2036 // Check if this block has any data to be sent.
2037 while (current_message_block_length
> 0)
2039 u_long
const this_chunk_length
=
2040 ACE_Utils::truncate_cast
<u_long
> (
2041 current_message_block_length
);
2043 // Collect the data in the iovec.
2044 iov
[iovcnt
].iov_base
= this_block_ptr
;
2045 iov
[iovcnt
].iov_len
= this_chunk_length
;
2046 current_message_block_length
-= this_chunk_length
;
2047 this_block_ptr
+= this_chunk_length
;
2049 // Increment iovec counter.
2052 // The buffer is full make a OS call. @@ TODO find a way to
2053 // find ACE_IOV_MAX for platforms that do not define it rather
2054 // than simply setting ACE_IOV_MAX to some arbitrary value such
2056 if (iovcnt
== ACE_IOV_MAX
)
2058 size_t current_transfer
= 0;
2060 ssize_t
const result
= ACE::sendv_n (handle
,
2066 // Add to total bytes transferred.
2067 bytes_transferred
+= current_transfer
;
2070 if (result
== -1 || result
== 0)
2073 // Reset iovec counter.
2078 // Select the next message block in the chain.
2079 current_message_block
= current_message_block
->cont ();
2082 // Selection of the next message block chain.
2083 message_block
= message_block
->next ();
2086 // Check for remaining buffers to be sent. This will happen when
2087 // ACE_IOV_MAX is not a multiple of the number of message blocks.
2090 size_t current_transfer
= 0;
2092 ssize_t
const result
= ACE::sendv_n (handle
,
2098 // Add to total bytes transferred.
2099 bytes_transferred
+= current_transfer
;
2102 if (result
== -1 || result
== 0)
2108 // Return total bytes transferred.
2109 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
2113 ACE::readv_n (ACE_HANDLE handle
,
2119 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
2120 bytes_transferred
= 0;
2126 ssize_t n
= ACE_OS::readv (handle
,
2130 if (n
== -1 || n
== 0)
2133 for (bytes_transferred
+= n
;
2135 && n
>= static_cast<ssize_t
> (iov
[s
].iov_len
);
2137 n
-= iov
[s
].iov_len
;
2141 char *base
= reinterpret_cast<char *> (iov
[s
].iov_base
);
2142 iov
[s
].iov_base
= base
+ n
;
2143 iov
[s
].iov_len
= iov
[s
].iov_len
- n
;
2147 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
2151 ACE::writev_n (ACE_HANDLE handle
,
2157 size_t &bytes_transferred
= bt
== 0 ? temp
: *bt
;
2158 bytes_transferred
= 0;
2160 iovec
*iov
= const_cast<iovec
*> (i
);
2166 ssize_t n
= ACE_OS::writev (handle
,
2170 if (n
== -1 || n
== 0)
2175 for (bytes_transferred
+= n
;
2177 && n
>= static_cast<ssize_t
> (iov
[s
].iov_len
);
2179 n
-= iov
[s
].iov_len
;
2183 char *base
= reinterpret_cast<char *> (iov
[s
].iov_base
);
2184 iov
[s
].iov_base
= base
+ n
;
2185 iov
[s
].iov_len
= iov
[s
].iov_len
- n
;
2189 return ACE_Utils::truncate_cast
<ssize_t
> (bytes_transferred
);
2193 ACE::handle_ready (ACE_HANDLE handle
,
2194 const ACE_Time_Value
*timeout
,
2197 int exception_ready
)
2199 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
2200 ACE_UNUSED_ARG (write_ready
);
2201 ACE_UNUSED_ARG (exception_ready
);
2206 fds
.events
= read_ready
? POLLIN
: POLLOUT
;
2209 int result
= ACE_OS::poll (&fds
, 1, timeout
);
2211 ACE_Handle_Set handle_set
;
2212 handle_set
.set_bit (handle
);
2214 // Wait for data or for the timeout to elapse.
2216 # if defined (ACE_WIN32)
2217 // This arg is ignored on Windows and causes pointer truncation
2218 // warnings on 64-bit compiles.
2221 select_width
= int (handle
) + 1;
2222 # endif /* ACE_WIN64 */
2223 int result
= ACE_OS::select (select_width
,
2224 read_ready
? handle_set
.fdset () : 0, // read_fds.
2225 write_ready
? handle_set
.fdset () : 0, // write_fds.
2226 exception_ready
? handle_set
.fdset () : 0, // exception_fds.
2229 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
2233 case 0: // Timer expired.
2236 case -1: // we got here directly - select() returned -1.
2238 case 1: // Handle has data.
2240 default: // default is case result > 0; return a
2241 // ACE_ASSERT (result == 1);
2247 ACE::enter_recv_timedwait (ACE_HANDLE handle
,
2248 const ACE_Time_Value
*timeout
,
2251 int result
= ACE::handle_read_ready (handle
,
2257 ACE::record_and_set_non_blocking_mode (handle
,
2264 ACE::enter_send_timedwait (ACE_HANDLE handle
,
2265 const ACE_Time_Value
*timeout
,
2268 int result
= ACE::handle_write_ready (handle
,
2274 ACE::record_and_set_non_blocking_mode (handle
,
2281 ACE::record_and_set_non_blocking_mode (ACE_HANDLE handle
,
2284 // We need to record whether we are already *in* nonblocking mode,
2285 // so that we can correctly reset the state when we're done.
2286 val
= ACE::get_flags (handle
);
2288 if (ACE_BIT_DISABLED (val
, ACE_NONBLOCK
))
2289 // Set the handle into non-blocking mode if it's not already in
2291 ACE::set_flags (handle
, ACE_NONBLOCK
);
2295 ACE::restore_non_blocking_mode (ACE_HANDLE handle
,
2298 if (ACE_BIT_DISABLED (val
,
2301 // Save/restore errno.
2302 ACE_Errno_Guard
error (errno
);
2303 // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
2305 ACE::clr_flags (handle
, ACE_NONBLOCK
);
2310 // Format buffer into printable format. This is useful for debugging.
2311 // Portions taken from mdump by J.P. Knight (J.P.Knight@lut.ac.uk)
2312 // Modifications by Todd Montgomery.
2315 ACE::format_hexdump (const char *buffer
,
2320 ACE_TRACE ("ACE::format_hexdump");
2323 ACE_TCHAR textver
[16 + 1];
2325 // We can fit 16 bytes output in text mode per line, 4 chars per byte.
2326 size_t maxlen
= (obuf_sz
/ 68) * 16;
2333 size_t lines
= size
/ 16;
2334 for (i
= 0; i
< lines
; i
++)
2338 for (j
= 0 ; j
< 16; j
++)
2340 c
= (u_char
) buffer
[(i
<< 4) + j
]; // or, buffer[i*16+j]
2341 ACE_OS::sprintf (obuf
,
2347 ACE_OS::sprintf (obuf
,
2351 textver
[j
] = ACE_OS::ace_isprint (c
) ? c
: '.';
2356 ACE_OS::sprintf (obuf
,
2360 while (*obuf
!= '\0')
2366 for (i
= 0 ; i
< size
% 16; i
++)
2368 c
= (u_char
) buffer
[size
- size
% 16 + i
];
2369 ACE_OS::sprintf (obuf
,
2375 ACE_OS::sprintf (obuf
,
2379 textver
[i
] = ACE_OS::ace_isprint (c
) ? c
: '.';
2382 for (i
= size
% 16; i
< 16; i
++)
2384 ACE_OS::sprintf (obuf
,
2389 ACE_OS::sprintf (obuf
,
2397 ACE_OS::sprintf (obuf
,
2404 // Returns the current timestamp in the form
2405 // "hour:minute:second:microsecond." The month, day, and year are
2406 // also stored in the beginning of the date_and_time array.
2409 ACE::timestamp (ACE_TCHAR date_and_time
[],
2410 size_t date_and_timelen
,
2411 bool return_pointer_to_first_digit
)
2413 //ACE_TRACE ("ACE::timestamp");
2415 if (date_and_timelen
< 35)
2422 // Emulate Unix. Win32 does NOT support all the UNIX versions
2423 // below, so DO we need this ifdef.
2424 static const ACE_TCHAR
*day_of_week_name
[] =
2435 static const ACE_TCHAR
*month_name
[] =
2452 ::GetLocalTime (&local
);
2454 ACE_OS::sprintf (date_and_time
,
2455 ACE_TEXT ("%3s %3s %2d %04d %02d:%02d:%02d.%06d"),
2456 day_of_week_name
[local
.wDayOfWeek
],
2457 month_name
[local
.wMonth
- 1],
2461 (int) local
.wMinute
,
2462 (int) local
.wSecond
,
2463 (int) (local
.wMilliseconds
* 1000));
2464 return &date_and_time
[15 + (return_pointer_to_first_digit
!= 0)];
2466 ACE_TCHAR timebuf
[26]; // This magic number is based on the ctime(3c) man page.
2467 ACE_Time_Value cur_time
= ACE_OS::gettimeofday ();
2468 time_t secs
= cur_time
.sec ();
2470 ACE_OS::ctime_r (&secs
,
2472 sizeof timebuf
/ sizeof (ACE_TCHAR
));
2473 // date_and_timelen > sizeof timebuf!
2474 ACE_OS::strsncpy (date_and_time
,
2477 ACE_TCHAR yeartmp
[5];
2478 ACE_OS::strsncpy (yeartmp
,
2481 ACE_TCHAR timetmp
[9];
2482 ACE_OS::strsncpy (timetmp
,
2485 ACE_OS::sprintf (&date_and_time
[11],
2486 # if defined (ACE_USES_WCHAR)
2487 ACE_TEXT ("%ls %ls.%06ld"),
2489 ACE_TEXT ("%s %s.%06ld"),
2490 # endif /* ACE_USES_WCHAR */
2494 date_and_time
[33] = '\0';
2495 return &date_and_time
[15 + (return_pointer_to_first_digit
!= 0)];
2499 // This function rounds the request to a multiple of the page size.
2502 ACE::round_to_pagesize (size_t len
)
2504 ACE_TRACE ("ACE::round_to_pagesize");
2506 if (ACE::pagesize_
== 0)
2507 ACE::pagesize_
= ACE_OS::getpagesize ();
2509 return (len
+ (ACE::pagesize_
- 1)) & ~(ACE::pagesize_
- 1);
2513 ACE::round_to_allocation_granularity (size_t len
)
2515 ACE_TRACE ("ACE::round_to_allocation_granularity");
2517 if (ACE::allocation_granularity_
== 0)
2518 ACE::allocation_granularity_
= ACE_OS::allocation_granularity ();
2520 return (len
+ (ACE::allocation_granularity_
- 1)) & ~(ACE::allocation_granularity_
- 1);
2524 ACE::handle_timed_complete (ACE_HANDLE h
,
2525 const ACE_Time_Value
*timeout
,
2528 ACE_TRACE ("ACE::handle_timed_complete");
2530 #if !defined (ACE_WIN32) && defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
2535 fds
.events
= POLLIN
| POLLOUT
;
2539 ACE_Handle_Set rd_handles
;
2540 ACE_Handle_Set wr_handles
;
2542 rd_handles
.set_bit (h
);
2543 wr_handles
.set_bit (h
);
2544 #endif /* !ACE_WIN32 && ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
2546 #if defined (ACE_WIN32)
2547 // Winsock is different - it sets the exception bit for failed connect,
2548 // unlike other platforms, where the read bit is set.
2549 ACE_Handle_Set ex_handles
;
2550 ex_handles
.set_bit (h
);
2551 #endif /* ACE_WIN32 */
2553 bool need_to_check
= false;
2554 bool known_failure
= false;
2556 #if defined (ACE_WIN32)
2557 int n
= ACE_OS::select (0, // Ignored on Windows: int (h) + 1,
2563 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
2565 int n
= ACE_OS::poll (&fds
, 1, timeout
);
2568 int n
= ACE_OS::select (int (h
) + 1,
2573 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
2574 #endif /* ACE_WIN32 */
2576 // If we failed to connect within the time period allocated by the
2577 // caller, then we fail (e.g., the remote host might have been too
2578 // busy to accept our call).
2581 if (n
== 0 && timeout
!= 0)
2583 return ACE_INVALID_HANDLE
;
2586 // Usually, a ready-for-write handle is successfully connected, and
2587 // ready-for-read (exception on Win32) is a failure. On fails, we
2588 // need to grab the error code via getsockopt. On possible success for
2589 // any platform where we can't tell just from select() (e.g. AIX),
2590 // we also need to check for success/fail.
2591 #if defined (ACE_WIN32)
2592 ACE_UNUSED_ARG (is_tli
);
2594 // On Win32, ex_handle set indicates a failure. We'll do the check
2595 // to try and get an errno value, but the connect failed regardless of
2596 // what getsockopt says about the error.
2597 if (ex_handles
.is_set (h
))
2599 need_to_check
= true;
2600 known_failure
= true;
2602 #elif defined (ACE_VXWORKS)
2603 ACE_UNUSED_ARG (is_tli
);
2605 // Force the check on VxWorks. The read handle for "h" is not set,
2606 // so "need_to_check" is false at this point. The write handle is
2607 // set, for what it's worth.
2608 need_to_check
= true;
2612 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
2613 need_to_check
= (fds
.revents
& POLLIN
) && !(fds
.revents
& POLLOUT
);
2615 need_to_check
= rd_handles
.is_set (h
) && !wr_handles
.is_set (h
);
2616 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
2620 // AIX is broken... both success and failed connect will set the
2621 // write handle only, so always check.
2622 need_to_check
= true;
2624 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
2625 need_to_check
= (fds
.revents
& POLLIN
);
2627 need_to_check
= rd_handles
.is_set (h
);
2628 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
2630 #endif /* ACE_WIN32 */
2634 #if defined (SOL_SOCKET) && defined (SO_ERROR)
2636 int sock_err_len
= sizeof (sock_err
);
2637 int sockopt_ret
= ACE_OS::getsockopt (h
, SOL_SOCKET
, SO_ERROR
,
2638 (char *)&sock_err
, &sock_err_len
);
2639 if (sockopt_ret
< 0)
2641 h
= ACE_INVALID_HANDLE
;
2644 if (sock_err
!= 0 || known_failure
)
2646 h
= ACE_INVALID_HANDLE
;
2652 // The following recv() won't block provided that the
2653 // ACE_NONBLOCK flag has not been turned off .
2654 n
= ACE::recv (h
, &dummy
, 1, MSG_PEEK
);
2656 // If no data was read/peeked at, check to see if it's because
2657 // of a non-connected socket (and therefore an error) or there's
2658 // just no data yet.
2663 errno
= ECONNREFUSED
;
2664 h
= ACE_INVALID_HANDLE
;
2666 else if (errno
!= EWOULDBLOCK
&& errno
!= EAGAIN
)
2667 h
= ACE_INVALID_HANDLE
;
2672 // 1. The HANDLE is ready for writing and doesn't need to be checked or
2673 // 2. recv() returned an indication of the state of the socket - if there is
2674 // either data present, or a recv is legit but there's no data yet,
2675 // the connection was successfully established.
2679 // Wait up to <timeout> amount of time to accept a connection.
2682 ACE::handle_timed_accept (ACE_HANDLE listener
,
2683 ACE_Time_Value
*timeout
,
2686 ACE_TRACE ("ACE::handle_timed_accept");
2687 // Make sure we don't bomb out on erroneous values.
2688 if (listener
== ACE_INVALID_HANDLE
)
2691 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
2696 fds
.events
= POLLIN
;
2700 // Use the select() implementation rather than poll().
2701 ACE_Handle_Set rd_handle
;
2702 rd_handle
.set_bit (listener
);
2703 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
2705 // We need a loop here if <restart> is enabled.
2709 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT)
2711 int n
= ACE_OS::poll (&fds
, 1, timeout
);
2715 # if defined (ACE_WIN32)
2716 // This arg is ignored on Windows and causes pointer truncation
2717 // warnings on 64-bit compiles.
2720 select_width
= int (listener
) + 1;
2721 # endif /* ACE_WIN32 */
2722 int n
= ACE_OS::select (select_width
,
2725 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */
2730 if (errno
== EINTR
&& restart
)
2737 && timeout
->sec () == 0
2738 && timeout
->usec () == 0)
2739 errno
= EWOULDBLOCK
;
2755 // Make the current process a UNIX daemon. This is based on Stevens
2759 ACE::daemonize (const ACE_TCHAR pathname
[],
2760 bool close_all_handles
,
2761 const ACE_TCHAR program_name
[])
2763 ACE_TRACE ("ACE::daemonize");
2764 #if !defined (ACE_LACKS_FORK)
2765 pid_t pid
= ACE_OS::fork ();
2770 ACE_OS::exit (0); // Parent exits.
2772 // 1st child continues.
2773 ACE_OS::setsid (); // Become session leader.
2775 ACE_OS::signal (SIGHUP
, SIG_IGN
);
2777 pid
= ACE_OS::fork (program_name
);
2780 ACE_OS::exit (0); // First child terminates.
2782 // Second child continues.
2785 // change working directory.
2786 ACE_OS::chdir (pathname
);
2788 ACE_OS::umask (0); // clear our file mode creation mask.
2790 // Close down the I/O handles.
2791 if (close_all_handles
)
2793 for (int i
= ACE::max_handles () - 1; i
>= 0; i
--)
2796 int fd
= ACE_OS::open ("/dev/null", O_RDWR
, 0);
2799 ACE_OS::dup2 (fd
, ACE_STDIN
);
2800 ACE_OS::dup2 (fd
, ACE_STDOUT
);
2801 ACE_OS::dup2 (fd
, ACE_STDERR
);
2803 if (fd
> ACE_STDERR
)
2810 ACE_UNUSED_ARG (pathname
);
2811 ACE_UNUSED_ARG (close_all_handles
);
2812 ACE_UNUSED_ARG (program_name
);
2814 ACE_NOTSUP_RETURN (-1);
2815 #endif /* ACE_LACKS_FORK */
2819 ACE::fork (const ACE_TCHAR
*program_name
,
2822 if (avoid_zombies
== 0)
2823 return ACE_OS::fork (program_name
);
2826 // This algorithm is adapted from an example in the Stevens book
2827 // "Advanced Programming in the Unix Environment" and an item in
2828 // Andrew Gierth's Unix Programming FAQ. It creates an orphan
2829 // process that's inherited by the init process; init cleans up
2830 // when the orphan process terminates.
2832 // Another way to avoid zombies is to ignore or catch the
2833 // SIGCHLD signal; we don't use that approach here.
2835 pid_t pid
= ACE_OS::fork ();
2838 // The child process forks again to create a grandchild.
2839 switch (ACE_OS::fork (program_name
))
2841 case 0: // grandchild returns 0.
2843 case -1: // assumes all errnos are < 256
2844 ACE_OS::_exit (errno
);
2845 default: // child terminates, orphaning grandchild
2850 // Parent process waits for child to terminate.
2851 ACE_exitcode status
;
2852 if (pid
< 0 || ACE_OS::waitpid (pid
, &status
, 0) < 0)
2855 // child terminated by calling exit()?
2856 if (WIFEXITED ((status
)))
2858 // child terminated normally?
2859 if (WEXITSTATUS ((status
)) == 0)
2862 errno
= WEXITSTATUS ((status
));
2865 // child didn't call exit(); perhaps it received a signal?
2873 ACE::max_handles (void)
2875 ACE_TRACE ("ACE::max_handles");
2876 #if defined (RLIMIT_NOFILE) && !defined (ACE_LACKS_RLIMIT)
2878 int const r
= ACE_OS::getrlimit (RLIMIT_NOFILE
, &rl
);
2879 # if !defined (RLIM_INFINITY)
2883 if (r
== 0 && rl
.rlim_cur
!= RLIM_INFINITY
)
2885 // If == RLIM_INFINITY, fall through to the ACE_LACKS_RLIMIT sections
2886 # endif /* RLIM_INFINITY */
2887 #endif /* RLIMIT_NOFILE && !ACE_LACKS_RLIMIT */
2889 #if defined (_SC_OPEN_MAX)
2890 return ACE_OS::sysconf (_SC_OPEN_MAX
);
2891 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x620)
2893 #elif defined (FD_SETSIZE)
2896 ACE_NOTSUP_RETURN (-1);
2897 #endif /* _SC_OPEN_MAX */
2900 // Set the number of currently open handles in the process.
2902 // If NEW_LIMIT == -1 set the limit to the maximum allowable.
2903 // Otherwise, set it to be the value of NEW_LIMIT.
2906 ACE::set_handle_limit (int new_limit
,
2907 int increase_limit_only
)
2909 ACE_TRACE ("ACE::set_handle_limit");
2910 int cur_limit
= ACE::max_handles ();
2911 int max_limit
= cur_limit
;
2913 if (cur_limit
== -1)
2916 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2919 ACE_OS::memset ((void *) &rl
, 0, sizeof rl
);
2920 int r
= ACE_OS::getrlimit (RLIMIT_NOFILE
, &rl
);
2922 max_limit
= rl
.rlim_max
;
2923 #endif /* ACE_LACKS_RLIMIT */
2925 if (new_limit
== -1)
2926 new_limit
= max_limit
;
2933 else if (new_limit
> cur_limit
)
2935 // Increase the limit.
2936 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2937 rl
.rlim_cur
= new_limit
;
2938 return ACE_OS::setrlimit (RLIMIT_NOFILE
, &rl
);
2939 #elif defined (ACE_LACKS_RLIMIT_NOFILE)
2942 // Must return EINVAL errno.
2943 ACE_NOTSUP_RETURN (-1);
2944 #endif /* ACE_LACKS_RLIMIT */
2946 else if (increase_limit_only
== 0)
2948 // Decrease the limit.
2949 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2950 rl
.rlim_cur
= new_limit
;
2951 return ACE_OS::setrlimit (RLIMIT_NOFILE
, &rl
);
2953 // We give a chance to platforms without RLIMIT to work.
2954 // Instead of ACE_NOTSUP_RETURN (0), just return 0 because
2955 // new_limit is <= cur_limit, so it's a no-op.
2957 #endif /* ACE_LACKS_RLIMIT */
2963 // Euclid's greatest common divisor algorithm.
2965 ACE::gcd (u_long x
, u_long y
)
2978 // Calculates the minimum enclosing frame size for the given values.
2980 ACE::minimum_frame_size (u_long period1
, u_long period2
)
2982 // if one of the periods is zero, treat it as though it as
2983 // uninitialized and return the other period as the frame size
2993 // if neither is zero, find the greatest common divisor of the two periods
2994 u_long greatest_common_divisor
= ACE::gcd (period1
, period2
);
2996 // explicitly consider cases to reduce risk of possible overflow errors
2997 if (greatest_common_divisor
== 1)
2999 // periods are relative primes: just multiply them together
3000 return period1
* period2
;
3002 else if (greatest_common_divisor
== period1
)
3004 // the first period divides the second: return the second
3007 else if (greatest_common_divisor
== period2
)
3009 // the second period divides the first: return the first
3014 // the current frame size and the entry's effective period
3015 // have a non-trivial greatest common divisor: return the
3016 // product of factors divided by those in their gcd.
3017 return (period1
* period2
) / greatest_common_divisor
;
3023 ACE::is_prime (const u_long n
,
3024 const u_long min_factor
,
3025 const u_long max_factor
)
3028 for (u_long factor
= min_factor
;
3029 factor
<= max_factor
;
3031 if (n
/ factor
* factor
== n
)
3038 ACE::sock_error (int error
)
3040 #if defined (ACE_WIN32)
3041 static ACE_TCHAR unknown_msg
[64];
3045 case WSAVERNOTSUPPORTED
:
3046 return ACE_TEXT ("version of WinSock not supported");
3048 case WSASYSNOTREADY
:
3049 return ACE_TEXT ("WinSock not present or not responding");
3052 return ACE_TEXT ("app version not supported by DLL");
3054 case WSAHOST_NOT_FOUND
:
3055 return ACE_TEXT ("Authoritive: Host not found");
3058 return ACE_TEXT ("Non-authoritive: host not found or server failure");
3060 case WSANO_RECOVERY
:
3061 return ACE_TEXT ("Non-recoverable: refused or not implemented");
3064 return ACE_TEXT ("Valid name, no data record for type");
3068 return "Valid name, no MX record";
3070 case WSANOTINITIALISED
:
3071 return ACE_TEXT ("WSA Startup not initialized");
3074 return ACE_TEXT ("Network subsystem failed");
3076 case WSAEINPROGRESS
:
3077 return ACE_TEXT ("Blocking operation in progress");
3080 return ACE_TEXT ("Blocking call cancelled");
3082 case WSAEAFNOSUPPORT
:
3083 return ACE_TEXT ("address family not supported");
3086 return ACE_TEXT ("no file handles available");
3089 return ACE_TEXT ("no buffer space available");
3091 case WSAEPROTONOSUPPORT
:
3092 return ACE_TEXT ("specified protocol not supported");
3095 return ACE_TEXT ("protocol wrong type for this socket");
3097 case WSAESOCKTNOSUPPORT
:
3098 return ACE_TEXT ("socket type not supported for address family");
3101 return ACE_TEXT ("handle is not a socket");
3103 case WSAEWOULDBLOCK
:
3104 return ACE_TEXT ("resource temporarily unavailable");
3107 return ACE_TEXT ("address already in use");
3109 case WSAECONNABORTED
:
3110 return ACE_TEXT ("connection aborted");
3113 return ACE_TEXT ("connection reset");
3116 return ACE_TEXT ("not connected");
3119 return ACE_TEXT ("connection timed out");
3121 case WSAECONNREFUSED
:
3122 return ACE_TEXT ("connection refused");
3125 return ACE_TEXT ("host down");
3127 case WSAEHOSTUNREACH
:
3128 return ACE_TEXT ("host unreachable");
3130 case WSAEADDRNOTAVAIL
:
3131 return ACE_TEXT ("address not available");
3134 return ACE_TEXT ("socket is already connected");
3137 return ACE_TEXT ("network dropped connection on reset");
3140 return ACE_TEXT ("message too long");
3142 case WSAENETUNREACH
:
3143 return ACE_TEXT ("network is unreachable");
3146 return ACE_TEXT ("bad address");
3149 return ACE_TEXT ("graceful shutdown in progress");
3152 return ACE_TEXT ("permission denied");
3155 return ACE_TEXT ("cannot send after socket shutdown");
3158 return ACE_TEXT ("too many processes");
3161 return ACE_TEXT ("operation already in progress");
3163 case WSAEPFNOSUPPORT
:
3164 return ACE_TEXT ("protocol family not supported");
3166 case WSAENOPROTOOPT
:
3167 return ACE_TEXT ("bad protocol option");
3169 case WSATYPE_NOT_FOUND
:
3170 return ACE_TEXT ("class type not found");
3173 return ACE_TEXT ("operation not supported");
3175 case WSAEDESTADDRREQ
:
3176 return ACE_TEXT ("destination address required");
3179 ACE_OS::sprintf (unknown_msg
, ACE_TEXT ("unknown error: %d"), error
);
3184 ACE_UNUSED_ARG (error
);
3185 ACE_NOTSUP_RETURN (0);
3186 #endif /* ACE_WIN32 */
3190 ACE::is_sock_error (int error
)
3192 #if defined (ACE_WIN32)
3195 case WSAVERNOTSUPPORTED
:
3196 case WSASYSNOTREADY
:
3198 case WSAHOST_NOT_FOUND
:
3200 case WSANO_RECOVERY
:
3205 case WSANOTINITIALISED
:
3207 case WSAEINPROGRESS
:
3209 case WSAEAFNOSUPPORT
:
3212 case WSAEPROTONOSUPPORT
:
3214 case WSAESOCKTNOSUPPORT
:
3216 case WSAEWOULDBLOCK
:
3218 case WSAECONNABORTED
:
3222 case WSAECONNREFUSED
:
3224 case WSAEHOSTUNREACH
:
3225 case WSAEADDRNOTAVAIL
:
3229 case WSAENETUNREACH
:
3236 case WSAEPFNOSUPPORT
:
3237 case WSAENOPROTOOPT
:
3238 case WSATYPE_NOT_FOUND
:
3243 ACE_UNUSED_ARG (error
);
3244 #endif /* ACE_WIN32 */
3249 ACE::strndup (const char *str
, size_t n
)
3251 const char *t
= str
;
3254 // Figure out how long this string is (remember, it might not be
3258 len
< n
&& *t
++ != '\0';
3263 ACE_ALLOCATOR_RETURN (s
,
3264 (char *) ACE_OS::malloc (len
+ 1),
3266 return ACE_OS::strsncpy (s
, str
, len
+ 1);
3269 #if defined (ACE_HAS_WCHAR)
3271 ACE::strndup (const wchar_t *str
, size_t n
)
3273 const wchar_t *t
= str
;
3276 // Figure out how long this string is (remember, it might not be
3280 len
< n
&& *t
++ != '\0';
3285 ACE_ALLOCATOR_RETURN (s
,
3286 static_cast<wchar_t *> (
3287 ACE_OS::malloc ((len
+ 1) * sizeof (wchar_t))),
3289 return ACE_OS::strsncpy (s
, str
, len
+ 1);
3291 #endif /* ACE_HAS_WCHAR */
3294 ACE::strnnew (const char *str
, size_t n
)
3296 const char *t
= str
;
3299 // Figure out how long this string is (remember, it might not be
3303 len
< n
&& *t
++ != L
'\0';
3311 return ACE_OS::strsncpy (s
, str
, len
+ 1);
3314 #if defined (ACE_HAS_WCHAR)
3316 ACE::strnnew (const wchar_t *str
, size_t n
)
3318 const wchar_t *t
= str
;
3321 // Figure out how long this string is (remember, it might not be
3325 len
< n
&& *t
++ != ACE_TEXT_WIDE ('\0');
3333 return ACE_OS::strsncpy (s
, str
, len
+ 1);
3335 #endif /* ACE_HAS_WCHAR */
3338 ACE::strend (const char *s
)
3340 while (*s
++ != '\0')
3346 #if defined ACE_HAS_WCHAR
3348 ACE::strend (const wchar_t *s
)
3350 while (*s
++ != ACE_TEXT_WIDE ('\0'))
3358 ACE::strnew (const char *s
)
3364 char [ACE_OS::strlen (s
) + 1],
3369 return ACE_OS::strcpy (t
, s
);
3372 #if defined (ACE_HAS_WCHAR)
3374 ACE::strnew (const wchar_t *s
)
3380 wchar_t[ACE_OS::strlen (s
) + 1],
3385 return ACE_OS::strcpy (t
, s
);
3387 #endif /* ACE_HAS_WCHAR */
3389 inline static bool equal_char(char a
, char b
, bool case_sensitive
)
3393 return ACE_OS::ace_tolower(a
) == ACE_OS::ace_tolower(b
);
3397 ACE::wild_match(const char* str
, const char* pat
, bool case_sensitive
)
3401 if (pat
== 0 || str
== 0)
3405 const char* s
= str
;
3406 const char* p
= pat
;
3413 while (*++pat
== '*') {}
3424 else if (! equal_char(*s
, *p
, case_sensitive
))
3438 while (*++p
== '*') {}
3443 // Close versioned namespace, if enabled by the user.
3444 ACE_END_VERSIONED_NAMESPACE_DECL