C++17 removes std::auto_ptr so we don't provide the ACE auto_ptr templates anymore...
[ACE_TAO.git] / ACE / ace / ACE.cpp
blob7971232741118785d779412869feffd47f4b4bcd
1 #include "ace/ACE.h"
3 #include "ace/Basic_Types.h"
4 #include "ace/Handle_Set.h"
5 #include "ace/SString.h"
6 #include "ace/Version.h"
7 #include "ace/Message_Block.h"
8 #include "ace/Log_Category.h"
9 #include "ace/Flag_Manip.h"
10 #include "ace/OS_NS_sys_select.h"
11 #include "ace/OS_NS_string.h"
12 #include "ace/OS_NS_strings.h"
13 #include "ace/OS_NS_signal.h"
14 #include "ace/OS_NS_stdio.h"
15 #include "ace/OS_NS_sys_resource.h"
16 #include "ace/OS_NS_sys_wait.h"
17 #include "ace/OS_NS_sys_time.h"
18 #include "ace/OS_NS_time.h"
19 #include "ace/OS_NS_sys_uio.h"
20 #include "ace/OS_NS_sys_stat.h"
21 #include "ace/OS_NS_ctype.h"
22 #include "ace/OS_NS_fcntl.h"
23 #include "ace/OS_TLI.h"
24 #include "ace/Truncate.h"
26 #if !defined (__ACE_INLINE__)
27 #include "ace/ACE.inl"
28 #endif /* __ACE_INLINE__ */
30 #if defined (ACE_HAS_POLL)
31 # include "ace/OS_NS_poll.h"
32 #endif /* ACE_HAS_POLL */
34 // Open versioned namespace, if enabled by the user.
35 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
37 namespace ACE
39 // private:
40 // Used internally so not exported.
42 // Size of allocation granularity.
43 size_t allocation_granularity_ = 0;
45 // Size of a VM page.
46 size_t pagesize_ = 0;
48 // Are we debugging ACE?
49 // Keeps track of whether we're in some global debug mode.
50 bool debug_ = false;
53 int
54 ACE::out_of_handles (int error)
56 // EMFILE is common to all platforms.
57 if (error == EMFILE ||
58 #if defined (ACE_WIN32)
59 // On Win32, we need to check for ENOBUFS also.
60 error == ENOBUFS ||
61 #elif defined (ACE_LINUX)
62 // On linux, we need to check for ENOENT also.
63 error == ENOENT ||
64 // For RedHat5.2, need to check for EINVAL too.
65 error == EINVAL ||
66 // Without threads check for EOPNOTSUPP
67 error == EOPNOTSUPP ||
68 #elif defined (__FreeBSD__)
69 // On FreeBSD we need to check for EOPNOTSUPP (LinuxThreads) or
70 // ENOSYS (libc_r threads) also.
71 error == EOPNOTSUPP ||
72 error == ENOSYS ||
73 #elif defined (__OpenBSD__)
74 // OpenBSD appears to return EBADF.
75 error == EBADF ||
76 #endif /* ACE_WIN32 */
77 error == ENFILE)
78 return 1;
79 else
80 return 0;
83 u_int
84 ACE::major_version ()
86 return ACE_MAJOR_VERSION;
89 u_int
90 ACE::minor_version ()
92 return ACE_MINOR_VERSION;
95 u_int
96 ACE::beta_version ()
98 return ACE_MICRO_VERSION;
101 u_int
102 ACE::micro_version ()
104 return ACE_MICRO_VERSION;
107 const ACE_TCHAR *
108 ACE::compiler_name ()
110 #ifdef ACE_CC_NAME
111 return ACE_CC_NAME;
112 #else
113 return ACE_TEXT ("");
114 #endif
117 u_int
118 ACE::compiler_major_version ()
120 #ifdef ACE_CC_MAJOR_VERSION
121 return ACE_CC_MAJOR_VERSION;
122 #else
123 return 0;
124 #endif
127 u_int
128 ACE::compiler_minor_version ()
130 #ifdef ACE_CC_MINOR_VERSION
131 return ACE_CC_MINOR_VERSION;
132 #else
133 return 0;
134 #endif
137 u_int
138 ACE::compiler_beta_version ()
140 #ifdef ACE_CC_BETA_VERSION
141 return ACE_CC_BETA_VERSION;
142 #else
143 return 0;
144 #endif
147 ACE_TCHAR
148 ACE::nibble2hex (u_int n)
150 // Yes, this works for UNICODE
151 return ACE_TEXT ("0123456789abcdef")[n & 0x0f];
154 bool
155 ACE::debug ()
157 //FUZZ: disable check_for_ace_log_categories
158 static const char *debug = ACE_OS::getenv ("ACE_DEBUG");
159 //FUZZ: enable check_for_ace_log_categories
160 return (ACE::debug_) ? ACE::debug_ : (debug != 0 ? (*debug != '0') : false);
163 void
164 ACE::debug (bool onoff)
166 ACE::debug_ = onoff;
170 ACE::select (int width,
171 ACE_Handle_Set *readfds,
172 ACE_Handle_Set *writefds,
173 ACE_Handle_Set *exceptfds,
174 const ACE_Time_Value *timeout)
176 int result = ACE_OS::select (width,
177 readfds ? readfds->fdset () : 0,
178 writefds ? writefds->fdset () : 0,
179 exceptfds ? exceptfds->fdset () : 0,
180 timeout);
181 if (result > 0)
183 # if !defined (ACE_WIN32)
184 // This isn't needed for Windows... it's a no-op anyway.
185 if (readfds)
186 readfds->sync ((ACE_HANDLE) width);
187 if (writefds)
188 writefds->sync ((ACE_HANDLE) width);
189 if (exceptfds)
190 exceptfds->sync ((ACE_HANDLE) width);
191 #endif /* ACE_WIN32 */
193 return result;
197 ACE::select (int width,
198 ACE_Handle_Set &readfds,
199 const ACE_Time_Value *timeout)
201 int result = ACE_OS::select (width,
202 readfds.fdset (),
205 timeout);
207 #if !defined (ACE_WIN32)
208 if (result > 0)
209 readfds.sync ((ACE_HANDLE) width);
210 #endif /* ACE_WIN32 */
211 return result;
215 ACE::terminate_process (pid_t pid)
217 #if defined (ACE_WIN32)
218 // Create a handle for the given process id.
219 ACE_HANDLE process_handle =
220 ::OpenProcess (PROCESS_TERMINATE,
221 FALSE, // New handle is not inheritable.
222 pid);
224 if (process_handle == ACE_INVALID_HANDLE
225 || process_handle == 0)
226 return -1;
227 else
229 // Kill the process associated with process_handle.
230 BOOL terminate_result =
231 ::TerminateProcess (process_handle, 0);
232 // Free up the kernel resources.
233 ACE_OS::close (process_handle);
234 return terminate_result ? 0 : -1;
236 #else
237 return ACE_OS::kill (pid, 9);
238 #endif /* ACE_WIN32 */
242 ACE::process_active (pid_t pid)
244 #if !defined(ACE_WIN32)
245 if (ACE_OS::kill (pid, 0) == 0)
246 return 1;
247 else if (errno == ESRCH)
248 return 0;
249 else
250 return -1;
251 #else
252 // Create a handle for the given process id.
253 ACE_HANDLE process_handle =
254 ::OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid);
255 if (process_handle == ACE_INVALID_HANDLE || process_handle == 0)
256 return 0;
257 else
259 DWORD status;
260 int result = 1;
261 if (::GetExitCodeProcess (process_handle,
262 &status) == 0
263 || status != STILL_ACTIVE)
264 result = 0;
266 ::CloseHandle (process_handle);
267 return result;
269 #endif /* !ACE_WIN32 */
272 const ACE_TCHAR *
273 ACE::execname (const ACE_TCHAR *old_name)
275 #if defined (ACE_WIN32)
276 const ACE_TCHAR *suffix = ACE_OS::strrchr (old_name, ACE_TEXT ('.'));
277 if (suffix == 0 || ACE_OS::strcasecmp (suffix, ACE_TEXT (".exe")) != 0)
279 ACE_TCHAR *new_name = 0;
281 size_t size =
282 ACE_OS::strlen (old_name)
283 + ACE_OS::strlen (ACE_TEXT (".exe"))
284 + 1;
286 ACE_NEW_RETURN (new_name,
287 ACE_TCHAR[size],
289 ACE_TCHAR *end = new_name;
291 end = ACE_OS::strecpy (new_name, old_name);
293 // Concatenate the .exe suffix onto the end of the executable.
294 // end points _after_ the terminating nul.
295 ACE_OS::strcpy (end - 1, ACE_TEXT (".exe"));
297 return new_name;
299 #endif /* ACE_WIN32 */
300 return old_name;
303 u_long
304 ACE::hash_pjw (const char *str, size_t len)
306 u_long hash = 0;
308 for (size_t i = 0; i < len; i++)
310 const char temp = str[i];
311 hash = (hash << 4) + (temp * 13);
313 u_long g = hash & 0xf0000000;
315 if (g)
317 hash ^= (g >> 24);
318 hash ^= g;
322 return hash;
325 u_long
326 ACE::hash_pjw (const char *str)
328 return ACE::hash_pjw (str, ACE_OS::strlen (str));
331 #if defined (ACE_HAS_WCHAR)
332 u_long
333 ACE::hash_pjw (const wchar_t *str, size_t len)
335 u_long hash = 0;
337 for (size_t i = 0; i < len; i++)
339 // @@ UNICODE: Does this function do the correct thing with wchar's?
341 const wchar_t temp = str[i];
342 hash = (hash << 4) + (temp * 13);
344 u_long g = hash & 0xf0000000;
346 if (g)
348 hash ^= (g >> 24);
349 hash ^= g;
353 return hash;
356 u_long
357 ACE::hash_pjw (const wchar_t *str)
359 return ACE::hash_pjw (str, ACE_OS::strlen (str));
361 #endif /* ACE_HAS_WCHAR */
363 ACE_TCHAR *
364 ACE::strenvdup (const ACE_TCHAR *str)
366 ACE_TRACE ("ACE::strenvdup");
368 return ACE_OS::strenvdup (str);
373 Examples:
375 Source NT UNIX
376 ==================================================================
377 netsvc netsvc.dll libnetsvc.so
378 (PATH will be (LD_LIBRARY_PATH
379 evaluated) evaluated)
381 libnetsvc.dll libnetsvc.dll libnetsvc.dll + warning
382 netsvc.so netsvc.so + warning libnetsvc.so
384 ..\../libs/netsvc ..\..\libs\netsvc.dll ../../libs/netsvc.so
385 (absolute path used) (absolute path used)
389 const ACE_TCHAR *
390 ACE::basename (const ACE_TCHAR *pathname, ACE_TCHAR delim)
392 ACE_TRACE ("ACE::basename");
393 const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);
395 if (temp == 0)
396 return pathname;
397 else
398 return temp + 1;
401 const ACE_TCHAR *
402 ACE::dirname (const ACE_TCHAR *pathname, ACE_TCHAR delim)
404 ACE_TRACE ("ACE::dirname");
405 static ACE_TCHAR return_dirname[MAXPATHLEN + 1];
407 const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);
409 if (temp == 0)
411 return_dirname[0] = '.';
412 return_dirname[1] = '\0';
414 return return_dirname;
416 else
418 // When the len is truncated, there are problems! This should
419 // not happen in normal circomstances
420 size_t len = temp - pathname + 1;
421 if (len > (sizeof return_dirname / sizeof (ACE_TCHAR)))
422 len = sizeof return_dirname / sizeof (ACE_TCHAR);
424 ACE_OS::strsncpy (return_dirname,
425 pathname,
426 len);
427 return return_dirname;
431 ssize_t
432 ACE::recv (ACE_HANDLE handle,
433 void *buf,
434 size_t len,
435 int flags,
436 const ACE_Time_Value *timeout)
438 if (timeout == 0)
439 return ACE_OS::recv (handle, (char *) buf, len, flags);
440 else
442 int val = 0;
443 if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1)
444 return -1;
445 else
447 ssize_t bytes_transferred =
448 ACE_OS::recv (handle, (char *) buf, len, flags);
449 ACE::restore_non_blocking_mode (handle, val);
450 return bytes_transferred;
455 #if defined (ACE_HAS_TLI)
457 ssize_t
458 ACE::t_rcv (ACE_HANDLE handle,
459 void *buf,
460 size_t len,
461 int *flags,
462 const ACE_Time_Value *timeout)
464 if (timeout == 0)
465 return ACE_OS::t_rcv (handle, (char *) buf, len, flags);
466 else
468 int val = 0;
469 if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1)
470 return -1;
471 else
473 ssize_t bytes_transferred =
474 ACE_OS::t_rcv (handle, (char *) buf, len, flags);
475 ACE::restore_non_blocking_mode (handle, val);
476 return bytes_transferred;
481 #endif /* ACE_HAS_TLI */
483 ssize_t
484 ACE::recv (ACE_HANDLE handle,
485 void *buf,
486 size_t n,
487 const ACE_Time_Value *timeout)
489 if (timeout == 0)
490 return ACE::recv_i (handle, buf, n);
491 else
493 int val = 0;
494 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
495 return -1;
496 else
498 ssize_t bytes_transferred = ACE::recv_i (handle, buf, n);
499 ACE::restore_non_blocking_mode (handle, val);
500 return bytes_transferred;
505 ssize_t
506 ACE::recvmsg (ACE_HANDLE handle,
507 struct msghdr *msg,
508 int flags,
509 const ACE_Time_Value *timeout)
511 if (timeout == 0)
512 return ACE_OS::recvmsg (handle, msg, flags);
513 else
515 int val = 0;
516 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
517 return -1;
518 else
520 ssize_t bytes_transferred = ACE_OS::recvmsg (handle, msg, flags);
521 ACE::restore_non_blocking_mode (handle, val);
522 return bytes_transferred;
527 ssize_t
528 ACE::recvfrom (ACE_HANDLE handle,
529 char *buf,
530 int len,
531 int flags,
532 struct sockaddr *addr,
533 int *addrlen,
534 const ACE_Time_Value *timeout)
536 if (timeout == 0)
537 return ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen);
538 else
540 int val = 0;
541 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
542 return -1;
543 else
545 ssize_t bytes_transferred =
546 ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen);
547 ACE::restore_non_blocking_mode (handle, val);
548 return bytes_transferred;
553 ssize_t
554 ACE::recv_n_i (ACE_HANDLE handle,
555 void *buf,
556 size_t len,
557 int flags,
558 size_t *bt)
560 size_t temp;
561 size_t &bytes_transferred = bt == 0 ? temp : *bt;
562 ssize_t n;
564 for (bytes_transferred = 0;
565 bytes_transferred < len;
566 bytes_transferred += n)
568 // Try to transfer as much of the remaining data as possible.
569 n = ACE_OS::recv (handle,
570 static_cast <char *> (buf) + bytes_transferred,
571 len - bytes_transferred,
572 flags);
573 // Check EOF.
574 if (n == 0)
575 return 0;
577 // Check for other errors.
578 if (n == -1)
580 // Check for possible blocking.
581 if (errno == EWOULDBLOCK)
583 // Wait for the blocking to subside.
584 int const result = ACE::handle_read_ready (handle, 0);
586 // Did select() succeed?
587 if (result != -1)
589 // Blocking subsided. Continue data transfer.
590 n = 0;
591 continue;
595 // Other data transfer or select() failures.
596 return -1;
600 return static_cast<ssize_t> (bytes_transferred);
603 ssize_t
604 ACE::recv_n_i (ACE_HANDLE handle,
605 void *buf,
606 size_t len,
607 int flags,
608 const ACE_Time_Value *timeout,
609 size_t *bt)
611 size_t temp;
612 size_t &bytes_transferred = bt == 0 ? temp : *bt;
613 ssize_t n;
614 ssize_t result = 0;
615 bool error = false;
617 int val = 0;
618 ACE::record_and_set_non_blocking_mode (handle, val);
620 for (bytes_transferred = 0;
621 bytes_transferred < len;
622 bytes_transferred += n)
624 // Try to transfer as much of the remaining data as possible.
625 // Since the socket is in non-blocking mode, this call will not
626 // block.
627 n = ACE_OS::recv (handle,
628 static_cast <char *> (buf) + bytes_transferred,
629 len - bytes_transferred,
630 flags);
632 // Check for errors.
633 if (n == 0 ||
634 n == -1)
636 // Check for possible blocking.
637 if (n == -1 &&
638 errno == EWOULDBLOCK)
640 // Wait upto <timeout> for the blocking to subside.
641 int const rtn = ACE::handle_read_ready (handle, timeout);
643 // Did select() succeed?
644 if (rtn != -1)
646 // Blocking subsided in <timeout> period. Continue
647 // data transfer.
648 n = 0;
649 continue;
653 // Wait in select() timed out or other data transfer or
654 // select() failures.
655 error = true;
656 result = n;
657 break;
661 ACE::restore_non_blocking_mode (handle, val);
663 if (error)
664 return result;
665 else
666 return static_cast<ssize_t> (bytes_transferred);
669 #if defined (ACE_HAS_TLI)
671 ssize_t
672 ACE::t_rcv_n_i (ACE_HANDLE handle,
673 void *buf,
674 size_t len,
675 int *flags,
676 size_t *bt)
678 size_t temp;
679 size_t &bytes_transferred = bt == 0 ? temp : *bt;
680 ssize_t n;
682 for (bytes_transferred = 0;
683 bytes_transferred < len;
684 bytes_transferred += n)
686 // Try to transfer as much of the remaining data as possible.
687 n = ACE_OS::t_rcv (handle,
688 (char *) buf + bytes_transferred,
689 len - bytes_transferred,
690 flags);
691 // Check EOF.
692 if (n == 0)
693 return 0;
695 // Check for other errors.
696 if (n == -1)
698 // Check for possible blocking.
699 if (errno == EWOULDBLOCK)
701 // Wait for the blocking to subside.
702 int const result = ACE::handle_read_ready (handle, 0);
704 // Did select() succeed?
705 if (result != -1)
707 // Blocking subsided. Continue data transfer.
708 n = 0;
709 continue;
713 // Other data transfer or select() failures.
714 return -1;
718 return bytes_transferred;
721 ssize_t
722 ACE::t_rcv_n_i (ACE_HANDLE handle,
723 void *buf,
724 size_t len,
725 int *flags,
726 const ACE_Time_Value *timeout,
727 size_t *bt)
729 size_t temp;
730 size_t &bytes_transferred = bt == 0 ? temp : *bt;
731 ssize_t n;
732 ssize_t result = 0;
733 bool error = false;
735 int val = 0;
736 ACE::record_and_set_non_blocking_mode (handle, val);
738 for (bytes_transferred = 0;
739 bytes_transferred < len;
740 bytes_transferred += n)
742 // Try to transfer as much of the remaining data as possible.
743 // Since the socket is in non-blocking mode, this call will not
744 // block.
745 n = ACE_OS::t_rcv (handle,
746 (char *) buf + bytes_transferred,
747 len - bytes_transferred,
748 flags);
750 // Check for errors.
751 if (n == 0 ||
752 n == -1)
754 // Check for possible blocking.
755 if (n == -1 &&
756 errno == EWOULDBLOCK)
758 // Wait upto <timeout> for the blocking to subside.
759 int const rtn = ACE::handle_read_ready (handle, timeout);
761 // Did select() succeed?
762 if (rtn != -1)
764 // Blocking subsided in <timeout> period. Continue
765 // data transfer.
766 n = 0;
767 continue;
771 // Wait in select() timed out or other data transfer or
772 // select() failures.
773 error = true;
774 result = n;
775 break;
779 ACE::restore_non_blocking_mode (handle, val);
781 if (error)
782 return result;
783 else
784 return bytes_transferred;
787 #endif /* ACE_HAS_TLI */
789 ssize_t
790 ACE::recv_n_i (ACE_HANDLE handle,
791 void *buf,
792 size_t len,
793 size_t *bt)
795 size_t temp;
796 size_t &bytes_transferred = bt == 0 ? temp : *bt;
797 ssize_t n;
799 for (bytes_transferred = 0;
800 bytes_transferred < len;
801 bytes_transferred += n)
803 // Try to transfer as much of the remaining data as possible.
804 n = ACE::recv_i (handle,
805 static_cast <char *> (buf) + bytes_transferred,
806 len - bytes_transferred);
807 // Check EOF.
808 if (n == 0)
810 return 0;
812 // Check for other errors.
813 if (n == -1)
815 // Check for possible blocking.
816 if (errno == EWOULDBLOCK)
818 // Wait for the blocking to subside.
819 int const result = ACE::handle_read_ready (handle, 0);
821 // Did select() succeed?
822 if (result != -1)
824 // Blocking subsided. Continue data transfer.
825 n = 0;
826 continue;
830 // Other data transfer or select() failures.
831 return -1;
835 return static_cast<ssize_t> (bytes_transferred);
838 ssize_t
839 ACE::recv_n_i (ACE_HANDLE handle,
840 void *buf,
841 size_t len,
842 const ACE_Time_Value *timeout,
843 size_t *bt)
845 size_t temp;
846 size_t &bytes_transferred = bt == 0 ? temp : *bt;
847 ssize_t n;
848 ssize_t result = 0;
849 bool error = false;
851 int val = 0;
852 ACE::record_and_set_non_blocking_mode (handle, val);
854 for (bytes_transferred = 0;
855 bytes_transferred < len;
856 bytes_transferred += n)
858 // Try to transfer as much of the remaining data as possible.
859 // Since the socket is in non-blocking mode, this call will not
860 // block.
861 n = ACE::recv_i (handle,
862 static_cast <char *> (buf) + bytes_transferred,
863 len - bytes_transferred);
865 // Check for errors.
866 if (n == 0 ||
867 n == -1)
869 // Check for possible blocking.
870 if (n == -1 &&
871 errno == EWOULDBLOCK)
873 // Wait upto <timeout> for the blocking to subside.
874 int const rtn = ACE::handle_read_ready (handle, timeout);
876 // Did select() succeed?
877 if (rtn != -1)
879 // Blocking subsided in <timeout> period. Continue
880 // data transfer.
881 n = 0;
882 continue;
886 // Wait in select() timed out or other data transfer or
887 // select() failures.
888 error = true;
889 result = n;
890 break;
894 ACE::restore_non_blocking_mode (handle, val);
896 if (error)
897 return result;
898 else
899 return static_cast<ssize_t> (bytes_transferred);
902 // This is basically an interface to ACE_OS::readv, that doesn't use
903 // the struct iovec explicitly. The ... can be passed as an arbitrary
904 // number of (char *ptr, int len) tuples. However, the count N is the
905 // *total* number of trailing arguments, *not* a couple of the number
906 // of tuple pairs!
907 #if !defined (ACE_LACKS_VA_FUNCTIONS)
908 ssize_t
909 ACE::recv (ACE_HANDLE handle, size_t n, ...)
911 va_list argp;
912 int const total_tuples = static_cast<int> (n / 2);
913 iovec *iovp = 0;
914 #if defined (ACE_HAS_ALLOCA)
915 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
916 #else
917 # ifdef ACE_HAS_ALLOC_HOOKS
918 ACE_ALLOCATOR_RETURN (iovp, (iovec *)
919 ACE_Allocator::instance ()->malloc (total_tuples *
920 sizeof (iovec)),
921 -1);
922 # else
923 ACE_NEW_RETURN (iovp,
924 iovec[total_tuples],
925 -1);
926 # endif /* ACE_HAS_ALLOC_HOOKS */
927 #endif /* !defined (ACE_HAS_ALLOCA) */
929 va_start (argp, n);
931 for (int i = 0; i < total_tuples; i++)
933 iovp[i].iov_base = va_arg (argp, char *);
934 iovp[i].iov_len = va_arg (argp, int);
937 ssize_t const result = ACE_OS::recvv (handle, iovp, total_tuples);
938 #if !defined (ACE_HAS_ALLOCA)
939 # ifdef ACE_HAS_ALLOC_HOOKS
940 ACE_Allocator::instance ()->free (iovp);
941 # else
942 delete [] iovp;
943 # endif /* ACE_HAS_ALLOC_HOOKS */
944 #endif /* !defined (ACE_HAS_ALLOCA) */
945 va_end (argp);
946 return result;
948 #endif /* ACE_LACKS_VA_FUNCTIONS */
951 ssize_t
952 ACE::recvv (ACE_HANDLE handle,
953 iovec *iov,
954 int iovcnt,
955 const ACE_Time_Value *timeout)
957 if (timeout == 0)
958 return ACE_OS::recvv (handle, iov, iovcnt);
959 else
961 int val = 0;
962 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
963 return -1;
964 else
966 ssize_t bytes_transferred = ACE_OS::recvv (handle, iov, iovcnt);
967 ACE::restore_non_blocking_mode (handle, val);
968 return bytes_transferred;
973 ssize_t
974 ACE::recvv_n_i (ACE_HANDLE handle,
975 iovec *iov,
976 int iovcnt,
977 size_t *bt)
979 size_t temp;
980 size_t &bytes_transferred = bt == 0 ? temp : *bt;
981 bytes_transferred = 0;
983 for (int s = 0; s < iovcnt; )
985 // Try to transfer as much of the remaining data as possible.
986 ssize_t n = ACE_OS::recvv (handle, iov + s, iovcnt - s);
987 // Check EOF.
988 if (n == 0)
989 return 0;
991 // Check for other errors.
992 if (n == -1)
994 // Check for possible blocking.
995 if (errno == EWOULDBLOCK)
997 // Wait for the blocking to subside.
998 int const result = ACE::handle_read_ready (handle, 0);
1000 // Did select() succeed?
1001 if (result != -1)
1003 // Blocking subsided. Continue data transfer.
1004 continue;
1008 // Other data transfer or select() failures.
1009 return -1;
1012 for (bytes_transferred += n;
1013 s < iovcnt
1014 && n >= static_cast<ssize_t> (iov[s].iov_len);
1015 s++)
1016 n -= iov[s].iov_len;
1018 if (n != 0)
1020 char *base = static_cast<char *> (iov[s].iov_base);
1021 iov[s].iov_base = base + n;
1022 // This blind cast is safe because n < iov_len, after above loop.
1023 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
1027 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1030 ssize_t
1031 ACE::recvv_n_i (ACE_HANDLE handle,
1032 iovec *iov,
1033 int iovcnt,
1034 const ACE_Time_Value *timeout,
1035 size_t *bt)
1037 size_t temp;
1038 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1039 bytes_transferred = 0;
1040 ssize_t result = 0;
1041 bool error = false;
1043 int val = 0;
1044 ACE::record_and_set_non_blocking_mode (handle, val);
1046 for (int s = 0; s < iovcnt; )
1048 // Try to transfer as much of the remaining data as possible.
1049 // Since the socket is in non-blocking mode, this call will not
1050 // block.
1051 ssize_t n = ACE_OS::recvv (handle, iov + s, iovcnt - s);
1053 // Check for errors.
1054 if (n == 0 || n == -1)
1056 // Check for possible blocking.
1057 if (n == -1 && errno == EWOULDBLOCK)
1059 // Wait upto <timeout> for the blocking to subside.
1060 int const rtn = ACE::handle_read_ready (handle, timeout);
1062 // Did select() succeed?
1063 if (rtn != -1)
1065 // Blocking subsided in <timeout> period. Continue
1066 // data transfer.
1067 continue;
1071 // Wait in select() timed out or other data transfer or
1072 // select() failures.
1073 error = true;
1074 result = n;
1075 break;
1078 for (bytes_transferred += n;
1079 s < iovcnt
1080 && n >= static_cast<ssize_t> (iov[s].iov_len);
1081 s++)
1082 n -= iov[s].iov_len;
1084 if (n != 0)
1086 char *base = reinterpret_cast<char *> (iov[s].iov_base);
1087 iov[s].iov_base = base + n;
1088 // This blind cast is safe because n < iov_len, after above loop.
1089 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
1093 ACE::restore_non_blocking_mode (handle, val);
1095 if (error)
1097 return result;
1099 else
1101 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1105 ssize_t
1106 ACE::recv_n (ACE_HANDLE handle,
1107 ACE_Message_Block *message_block,
1108 const ACE_Time_Value *timeout,
1109 size_t *bt)
1111 size_t temp;
1112 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1113 bytes_transferred = 0;
1115 iovec iov[ACE_IOV_MAX];
1116 int iovcnt = 0;
1118 while (message_block != 0)
1120 // Our current message block chain.
1121 const ACE_Message_Block *current_message_block = message_block;
1123 while (current_message_block != 0)
1125 size_t current_message_block_length =
1126 current_message_block->length ();
1127 char *this_rd_ptr = current_message_block->rd_ptr ();
1129 // Check if this block has any space for incoming data.
1130 while (current_message_block_length > 0)
1132 u_long const this_chunk_length =
1133 ACE_Utils::truncate_cast<u_long> (
1134 current_message_block_length);
1136 // Collect the data in the iovec.
1137 iov[iovcnt].iov_base = this_rd_ptr;
1138 iov[iovcnt].iov_len = this_chunk_length;
1139 current_message_block_length -= this_chunk_length;
1140 this_rd_ptr += this_chunk_length;
1142 // Increment iovec counter.
1143 ++iovcnt;
1145 // The buffer is full make a OS call. @@ TODO find a way to
1146 // find ACE_IOV_MAX for platforms that do not define it rather
1147 // than simply setting ACE_IOV_MAX to some arbitrary value such
1148 // as 16.
1149 if (iovcnt == ACE_IOV_MAX)
1151 size_t current_transfer = 0;
1153 ssize_t const result = ACE::recvv_n (handle,
1154 iov,
1155 iovcnt,
1156 timeout,
1157 &current_transfer);
1159 // Add to total bytes transferred.
1160 bytes_transferred += current_transfer;
1162 // Errors.
1163 if (result == -1 || result == 0)
1164 return result;
1166 // Reset iovec counter.
1167 iovcnt = 0;
1171 // Select the next message block in the chain.
1172 current_message_block = current_message_block->cont ();
1175 // Selection of the next message block chain.
1176 message_block = message_block->next ();
1179 // Check for remaining buffers to be sent. This will happen when
1180 // ACE_IOV_MAX is not a multiple of the number of message blocks.
1181 if (iovcnt != 0)
1183 size_t current_transfer = 0;
1185 ssize_t const result = ACE::recvv_n (handle,
1186 iov,
1187 iovcnt,
1188 timeout,
1189 &current_transfer);
1191 // Add to total bytes transferred.
1192 bytes_transferred += current_transfer;
1194 // Errors.
1195 if (result == -1 || result == 0)
1197 return result;
1201 // Return total bytes transferred.
1202 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1205 ssize_t
1206 ACE::send (ACE_HANDLE handle,
1207 const void *buf,
1208 size_t n,
1209 int flags,
1210 const ACE_Time_Value *timeout)
1212 if (timeout == 0)
1213 return ACE_OS::send (handle, (const char *) buf, n, flags);
1214 else
1216 int val = 0;
1217 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1218 return -1;
1219 else
1221 ssize_t const bytes_transferred =
1222 ACE_OS::send (handle, (const char *) buf, n, flags);
1223 ACE::restore_non_blocking_mode (handle, val);
1224 return bytes_transferred;
1229 #if defined (ACE_HAS_TLI)
1231 ssize_t
1232 ACE::t_snd (ACE_HANDLE handle,
1233 const void *buf,
1234 size_t n,
1235 int flags,
1236 const ACE_Time_Value *timeout)
1238 if (timeout == 0)
1239 return ACE_OS::t_snd (handle, (const char *) buf, n, flags);
1240 else
1242 int val = 0;
1243 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1244 return -1;
1245 else
1247 ssize_t const bytes_transferred =
1248 ACE_OS::t_snd (handle, (const char *) buf, n, flags);
1249 ACE::restore_non_blocking_mode (handle, val);
1250 return bytes_transferred;
1255 #endif /* ACE_HAS_TLI */
1257 ssize_t
1258 ACE::send (ACE_HANDLE handle,
1259 const void *buf,
1260 size_t n,
1261 const ACE_Time_Value *timeout)
1263 if (timeout == 0)
1264 return ACE::send_i (handle, buf, n);
1265 else
1267 int val = 0;
1268 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1269 return -1;
1270 else
1272 ssize_t const bytes_transferred = ACE::send_i (handle, buf, n);
1273 ACE::restore_non_blocking_mode (handle, val);
1274 return bytes_transferred;
1279 ssize_t
1280 ACE::sendmsg (ACE_HANDLE handle,
1281 const struct msghdr *msg,
1282 int flags,
1283 const ACE_Time_Value *timeout)
1285 if (timeout == 0)
1286 return ACE_OS::sendmsg (handle, msg, flags);
1287 else
1289 int val = 0;
1290 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1291 return -1;
1292 else
1294 ssize_t const bytes_transferred =
1295 ACE_OS::sendmsg (handle, msg, flags);
1296 ACE::restore_non_blocking_mode (handle, val);
1297 return bytes_transferred;
1302 ssize_t
1303 ACE::sendto (ACE_HANDLE handle,
1304 const char *buf,
1305 int len,
1306 int flags,
1307 const struct sockaddr *addr,
1308 int addrlen,
1309 const ACE_Time_Value *timeout)
1311 if (timeout == 0)
1312 return ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
1313 else
1315 int val = 0;
1316 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1317 return -1;
1318 else
1320 ssize_t const bytes_transferred =
1321 ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
1322 ACE::restore_non_blocking_mode (handle, val);
1323 return bytes_transferred;
1328 ssize_t
1329 ACE::send_n_i (ACE_HANDLE handle,
1330 const void *buf,
1331 size_t len,
1332 int flags,
1333 size_t *bt)
1335 size_t temp;
1336 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1337 ssize_t n;
1339 for (bytes_transferred = 0;
1340 bytes_transferred < len;
1341 bytes_transferred += n)
1343 // Try to transfer as much of the remaining data as possible.
1344 n = ACE_OS::send (handle,
1345 (char *) buf + bytes_transferred,
1346 len - bytes_transferred,
1347 flags);
1348 // Check EOF.
1349 if (n == 0)
1350 return 0;
1352 // Check for other errors.
1353 if (n == -1)
1355 // Check for possible blocking.
1356 #if defined (ACE_WIN32)
1357 if (errno == EWOULDBLOCK) // If enobufs no need to loop
1358 #else
1359 if (errno == EWOULDBLOCK || errno == ENOBUFS)
1360 #endif /* ACE_WIN32 */
1362 // Wait for the blocking to subside.
1363 int const result = ACE::handle_write_ready (handle, 0);
1365 // Did select() succeed?
1366 if (result != -1)
1368 // Blocking subsided. Continue data transfer.
1369 n = 0;
1370 continue;
1374 // Other data transfer or select() failures.
1375 return -1;
1379 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1382 ssize_t
1383 ACE::send_n_i (ACE_HANDLE handle,
1384 const void *buf,
1385 size_t len,
1386 int flags,
1387 const ACE_Time_Value *timeout,
1388 size_t *bt)
1390 size_t temp;
1391 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1392 ssize_t n;
1393 ssize_t result = 0;
1394 bool error = false;
1396 int val = 0;
1397 ACE::record_and_set_non_blocking_mode (handle, val);
1399 for (bytes_transferred = 0;
1400 bytes_transferred < len;
1401 bytes_transferred += n)
1403 // Try to transfer as much of the remaining data as possible.
1404 // Since the socket is in non-blocking mode, this call will not
1405 // block.
1406 n = ACE_OS::send (handle,
1407 (char *) buf + bytes_transferred,
1408 len - bytes_transferred,
1409 flags);
1411 // Check for errors.
1412 if (n == 0 ||
1413 n == -1)
1415 // Check for possible blocking.
1416 if (n == -1 && (errno == EWOULDBLOCK || errno == ENOBUFS))
1418 // Wait upto <timeout> for the blocking to subside.
1419 int const rtn = ACE::handle_write_ready (handle, timeout);
1421 // Did select() succeed?
1422 if (rtn != -1)
1424 // Blocking subsided in <timeout> period. Continue
1425 // data transfer.
1426 n = 0;
1427 continue;
1431 // Wait in select() timed out or other data transfer or
1432 // select() failures.
1433 error = true;
1434 result = n;
1435 break;
1439 ACE::restore_non_blocking_mode (handle, val);
1441 if (error)
1443 return result;
1445 else
1447 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1451 #if defined (ACE_HAS_TLI)
1453 ssize_t
1454 ACE::t_snd_n_i (ACE_HANDLE handle,
1455 const void *buf,
1456 size_t len,
1457 int flags,
1458 size_t *bt)
1460 size_t temp;
1461 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1462 ssize_t n;
1464 for (bytes_transferred = 0;
1465 bytes_transferred < len;
1466 bytes_transferred += n)
1468 // Try to transfer as much of the remaining data as possible.
1469 n = ACE_OS::t_snd (handle,
1470 (char *) buf + bytes_transferred,
1471 len - bytes_transferred,
1472 flags);
1473 // Check EOF.
1474 if (n == 0)
1475 return 0;
1477 // Check for other errors.
1478 if (n == -1)
1480 // Check for possible blocking.
1481 if (errno == EWOULDBLOCK || errno == ENOBUFS)
1483 // Wait for the blocking to subside.
1484 int const result = ACE::handle_write_ready (handle, 0);
1486 // Did select() succeed?
1487 if (result != -1)
1489 // Blocking subsided. Continue data transfer.
1490 n = 0;
1491 continue;
1495 // Other data transfer or select() failures.
1496 return -1;
1500 return bytes_transferred;
1503 ssize_t
1504 ACE::t_snd_n_i (ACE_HANDLE handle,
1505 const void *buf,
1506 size_t len,
1507 int flags,
1508 const ACE_Time_Value *timeout,
1509 size_t *bt)
1511 size_t temp;
1512 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1513 ssize_t n;
1514 ssize_t result = 0;
1515 bool error = false;
1517 int val = 0;
1518 ACE::record_and_set_non_blocking_mode (handle, val);
1520 for (bytes_transferred = 0;
1521 bytes_transferred < len;
1522 bytes_transferred += n)
1524 // Try to transfer as much of the remaining data as possible.
1525 // Since the socket is in non-blocking mode, this call will not
1526 // block.
1527 n = ACE_OS::t_snd (handle,
1528 (char *) buf + bytes_transferred,
1529 len - bytes_transferred,
1530 flags);
1532 // Check for errors.
1533 if (n == 0 ||
1534 n == -1)
1536 // Check for possible blocking.
1537 if (n == -1 &&
1538 (errno == EWOULDBLOCK || errno == ENOBUFS))
1540 // Wait upto <timeout> for the blocking to subside.
1541 int const rtn = ACE::handle_write_ready (handle, timeout);
1543 // Did select() succeed?
1544 if (rtn != -1)
1546 // Blocking subsided in <timeout> period. Continue
1547 // data transfer.
1548 n = 0;
1549 continue;
1553 // Wait in select() timed out or other data transfer or
1554 // select() failures.
1555 error = true;
1556 result = n;
1557 break;
1561 ACE::restore_non_blocking_mode (handle, val);
1563 if (error)
1564 return result;
1565 else
1566 return bytes_transferred;
1569 #endif /* ACE_HAS_TLI */
1571 ssize_t
1572 ACE::send_n_i (ACE_HANDLE handle,
1573 const void *buf,
1574 size_t len,
1575 size_t *bt)
1577 size_t temp;
1578 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1579 ssize_t n;
1581 for (bytes_transferred = 0;
1582 bytes_transferred < len;
1583 bytes_transferred += n)
1585 // Try to transfer as much of the remaining data as possible.
1586 n = ACE::send_i (handle,
1587 (char *) buf + bytes_transferred,
1588 len - bytes_transferred);
1589 // Check EOF.
1590 if (n == 0)
1592 return 0;
1595 // Check for other errors.
1596 if (n == -1)
1598 // Check for possible blocking.
1599 if (errno == EWOULDBLOCK || errno == ENOBUFS)
1601 // Wait for the blocking to subside.
1602 int const result = ACE::handle_write_ready (handle, 0);
1604 // Did select() succeed?
1605 if (result != -1)
1607 // Blocking subsided. Continue data transfer.
1608 n = 0;
1609 continue;
1613 // Other data transfer or select() failures.
1614 return -1;
1618 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1621 ssize_t
1622 ACE::send_n_i (ACE_HANDLE handle,
1623 const void *buf,
1624 size_t len,
1625 const ACE_Time_Value *timeout,
1626 size_t *bt)
1628 size_t temp;
1629 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1630 ssize_t n;
1631 ssize_t result = 0;
1632 bool error = false;
1634 int val = 0;
1635 ACE::record_and_set_non_blocking_mode (handle, val);
1637 for (bytes_transferred = 0;
1638 bytes_transferred < len;
1639 bytes_transferred += n)
1641 // Try to transfer as much of the remaining data as possible.
1642 // Since the socket is in non-blocking mode, this call will not
1643 // block.
1644 n = ACE::send_i (handle,
1645 (char *) buf + bytes_transferred,
1646 len - bytes_transferred);
1648 // Check for errors.
1649 if (n == 0 ||
1650 n == -1)
1652 // Check for possible blocking.
1653 if (n == -1 &&
1654 (errno == EWOULDBLOCK || errno == ENOBUFS))
1656 // Wait upto <timeout> for the blocking to subside.
1657 int const rtn = ACE::handle_write_ready (handle, timeout);
1659 // Did select() succeed?
1660 if (rtn != -1)
1662 // Blocking subsided in <timeout> period. Continue
1663 // data transfer.
1664 n = 0;
1665 continue;
1669 // Wait in select() timed out or other data transfer or
1670 // select() failures.
1671 error = true;
1672 result = n;
1673 break;
1677 ACE::restore_non_blocking_mode (handle, val);
1679 if (error)
1681 return result;
1683 else
1685 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1689 // Send N char *ptrs and int lengths. Note that the char *'s precede
1690 // the ints (basically, an varargs version of writev). The count N is
1691 // the *total* number of trailing arguments, *not* a couple of the
1692 // number of tuple pairs!
1693 #if !defined (ACE_LACKS_VA_FUNCTIONS)
1694 ssize_t
1695 ACE::send (ACE_HANDLE handle, size_t n, ...)
1697 va_list argp;
1698 int total_tuples = static_cast<int> (n / 2);
1699 iovec *iovp;
1700 #if defined (ACE_HAS_ALLOCA)
1701 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
1702 #else
1703 # ifdef ACE_HAS_ALLOC_HOOKS
1704 ACE_ALLOCATOR_RETURN (iovp, (iovec *)
1705 ACE_Allocator::instance ()->malloc (total_tuples *
1706 sizeof (iovec)),
1707 -1);
1708 # else
1709 ACE_NEW_RETURN (iovp,
1710 iovec[total_tuples],
1711 -1);
1712 # endif /* ACE_HAS_ALLOC_HOOKS */
1713 #endif /* !defined (ACE_HAS_ALLOCA) */
1715 va_start (argp, n);
1717 for (int i = 0; i < total_tuples; i++)
1719 iovp[i].iov_base = va_arg (argp, char *);
1720 iovp[i].iov_len = va_arg (argp, int);
1723 ssize_t result = ACE_OS::sendv (handle, iovp, total_tuples);
1724 #if !defined (ACE_HAS_ALLOCA)
1725 # ifdef ACE_HAS_ALLOC_HOOKS
1726 ACE_Allocator::instance ()->free (iovp);
1727 # else
1728 delete [] iovp;
1729 # endif /* ACE_HAS_ALLOC_HOOKS */
1730 #endif /* !defined (ACE_HAS_ALLOCA) */
1731 va_end (argp);
1732 return result;
1734 #endif /* ACE_LACKS_VA_FUNCTIONS */
1736 ssize_t
1737 ACE::sendv (ACE_HANDLE handle,
1738 const iovec *iov,
1739 int iovcnt,
1740 const ACE_Time_Value *timeout)
1742 if (timeout == 0)
1743 return ACE_OS::sendv (handle, iov, iovcnt);
1744 else
1746 int val = 0;
1747 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1748 return -1;
1749 else
1751 ssize_t bytes_transferred = ACE_OS::sendv (handle, iov, iovcnt);
1752 ACE::restore_non_blocking_mode (handle, val);
1753 return bytes_transferred;
1758 ssize_t
1759 ACE::sendv_n_i (ACE_HANDLE handle,
1760 const iovec *i,
1761 int iovcnt,
1762 size_t *bt)
1764 size_t temp;
1765 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1766 bytes_transferred = 0;
1768 iovec *iov = const_cast<iovec *> (i);
1770 for (int s = 0;
1771 s < iovcnt;
1774 // Try to transfer as much of the remaining data as possible.
1775 ssize_t n = ACE_OS::sendv (handle, iov + s, iovcnt - s);
1777 // Check EOF.
1778 if (n == 0)
1779 return 0;
1781 // Check for other errors.
1782 if (n == -1)
1784 // Check for possible blocking.
1785 if (errno == EWOULDBLOCK || errno == ENOBUFS)
1787 // Wait for the blocking to subside.
1788 int const result = ACE::handle_write_ready (handle, 0);
1790 // Did select() succeed?
1791 if (result != -1)
1793 // Blocking subsided. Continue data transfer.
1794 continue;
1798 // Other data transfer or select() failures.
1799 return -1;
1802 for (bytes_transferred += n;
1803 s < iovcnt
1804 && n >= static_cast<ssize_t> (iov[s].iov_len);
1805 s++)
1806 n -= iov[s].iov_len;
1808 if (n != 0)
1810 char *base = reinterpret_cast<char *> (iov[s].iov_base);
1811 iov[s].iov_base = base + n;
1812 // This blind cast is safe because n < iov_len, after above loop.
1813 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
1817 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1820 ssize_t
1821 ACE::sendv_n_i (ACE_HANDLE handle,
1822 const iovec *i,
1823 int iovcnt,
1824 const ACE_Time_Value *timeout,
1825 size_t *bt)
1827 size_t temp;
1828 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1829 bytes_transferred = 0;
1830 ssize_t result = 0;
1831 bool error = false;
1833 int val = 0;
1834 ACE::record_and_set_non_blocking_mode (handle, val);
1836 iovec *iov = const_cast<iovec *> (i);
1838 for (int s = 0;
1839 s < iovcnt;
1842 // Try to transfer as much of the remaining data as possible.
1843 // Since the socket is in non-blocking mode, this call will not
1844 // block.
1845 ssize_t n = ACE_OS::sendv (handle, iov + s, iovcnt - s);
1847 // Check for errors.
1848 if (n == 0 ||
1849 n == -1)
1851 // Check for possible blocking.
1852 if (n == -1 &&
1853 (errno == EWOULDBLOCK || errno == ENOBUFS))
1855 // Wait upto <timeout> for the blocking to subside.
1856 int const rtn = ACE::handle_write_ready (handle, timeout);
1858 // Did select() succeed?
1859 if (rtn != -1)
1861 // Blocking subsided in <timeout> period. Continue
1862 // data transfer.
1863 continue;
1867 // Wait in select() timed out or other data transfer or
1868 // select() failures.
1869 error = true;
1870 result = n;
1871 break;
1874 for (bytes_transferred += n;
1875 s < iovcnt
1876 && n >= static_cast<ssize_t> (iov[s].iov_len);
1877 s++)
1878 n -= iov[s].iov_len;
1880 if (n != 0)
1882 char *base = reinterpret_cast<char *> (iov[s].iov_base);
1883 iov[s].iov_base = base + n;
1884 // This blind cast is safe because n < iov_len, after above loop.
1885 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
1889 ACE::restore_non_blocking_mode (handle, val);
1891 if (error)
1893 return result;
1895 else
1897 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1901 ssize_t
1902 ACE::write_n (ACE_HANDLE handle,
1903 const ACE_Message_Block *message_block,
1904 size_t *bt)
1906 size_t temp;
1907 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1908 bytes_transferred = 0;
1910 iovec iov[ACE_IOV_MAX];
1911 int iovcnt = 0;
1913 while (message_block != 0)
1915 // Our current message block chain.
1916 const ACE_Message_Block *current_message_block = message_block;
1918 while (current_message_block != 0)
1920 size_t current_message_block_length =
1921 current_message_block->length ();
1922 char *this_block_ptr = current_message_block->rd_ptr ();
1924 // Check if this block has any data to be sent.
1925 while (current_message_block_length > 0)
1927 u_long const this_chunk_length =
1928 ACE_Utils::truncate_cast<u_long> (
1929 current_message_block_length);
1931 // Collect the data in the iovec.
1932 iov[iovcnt].iov_base = this_block_ptr;
1933 iov[iovcnt].iov_len = this_chunk_length;
1934 current_message_block_length -= this_chunk_length;
1935 this_block_ptr += this_chunk_length;
1937 // Increment iovec counter.
1938 ++iovcnt;
1940 // The buffer is full make a OS call. @@ TODO find a way to
1941 // find ACE_IOV_MAX for platforms that do not define it rather
1942 // than simply setting ACE_IOV_MAX to some arbitrary value such
1943 // as 16.
1944 if (iovcnt == ACE_IOV_MAX)
1946 size_t current_transfer = 0;
1948 ssize_t const result = ACE::writev_n (handle,
1949 iov,
1950 iovcnt,
1951 &current_transfer);
1953 // Add to total bytes transferred.
1954 bytes_transferred += current_transfer;
1956 // Errors.
1957 if (result == -1 || result == 0)
1958 return result;
1960 // Reset iovec counter.
1961 iovcnt = 0;
1965 // Select the next message block in the chain.
1966 current_message_block = current_message_block->cont ();
1969 // Selection of the next message block chain.
1970 message_block = message_block->next ();
1973 // Check for remaining buffers to be sent. This will happen when
1974 // ACE_IOV_MAX is not a multiple of the number of message blocks.
1975 if (iovcnt != 0)
1977 size_t current_transfer = 0;
1979 ssize_t const result = ACE::writev_n (handle,
1980 iov,
1981 iovcnt,
1982 &current_transfer);
1984 // Add to total bytes transferred.
1985 bytes_transferred += current_transfer;
1987 // Errors.
1988 if (result == -1 || result == 0)
1989 return result;
1992 // Return total bytes transferred.
1993 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1996 ssize_t
1997 ACE::send_n (ACE_HANDLE handle,
1998 const ACE_Message_Block *message_block,
1999 const ACE_Time_Value *timeout,
2000 size_t *bt)
2002 size_t temp;
2003 size_t &bytes_transferred = bt == 0 ? temp : *bt;
2004 bytes_transferred = 0;
2006 iovec iov[ACE_IOV_MAX];
2007 int iovcnt = 0;
2009 while (message_block != 0)
2011 // Our current message block chain.
2012 const ACE_Message_Block *current_message_block = message_block;
2014 while (current_message_block != 0)
2016 char *this_block_ptr = current_message_block->rd_ptr ();
2017 size_t current_message_block_length =
2018 current_message_block->length ();
2020 // Check if this block has any data to be sent.
2021 while (current_message_block_length > 0)
2023 u_long const this_chunk_length =
2024 ACE_Utils::truncate_cast<u_long> (
2025 current_message_block_length);
2027 // Collect the data in the iovec.
2028 iov[iovcnt].iov_base = this_block_ptr;
2029 iov[iovcnt].iov_len = this_chunk_length;
2030 current_message_block_length -= this_chunk_length;
2031 this_block_ptr += this_chunk_length;
2033 // Increment iovec counter.
2034 ++iovcnt;
2036 // The buffer is full make a OS call. @@ TODO find a way to
2037 // find ACE_IOV_MAX for platforms that do not define it rather
2038 // than simply setting ACE_IOV_MAX to some arbitrary value such
2039 // as 16.
2040 if (iovcnt == ACE_IOV_MAX)
2042 size_t current_transfer = 0;
2044 ssize_t const result = ACE::sendv_n (handle,
2045 iov,
2046 iovcnt,
2047 timeout,
2048 &current_transfer);
2050 // Add to total bytes transferred.
2051 bytes_transferred += current_transfer;
2053 // Errors.
2054 if (result == -1 || result == 0)
2055 return result;
2057 // Reset iovec counter.
2058 iovcnt = 0;
2062 // Select the next message block in the chain.
2063 current_message_block = current_message_block->cont ();
2066 // Selection of the next message block chain.
2067 message_block = message_block->next ();
2070 // Check for remaining buffers to be sent. This will happen when
2071 // ACE_IOV_MAX is not a multiple of the number of message blocks.
2072 if (iovcnt != 0)
2074 size_t current_transfer = 0;
2076 ssize_t const result = ACE::sendv_n (handle,
2077 iov,
2078 iovcnt,
2079 timeout,
2080 &current_transfer);
2082 // Add to total bytes transferred.
2083 bytes_transferred += current_transfer;
2085 // Errors.
2086 if (result == -1 || result == 0)
2088 return result;
2092 // Return total bytes transferred.
2093 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
2096 ssize_t
2097 ACE::readv_n (ACE_HANDLE handle,
2098 iovec *iov,
2099 int iovcnt,
2100 size_t *bt)
2102 size_t temp;
2103 size_t &bytes_transferred = bt == 0 ? temp : *bt;
2104 bytes_transferred = 0;
2106 for (int s = 0;
2107 s < iovcnt;
2110 ssize_t n = ACE_OS::readv (handle,
2111 iov + s,
2112 iovcnt - s);
2114 if (n == -1 || n == 0)
2115 return n;
2117 for (bytes_transferred += n;
2118 s < iovcnt
2119 && n >= static_cast<ssize_t> (iov[s].iov_len);
2120 s++)
2121 n -= iov[s].iov_len;
2123 if (n != 0)
2125 char *base = reinterpret_cast<char *> (iov[s].iov_base);
2126 iov[s].iov_base = base + n;
2127 // This blind cast is safe because n < iov_len, after above loop.
2128 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
2132 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
2135 ssize_t
2136 ACE::writev_n (ACE_HANDLE handle,
2137 const iovec *i,
2138 int iovcnt,
2139 size_t *bt)
2141 size_t temp;
2142 size_t &bytes_transferred = bt == 0 ? temp : *bt;
2143 bytes_transferred = 0;
2145 iovec *iov = const_cast<iovec *> (i);
2147 for (int s = 0;
2148 s < iovcnt;
2151 ssize_t n = ACE_OS::writev (handle,
2152 iov + s,
2153 iovcnt - s);
2155 if (n == -1 || n == 0)
2157 return n;
2160 for (bytes_transferred += n;
2161 s < iovcnt
2162 && n >= static_cast<ssize_t> (iov[s].iov_len);
2163 s++)
2164 n -= iov[s].iov_len;
2166 if (n != 0)
2168 char *base = reinterpret_cast<char *> (iov[s].iov_base);
2169 iov[s].iov_base = base + n;
2170 // This blind cast is safe because n < iov_len, after above loop.
2171 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
2175 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
2179 ACE::handle_ready (ACE_HANDLE handle,
2180 const ACE_Time_Value *timeout,
2181 bool read_ready,
2182 bool write_ready,
2183 bool exception_ready)
2185 #if defined (ACE_HAS_POLL)
2186 ACE_UNUSED_ARG (exception_ready);
2188 struct pollfd fds;
2190 fds.fd = handle;
2191 fds.events = read_ready ? POLLIN : 0;
2193 if( write_ready )
2195 fds.events |= POLLOUT;
2198 fds.revents = 0;
2200 int const result = ACE_OS::poll (&fds, 1, timeout);
2201 #else
2202 ACE_Handle_Set handle_set;
2203 handle_set.set_bit (handle);
2205 // Wait for data or for the timeout to elapse.
2206 int select_width = 0;
2207 #if !defined (ACE_WIN32)
2208 select_width = int (handle) + 1;
2209 # endif /* ACE_WIN64 */
2210 int result = ACE_OS::select (select_width,
2211 read_ready ? handle_set.fdset () : 0, // read_fds.
2212 write_ready ? handle_set.fdset () : 0, // write_fds.
2213 exception_ready ? handle_set.fdset () : 0, // exception_fds.
2214 timeout);
2216 #endif /* ACE_HAS_POLL */
2217 switch (result)
2219 case 0: // Timer expired.
2220 errno = ETIME;
2221 ACE_FALLTHROUGH;
2222 case -1: // we got here directly - select() returned -1.
2223 return -1;
2224 case 1: // Handle has data.
2225 ACE_FALLTHROUGH;
2226 default: // default is case result > 0; return a
2227 // ACE_ASSERT (result == 1);
2228 return result;
2233 ACE::enter_recv_timedwait (ACE_HANDLE handle,
2234 const ACE_Time_Value *timeout,
2235 int &val)
2237 int const result = ACE::handle_read_ready (handle, timeout);
2239 if (result == -1)
2240 return -1;
2242 ACE::record_and_set_non_blocking_mode (handle, val);
2244 return result;
2248 ACE::enter_send_timedwait (ACE_HANDLE handle,
2249 const ACE_Time_Value *timeout,
2250 int &val)
2252 int const result = ACE::handle_write_ready (handle, timeout);
2254 if (result == -1)
2255 return -1;
2257 ACE::record_and_set_non_blocking_mode (handle, val);
2259 return result;
2262 void
2263 ACE::record_and_set_non_blocking_mode (ACE_HANDLE handle, int &val)
2265 // We need to record whether we are already *in* nonblocking mode,
2266 // so that we can correctly reset the state when we're done.
2267 val = ACE::get_flags (handle);
2269 if (ACE_BIT_DISABLED (val, ACE_NONBLOCK))
2270 // Set the handle into non-blocking mode if it's not already in
2271 // it.
2272 ACE::set_flags (handle, ACE_NONBLOCK);
2275 void
2276 ACE::restore_non_blocking_mode (ACE_HANDLE handle, int val)
2278 if (ACE_BIT_DISABLED (val, ACE_NONBLOCK))
2280 // Save/restore errno.
2281 ACE_Errno_Guard error (errno);
2282 // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
2283 // originally.
2284 ACE::clr_flags (handle, ACE_NONBLOCK);
2288 /// Format buffer into printable format. This is useful for debugging.
2289 /// Portions taken from mdump by J.P. Knight (J.P.Knight@lut.ac.uk)
2290 /// Modifications by Todd Montgomery.
2291 size_t
2292 ACE::format_hexdump (const char *buffer,
2293 size_t size,
2294 ACE_TCHAR *obuf,
2295 size_t obuf_sz)
2297 ACE_TRACE ("ACE::format_hexdump");
2299 u_char c;
2300 ACE_TCHAR textver[16 + 1];
2302 // We can fit 16 bytes output in text mode per line, 4 chars per byte.
2303 size_t maxlen = (obuf_sz / 68) * 16;
2304 const ACE_TCHAR *const obuf_start = obuf;
2306 if (size > maxlen)
2307 size = maxlen;
2309 size_t i;
2311 size_t const lines = size / 16;
2312 for (i = 0; i < lines; i++)
2314 size_t j;
2316 for (j = 0 ; j < 16; j++)
2318 c = (u_char) buffer[(i << 4) + j]; // or, buffer[i*16+j]
2319 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2320 ACE_TEXT ("%02x "),
2322 obuf += 3;
2323 if (j == 7)
2325 *obuf++ = ACE_TEXT (' ');
2327 textver[j] = ACE_OS::ace_isprint (c) ? c : u_char ('.');
2330 textver[j] = 0;
2332 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2333 ACE_TEXT (" %") ACE_TEXT_PRIs ACE_TEXT ("\n"),
2334 textver);
2336 while (*obuf != '\0')
2337 ++obuf;
2340 if (size % 16)
2342 for (i = 0 ; i < size % 16; i++)
2344 c = (u_char) buffer[size - size % 16 + i];
2345 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2346 ACE_TEXT ("%02x "),
2348 obuf += 3;
2349 if (i == 7)
2351 *obuf++ = ACE_TEXT (' ');
2353 textver[i] = ACE_OS::ace_isprint (c) ? c : u_char ('.');
2356 for (i = size % 16; i < 16; i++)
2358 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2359 ACE_TEXT (" "));
2360 obuf += 3;
2361 if (i == 7)
2363 *obuf++ = ACE_TEXT (' ');
2365 textver[i] = ' ';
2368 textver[i] = 0;
2369 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2370 ACE_TEXT (" %") ACE_TEXT_PRIs ACE_TEXT ("\n"),
2371 textver);
2373 return size;
2376 /// Returns the current timestamp in the form
2377 /// "hour:minute:second:microsecond." The month, day, and year are
2378 /// also stored in the beginning of the date_and_time array
2379 /// using ISO-8601 format.
2380 ACE_TCHAR *
2381 ACE::timestamp (ACE_TCHAR date_and_time[],
2382 size_t date_and_timelen,
2383 bool return_pointer_to_first_digit)
2385 return ACE::timestamp (ACE_Time_Value::zero,
2386 date_and_time,
2387 date_and_timelen,
2388 return_pointer_to_first_digit);
2391 /// Returns the given timestamp in the form
2392 /// "hour:minute:second:microsecond." The month, day, and year are
2393 /// also stored in the beginning of the date_and_time array
2394 /// using ISO-8601 format.
2395 /// 012345678901234567890123456
2396 /// 2010-12-02 12:56:00.123456<nul>
2397 ACE_TCHAR *
2398 ACE::timestamp (const ACE_Time_Value& time_value,
2399 ACE_TCHAR date_and_time[],
2400 size_t date_and_timelen,
2401 bool return_pointer_to_first_digit)
2403 //ACE_TRACE ("ACE::timestamp");
2405 // This magic number is from the formatting statement
2406 // farther down this routine.
2407 if (date_and_timelen < 27)
2409 errno = EINVAL;
2410 return 0;
2413 ACE_Time_Value cur_time =
2414 (time_value == ACE_Time_Value::zero) ?
2415 ACE_Time_Value (ACE_OS::gettimeofday ()) : time_value;
2416 time_t secs = cur_time.sec ();
2417 struct tm tms;
2418 ACE_OS::localtime_r (&secs, &tms);
2419 ACE_OS::snprintf (date_and_time,
2420 date_and_timelen,
2421 ACE_TEXT ("%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d.%06ld"),
2422 tms.tm_year + 1900,
2423 tms.tm_mon + 1,
2424 tms.tm_mday,
2425 tms.tm_hour,
2426 tms.tm_min,
2427 tms.tm_sec,
2428 static_cast<long> (cur_time.usec()));
2429 date_and_time[date_and_timelen - 1] = '\0';
2430 return &date_and_time[10 + (return_pointer_to_first_digit != 0)];
2433 /// This function rounds the request to a multiple of the page size.
2434 size_t
2435 ACE::round_to_pagesize (size_t len)
2437 ACE_TRACE ("ACE::round_to_pagesize");
2439 if (ACE::pagesize_ == 0)
2440 ACE::pagesize_ = ACE_OS::getpagesize ();
2442 return (len + (ACE::pagesize_ - 1)) & ~(ACE::pagesize_ - 1);
2445 size_t
2446 ACE::round_to_allocation_granularity (size_t len)
2448 ACE_TRACE ("ACE::round_to_allocation_granularity");
2450 if (ACE::allocation_granularity_ == 0)
2451 ACE::allocation_granularity_ = ACE_OS::allocation_granularity ();
2453 return (len + (ACE::allocation_granularity_ - 1)) & ~(ACE::allocation_granularity_ - 1);
2456 ACE_HANDLE
2457 ACE::handle_timed_complete (ACE_HANDLE h,
2458 const ACE_Time_Value *timeout,
2459 int is_tli)
2461 ACE_TRACE ("ACE::handle_timed_complete");
2463 #if !defined (ACE_WIN32) && defined (ACE_HAS_POLL)
2465 struct pollfd fds;
2467 fds.fd = h;
2468 fds.events = POLLIN | POLLOUT;
2469 fds.revents = 0;
2471 #else
2472 ACE_Handle_Set rd_handles;
2473 ACE_Handle_Set wr_handles;
2474 rd_handles.set_bit (h);
2475 wr_handles.set_bit (h);
2476 #endif /* !ACE_WIN32 && ACE_HAS_POLL */
2478 #if defined (ACE_WIN32)
2479 // Winsock is different - it sets the exception bit for failed connect,
2480 // unlike other platforms, where the write bit is set for both success
2481 // and fail.
2482 ACE_Handle_Set ex_handles;
2483 ex_handles.set_bit (h);
2484 #endif /* ACE_WIN32 */
2486 bool need_to_check = false;
2487 bool known_failure = false;
2489 #if defined (ACE_WIN32)
2490 int n = ACE_OS::select (0, // Ignored on Windows: int (h) + 1,
2492 wr_handles,
2493 ex_handles,
2494 timeout);
2495 #else
2496 # if defined (ACE_HAS_POLL)
2498 int n = ACE_OS::poll (&fds, 1, timeout);
2500 # else
2501 int n = 0;
2502 if (is_tli)
2503 n = ACE_OS::select (int (h) + 1,
2504 rd_handles,
2505 wr_handles,
2507 timeout);
2508 else
2509 n = ACE_OS::select (int (h) + 1,
2511 wr_handles,
2513 timeout);
2514 # endif /* ACE_HAS_POLL */
2515 #endif /* ACE_WIN32 */
2517 // If we failed to connect within the time period allocated by the
2518 // caller, then we fail (e.g., the remote host might have been too
2519 // busy to accept our call).
2520 if (n <= 0)
2522 if (n == 0 && timeout != 0)
2523 errno = ETIME;
2524 return ACE_INVALID_HANDLE;
2527 // On Windows, a ready-for-write handle is successfully connected, and
2528 // ready-for-exception is a failure. On fails, we need to grab the error
2529 // code via getsockopt.
2530 // On BSD sockets using select(), the handle becomes writable on
2531 // completion either success or fail, so if the select() does not time
2532 // out, we need to check for success/fail.
2533 // It is believed that TLI sockets use the readable=fail, writeable=success
2534 // but that hasn't been as well tested.
2535 #if defined (ACE_WIN32)
2536 ACE_UNUSED_ARG (is_tli);
2538 // On Win32, ex_handle set indicates a failure. We'll do the check
2539 // to try and get an errno value, but the connect failed regardless of
2540 // what getsockopt says about the error.
2541 if (ex_handles.is_set (h))
2543 need_to_check = true;
2544 known_failure = true;
2546 #else
2547 if (is_tli)
2548 # if defined (ACE_HAS_POLL)
2549 need_to_check = (fds.revents & POLLIN) && !(fds.revents & POLLOUT);
2550 # else
2551 need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h);
2552 # endif /* ACE_HAS_POLL */
2554 else
2555 # if defined (ACE_HAS_POLL)
2557 // The "official" bit for failed connect is POLLIN. However, POLLERR
2558 // is often set and there are occasional cases seen with some kernels
2559 // where only POLLERR is set on a failed connect.
2560 need_to_check = (fds.revents & POLLIN) || (fds.revents & POLLERR);
2561 known_failure = (fds.revents & POLLERR);
2563 # else
2564 need_to_check = true;
2565 # endif /* ACE_HAS_POLL */
2566 #endif /* ACE_WIN32 */
2568 if (need_to_check)
2570 #if defined (SOL_SOCKET) && defined (SO_ERROR)
2571 int sock_err = 0;
2572 int sock_err_len = sizeof (sock_err);
2573 int sockopt_ret = ACE_OS::getsockopt (h, SOL_SOCKET, SO_ERROR,
2574 (char *)&sock_err, &sock_err_len);
2575 if (sockopt_ret < 0)
2577 h = ACE_INVALID_HANDLE;
2580 if (sock_err != 0 || known_failure)
2582 h = ACE_INVALID_HANDLE;
2583 errno = sock_err;
2585 #else
2586 char dummy;
2588 // The following recv() won't block provided that the
2589 // ACE_NONBLOCK flag has not been turned off .
2590 n = ACE::recv (h, &dummy, 1, MSG_PEEK);
2592 // If no data was read/peeked at, check to see if it's because
2593 // of a non-connected socket (and therefore an error) or there's
2594 // just no data yet.
2595 if (n <= 0)
2597 if (n == 0)
2599 errno = ECONNREFUSED;
2600 h = ACE_INVALID_HANDLE;
2602 else if (errno != EWOULDBLOCK && errno != EAGAIN)
2603 h = ACE_INVALID_HANDLE;
2605 #endif
2608 // 1. The HANDLE is ready for writing and doesn't need to be checked or
2609 // 2. recv() returned an indication of the state of the socket - if there is
2610 // either data present, or a recv is legit but there's no data yet,
2611 // the connection was successfully established.
2612 return h;
2615 /// Wait up to @a timeout amount of time to accept a connection.
2617 ACE::handle_timed_accept (ACE_HANDLE listener,
2618 ACE_Time_Value *timeout,
2619 bool restart)
2621 ACE_TRACE ("ACE::handle_timed_accept");
2622 // Make sure we don't bomb out on erroneous values.
2623 if (listener == ACE_INVALID_HANDLE)
2624 return -1;
2626 #if defined (ACE_HAS_POLL)
2628 struct pollfd fds;
2630 fds.fd = listener;
2631 fds.events = POLLIN;
2632 fds.revents = 0;
2634 #else
2635 // Use the select() implementation rather than poll().
2636 ACE_Handle_Set rd_handle;
2637 rd_handle.set_bit (listener);
2638 #endif /* ACE_HAS_POLL */
2640 // We need a loop here if <restart> is enabled.
2642 for (;;)
2644 #if defined (ACE_HAS_POLL)
2646 int n = ACE_OS::poll (&fds, 1, timeout);
2648 #else
2649 int select_width = 0;
2650 # if !defined (ACE_WIN32)
2651 select_width = int (listener) + 1;
2652 # endif /* ACE_WIN32 */
2653 int n = ACE_OS::select (select_width,
2654 rd_handle, 0, 0,
2655 timeout);
2656 #endif /* ACE_HAS_POLL */
2658 switch (n)
2660 case -1:
2661 if (errno == EINTR && restart)
2662 continue;
2663 else
2664 return -1;
2665 /* NOTREACHED */
2666 case 0:
2667 if (timeout != 0 && *timeout == ACE_Time_Value::zero)
2668 errno = EWOULDBLOCK;
2669 else
2670 errno = ETIMEDOUT;
2671 return -1;
2672 /* NOTREACHED */
2673 case 1:
2674 return 0;
2675 /* NOTREACHED */
2676 default:
2677 errno = EINVAL;
2678 return -1;
2679 /* NOTREACHED */
2684 /// Make the current process a UNIX daemon. This is based on Stevens
2685 /// code from APUE.
2687 ACE::daemonize (const ACE_TCHAR pathname[],
2688 bool close_all_handles,
2689 const ACE_TCHAR program_name[])
2691 ACE_TRACE ("ACE::daemonize");
2692 #if !defined (ACE_LACKS_FORK)
2693 pid_t pid = ACE_OS::fork ();
2695 if (pid == -1)
2696 return -1;
2697 else if (pid != 0)
2698 ACE_OS::exit (0); // Parent exits.
2700 // 1st child continues.
2701 ACE_OS::setsid (); // Become session leader.
2703 ACE_OS::signal (SIGHUP, SIG_IGN);
2705 pid = ACE_OS::fork (program_name);
2707 if (pid != 0)
2708 ACE_OS::exit (0); // First child terminates.
2710 // Second child continues.
2712 if (pathname != 0)
2713 // change working directory.
2714 ACE_OS::chdir (pathname);
2716 ACE_OS::umask (0); // clear our file mode creation mask.
2718 // Close down the I/O handles.
2719 if (close_all_handles)
2721 for (int i = ACE::max_handles () - 1; i >= 0; i--)
2722 ACE_OS::close (i);
2724 int fd = ACE_OS::open ("/dev/null", O_RDWR, 0);
2725 if (fd != -1)
2727 ACE_OS::dup2 (fd, ACE_STDIN);
2728 ACE_OS::dup2 (fd, ACE_STDOUT);
2729 ACE_OS::dup2 (fd, ACE_STDERR);
2731 if (fd > ACE_STDERR)
2732 ACE_OS::close (fd);
2736 return 0;
2737 #else
2738 ACE_UNUSED_ARG (pathname);
2739 ACE_UNUSED_ARG (close_all_handles);
2740 ACE_UNUSED_ARG (program_name);
2742 ACE_NOTSUP_RETURN (-1);
2743 #endif /* ACE_LACKS_FORK */
2746 pid_t
2747 ACE::fork (const ACE_TCHAR *program_name,
2748 int avoid_zombies)
2750 if (avoid_zombies == 0)
2751 return ACE_OS::fork (program_name);
2752 else
2754 // This algorithm is adapted from an example in the Stevens book
2755 // "Advanced Programming in the Unix Environment" and an item in
2756 // Andrew Gierth's Unix Programming FAQ. It creates an orphan
2757 // process that's inherited by the init process; init cleans up
2758 // when the orphan process terminates.
2760 // Another way to avoid zombies is to ignore or catch the
2761 // SIGCHLD signal; we don't use that approach here.
2763 pid_t pid = ACE_OS::fork ();
2764 if (pid == 0)
2766 // The child process forks again to create a grandchild.
2767 switch (ACE_OS::fork (program_name))
2769 case 0: // grandchild returns 0.
2770 return 0;
2771 case static_cast<pid_t>(-1): // assumes all errnos are < 256
2772 ACE_OS::_exit (errno);
2773 ACE_FALLTHROUGH; // gcc sees this as a fallthrough
2774 default: // child terminates, orphaning grandchild
2775 ACE_OS::_exit (0);
2779 // Parent process waits for child to terminate.
2780 ACE_exitcode status;
2781 if (pid < 0 || ACE_OS::waitpid (pid, &status, 0) < 0)
2782 return -1;
2784 // child terminated by calling exit()?
2785 if (WIFEXITED ((status)))
2787 // child terminated normally?
2788 if (WEXITSTATUS ((status)) == 0)
2789 return 1;
2790 else
2791 errno = WEXITSTATUS ((status));
2793 else
2794 // child didn't call exit(); perhaps it received a signal?
2795 errno = EINTR;
2797 return -1;
2802 ACE::max_handles ()
2804 ACE_TRACE ("ACE::max_handles");
2805 #if defined (RLIMIT_NOFILE) && !defined (ACE_LACKS_RLIMIT)
2806 rlimit rl;
2807 int const r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
2808 # if !defined (RLIM_INFINITY)
2809 if (r == 0)
2810 return rl.rlim_cur;
2811 # else
2812 if (r == 0 && rl.rlim_cur != RLIM_INFINITY)
2813 return rl.rlim_cur;
2814 // If == RLIM_INFINITY, fall through to the ACE_LACKS_RLIMIT sections
2815 # endif /* RLIM_INFINITY */
2816 #endif /* RLIMIT_NOFILE && !ACE_LACKS_RLIMIT */
2818 #if defined (_SC_OPEN_MAX) && !defined (ACE_LACKS_SYSCONF)
2819 return static_cast<int> (ACE_OS::sysconf (_SC_OPEN_MAX));
2820 #elif defined (FD_SETSIZE)
2821 return FD_SETSIZE;
2822 #else
2823 ACE_NOTSUP_RETURN (-1);
2824 #endif /* _SC_OPEN_MAX */
2827 // Set the number of currently open handles in the process.
2829 // If NEW_LIMIT == -1 set the limit to the maximum allowable.
2830 // Otherwise, set it to be the value of NEW_LIMIT.
2833 ACE::set_handle_limit (int new_limit,
2834 int increase_limit_only)
2836 ACE_TRACE ("ACE::set_handle_limit");
2837 int cur_limit = ACE::max_handles ();
2838 int max_limit = cur_limit;
2840 if (cur_limit == -1)
2841 return -1;
2843 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2844 struct rlimit rl;
2846 ACE_OS::memset ((void *) &rl, 0, sizeof rl);
2847 int r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
2848 if (r == 0)
2849 max_limit = rl.rlim_max;
2850 #endif /* ACE_LACKS_RLIMIT */
2852 if (new_limit == -1)
2853 new_limit = max_limit;
2855 if (new_limit < 0)
2857 errno = EINVAL;
2858 return -1;
2860 else if (new_limit > cur_limit)
2862 // Increase the limit.
2863 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2864 rl.rlim_cur = new_limit;
2865 return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl);
2866 #elif !defined (RLIMIT_NOFILE)
2867 return 0;
2868 #else
2869 // Must return EINVAL errno.
2870 ACE_NOTSUP_RETURN (-1);
2871 #endif /* ACE_LACKS_RLIMIT */
2873 else if (increase_limit_only == 0)
2875 // Decrease the limit.
2876 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2877 rl.rlim_cur = new_limit;
2878 return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl);
2879 #else
2880 // We give a chance to platforms without RLIMIT to work.
2881 // Instead of ACE_NOTSUP_RETURN (0), just return 0 because
2882 // new_limit is <= cur_limit, so it's a no-op.
2883 return 0;
2884 #endif /* ACE_LACKS_RLIMIT */
2887 return 0;
2890 /// Euclid's greatest common divisor algorithm.
2891 u_long
2892 ACE::gcd (u_long x, u_long y)
2894 while (y != 0)
2896 u_long r = x % y;
2897 x = y;
2898 y = r;
2901 return x;
2904 /// Calculates the minimum enclosing frame size for the given values.
2905 u_long
2906 ACE::minimum_frame_size (u_long period1, u_long period2)
2908 // if one of the periods is zero, treat it as though it as
2909 // uninitialized and return the other period as the frame size
2910 if (0 == period1)
2912 return period2;
2914 if (0 == period2)
2916 return period1;
2919 // if neither is zero, find the greatest common divisor of the two periods
2920 u_long greatest_common_divisor = ACE::gcd (period1, period2);
2922 // explicitly consider cases to reduce risk of possible overflow errors
2923 if (greatest_common_divisor == 1)
2925 // periods are relative primes: just multiply them together
2926 return period1 * period2;
2928 else if (greatest_common_divisor == period1)
2930 // the first period divides the second: return the second
2931 return period2;
2933 else if (greatest_common_divisor == period2)
2935 // the second period divides the first: return the first
2936 return period1;
2938 else
2940 // the current frame size and the entry's effective period
2941 // have a non-trivial greatest common divisor: return the
2942 // product of factors divided by those in their gcd.
2943 return (period1 * period2) / greatest_common_divisor;
2947 u_long
2948 ACE::is_prime (const u_long n,
2949 const u_long min_factor,
2950 const u_long max_factor)
2952 if (n > 3)
2953 for (u_long factor = min_factor;
2954 factor <= max_factor;
2955 ++factor)
2956 if (n / factor * factor == n)
2957 return factor;
2959 return 0;
2962 const ACE_TCHAR *
2963 ACE::sock_error (int error)
2965 #if defined (ACE_WIN32)
2966 static ACE_TCHAR unknown_msg[64];
2968 switch (error)
2970 case WSAVERNOTSUPPORTED:
2971 return ACE_TEXT ("version of WinSock not supported");
2972 /* NOTREACHED */
2973 case WSASYSNOTREADY:
2974 return ACE_TEXT ("WinSock not present or not responding");
2975 /* NOTREACHED */
2976 case WSAEINVAL:
2977 return ACE_TEXT ("app version not supported by DLL");
2978 /* NOTREACHED */
2979 case WSAHOST_NOT_FOUND:
2980 return ACE_TEXT ("Authoritive: Host not found");
2981 /* NOTREACHED */
2982 case WSATRY_AGAIN:
2983 return ACE_TEXT ("Non-authoritive: host not found or server failure");
2984 /* NOTREACHED */
2985 case WSANO_RECOVERY:
2986 return ACE_TEXT ("Non-recoverable: refused or not implemented");
2987 /* NOTREACHED */
2988 case WSANO_DATA:
2989 return ACE_TEXT ("Valid name, no data record for type");
2990 /* NOTREACHED */
2992 case WSANO_ADDRESS:
2993 return "Valid name, no MX record";
2995 case WSANOTINITIALISED:
2996 return ACE_TEXT ("WSA Startup not initialized");
2997 /* NOTREACHED */
2998 case WSAENETDOWN:
2999 return ACE_TEXT ("Network subsystem failed");
3000 /* NOTREACHED */
3001 case WSAEINPROGRESS:
3002 return ACE_TEXT ("Blocking operation in progress");
3003 /* NOTREACHED */
3004 case WSAEINTR:
3005 return ACE_TEXT ("Blocking call cancelled");
3006 /* NOTREACHED */
3007 case WSAEAFNOSUPPORT:
3008 return ACE_TEXT ("address family not supported");
3009 /* NOTREACHED */
3010 case WSAEMFILE:
3011 return ACE_TEXT ("no file handles available");
3012 /* NOTREACHED */
3013 case WSAENOBUFS:
3014 return ACE_TEXT ("no buffer space available");
3015 /* NOTREACHED */
3016 case WSAEPROTONOSUPPORT:
3017 return ACE_TEXT ("specified protocol not supported");
3018 /* NOTREACHED */
3019 case WSAEPROTOTYPE:
3020 return ACE_TEXT ("protocol wrong type for this socket");
3021 /* NOTREACHED */
3022 case WSAESOCKTNOSUPPORT:
3023 return ACE_TEXT ("socket type not supported for address family");
3024 /* NOTREACHED */
3025 case WSAENOTSOCK:
3026 return ACE_TEXT ("handle is not a socket");
3027 /* NOTREACHED */
3028 case WSAEWOULDBLOCK:
3029 return ACE_TEXT ("resource temporarily unavailable");
3030 /* NOTREACHED */
3031 case WSAEADDRINUSE:
3032 return ACE_TEXT ("address already in use");
3033 /* NOTREACHED */
3034 case WSAECONNABORTED:
3035 return ACE_TEXT ("connection aborted");
3036 /* NOTREACHED */
3037 case WSAECONNRESET:
3038 return ACE_TEXT ("connection reset");
3039 /* NOTREACHED */
3040 case WSAENOTCONN:
3041 return ACE_TEXT ("not connected");
3042 /* NOTREACHED */
3043 case WSAETIMEDOUT:
3044 return ACE_TEXT ("connection timed out");
3045 /* NOTREACHED */
3046 case WSAECONNREFUSED:
3047 return ACE_TEXT ("connection refused");
3048 /* NOTREACHED */
3049 case WSAEHOSTDOWN:
3050 return ACE_TEXT ("host down");
3051 /* NOTREACHED */
3052 case WSAEHOSTUNREACH:
3053 return ACE_TEXT ("host unreachable");
3054 /* NOTREACHED */
3055 case WSAEADDRNOTAVAIL:
3056 return ACE_TEXT ("address not available");
3057 /* NOTREACHED */
3058 case WSAEISCONN:
3059 return ACE_TEXT ("socket is already connected");
3060 /* NOTREACHED */
3061 case WSAENETRESET:
3062 return ACE_TEXT ("network dropped connection on reset");
3063 /* NOTREACHED */
3064 case WSAEMSGSIZE:
3065 return ACE_TEXT ("message too long");
3066 /* NOTREACHED */
3067 case WSAENETUNREACH:
3068 return ACE_TEXT ("network is unreachable");
3069 /* NOTREACHED */
3070 case WSAEFAULT:
3071 return ACE_TEXT ("bad address");
3072 /* NOTREACHED */
3073 case WSAEDISCON:
3074 return ACE_TEXT ("graceful shutdown in progress");
3075 /* NOTREACHED */
3076 case WSAEACCES:
3077 return ACE_TEXT ("permission denied");
3078 /* NOTREACHED */
3079 case WSAESHUTDOWN:
3080 return ACE_TEXT ("cannot send after socket shutdown");
3081 /* NOTREACHED */
3082 case WSAEPROCLIM:
3083 return ACE_TEXT ("too many processes");
3084 /* NOTREACHED */
3085 case WSAEALREADY:
3086 return ACE_TEXT ("operation already in progress");
3087 /* NOTREACHED */
3088 case WSAEPFNOSUPPORT:
3089 return ACE_TEXT ("protocol family not supported");
3090 /* NOTREACHED */
3091 case WSAENOPROTOOPT:
3092 return ACE_TEXT ("bad protocol option");
3093 /* NOTREACHED */
3094 case WSATYPE_NOT_FOUND:
3095 return ACE_TEXT ("class type not found");
3096 /* NOTREACHED */
3097 case WSAEOPNOTSUPP:
3098 return ACE_TEXT ("operation not supported");
3099 /* NOTREACHED */
3100 case WSAEDESTADDRREQ:
3101 return ACE_TEXT ("destination address required");
3102 /* NOTREACHED */
3103 default:
3104 ACE_OS::snprintf (unknown_msg,
3105 sizeof unknown_msg / sizeof unknown_msg[0],
3106 ACE_TEXT ("unknown error: %d"), error);
3107 return unknown_msg;
3108 /* NOTREACHED */
3110 #else
3111 ACE_UNUSED_ARG (error);
3112 ACE_NOTSUP_RETURN (0);
3113 #endif /* ACE_WIN32 */
3116 bool
3117 ACE::is_sock_error (int error)
3119 #if defined (ACE_WIN32)
3120 switch (error)
3122 case WSAVERNOTSUPPORTED:
3123 case WSASYSNOTREADY:
3124 case WSAEINVAL:
3125 case WSAHOST_NOT_FOUND:
3126 case WSATRY_AGAIN:
3127 case WSANO_RECOVERY:
3128 case WSANO_DATA:
3130 case WSANO_ADDRESS:
3132 case WSANOTINITIALISED:
3133 case WSAENETDOWN:
3134 case WSAEINPROGRESS:
3135 case WSAEINTR:
3136 case WSAEAFNOSUPPORT:
3137 case WSAEMFILE:
3138 case WSAENOBUFS:
3139 case WSAEPROTONOSUPPORT:
3140 case WSAEPROTOTYPE:
3141 case WSAESOCKTNOSUPPORT:
3142 case WSAENOTSOCK:
3143 case WSAEWOULDBLOCK:
3144 case WSAEADDRINUSE:
3145 case WSAECONNABORTED:
3146 case WSAECONNRESET:
3147 case WSAENOTCONN:
3148 case WSAETIMEDOUT:
3149 case WSAECONNREFUSED:
3150 case WSAEHOSTDOWN:
3151 case WSAEHOSTUNREACH:
3152 case WSAEADDRNOTAVAIL:
3153 case WSAEISCONN:
3154 case WSAENETRESET:
3155 case WSAEMSGSIZE:
3156 case WSAENETUNREACH:
3157 case WSAEFAULT:
3158 case WSAEDISCON:
3159 case WSAEACCES:
3160 case WSAESHUTDOWN:
3161 case WSAEPROCLIM:
3162 case WSAEALREADY:
3163 case WSAEPFNOSUPPORT:
3164 case WSAENOPROTOOPT:
3165 case WSATYPE_NOT_FOUND:
3166 case WSAEOPNOTSUPP:
3167 return true;
3169 #else
3170 ACE_UNUSED_ARG (error);
3171 #endif /* ACE_WIN32 */
3172 return false;
3175 char *
3176 ACE::strndup (const char *str, size_t n)
3178 const char *t = str;
3179 size_t len;
3181 // Figure out how long this string is (remember, it might not be
3182 // NUL-terminated).
3184 for (len = 0;
3185 len < n && *t++ != '\0';
3186 len++)
3187 continue;
3189 char *s;
3190 #if defined (ACE_HAS_ALLOC_HOOKS)
3191 ACE_ALLOCATOR_RETURN (s,
3192 (char *) ACE_Allocator::instance()->malloc (len + 1),
3194 #else
3195 ACE_ALLOCATOR_RETURN (s,
3196 (char *) ACE_OS::malloc (len + 1),
3198 #endif /* ACE_HAS_ALLOC_HOOKS */
3199 return ACE_OS::strsncpy (s, str, len + 1);
3202 #if defined (ACE_HAS_WCHAR)
3203 wchar_t *
3204 ACE::strndup (const wchar_t *str, size_t n)
3206 const wchar_t *t = str;
3207 size_t len;
3209 // Figure out how long this string is (remember, it might not be
3210 // NUL-terminated).
3212 for (len = 0;
3213 len < n && *t++ != '\0';
3214 len++)
3215 continue;
3217 size_t const size = (len + 1) * sizeof (wchar_t);
3218 wchar_t *s = 0;
3219 #if defined (ACE_HAS_ALLOC_HOOKS)
3220 ACE_ALLOCATOR_RETURN (s,
3221 static_cast<wchar_t*> (
3222 ACE_Allocator::instance ()->malloc (size)),
3224 #else
3225 ACE_ALLOCATOR_RETURN (s,
3226 static_cast<wchar_t*> (ACE_OS::malloc (size)),
3228 #endif /* ACE_HAS_ALLOC_HOOKS */
3229 return ACE_OS::strsncpy (s, str, len + 1);
3231 #endif /* ACE_HAS_WCHAR */
3233 char *
3234 ACE::strnnew (const char *str, size_t n)
3236 const char *t = str;
3237 size_t len;
3239 // Figure out how long this string is (remember, it might not be
3240 // NUL-terminated).
3242 for (len = 0;
3243 len < n && *t++ != L'\0';
3244 len++)
3245 continue;
3247 char *s;
3249 #if defined (ACE_HAS_ALLOC_HOOKS)
3250 ACE_ALLOCATOR_RETURN (s,
3251 static_cast<char*> (ACE_Allocator::instance ()->malloc (sizeof (char) * (len + 1))),
3253 #else
3254 ACE_NEW_RETURN (s,
3255 char[len + 1],
3257 #endif /* ACE_HAS_ALLOC_HOOKS */
3259 return ACE_OS::strsncpy (s, str, len + 1);
3262 #if defined (ACE_HAS_WCHAR)
3263 wchar_t *
3264 ACE::strnnew (const wchar_t *str, size_t n)
3266 const wchar_t *t = str;
3267 size_t len;
3269 // Figure out how long this string is (remember, it might not be
3270 // NUL-terminated).
3272 for (len = 0;
3273 len < n && *t++ != ACE_TEXT_WIDE ('\0');
3274 len++)
3275 continue;
3277 wchar_t *s;
3278 ACE_NEW_RETURN (s,
3279 wchar_t[len + 1],
3281 return ACE_OS::strsncpy (s, str, len + 1);
3283 #endif /* ACE_HAS_WCHAR */
3285 const char *
3286 ACE::strend (const char *s)
3288 while (*s++ != '\0')
3289 continue;
3291 return s;
3294 #if defined ACE_HAS_WCHAR
3295 const wchar_t *
3296 ACE::strend (const wchar_t *s)
3298 while (*s++ != ACE_TEXT_WIDE ('\0'))
3299 continue;
3301 return s;
3303 #endif
3305 char *
3306 ACE::strnew (const char *s)
3308 if (s == 0)
3309 return 0;
3310 char *t = 0;
3311 #if defined (ACE_HAS_ALLOC_HOOKS)
3312 ACE_ALLOCATOR_RETURN (t,
3313 static_cast<char*> (ACE_Allocator::instance ()->malloc (sizeof (char) * (ACE_OS::strlen (s) + 1))),
3315 #else
3316 ACE_NEW_RETURN (t,
3317 char [ACE_OS::strlen (s) + 1],
3319 #endif /* ACE_HAS_ALLOC_HOOKS */
3321 return ACE_OS::strcpy (t, s);
3324 #if defined (ACE_HAS_WCHAR)
3325 wchar_t *
3326 ACE::strnew (const wchar_t *s)
3328 if (s == 0)
3329 return 0;
3331 size_t const n = ACE_OS::strlen (s) + 1;
3332 wchar_t *t = 0;
3333 #if defined (ACE_HAS_ALLOC_HOOKS)
3334 ACE_ALLOCATOR_RETURN (t,
3335 static_cast<wchar_t*> (
3336 ACE_Allocator::instance ()->malloc (
3337 sizeof (wchar_t) * (n))),
3339 #else
3340 ACE_NEW_RETURN (t, wchar_t[n], 0);
3341 #endif /* ACE_HAS_ALLOC_HOOKS */
3343 return ACE_OS::strcpy (t, s);
3345 #endif /* ACE_HAS_WCHAR */
3347 // helper functions for ACE::wild_match()
3348 namespace
3350 inline bool equal_char (char a, char b, bool case_sensitive)
3352 if (case_sensitive)
3353 return a == b;
3354 return ACE_OS::ace_tolower (a) == ACE_OS::ace_tolower (b);
3357 // precond: *p == '[' start of char class
3358 // postcond: *p == ']' end of the char class
3359 inline bool equal_class (char s, const char *&p, bool case_sensitive)
3361 ++p;
3362 bool negate = false;
3363 if (*p == '!')
3365 negate = true;
3366 ++p;
3368 // ] and - are regular in 1st position
3369 for (bool first = true; *p && (first || *p != ']'); ++p)
3371 if (!first && *p == '-' && p[1] != ']')
3373 if (!p[1] || p[1] <= p[-1]) // invalid range
3375 continue;
3377 // Since we are in the POSIX locale, only the basic ASCII
3378 // characters are allowed as the range endpoints. These characters
3379 // are the same values in both signed and unsigned chars so we
3380 // don't have to account for any "pathological cases."
3381 for (char range = static_cast<char> (p[-1] + 1); range <= p[1]; ++range)
3383 if (equal_char (s, range, case_sensitive))
3385 while (*++p != ']') {}
3386 return !negate;
3389 ++p; // consume the character 1 past the -
3391 else if (equal_char (s, *p, case_sensitive))
3393 while (*++p != ']') {}
3394 return !negate;
3396 first = false;
3398 return negate;
3402 bool
3403 ACE::wild_match(const char *str, const char *pat, bool case_sensitive,
3404 bool character_classes)
3406 if (str == pat)
3407 return true;
3408 if (pat == 0 || str == 0)
3409 return false;
3411 bool star = false, escape = false;
3412 const char *s = str;
3413 const char *p = pat;
3414 while (*s != '\0')
3416 if (!escape && *p == '\\')
3418 ++p;
3419 escape = true;
3421 else if (!escape && *p == '*')
3423 star = true;
3424 pat = p;
3425 while (*++pat == '*') {}
3427 if (*pat == '\0')
3428 return true;
3429 p = pat;
3431 else if (!escape && *p == '?')
3433 ++s;
3434 ++p;
3436 else if (!escape && character_classes && *p == '[')
3438 if (equal_class (*s, p, case_sensitive))
3440 ++p;
3442 else
3444 if (!star)
3445 return false;
3446 p = pat;
3448 ++s;
3450 else if (!equal_char (*s, *p, case_sensitive))
3452 if (!star)
3453 return false;
3454 ++s;
3455 p = pat;
3456 escape = false;
3458 else
3460 ++s;
3461 ++p;
3462 escape = false;
3465 if (*p == '*')
3466 while (*++p == '*') {}
3468 return *p == '\0';
3471 // Close versioned namespace, if enabled by the user.
3472 ACE_END_VERSIONED_NAMESPACE_DECL