Document return values
[ACE_TAO.git] / ACE / ace / ACE.cpp
blob88e75e8a9e486d034a6a3d74f7f6d2ec47be5a14
1 #include "ace/ACE.h"
3 #include "ace/Basic_Types.h"
4 #include "ace/Handle_Set.h"
5 #include "ace/Auto_Ptr.h"
6 #include "ace/SString.h"
7 #include "ace/Version.h"
8 #include "ace/Message_Block.h"
9 #include "ace/Log_Category.h"
10 #include "ace/Flag_Manip.h"
11 #include "ace/OS_NS_sys_select.h"
12 #include "ace/OS_NS_string.h"
13 #include "ace/OS_NS_strings.h"
14 #include "ace/OS_NS_signal.h"
15 #include "ace/OS_NS_stdio.h"
16 #include "ace/OS_NS_sys_resource.h"
17 #include "ace/OS_NS_sys_wait.h"
18 #include "ace/OS_NS_sys_time.h"
19 #include "ace/OS_NS_time.h"
20 #include "ace/OS_NS_sys_uio.h"
21 #include "ace/OS_NS_sys_stat.h"
22 #include "ace/OS_NS_ctype.h"
23 #include "ace/OS_NS_fcntl.h"
24 #include "ace/OS_TLI.h"
25 #include "ace/Truncate.h"
27 #if !defined (__ACE_INLINE__)
28 #include "ace/ACE.inl"
29 #endif /* __ACE_INLINE__ */
31 #if defined (ACE_HAS_POLL)
32 # include "ace/OS_NS_poll.h"
33 #endif /* ACE_HAS_POLL */
35 // Open versioned namespace, if enabled by the user.
36 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
38 namespace ACE
40 // private:
41 // Used internally so not exported.
43 // Size of allocation granularity.
44 size_t allocation_granularity_ = 0;
46 // Size of a VM page.
47 size_t pagesize_ = 0;
49 // Are we debugging ACE?
50 // Keeps track of whether we're in some global debug mode.
51 bool debug_ = false;
54 int
55 ACE::out_of_handles (int error)
57 // EMFILE is common to all platforms.
58 if (error == EMFILE ||
59 #if defined (ACE_WIN32)
60 // On Win32, we need to check for ENOBUFS also.
61 error == ENOBUFS ||
62 #elif defined (ACE_LINUX)
63 // On linux, we need to check for ENOENT also.
64 error == ENOENT ||
65 // For RedHat5.2, need to check for EINVAL too.
66 error == EINVAL ||
67 // Without threads check for EOPNOTSUPP
68 error == EOPNOTSUPP ||
69 #elif defined (__FreeBSD__)
70 // On FreeBSD we need to check for EOPNOTSUPP (LinuxThreads) or
71 // ENOSYS (libc_r threads) also.
72 error == EOPNOTSUPP ||
73 error == ENOSYS ||
74 #elif defined (__OpenBSD__)
75 // OpenBSD appears to return EBADF.
76 error == EBADF ||
77 #endif /* ACE_WIN32 */
78 error == ENFILE)
79 return 1;
80 else
81 return 0;
84 u_int
85 ACE::major_version ()
87 return ACE_MAJOR_VERSION;
90 u_int
91 ACE::minor_version ()
93 return ACE_MINOR_VERSION;
96 u_int
97 ACE::beta_version ()
99 return ACE_MICRO_VERSION;
102 u_int
103 ACE::micro_version ()
105 return ACE_MICRO_VERSION;
108 const ACE_TCHAR *
109 ACE::compiler_name ()
111 #ifdef ACE_CC_NAME
112 return ACE_CC_NAME;
113 #else
114 return ACE_TEXT ("");
115 #endif
118 u_int
119 ACE::compiler_major_version ()
121 #ifdef ACE_CC_MAJOR_VERSION
122 return ACE_CC_MAJOR_VERSION;
123 #else
124 return 0;
125 #endif
128 u_int
129 ACE::compiler_minor_version ()
131 #ifdef ACE_CC_MINOR_VERSION
132 return ACE_CC_MINOR_VERSION;
133 #else
134 return 0;
135 #endif
138 u_int
139 ACE::compiler_beta_version ()
141 #ifdef ACE_CC_BETA_VERSION
142 return ACE_CC_BETA_VERSION;
143 #else
144 return 0;
145 #endif
148 ACE_TCHAR
149 ACE::nibble2hex (u_int n)
151 // Yes, this works for UNICODE
152 return ACE_TEXT ("0123456789abcdef")[n & 0x0f];
155 bool
156 ACE::debug ()
158 //FUZZ: disable check_for_ace_log_categories
159 static const char *debug = ACE_OS::getenv ("ACE_DEBUG");
160 //FUZZ: enable check_for_ace_log_categories
161 return (ACE::debug_) ? ACE::debug_ : (debug != 0 ? (*debug != '0') : false);
164 void
165 ACE::debug (bool onoff)
167 ACE::debug_ = onoff;
171 ACE::select (int width,
172 ACE_Handle_Set *readfds,
173 ACE_Handle_Set *writefds,
174 ACE_Handle_Set *exceptfds,
175 const ACE_Time_Value *timeout)
177 int result = ACE_OS::select (width,
178 readfds ? readfds->fdset () : 0,
179 writefds ? writefds->fdset () : 0,
180 exceptfds ? exceptfds->fdset () : 0,
181 timeout);
182 if (result > 0)
184 # if !defined (ACE_WIN32)
185 // This isn't needed for Windows... it's a no-op anyway.
186 if (readfds)
187 readfds->sync ((ACE_HANDLE) width);
188 if (writefds)
189 writefds->sync ((ACE_HANDLE) width);
190 if (exceptfds)
191 exceptfds->sync ((ACE_HANDLE) width);
192 #endif /* ACE_WIN32 */
194 return result;
198 ACE::select (int width,
199 ACE_Handle_Set &readfds,
200 const ACE_Time_Value *timeout)
202 int result = ACE_OS::select (width,
203 readfds.fdset (),
206 timeout);
208 #if !defined (ACE_WIN32)
209 if (result > 0)
210 readfds.sync ((ACE_HANDLE) width);
211 #endif /* ACE_WIN32 */
212 return result;
216 ACE::terminate_process (pid_t pid)
218 #if defined (ACE_WIN32)
219 // Create a handle for the given process id.
220 ACE_HANDLE process_handle =
221 ::OpenProcess (PROCESS_TERMINATE,
222 FALSE, // New handle is not inheritable.
223 pid);
225 if (process_handle == ACE_INVALID_HANDLE
226 || process_handle == 0)
227 return -1;
228 else
230 // Kill the process associated with process_handle.
231 BOOL terminate_result =
232 ::TerminateProcess (process_handle, 0);
233 // Free up the kernel resources.
234 ACE_OS::close (process_handle);
235 return terminate_result ? 0 : -1;
237 #else
238 return ACE_OS::kill (pid, 9);
239 #endif /* ACE_WIN32 */
243 ACE::process_active (pid_t pid)
245 #if !defined(ACE_WIN32)
246 if (ACE_OS::kill (pid, 0) == 0)
247 return 1;
248 else if (errno == ESRCH)
249 return 0;
250 else
251 return -1;
252 #else
253 // Create a handle for the given process id.
254 ACE_HANDLE process_handle =
255 ::OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid);
256 if (process_handle == ACE_INVALID_HANDLE || process_handle == 0)
257 return 0;
258 else
260 DWORD status;
261 int result = 1;
262 if (::GetExitCodeProcess (process_handle,
263 &status) == 0
264 || status != STILL_ACTIVE)
265 result = 0;
267 ::CloseHandle (process_handle);
268 return result;
270 #endif /* !ACE_WIN32 */
273 const ACE_TCHAR *
274 ACE::execname (const ACE_TCHAR *old_name)
276 #if defined (ACE_WIN32)
277 const ACE_TCHAR *suffix = ACE_OS::strrchr (old_name, ACE_TEXT ('.'));
278 if (suffix == 0 || ACE_OS::strcasecmp (suffix, ACE_TEXT (".exe")) != 0)
280 ACE_TCHAR *new_name = 0;
282 size_t size =
283 ACE_OS::strlen (old_name)
284 + ACE_OS::strlen (ACE_TEXT (".exe"))
285 + 1;
287 ACE_NEW_RETURN (new_name,
288 ACE_TCHAR[size],
290 ACE_TCHAR *end = new_name;
292 end = ACE_OS::strecpy (new_name, old_name);
294 // Concatenate the .exe suffix onto the end of the executable.
295 // end points _after_ the terminating nul.
296 ACE_OS::strcpy (end - 1, ACE_TEXT (".exe"));
298 return new_name;
300 #endif /* ACE_WIN32 */
301 return old_name;
304 u_long
305 ACE::hash_pjw (const char *str, size_t len)
307 u_long hash = 0;
309 for (size_t i = 0; i < len; i++)
311 const char temp = str[i];
312 hash = (hash << 4) + (temp * 13);
314 u_long g = hash & 0xf0000000;
316 if (g)
318 hash ^= (g >> 24);
319 hash ^= g;
323 return hash;
326 u_long
327 ACE::hash_pjw (const char *str)
329 return ACE::hash_pjw (str, ACE_OS::strlen (str));
332 #if defined (ACE_HAS_WCHAR)
333 u_long
334 ACE::hash_pjw (const wchar_t *str, size_t len)
336 u_long hash = 0;
338 for (size_t i = 0; i < len; i++)
340 // @@ UNICODE: Does this function do the correct thing with wchar's?
342 const wchar_t temp = str[i];
343 hash = (hash << 4) + (temp * 13);
345 u_long g = hash & 0xf0000000;
347 if (g)
349 hash ^= (g >> 24);
350 hash ^= g;
354 return hash;
357 u_long
358 ACE::hash_pjw (const wchar_t *str)
360 return ACE::hash_pjw (str, ACE_OS::strlen (str));
362 #endif /* ACE_HAS_WCHAR */
364 ACE_TCHAR *
365 ACE::strenvdup (const ACE_TCHAR *str)
367 ACE_TRACE ("ACE::strenvdup");
369 return ACE_OS::strenvdup (str);
374 Examples:
376 Source NT UNIX
377 ==================================================================
378 netsvc netsvc.dll libnetsvc.so
379 (PATH will be (LD_LIBRARY_PATH
380 evaluated) evaluated)
382 libnetsvc.dll libnetsvc.dll libnetsvc.dll + warning
383 netsvc.so netsvc.so + warning libnetsvc.so
385 ..\../libs/netsvc ..\..\libs\netsvc.dll ../../libs/netsvc.so
386 (absolute path used) (absolute path used)
390 const ACE_TCHAR *
391 ACE::basename (const ACE_TCHAR *pathname, ACE_TCHAR delim)
393 ACE_TRACE ("ACE::basename");
394 const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);
396 if (temp == 0)
397 return pathname;
398 else
399 return temp + 1;
402 const ACE_TCHAR *
403 ACE::dirname (const ACE_TCHAR *pathname, ACE_TCHAR delim)
405 ACE_TRACE ("ACE::dirname");
406 static ACE_TCHAR return_dirname[MAXPATHLEN + 1];
408 const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim);
410 if (temp == 0)
412 return_dirname[0] = '.';
413 return_dirname[1] = '\0';
415 return return_dirname;
417 else
419 // When the len is truncated, there are problems! This should
420 // not happen in normal circomstances
421 size_t len = temp - pathname + 1;
422 if (len > (sizeof return_dirname / sizeof (ACE_TCHAR)))
423 len = sizeof return_dirname / sizeof (ACE_TCHAR);
425 ACE_OS::strsncpy (return_dirname,
426 pathname,
427 len);
428 return return_dirname;
432 ssize_t
433 ACE::recv (ACE_HANDLE handle,
434 void *buf,
435 size_t len,
436 int flags,
437 const ACE_Time_Value *timeout)
439 if (timeout == 0)
440 return ACE_OS::recv (handle, (char *) buf, len, flags);
441 else
443 int val = 0;
444 if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1)
445 return -1;
446 else
448 ssize_t bytes_transferred =
449 ACE_OS::recv (handle, (char *) buf, len, flags);
450 ACE::restore_non_blocking_mode (handle, val);
451 return bytes_transferred;
456 #if defined (ACE_HAS_TLI)
458 ssize_t
459 ACE::t_rcv (ACE_HANDLE handle,
460 void *buf,
461 size_t len,
462 int *flags,
463 const ACE_Time_Value *timeout)
465 if (timeout == 0)
466 return ACE_OS::t_rcv (handle, (char *) buf, len, flags);
467 else
469 int val = 0;
470 if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1)
471 return -1;
472 else
474 ssize_t bytes_transferred =
475 ACE_OS::t_rcv (handle, (char *) buf, len, flags);
476 ACE::restore_non_blocking_mode (handle, val);
477 return bytes_transferred;
482 #endif /* ACE_HAS_TLI */
484 ssize_t
485 ACE::recv (ACE_HANDLE handle,
486 void *buf,
487 size_t n,
488 const ACE_Time_Value *timeout)
490 if (timeout == 0)
491 return ACE::recv_i (handle, buf, n);
492 else
494 int val = 0;
495 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
496 return -1;
497 else
499 ssize_t bytes_transferred = ACE::recv_i (handle, buf, n);
500 ACE::restore_non_blocking_mode (handle, val);
501 return bytes_transferred;
506 ssize_t
507 ACE::recvmsg (ACE_HANDLE handle,
508 struct msghdr *msg,
509 int flags,
510 const ACE_Time_Value *timeout)
512 if (timeout == 0)
513 return ACE_OS::recvmsg (handle, msg, flags);
514 else
516 int val = 0;
517 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
518 return -1;
519 else
521 ssize_t bytes_transferred = ACE_OS::recvmsg (handle, msg, flags);
522 ACE::restore_non_blocking_mode (handle, val);
523 return bytes_transferred;
528 ssize_t
529 ACE::recvfrom (ACE_HANDLE handle,
530 char *buf,
531 int len,
532 int flags,
533 struct sockaddr *addr,
534 int *addrlen,
535 const ACE_Time_Value *timeout)
537 if (timeout == 0)
538 return ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen);
539 else
541 int val = 0;
542 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
543 return -1;
544 else
546 ssize_t bytes_transferred =
547 ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen);
548 ACE::restore_non_blocking_mode (handle, val);
549 return bytes_transferred;
554 ssize_t
555 ACE::recv_n_i (ACE_HANDLE handle,
556 void *buf,
557 size_t len,
558 int flags,
559 size_t *bt)
561 size_t temp;
562 size_t &bytes_transferred = bt == 0 ? temp : *bt;
563 ssize_t n;
565 for (bytes_transferred = 0;
566 bytes_transferred < len;
567 bytes_transferred += n)
569 // Try to transfer as much of the remaining data as possible.
570 n = ACE_OS::recv (handle,
571 static_cast <char *> (buf) + bytes_transferred,
572 len - bytes_transferred,
573 flags);
574 // Check EOF.
575 if (n == 0)
576 return 0;
578 // Check for other errors.
579 if (n == -1)
581 // Check for possible blocking.
582 if (errno == EWOULDBLOCK)
584 // Wait for the blocking to subside.
585 int const result = ACE::handle_read_ready (handle, 0);
587 // Did select() succeed?
588 if (result != -1)
590 // Blocking subsided. Continue data transfer.
591 n = 0;
592 continue;
596 // Other data transfer or select() failures.
597 return -1;
601 return static_cast<ssize_t> (bytes_transferred);
604 ssize_t
605 ACE::recv_n_i (ACE_HANDLE handle,
606 void *buf,
607 size_t len,
608 int flags,
609 const ACE_Time_Value *timeout,
610 size_t *bt)
612 size_t temp;
613 size_t &bytes_transferred = bt == 0 ? temp : *bt;
614 ssize_t n;
615 ssize_t result = 0;
616 bool error = false;
618 int val = 0;
619 ACE::record_and_set_non_blocking_mode (handle, val);
621 for (bytes_transferred = 0;
622 bytes_transferred < len;
623 bytes_transferred += n)
625 // Try to transfer as much of the remaining data as possible.
626 // Since the socket is in non-blocking mode, this call will not
627 // block.
628 n = ACE_OS::recv (handle,
629 static_cast <char *> (buf) + bytes_transferred,
630 len - bytes_transferred,
631 flags);
633 // Check for errors.
634 if (n == 0 ||
635 n == -1)
637 // Check for possible blocking.
638 if (n == -1 &&
639 errno == EWOULDBLOCK)
641 // Wait upto <timeout> for the blocking to subside.
642 int const rtn = ACE::handle_read_ready (handle, timeout);
644 // Did select() succeed?
645 if (rtn != -1)
647 // Blocking subsided in <timeout> period. Continue
648 // data transfer.
649 n = 0;
650 continue;
654 // Wait in select() timed out or other data transfer or
655 // select() failures.
656 error = true;
657 result = n;
658 break;
662 ACE::restore_non_blocking_mode (handle, val);
664 if (error)
665 return result;
666 else
667 return static_cast<ssize_t> (bytes_transferred);
670 #if defined (ACE_HAS_TLI)
672 ssize_t
673 ACE::t_rcv_n_i (ACE_HANDLE handle,
674 void *buf,
675 size_t len,
676 int *flags,
677 size_t *bt)
679 size_t temp;
680 size_t &bytes_transferred = bt == 0 ? temp : *bt;
681 ssize_t n;
683 for (bytes_transferred = 0;
684 bytes_transferred < len;
685 bytes_transferred += n)
687 // Try to transfer as much of the remaining data as possible.
688 n = ACE_OS::t_rcv (handle,
689 (char *) buf + bytes_transferred,
690 len - bytes_transferred,
691 flags);
692 // Check EOF.
693 if (n == 0)
694 return 0;
696 // Check for other errors.
697 if (n == -1)
699 // Check for possible blocking.
700 if (errno == EWOULDBLOCK)
702 // Wait for the blocking to subside.
703 int const result = ACE::handle_read_ready (handle, 0);
705 // Did select() succeed?
706 if (result != -1)
708 // Blocking subsided. Continue data transfer.
709 n = 0;
710 continue;
714 // Other data transfer or select() failures.
715 return -1;
719 return bytes_transferred;
722 ssize_t
723 ACE::t_rcv_n_i (ACE_HANDLE handle,
724 void *buf,
725 size_t len,
726 int *flags,
727 const ACE_Time_Value *timeout,
728 size_t *bt)
730 size_t temp;
731 size_t &bytes_transferred = bt == 0 ? temp : *bt;
732 ssize_t n;
733 ssize_t result = 0;
734 bool error = false;
736 int val = 0;
737 ACE::record_and_set_non_blocking_mode (handle, val);
739 for (bytes_transferred = 0;
740 bytes_transferred < len;
741 bytes_transferred += n)
743 // Try to transfer as much of the remaining data as possible.
744 // Since the socket is in non-blocking mode, this call will not
745 // block.
746 n = ACE_OS::t_rcv (handle,
747 (char *) buf + bytes_transferred,
748 len - bytes_transferred,
749 flags);
751 // Check for errors.
752 if (n == 0 ||
753 n == -1)
755 // Check for possible blocking.
756 if (n == -1 &&
757 errno == EWOULDBLOCK)
759 // Wait upto <timeout> for the blocking to subside.
760 int const rtn = ACE::handle_read_ready (handle, timeout);
762 // Did select() succeed?
763 if (rtn != -1)
765 // Blocking subsided in <timeout> period. Continue
766 // data transfer.
767 n = 0;
768 continue;
772 // Wait in select() timed out or other data transfer or
773 // select() failures.
774 error = true;
775 result = n;
776 break;
780 ACE::restore_non_blocking_mode (handle, val);
782 if (error)
783 return result;
784 else
785 return bytes_transferred;
788 #endif /* ACE_HAS_TLI */
790 ssize_t
791 ACE::recv_n_i (ACE_HANDLE handle,
792 void *buf,
793 size_t len,
794 size_t *bt)
796 size_t temp;
797 size_t &bytes_transferred = bt == 0 ? temp : *bt;
798 ssize_t n;
800 for (bytes_transferred = 0;
801 bytes_transferred < len;
802 bytes_transferred += n)
804 // Try to transfer as much of the remaining data as possible.
805 n = ACE::recv_i (handle,
806 static_cast <char *> (buf) + bytes_transferred,
807 len - bytes_transferred);
808 // Check EOF.
809 if (n == 0)
811 return 0;
813 // Check for other errors.
814 if (n == -1)
816 // Check for possible blocking.
817 if (errno == EWOULDBLOCK)
819 // Wait for the blocking to subside.
820 int const result = ACE::handle_read_ready (handle, 0);
822 // Did select() succeed?
823 if (result != -1)
825 // Blocking subsided. Continue data transfer.
826 n = 0;
827 continue;
831 // Other data transfer or select() failures.
832 return -1;
836 return static_cast<ssize_t> (bytes_transferred);
839 ssize_t
840 ACE::recv_n_i (ACE_HANDLE handle,
841 void *buf,
842 size_t len,
843 const ACE_Time_Value *timeout,
844 size_t *bt)
846 size_t temp;
847 size_t &bytes_transferred = bt == 0 ? temp : *bt;
848 ssize_t n;
849 ssize_t result = 0;
850 bool error = false;
852 int val = 0;
853 ACE::record_and_set_non_blocking_mode (handle, val);
855 for (bytes_transferred = 0;
856 bytes_transferred < len;
857 bytes_transferred += n)
859 // Try to transfer as much of the remaining data as possible.
860 // Since the socket is in non-blocking mode, this call will not
861 // block.
862 n = ACE::recv_i (handle,
863 static_cast <char *> (buf) + bytes_transferred,
864 len - bytes_transferred);
866 // Check for errors.
867 if (n == 0 ||
868 n == -1)
870 // Check for possible blocking.
871 if (n == -1 &&
872 errno == EWOULDBLOCK)
874 // Wait upto <timeout> for the blocking to subside.
875 int const rtn = ACE::handle_read_ready (handle, timeout);
877 // Did select() succeed?
878 if (rtn != -1)
880 // Blocking subsided in <timeout> period. Continue
881 // data transfer.
882 n = 0;
883 continue;
887 // Wait in select() timed out or other data transfer or
888 // select() failures.
889 error = true;
890 result = n;
891 break;
895 ACE::restore_non_blocking_mode (handle, val);
897 if (error)
898 return result;
899 else
900 return static_cast<ssize_t> (bytes_transferred);
903 // This is basically an interface to ACE_OS::readv, that doesn't use
904 // the struct iovec explicitly. The ... can be passed as an arbitrary
905 // number of (char *ptr, int len) tuples. However, the count N is the
906 // *total* number of trailing arguments, *not* a couple of the number
907 // of tuple pairs!
908 #if !defined (ACE_LACKS_VA_FUNCTIONS)
909 ssize_t
910 ACE::recv (ACE_HANDLE handle, size_t n, ...)
912 va_list argp;
913 int const total_tuples = static_cast<int> (n / 2);
914 iovec *iovp = 0;
915 #if defined (ACE_HAS_ALLOCA)
916 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
917 #else
918 # ifdef ACE_HAS_ALLOC_HOOKS
919 ACE_ALLOCATOR_RETURN (iovp, (iovec *)
920 ACE_Allocator::instance ()->malloc (total_tuples *
921 sizeof (iovec)),
922 -1);
923 # else
924 ACE_NEW_RETURN (iovp,
925 iovec[total_tuples],
926 -1);
927 # endif /* ACE_HAS_ALLOC_HOOKS */
928 #endif /* !defined (ACE_HAS_ALLOCA) */
930 va_start (argp, n);
932 for (int i = 0; i < total_tuples; i++)
934 iovp[i].iov_base = va_arg (argp, char *);
935 iovp[i].iov_len = va_arg (argp, int);
938 ssize_t const result = ACE_OS::recvv (handle, iovp, total_tuples);
939 #if !defined (ACE_HAS_ALLOCA)
940 # ifdef ACE_HAS_ALLOC_HOOKS
941 ACE_Allocator::instance ()->free (iovp);
942 # else
943 delete [] iovp;
944 # endif /* ACE_HAS_ALLOC_HOOKS */
945 #endif /* !defined (ACE_HAS_ALLOCA) */
946 va_end (argp);
947 return result;
949 #endif /* ACE_LACKS_VA_FUNCTIONS */
952 ssize_t
953 ACE::recvv (ACE_HANDLE handle,
954 iovec *iov,
955 int iovcnt,
956 const ACE_Time_Value *timeout)
958 if (timeout == 0)
959 return ACE_OS::recvv (handle, iov, iovcnt);
960 else
962 int val = 0;
963 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1)
964 return -1;
965 else
967 ssize_t bytes_transferred = ACE_OS::recvv (handle, iov, iovcnt);
968 ACE::restore_non_blocking_mode (handle, val);
969 return bytes_transferred;
974 ssize_t
975 ACE::recvv_n_i (ACE_HANDLE handle,
976 iovec *iov,
977 int iovcnt,
978 size_t *bt)
980 size_t temp;
981 size_t &bytes_transferred = bt == 0 ? temp : *bt;
982 bytes_transferred = 0;
984 for (int s = 0; s < iovcnt; )
986 // Try to transfer as much of the remaining data as possible.
987 ssize_t n = ACE_OS::recvv (handle, iov + s, iovcnt - s);
988 // Check EOF.
989 if (n == 0)
990 return 0;
992 // Check for other errors.
993 if (n == -1)
995 // Check for possible blocking.
996 if (errno == EWOULDBLOCK)
998 // Wait for the blocking to subside.
999 int const result = ACE::handle_read_ready (handle, 0);
1001 // Did select() succeed?
1002 if (result != -1)
1004 // Blocking subsided. Continue data transfer.
1005 continue;
1009 // Other data transfer or select() failures.
1010 return -1;
1013 for (bytes_transferred += n;
1014 s < iovcnt
1015 && n >= static_cast<ssize_t> (iov[s].iov_len);
1016 s++)
1017 n -= iov[s].iov_len;
1019 if (n != 0)
1021 char *base = static_cast<char *> (iov[s].iov_base);
1022 iov[s].iov_base = base + n;
1023 // This blind cast is safe because n < iov_len, after above loop.
1024 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
1028 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1031 ssize_t
1032 ACE::recvv_n_i (ACE_HANDLE handle,
1033 iovec *iov,
1034 int iovcnt,
1035 const ACE_Time_Value *timeout,
1036 size_t *bt)
1038 size_t temp;
1039 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1040 bytes_transferred = 0;
1041 ssize_t result = 0;
1042 bool error = false;
1044 int val = 0;
1045 ACE::record_and_set_non_blocking_mode (handle, val);
1047 for (int s = 0; s < iovcnt; )
1049 // Try to transfer as much of the remaining data as possible.
1050 // Since the socket is in non-blocking mode, this call will not
1051 // block.
1052 ssize_t n = ACE_OS::recvv (handle, iov + s, iovcnt - s);
1054 // Check for errors.
1055 if (n == 0 || n == -1)
1057 // Check for possible blocking.
1058 if (n == -1 && errno == EWOULDBLOCK)
1060 // Wait upto <timeout> for the blocking to subside.
1061 int const rtn = ACE::handle_read_ready (handle, timeout);
1063 // Did select() succeed?
1064 if (rtn != -1)
1066 // Blocking subsided in <timeout> period. Continue
1067 // data transfer.
1068 continue;
1072 // Wait in select() timed out or other data transfer or
1073 // select() failures.
1074 error = true;
1075 result = n;
1076 break;
1079 for (bytes_transferred += n;
1080 s < iovcnt
1081 && n >= static_cast<ssize_t> (iov[s].iov_len);
1082 s++)
1083 n -= iov[s].iov_len;
1085 if (n != 0)
1087 char *base = reinterpret_cast<char *> (iov[s].iov_base);
1088 iov[s].iov_base = base + n;
1089 // This blind cast is safe because n < iov_len, after above loop.
1090 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
1094 ACE::restore_non_blocking_mode (handle, val);
1096 if (error)
1098 return result;
1100 else
1102 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1106 ssize_t
1107 ACE::recv_n (ACE_HANDLE handle,
1108 ACE_Message_Block *message_block,
1109 const ACE_Time_Value *timeout,
1110 size_t *bt)
1112 size_t temp;
1113 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1114 bytes_transferred = 0;
1116 iovec iov[ACE_IOV_MAX];
1117 int iovcnt = 0;
1119 while (message_block != 0)
1121 // Our current message block chain.
1122 const ACE_Message_Block *current_message_block = message_block;
1124 while (current_message_block != 0)
1126 size_t current_message_block_length =
1127 current_message_block->length ();
1128 char *this_rd_ptr = current_message_block->rd_ptr ();
1130 // Check if this block has any space for incoming data.
1131 while (current_message_block_length > 0)
1133 u_long const this_chunk_length =
1134 ACE_Utils::truncate_cast<u_long> (
1135 current_message_block_length);
1137 // Collect the data in the iovec.
1138 iov[iovcnt].iov_base = this_rd_ptr;
1139 iov[iovcnt].iov_len = this_chunk_length;
1140 current_message_block_length -= this_chunk_length;
1141 this_rd_ptr += this_chunk_length;
1143 // Increment iovec counter.
1144 ++iovcnt;
1146 // The buffer is full make a OS call. @@ TODO find a way to
1147 // find ACE_IOV_MAX for platforms that do not define it rather
1148 // than simply setting ACE_IOV_MAX to some arbitrary value such
1149 // as 16.
1150 if (iovcnt == ACE_IOV_MAX)
1152 size_t current_transfer = 0;
1154 ssize_t const result = ACE::recvv_n (handle,
1155 iov,
1156 iovcnt,
1157 timeout,
1158 &current_transfer);
1160 // Add to total bytes transferred.
1161 bytes_transferred += current_transfer;
1163 // Errors.
1164 if (result == -1 || result == 0)
1165 return result;
1167 // Reset iovec counter.
1168 iovcnt = 0;
1172 // Select the next message block in the chain.
1173 current_message_block = current_message_block->cont ();
1176 // Selection of the next message block chain.
1177 message_block = message_block->next ();
1180 // Check for remaining buffers to be sent. This will happen when
1181 // ACE_IOV_MAX is not a multiple of the number of message blocks.
1182 if (iovcnt != 0)
1184 size_t current_transfer = 0;
1186 ssize_t const result = ACE::recvv_n (handle,
1187 iov,
1188 iovcnt,
1189 timeout,
1190 &current_transfer);
1192 // Add to total bytes transferred.
1193 bytes_transferred += current_transfer;
1195 // Errors.
1196 if (result == -1 || result == 0)
1198 return result;
1202 // Return total bytes transferred.
1203 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1206 ssize_t
1207 ACE::send (ACE_HANDLE handle,
1208 const void *buf,
1209 size_t n,
1210 int flags,
1211 const ACE_Time_Value *timeout)
1213 if (timeout == 0)
1214 return ACE_OS::send (handle, (const char *) buf, n, flags);
1215 else
1217 int val = 0;
1218 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1219 return -1;
1220 else
1222 ssize_t const bytes_transferred =
1223 ACE_OS::send (handle, (const char *) buf, n, flags);
1224 ACE::restore_non_blocking_mode (handle, val);
1225 return bytes_transferred;
1230 #if defined (ACE_HAS_TLI)
1232 ssize_t
1233 ACE::t_snd (ACE_HANDLE handle,
1234 const void *buf,
1235 size_t n,
1236 int flags,
1237 const ACE_Time_Value *timeout)
1239 if (timeout == 0)
1240 return ACE_OS::t_snd (handle, (const char *) buf, n, flags);
1241 else
1243 int val = 0;
1244 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1245 return -1;
1246 else
1248 ssize_t const bytes_transferred =
1249 ACE_OS::t_snd (handle, (const char *) buf, n, flags);
1250 ACE::restore_non_blocking_mode (handle, val);
1251 return bytes_transferred;
1256 #endif /* ACE_HAS_TLI */
1258 ssize_t
1259 ACE::send (ACE_HANDLE handle,
1260 const void *buf,
1261 size_t n,
1262 const ACE_Time_Value *timeout)
1264 if (timeout == 0)
1265 return ACE::send_i (handle, buf, n);
1266 else
1268 int val = 0;
1269 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1270 return -1;
1271 else
1273 ssize_t const bytes_transferred = ACE::send_i (handle, buf, n);
1274 ACE::restore_non_blocking_mode (handle, val);
1275 return bytes_transferred;
1280 ssize_t
1281 ACE::sendmsg (ACE_HANDLE handle,
1282 const struct msghdr *msg,
1283 int flags,
1284 const ACE_Time_Value *timeout)
1286 if (timeout == 0)
1287 return ACE_OS::sendmsg (handle, msg, flags);
1288 else
1290 int val = 0;
1291 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1292 return -1;
1293 else
1295 ssize_t const bytes_transferred =
1296 ACE_OS::sendmsg (handle, msg, flags);
1297 ACE::restore_non_blocking_mode (handle, val);
1298 return bytes_transferred;
1303 ssize_t
1304 ACE::sendto (ACE_HANDLE handle,
1305 const char *buf,
1306 int len,
1307 int flags,
1308 const struct sockaddr *addr,
1309 int addrlen,
1310 const ACE_Time_Value *timeout)
1312 if (timeout == 0)
1313 return ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
1314 else
1316 int val = 0;
1317 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1318 return -1;
1319 else
1321 ssize_t const bytes_transferred =
1322 ACE_OS::sendto (handle, buf, len, flags, addr, addrlen);
1323 ACE::restore_non_blocking_mode (handle, val);
1324 return bytes_transferred;
1329 ssize_t
1330 ACE::send_n_i (ACE_HANDLE handle,
1331 const void *buf,
1332 size_t len,
1333 int flags,
1334 size_t *bt)
1336 size_t temp;
1337 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1338 ssize_t n;
1340 for (bytes_transferred = 0;
1341 bytes_transferred < len;
1342 bytes_transferred += n)
1344 // Try to transfer as much of the remaining data as possible.
1345 n = ACE_OS::send (handle,
1346 (char *) buf + bytes_transferred,
1347 len - bytes_transferred,
1348 flags);
1349 // Check EOF.
1350 if (n == 0)
1351 return 0;
1353 // Check for other errors.
1354 if (n == -1)
1356 // Check for possible blocking.
1357 #if defined (ACE_WIN32)
1358 if (errno == EWOULDBLOCK) // If enobufs no need to loop
1359 #else
1360 if (errno == EWOULDBLOCK || errno == ENOBUFS)
1361 #endif /* ACE_WIN32 */
1363 // Wait for the blocking to subside.
1364 int const result = ACE::handle_write_ready (handle, 0);
1366 // Did select() succeed?
1367 if (result != -1)
1369 // Blocking subsided. Continue data transfer.
1370 n = 0;
1371 continue;
1375 // Other data transfer or select() failures.
1376 return -1;
1380 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1383 ssize_t
1384 ACE::send_n_i (ACE_HANDLE handle,
1385 const void *buf,
1386 size_t len,
1387 int flags,
1388 const ACE_Time_Value *timeout,
1389 size_t *bt)
1391 size_t temp;
1392 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1393 ssize_t n;
1394 ssize_t result = 0;
1395 bool error = false;
1397 int val = 0;
1398 ACE::record_and_set_non_blocking_mode (handle, val);
1400 for (bytes_transferred = 0;
1401 bytes_transferred < len;
1402 bytes_transferred += n)
1404 // Try to transfer as much of the remaining data as possible.
1405 // Since the socket is in non-blocking mode, this call will not
1406 // block.
1407 n = ACE_OS::send (handle,
1408 (char *) buf + bytes_transferred,
1409 len - bytes_transferred,
1410 flags);
1412 // Check for errors.
1413 if (n == 0 ||
1414 n == -1)
1416 // Check for possible blocking.
1417 if (n == -1 && (errno == EWOULDBLOCK || errno == ENOBUFS))
1419 // Wait upto <timeout> for the blocking to subside.
1420 int const rtn = ACE::handle_write_ready (handle, timeout);
1422 // Did select() succeed?
1423 if (rtn != -1)
1425 // Blocking subsided in <timeout> period. Continue
1426 // data transfer.
1427 n = 0;
1428 continue;
1432 // Wait in select() timed out or other data transfer or
1433 // select() failures.
1434 error = true;
1435 result = n;
1436 break;
1440 ACE::restore_non_blocking_mode (handle, val);
1442 if (error)
1444 return result;
1446 else
1448 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1452 #if defined (ACE_HAS_TLI)
1454 ssize_t
1455 ACE::t_snd_n_i (ACE_HANDLE handle,
1456 const void *buf,
1457 size_t len,
1458 int flags,
1459 size_t *bt)
1461 size_t temp;
1462 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1463 ssize_t n;
1465 for (bytes_transferred = 0;
1466 bytes_transferred < len;
1467 bytes_transferred += n)
1469 // Try to transfer as much of the remaining data as possible.
1470 n = ACE_OS::t_snd (handle,
1471 (char *) buf + bytes_transferred,
1472 len - bytes_transferred,
1473 flags);
1474 // Check EOF.
1475 if (n == 0)
1476 return 0;
1478 // Check for other errors.
1479 if (n == -1)
1481 // Check for possible blocking.
1482 if (errno == EWOULDBLOCK || errno == ENOBUFS)
1484 // Wait for the blocking to subside.
1485 int const result = ACE::handle_write_ready (handle, 0);
1487 // Did select() succeed?
1488 if (result != -1)
1490 // Blocking subsided. Continue data transfer.
1491 n = 0;
1492 continue;
1496 // Other data transfer or select() failures.
1497 return -1;
1501 return bytes_transferred;
1504 ssize_t
1505 ACE::t_snd_n_i (ACE_HANDLE handle,
1506 const void *buf,
1507 size_t len,
1508 int flags,
1509 const ACE_Time_Value *timeout,
1510 size_t *bt)
1512 size_t temp;
1513 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1514 ssize_t n;
1515 ssize_t result = 0;
1516 bool error = false;
1518 int val = 0;
1519 ACE::record_and_set_non_blocking_mode (handle, val);
1521 for (bytes_transferred = 0;
1522 bytes_transferred < len;
1523 bytes_transferred += n)
1525 // Try to transfer as much of the remaining data as possible.
1526 // Since the socket is in non-blocking mode, this call will not
1527 // block.
1528 n = ACE_OS::t_snd (handle,
1529 (char *) buf + bytes_transferred,
1530 len - bytes_transferred,
1531 flags);
1533 // Check for errors.
1534 if (n == 0 ||
1535 n == -1)
1537 // Check for possible blocking.
1538 if (n == -1 &&
1539 (errno == EWOULDBLOCK || errno == ENOBUFS))
1541 // Wait upto <timeout> for the blocking to subside.
1542 int const rtn = ACE::handle_write_ready (handle, timeout);
1544 // Did select() succeed?
1545 if (rtn != -1)
1547 // Blocking subsided in <timeout> period. Continue
1548 // data transfer.
1549 n = 0;
1550 continue;
1554 // Wait in select() timed out or other data transfer or
1555 // select() failures.
1556 error = true;
1557 result = n;
1558 break;
1562 ACE::restore_non_blocking_mode (handle, val);
1564 if (error)
1565 return result;
1566 else
1567 return bytes_transferred;
1570 #endif /* ACE_HAS_TLI */
1572 ssize_t
1573 ACE::send_n_i (ACE_HANDLE handle,
1574 const void *buf,
1575 size_t len,
1576 size_t *bt)
1578 size_t temp;
1579 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1580 ssize_t n;
1582 for (bytes_transferred = 0;
1583 bytes_transferred < len;
1584 bytes_transferred += n)
1586 // Try to transfer as much of the remaining data as possible.
1587 n = ACE::send_i (handle,
1588 (char *) buf + bytes_transferred,
1589 len - bytes_transferred);
1590 // Check EOF.
1591 if (n == 0)
1593 return 0;
1596 // Check for other errors.
1597 if (n == -1)
1599 // Check for possible blocking.
1600 if (errno == EWOULDBLOCK || errno == ENOBUFS)
1602 // Wait for the blocking to subside.
1603 int const result = ACE::handle_write_ready (handle, 0);
1605 // Did select() succeed?
1606 if (result != -1)
1608 // Blocking subsided. Continue data transfer.
1609 n = 0;
1610 continue;
1614 // Other data transfer or select() failures.
1615 return -1;
1619 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1622 ssize_t
1623 ACE::send_n_i (ACE_HANDLE handle,
1624 const void *buf,
1625 size_t len,
1626 const ACE_Time_Value *timeout,
1627 size_t *bt)
1629 size_t temp;
1630 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1631 ssize_t n;
1632 ssize_t result = 0;
1633 bool error = false;
1635 int val = 0;
1636 ACE::record_and_set_non_blocking_mode (handle, val);
1638 for (bytes_transferred = 0;
1639 bytes_transferred < len;
1640 bytes_transferred += n)
1642 // Try to transfer as much of the remaining data as possible.
1643 // Since the socket is in non-blocking mode, this call will not
1644 // block.
1645 n = ACE::send_i (handle,
1646 (char *) buf + bytes_transferred,
1647 len - bytes_transferred);
1649 // Check for errors.
1650 if (n == 0 ||
1651 n == -1)
1653 // Check for possible blocking.
1654 if (n == -1 &&
1655 (errno == EWOULDBLOCK || errno == ENOBUFS))
1657 // Wait upto <timeout> for the blocking to subside.
1658 int const rtn = ACE::handle_write_ready (handle, timeout);
1660 // Did select() succeed?
1661 if (rtn != -1)
1663 // Blocking subsided in <timeout> period. Continue
1664 // data transfer.
1665 n = 0;
1666 continue;
1670 // Wait in select() timed out or other data transfer or
1671 // select() failures.
1672 error = true;
1673 result = n;
1674 break;
1678 ACE::restore_non_blocking_mode (handle, val);
1680 if (error)
1682 return result;
1684 else
1686 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1690 // Send N char *ptrs and int lengths. Note that the char *'s precede
1691 // the ints (basically, an varargs version of writev). The count N is
1692 // the *total* number of trailing arguments, *not* a couple of the
1693 // number of tuple pairs!
1694 #if !defined (ACE_LACKS_VA_FUNCTIONS)
1695 ssize_t
1696 ACE::send (ACE_HANDLE handle, size_t n, ...)
1698 va_list argp;
1699 int total_tuples = static_cast<int> (n / 2);
1700 iovec *iovp;
1701 #if defined (ACE_HAS_ALLOCA)
1702 iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
1703 #else
1704 # ifdef ACE_HAS_ALLOC_HOOKS
1705 ACE_ALLOCATOR_RETURN (iovp, (iovec *)
1706 ACE_Allocator::instance ()->malloc (total_tuples *
1707 sizeof (iovec)),
1708 -1);
1709 # else
1710 ACE_NEW_RETURN (iovp,
1711 iovec[total_tuples],
1712 -1);
1713 # endif /* ACE_HAS_ALLOC_HOOKS */
1714 #endif /* !defined (ACE_HAS_ALLOCA) */
1716 va_start (argp, n);
1718 for (int i = 0; i < total_tuples; i++)
1720 iovp[i].iov_base = va_arg (argp, char *);
1721 iovp[i].iov_len = va_arg (argp, int);
1724 ssize_t result = ACE_OS::sendv (handle, iovp, total_tuples);
1725 #if !defined (ACE_HAS_ALLOCA)
1726 # ifdef ACE_HAS_ALLOC_HOOKS
1727 ACE_Allocator::instance ()->free (iovp);
1728 # else
1729 delete [] iovp;
1730 # endif /* ACE_HAS_ALLOC_HOOKS */
1731 #endif /* !defined (ACE_HAS_ALLOCA) */
1732 va_end (argp);
1733 return result;
1735 #endif /* ACE_LACKS_VA_FUNCTIONS */
1737 ssize_t
1738 ACE::sendv (ACE_HANDLE handle,
1739 const iovec *iov,
1740 int iovcnt,
1741 const ACE_Time_Value *timeout)
1743 if (timeout == 0)
1744 return ACE_OS::sendv (handle, iov, iovcnt);
1745 else
1747 int val = 0;
1748 if (ACE::enter_send_timedwait (handle, timeout, val) == -1)
1749 return -1;
1750 else
1752 ssize_t bytes_transferred = ACE_OS::sendv (handle, iov, iovcnt);
1753 ACE::restore_non_blocking_mode (handle, val);
1754 return bytes_transferred;
1759 ssize_t
1760 ACE::sendv_n_i (ACE_HANDLE handle,
1761 const iovec *i,
1762 int iovcnt,
1763 size_t *bt)
1765 size_t temp;
1766 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1767 bytes_transferred = 0;
1769 iovec *iov = const_cast<iovec *> (i);
1771 for (int s = 0;
1772 s < iovcnt;
1775 // Try to transfer as much of the remaining data as possible.
1776 ssize_t n = ACE_OS::sendv (handle, iov + s, iovcnt - s);
1778 // Check EOF.
1779 if (n == 0)
1780 return 0;
1782 // Check for other errors.
1783 if (n == -1)
1785 // Check for possible blocking.
1786 if (errno == EWOULDBLOCK || errno == ENOBUFS)
1788 // Wait for the blocking to subside.
1789 int const result = ACE::handle_write_ready (handle, 0);
1791 // Did select() succeed?
1792 if (result != -1)
1794 // Blocking subsided. Continue data transfer.
1795 continue;
1799 // Other data transfer or select() failures.
1800 return -1;
1803 for (bytes_transferred += n;
1804 s < iovcnt
1805 && n >= static_cast<ssize_t> (iov[s].iov_len);
1806 s++)
1807 n -= iov[s].iov_len;
1809 if (n != 0)
1811 char *base = reinterpret_cast<char *> (iov[s].iov_base);
1812 iov[s].iov_base = base + n;
1813 // This blind cast is safe because n < iov_len, after above loop.
1814 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
1818 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1821 ssize_t
1822 ACE::sendv_n_i (ACE_HANDLE handle,
1823 const iovec *i,
1824 int iovcnt,
1825 const ACE_Time_Value *timeout,
1826 size_t *bt)
1828 size_t temp;
1829 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1830 bytes_transferred = 0;
1831 ssize_t result = 0;
1832 bool error = false;
1834 int val = 0;
1835 ACE::record_and_set_non_blocking_mode (handle, val);
1837 iovec *iov = const_cast<iovec *> (i);
1839 for (int s = 0;
1840 s < iovcnt;
1843 // Try to transfer as much of the remaining data as possible.
1844 // Since the socket is in non-blocking mode, this call will not
1845 // block.
1846 ssize_t n = ACE_OS::sendv (handle, iov + s, iovcnt - s);
1848 // Check for errors.
1849 if (n == 0 ||
1850 n == -1)
1852 // Check for possible blocking.
1853 if (n == -1 &&
1854 (errno == EWOULDBLOCK || errno == ENOBUFS))
1856 // Wait upto <timeout> for the blocking to subside.
1857 int const rtn = ACE::handle_write_ready (handle, timeout);
1859 // Did select() succeed?
1860 if (rtn != -1)
1862 // Blocking subsided in <timeout> period. Continue
1863 // data transfer.
1864 continue;
1868 // Wait in select() timed out or other data transfer or
1869 // select() failures.
1870 error = true;
1871 result = n;
1872 break;
1875 for (bytes_transferred += n;
1876 s < iovcnt
1877 && n >= static_cast<ssize_t> (iov[s].iov_len);
1878 s++)
1879 n -= iov[s].iov_len;
1881 if (n != 0)
1883 char *base = reinterpret_cast<char *> (iov[s].iov_base);
1884 iov[s].iov_base = base + n;
1885 // This blind cast is safe because n < iov_len, after above loop.
1886 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
1890 ACE::restore_non_blocking_mode (handle, val);
1892 if (error)
1894 return result;
1896 else
1898 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1902 ssize_t
1903 ACE::write_n (ACE_HANDLE handle,
1904 const ACE_Message_Block *message_block,
1905 size_t *bt)
1907 size_t temp;
1908 size_t &bytes_transferred = bt == 0 ? temp : *bt;
1909 bytes_transferred = 0;
1911 iovec iov[ACE_IOV_MAX];
1912 int iovcnt = 0;
1914 while (message_block != 0)
1916 // Our current message block chain.
1917 const ACE_Message_Block *current_message_block = message_block;
1919 while (current_message_block != 0)
1921 size_t current_message_block_length =
1922 current_message_block->length ();
1923 char *this_block_ptr = current_message_block->rd_ptr ();
1925 // Check if this block has any data to be sent.
1926 while (current_message_block_length > 0)
1928 u_long const this_chunk_length =
1929 ACE_Utils::truncate_cast<u_long> (
1930 current_message_block_length);
1932 // Collect the data in the iovec.
1933 iov[iovcnt].iov_base = this_block_ptr;
1934 iov[iovcnt].iov_len = this_chunk_length;
1935 current_message_block_length -= this_chunk_length;
1936 this_block_ptr += this_chunk_length;
1938 // Increment iovec counter.
1939 ++iovcnt;
1941 // The buffer is full make a OS call. @@ TODO find a way to
1942 // find ACE_IOV_MAX for platforms that do not define it rather
1943 // than simply setting ACE_IOV_MAX to some arbitrary value such
1944 // as 16.
1945 if (iovcnt == ACE_IOV_MAX)
1947 size_t current_transfer = 0;
1949 ssize_t const result = ACE::writev_n (handle,
1950 iov,
1951 iovcnt,
1952 &current_transfer);
1954 // Add to total bytes transferred.
1955 bytes_transferred += current_transfer;
1957 // Errors.
1958 if (result == -1 || result == 0)
1959 return result;
1961 // Reset iovec counter.
1962 iovcnt = 0;
1966 // Select the next message block in the chain.
1967 current_message_block = current_message_block->cont ();
1970 // Selection of the next message block chain.
1971 message_block = message_block->next ();
1974 // Check for remaining buffers to be sent. This will happen when
1975 // ACE_IOV_MAX is not a multiple of the number of message blocks.
1976 if (iovcnt != 0)
1978 size_t current_transfer = 0;
1980 ssize_t const result = ACE::writev_n (handle,
1981 iov,
1982 iovcnt,
1983 &current_transfer);
1985 // Add to total bytes transferred.
1986 bytes_transferred += current_transfer;
1988 // Errors.
1989 if (result == -1 || result == 0)
1990 return result;
1993 // Return total bytes transferred.
1994 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
1997 ssize_t
1998 ACE::send_n (ACE_HANDLE handle,
1999 const ACE_Message_Block *message_block,
2000 const ACE_Time_Value *timeout,
2001 size_t *bt)
2003 size_t temp;
2004 size_t &bytes_transferred = bt == 0 ? temp : *bt;
2005 bytes_transferred = 0;
2007 iovec iov[ACE_IOV_MAX];
2008 int iovcnt = 0;
2010 while (message_block != 0)
2012 // Our current message block chain.
2013 const ACE_Message_Block *current_message_block = message_block;
2015 while (current_message_block != 0)
2017 char *this_block_ptr = current_message_block->rd_ptr ();
2018 size_t current_message_block_length =
2019 current_message_block->length ();
2021 // Check if this block has any data to be sent.
2022 while (current_message_block_length > 0)
2024 u_long const this_chunk_length =
2025 ACE_Utils::truncate_cast<u_long> (
2026 current_message_block_length);
2028 // Collect the data in the iovec.
2029 iov[iovcnt].iov_base = this_block_ptr;
2030 iov[iovcnt].iov_len = this_chunk_length;
2031 current_message_block_length -= this_chunk_length;
2032 this_block_ptr += this_chunk_length;
2034 // Increment iovec counter.
2035 ++iovcnt;
2037 // The buffer is full make a OS call. @@ TODO find a way to
2038 // find ACE_IOV_MAX for platforms that do not define it rather
2039 // than simply setting ACE_IOV_MAX to some arbitrary value such
2040 // as 16.
2041 if (iovcnt == ACE_IOV_MAX)
2043 size_t current_transfer = 0;
2045 ssize_t const result = ACE::sendv_n (handle,
2046 iov,
2047 iovcnt,
2048 timeout,
2049 &current_transfer);
2051 // Add to total bytes transferred.
2052 bytes_transferred += current_transfer;
2054 // Errors.
2055 if (result == -1 || result == 0)
2056 return result;
2058 // Reset iovec counter.
2059 iovcnt = 0;
2063 // Select the next message block in the chain.
2064 current_message_block = current_message_block->cont ();
2067 // Selection of the next message block chain.
2068 message_block = message_block->next ();
2071 // Check for remaining buffers to be sent. This will happen when
2072 // ACE_IOV_MAX is not a multiple of the number of message blocks.
2073 if (iovcnt != 0)
2075 size_t current_transfer = 0;
2077 ssize_t const result = ACE::sendv_n (handle,
2078 iov,
2079 iovcnt,
2080 timeout,
2081 &current_transfer);
2083 // Add to total bytes transferred.
2084 bytes_transferred += current_transfer;
2086 // Errors.
2087 if (result == -1 || result == 0)
2089 return result;
2093 // Return total bytes transferred.
2094 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
2097 ssize_t
2098 ACE::readv_n (ACE_HANDLE handle,
2099 iovec *iov,
2100 int iovcnt,
2101 size_t *bt)
2103 size_t temp;
2104 size_t &bytes_transferred = bt == 0 ? temp : *bt;
2105 bytes_transferred = 0;
2107 for (int s = 0;
2108 s < iovcnt;
2111 ssize_t n = ACE_OS::readv (handle,
2112 iov + s,
2113 iovcnt - s);
2115 if (n == -1 || n == 0)
2116 return n;
2118 for (bytes_transferred += n;
2119 s < iovcnt
2120 && n >= static_cast<ssize_t> (iov[s].iov_len);
2121 s++)
2122 n -= iov[s].iov_len;
2124 if (n != 0)
2126 char *base = reinterpret_cast<char *> (iov[s].iov_base);
2127 iov[s].iov_base = base + n;
2128 // This blind cast is safe because n < iov_len, after above loop.
2129 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
2133 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
2136 ssize_t
2137 ACE::writev_n (ACE_HANDLE handle,
2138 const iovec *i,
2139 int iovcnt,
2140 size_t *bt)
2142 size_t temp;
2143 size_t &bytes_transferred = bt == 0 ? temp : *bt;
2144 bytes_transferred = 0;
2146 iovec *iov = const_cast<iovec *> (i);
2148 for (int s = 0;
2149 s < iovcnt;
2152 ssize_t n = ACE_OS::writev (handle,
2153 iov + s,
2154 iovcnt - s);
2156 if (n == -1 || n == 0)
2158 return n;
2161 for (bytes_transferred += n;
2162 s < iovcnt
2163 && n >= static_cast<ssize_t> (iov[s].iov_len);
2164 s++)
2165 n -= iov[s].iov_len;
2167 if (n != 0)
2169 char *base = reinterpret_cast<char *> (iov[s].iov_base);
2170 iov[s].iov_base = base + n;
2171 // This blind cast is safe because n < iov_len, after above loop.
2172 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n);
2176 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred);
2180 ACE::handle_ready (ACE_HANDLE handle,
2181 const ACE_Time_Value *timeout,
2182 bool read_ready,
2183 bool write_ready,
2184 bool exception_ready)
2186 #if defined (ACE_HAS_POLL)
2187 ACE_UNUSED_ARG (exception_ready);
2189 struct pollfd fds;
2191 fds.fd = handle;
2192 fds.events = read_ready ? POLLIN : 0;
2194 if( write_ready )
2196 fds.events |= POLLOUT;
2199 fds.revents = 0;
2201 int const result = ACE_OS::poll (&fds, 1, timeout);
2202 #else
2203 ACE_Handle_Set handle_set;
2204 handle_set.set_bit (handle);
2206 // Wait for data or for the timeout to elapse.
2207 int select_width = 0;
2208 #if !defined (ACE_WIN32)
2209 select_width = int (handle) + 1;
2210 # endif /* ACE_WIN64 */
2211 int result = ACE_OS::select (select_width,
2212 read_ready ? handle_set.fdset () : 0, // read_fds.
2213 write_ready ? handle_set.fdset () : 0, // write_fds.
2214 exception_ready ? handle_set.fdset () : 0, // exception_fds.
2215 timeout);
2217 #endif /* ACE_HAS_POLL */
2218 switch (result)
2220 case 0: // Timer expired.
2221 errno = ETIME;
2222 ACE_FALLTHROUGH;
2223 case -1: // we got here directly - select() returned -1.
2224 return -1;
2225 case 1: // Handle has data.
2226 ACE_FALLTHROUGH;
2227 default: // default is case result > 0; return a
2228 // ACE_ASSERT (result == 1);
2229 return result;
2234 ACE::enter_recv_timedwait (ACE_HANDLE handle,
2235 const ACE_Time_Value *timeout,
2236 int &val)
2238 int const result = ACE::handle_read_ready (handle, timeout);
2240 if (result == -1)
2241 return -1;
2243 ACE::record_and_set_non_blocking_mode (handle, val);
2245 return result;
2249 ACE::enter_send_timedwait (ACE_HANDLE handle,
2250 const ACE_Time_Value *timeout,
2251 int &val)
2253 int const result = ACE::handle_write_ready (handle, timeout);
2255 if (result == -1)
2256 return -1;
2258 ACE::record_and_set_non_blocking_mode (handle, val);
2260 return result;
2263 void
2264 ACE::record_and_set_non_blocking_mode (ACE_HANDLE handle, int &val)
2266 // We need to record whether we are already *in* nonblocking mode,
2267 // so that we can correctly reset the state when we're done.
2268 val = ACE::get_flags (handle);
2270 if (ACE_BIT_DISABLED (val, ACE_NONBLOCK))
2271 // Set the handle into non-blocking mode if it's not already in
2272 // it.
2273 ACE::set_flags (handle, ACE_NONBLOCK);
2276 void
2277 ACE::restore_non_blocking_mode (ACE_HANDLE handle, int val)
2279 if (ACE_BIT_DISABLED (val, ACE_NONBLOCK))
2281 // Save/restore errno.
2282 ACE_Errno_Guard error (errno);
2283 // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
2284 // originally.
2285 ACE::clr_flags (handle, ACE_NONBLOCK);
2289 /// Format buffer into printable format. This is useful for debugging.
2290 /// Portions taken from mdump by J.P. Knight (J.P.Knight@lut.ac.uk)
2291 /// Modifications by Todd Montgomery.
2292 size_t
2293 ACE::format_hexdump (const char *buffer,
2294 size_t size,
2295 ACE_TCHAR *obuf,
2296 size_t obuf_sz)
2298 ACE_TRACE ("ACE::format_hexdump");
2300 u_char c;
2301 ACE_TCHAR textver[16 + 1];
2303 // We can fit 16 bytes output in text mode per line, 4 chars per byte.
2304 size_t maxlen = (obuf_sz / 68) * 16;
2305 const ACE_TCHAR *const obuf_start = obuf;
2307 if (size > maxlen)
2308 size = maxlen;
2310 size_t i;
2312 size_t const lines = size / 16;
2313 for (i = 0; i < lines; i++)
2315 size_t j;
2317 for (j = 0 ; j < 16; j++)
2319 c = (u_char) buffer[(i << 4) + j]; // or, buffer[i*16+j]
2320 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2321 ACE_TEXT ("%02x "),
2323 obuf += 3;
2324 if (j == 7)
2326 *obuf++ = ACE_TEXT (' ');
2328 textver[j] = ACE_OS::ace_isprint (c) ? c : u_char ('.');
2331 textver[j] = 0;
2333 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2334 ACE_TEXT (" %") ACE_TEXT_PRIs ACE_TEXT ("\n"),
2335 textver);
2337 while (*obuf != '\0')
2338 ++obuf;
2341 if (size % 16)
2343 for (i = 0 ; i < size % 16; i++)
2345 c = (u_char) buffer[size - size % 16 + i];
2346 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2347 ACE_TEXT ("%02x "),
2349 obuf += 3;
2350 if (i == 7)
2352 *obuf++ = ACE_TEXT (' ');
2354 textver[i] = ACE_OS::ace_isprint (c) ? c : u_char ('.');
2357 for (i = size % 16; i < 16; i++)
2359 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2360 ACE_TEXT (" "));
2361 obuf += 3;
2362 if (i == 7)
2364 *obuf++ = ACE_TEXT (' ');
2366 textver[i] = ' ';
2369 textver[i] = 0;
2370 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start),
2371 ACE_TEXT (" %") ACE_TEXT_PRIs ACE_TEXT ("\n"),
2372 textver);
2374 return size;
2377 /// Returns the current timestamp in the form
2378 /// "hour:minute:second:microsecond." The month, day, and year are
2379 /// also stored in the beginning of the date_and_time array
2380 /// using ISO-8601 format.
2381 ACE_TCHAR *
2382 ACE::timestamp (ACE_TCHAR date_and_time[],
2383 size_t date_and_timelen,
2384 bool return_pointer_to_first_digit)
2386 return ACE::timestamp (ACE_Time_Value::zero,
2387 date_and_time,
2388 date_and_timelen,
2389 return_pointer_to_first_digit);
2392 /// Returns the given timestamp in the form
2393 /// "hour:minute:second:microsecond." The month, day, and year are
2394 /// also stored in the beginning of the date_and_time array
2395 /// using ISO-8601 format.
2396 /// 012345678901234567890123456
2397 /// 2010-12-02 12:56:00.123456<nul>
2398 ACE_TCHAR *
2399 ACE::timestamp (const ACE_Time_Value& time_value,
2400 ACE_TCHAR date_and_time[],
2401 size_t date_and_timelen,
2402 bool return_pointer_to_first_digit)
2404 //ACE_TRACE ("ACE::timestamp");
2406 // This magic number is from the formatting statement
2407 // farther down this routine.
2408 if (date_and_timelen < 27)
2410 errno = EINVAL;
2411 return 0;
2414 ACE_Time_Value cur_time =
2415 (time_value == ACE_Time_Value::zero) ?
2416 ACE_Time_Value (ACE_OS::gettimeofday ()) : time_value;
2417 time_t secs = cur_time.sec ();
2418 struct tm tms;
2419 ACE_OS::localtime_r (&secs, &tms);
2420 ACE_OS::snprintf (date_and_time,
2421 date_and_timelen,
2422 ACE_TEXT ("%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d.%06ld"),
2423 tms.tm_year + 1900,
2424 tms.tm_mon + 1,
2425 tms.tm_mday,
2426 tms.tm_hour,
2427 tms.tm_min,
2428 tms.tm_sec,
2429 static_cast<long> (cur_time.usec()));
2430 date_and_time[date_and_timelen - 1] = '\0';
2431 return &date_and_time[10 + (return_pointer_to_first_digit != 0)];
2434 /// This function rounds the request to a multiple of the page size.
2435 size_t
2436 ACE::round_to_pagesize (size_t len)
2438 ACE_TRACE ("ACE::round_to_pagesize");
2440 if (ACE::pagesize_ == 0)
2441 ACE::pagesize_ = ACE_OS::getpagesize ();
2443 return (len + (ACE::pagesize_ - 1)) & ~(ACE::pagesize_ - 1);
2446 size_t
2447 ACE::round_to_allocation_granularity (size_t len)
2449 ACE_TRACE ("ACE::round_to_allocation_granularity");
2451 if (ACE::allocation_granularity_ == 0)
2452 ACE::allocation_granularity_ = ACE_OS::allocation_granularity ();
2454 return (len + (ACE::allocation_granularity_ - 1)) & ~(ACE::allocation_granularity_ - 1);
2457 ACE_HANDLE
2458 ACE::handle_timed_complete (ACE_HANDLE h,
2459 const ACE_Time_Value *timeout,
2460 int is_tli)
2462 ACE_TRACE ("ACE::handle_timed_complete");
2464 #if !defined (ACE_WIN32) && defined (ACE_HAS_POLL)
2466 struct pollfd fds;
2468 fds.fd = h;
2469 fds.events = POLLIN | POLLOUT;
2470 fds.revents = 0;
2472 #else
2473 ACE_Handle_Set rd_handles;
2474 ACE_Handle_Set wr_handles;
2475 rd_handles.set_bit (h);
2476 wr_handles.set_bit (h);
2477 #endif /* !ACE_WIN32 && ACE_HAS_POLL */
2479 #if defined (ACE_WIN32)
2480 // Winsock is different - it sets the exception bit for failed connect,
2481 // unlike other platforms, where the write bit is set for both success
2482 // and fail.
2483 ACE_Handle_Set ex_handles;
2484 ex_handles.set_bit (h);
2485 #endif /* ACE_WIN32 */
2487 bool need_to_check = false;
2488 bool known_failure = false;
2490 #if defined (ACE_WIN32)
2491 int n = ACE_OS::select (0, // Ignored on Windows: int (h) + 1,
2493 wr_handles,
2494 ex_handles,
2495 timeout);
2496 #else
2497 # if defined (ACE_HAS_POLL)
2499 int n = ACE_OS::poll (&fds, 1, timeout);
2501 # else
2502 int n = 0;
2503 if (is_tli)
2504 n = ACE_OS::select (int (h) + 1,
2505 rd_handles,
2506 wr_handles,
2508 timeout);
2509 else
2510 n = ACE_OS::select (int (h) + 1,
2512 wr_handles,
2514 timeout);
2515 # endif /* ACE_HAS_POLL */
2516 #endif /* ACE_WIN32 */
2518 // If we failed to connect within the time period allocated by the
2519 // caller, then we fail (e.g., the remote host might have been too
2520 // busy to accept our call).
2521 if (n <= 0)
2523 if (n == 0 && timeout != 0)
2524 errno = ETIME;
2525 return ACE_INVALID_HANDLE;
2528 // On Windows, a ready-for-write handle is successfully connected, and
2529 // ready-for-exception is a failure. On fails, we need to grab the error
2530 // code via getsockopt.
2531 // On BSD sockets using select(), the handle becomes writable on
2532 // completion either success or fail, so if the select() does not time
2533 // out, we need to check for success/fail.
2534 // It is believed that TLI sockets use the readable=fail, writeable=success
2535 // but that hasn't been as well tested.
2536 #if defined (ACE_WIN32)
2537 ACE_UNUSED_ARG (is_tli);
2539 // On Win32, ex_handle set indicates a failure. We'll do the check
2540 // to try and get an errno value, but the connect failed regardless of
2541 // what getsockopt says about the error.
2542 if (ex_handles.is_set (h))
2544 need_to_check = true;
2545 known_failure = true;
2547 #else
2548 if (is_tli)
2549 # if defined (ACE_HAS_POLL)
2550 need_to_check = (fds.revents & POLLIN) && !(fds.revents & POLLOUT);
2551 # else
2552 need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h);
2553 # endif /* ACE_HAS_POLL */
2555 else
2556 # if defined (ACE_HAS_POLL)
2558 // The "official" bit for failed connect is POLLIN. However, POLLERR
2559 // is often set and there are occasional cases seen with some kernels
2560 // where only POLLERR is set on a failed connect.
2561 need_to_check = (fds.revents & POLLIN) || (fds.revents & POLLERR);
2562 known_failure = (fds.revents & POLLERR);
2564 # else
2565 need_to_check = true;
2566 # endif /* ACE_HAS_POLL */
2567 #endif /* ACE_WIN32 */
2569 if (need_to_check)
2571 #if defined (SOL_SOCKET) && defined (SO_ERROR)
2572 int sock_err = 0;
2573 int sock_err_len = sizeof (sock_err);
2574 int sockopt_ret = ACE_OS::getsockopt (h, SOL_SOCKET, SO_ERROR,
2575 (char *)&sock_err, &sock_err_len);
2576 if (sockopt_ret < 0)
2578 h = ACE_INVALID_HANDLE;
2581 if (sock_err != 0 || known_failure)
2583 h = ACE_INVALID_HANDLE;
2584 errno = sock_err;
2586 #else
2587 char dummy;
2589 // The following recv() won't block provided that the
2590 // ACE_NONBLOCK flag has not been turned off .
2591 n = ACE::recv (h, &dummy, 1, MSG_PEEK);
2593 // If no data was read/peeked at, check to see if it's because
2594 // of a non-connected socket (and therefore an error) or there's
2595 // just no data yet.
2596 if (n <= 0)
2598 if (n == 0)
2600 errno = ECONNREFUSED;
2601 h = ACE_INVALID_HANDLE;
2603 else if (errno != EWOULDBLOCK && errno != EAGAIN)
2604 h = ACE_INVALID_HANDLE;
2606 #endif
2609 // 1. The HANDLE is ready for writing and doesn't need to be checked or
2610 // 2. recv() returned an indication of the state of the socket - if there is
2611 // either data present, or a recv is legit but there's no data yet,
2612 // the connection was successfully established.
2613 return h;
2616 /// Wait up to @a timeout amount of time to accept a connection.
2618 ACE::handle_timed_accept (ACE_HANDLE listener,
2619 ACE_Time_Value *timeout,
2620 bool restart)
2622 ACE_TRACE ("ACE::handle_timed_accept");
2623 // Make sure we don't bomb out on erroneous values.
2624 if (listener == ACE_INVALID_HANDLE)
2625 return -1;
2627 #if defined (ACE_HAS_POLL)
2629 struct pollfd fds;
2631 fds.fd = listener;
2632 fds.events = POLLIN;
2633 fds.revents = 0;
2635 #else
2636 // Use the select() implementation rather than poll().
2637 ACE_Handle_Set rd_handle;
2638 rd_handle.set_bit (listener);
2639 #endif /* ACE_HAS_POLL */
2641 // We need a loop here if <restart> is enabled.
2643 for (;;)
2645 #if defined (ACE_HAS_POLL)
2647 int n = ACE_OS::poll (&fds, 1, timeout);
2649 #else
2650 int select_width = 0;
2651 # if !defined (ACE_WIN32)
2652 select_width = int (listener) + 1;
2653 # endif /* ACE_WIN32 */
2654 int n = ACE_OS::select (select_width,
2655 rd_handle, 0, 0,
2656 timeout);
2657 #endif /* ACE_HAS_POLL */
2659 switch (n)
2661 case -1:
2662 if (errno == EINTR && restart)
2663 continue;
2664 else
2665 return -1;
2666 /* NOTREACHED */
2667 case 0:
2668 if (timeout != 0 && *timeout == ACE_Time_Value::zero)
2669 errno = EWOULDBLOCK;
2670 else
2671 errno = ETIMEDOUT;
2672 return -1;
2673 /* NOTREACHED */
2674 case 1:
2675 return 0;
2676 /* NOTREACHED */
2677 default:
2678 errno = EINVAL;
2679 return -1;
2680 /* NOTREACHED */
2685 /// Make the current process a UNIX daemon. This is based on Stevens
2686 /// code from APUE.
2688 ACE::daemonize (const ACE_TCHAR pathname[],
2689 bool close_all_handles,
2690 const ACE_TCHAR program_name[])
2692 ACE_TRACE ("ACE::daemonize");
2693 #if !defined (ACE_LACKS_FORK)
2694 pid_t pid = ACE_OS::fork ();
2696 if (pid == -1)
2697 return -1;
2698 else if (pid != 0)
2699 ACE_OS::exit (0); // Parent exits.
2701 // 1st child continues.
2702 ACE_OS::setsid (); // Become session leader.
2704 ACE_OS::signal (SIGHUP, SIG_IGN);
2706 pid = ACE_OS::fork (program_name);
2708 if (pid != 0)
2709 ACE_OS::exit (0); // First child terminates.
2711 // Second child continues.
2713 if (pathname != 0)
2714 // change working directory.
2715 ACE_OS::chdir (pathname);
2717 ACE_OS::umask (0); // clear our file mode creation mask.
2719 // Close down the I/O handles.
2720 if (close_all_handles)
2722 for (int i = ACE::max_handles () - 1; i >= 0; i--)
2723 ACE_OS::close (i);
2725 int fd = ACE_OS::open ("/dev/null", O_RDWR, 0);
2726 if (fd != -1)
2728 ACE_OS::dup2 (fd, ACE_STDIN);
2729 ACE_OS::dup2 (fd, ACE_STDOUT);
2730 ACE_OS::dup2 (fd, ACE_STDERR);
2732 if (fd > ACE_STDERR)
2733 ACE_OS::close (fd);
2737 return 0;
2738 #else
2739 ACE_UNUSED_ARG (pathname);
2740 ACE_UNUSED_ARG (close_all_handles);
2741 ACE_UNUSED_ARG (program_name);
2743 ACE_NOTSUP_RETURN (-1);
2744 #endif /* ACE_LACKS_FORK */
2747 pid_t
2748 ACE::fork (const ACE_TCHAR *program_name,
2749 int avoid_zombies)
2751 if (avoid_zombies == 0)
2752 return ACE_OS::fork (program_name);
2753 else
2755 // This algorithm is adapted from an example in the Stevens book
2756 // "Advanced Programming in the Unix Environment" and an item in
2757 // Andrew Gierth's Unix Programming FAQ. It creates an orphan
2758 // process that's inherited by the init process; init cleans up
2759 // when the orphan process terminates.
2761 // Another way to avoid zombies is to ignore or catch the
2762 // SIGCHLD signal; we don't use that approach here.
2764 pid_t pid = ACE_OS::fork ();
2765 if (pid == 0)
2767 // The child process forks again to create a grandchild.
2768 switch (ACE_OS::fork (program_name))
2770 case 0: // grandchild returns 0.
2771 return 0;
2772 case static_cast<pid_t>(-1): // assumes all errnos are < 256
2773 ACE_OS::_exit (errno);
2774 ACE_FALLTHROUGH; // gcc sees this as a fallthrough
2775 default: // child terminates, orphaning grandchild
2776 ACE_OS::_exit (0);
2780 // Parent process waits for child to terminate.
2781 ACE_exitcode status;
2782 if (pid < 0 || ACE_OS::waitpid (pid, &status, 0) < 0)
2783 return -1;
2785 // child terminated by calling exit()?
2786 if (WIFEXITED ((status)))
2788 // child terminated normally?
2789 if (WEXITSTATUS ((status)) == 0)
2790 return 1;
2791 else
2792 errno = WEXITSTATUS ((status));
2794 else
2795 // child didn't call exit(); perhaps it received a signal?
2796 errno = EINTR;
2798 return -1;
2803 ACE::max_handles ()
2805 ACE_TRACE ("ACE::max_handles");
2806 #if defined (RLIMIT_NOFILE) && !defined (ACE_LACKS_RLIMIT)
2807 rlimit rl;
2808 int const r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
2809 # if !defined (RLIM_INFINITY)
2810 if (r == 0)
2811 return rl.rlim_cur;
2812 # else
2813 if (r == 0 && rl.rlim_cur != RLIM_INFINITY)
2814 return rl.rlim_cur;
2815 // If == RLIM_INFINITY, fall through to the ACE_LACKS_RLIMIT sections
2816 # endif /* RLIM_INFINITY */
2817 #endif /* RLIMIT_NOFILE && !ACE_LACKS_RLIMIT */
2819 #if defined (_SC_OPEN_MAX) && !defined (ACE_LACKS_SYSCONF)
2820 return static_cast<int> (ACE_OS::sysconf (_SC_OPEN_MAX));
2821 #elif defined (FD_SETSIZE)
2822 return FD_SETSIZE;
2823 #else
2824 ACE_NOTSUP_RETURN (-1);
2825 #endif /* _SC_OPEN_MAX */
2828 // Set the number of currently open handles in the process.
2830 // If NEW_LIMIT == -1 set the limit to the maximum allowable.
2831 // Otherwise, set it to be the value of NEW_LIMIT.
2834 ACE::set_handle_limit (int new_limit,
2835 int increase_limit_only)
2837 ACE_TRACE ("ACE::set_handle_limit");
2838 int cur_limit = ACE::max_handles ();
2839 int max_limit = cur_limit;
2841 if (cur_limit == -1)
2842 return -1;
2844 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2845 struct rlimit rl;
2847 ACE_OS::memset ((void *) &rl, 0, sizeof rl);
2848 int r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl);
2849 if (r == 0)
2850 max_limit = rl.rlim_max;
2851 #endif /* ACE_LACKS_RLIMIT */
2853 if (new_limit == -1)
2854 new_limit = max_limit;
2856 if (new_limit < 0)
2858 errno = EINVAL;
2859 return -1;
2861 else if (new_limit > cur_limit)
2863 // Increase the limit.
2864 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2865 rl.rlim_cur = new_limit;
2866 return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl);
2867 #elif !defined (RLIMIT_NOFILE)
2868 return 0;
2869 #else
2870 // Must return EINVAL errno.
2871 ACE_NOTSUP_RETURN (-1);
2872 #endif /* ACE_LACKS_RLIMIT */
2874 else if (increase_limit_only == 0)
2876 // Decrease the limit.
2877 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE)
2878 rl.rlim_cur = new_limit;
2879 return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl);
2880 #else
2881 // We give a chance to platforms without RLIMIT to work.
2882 // Instead of ACE_NOTSUP_RETURN (0), just return 0 because
2883 // new_limit is <= cur_limit, so it's a no-op.
2884 return 0;
2885 #endif /* ACE_LACKS_RLIMIT */
2888 return 0;
2891 /// Euclid's greatest common divisor algorithm.
2892 u_long
2893 ACE::gcd (u_long x, u_long y)
2895 while (y != 0)
2897 u_long r = x % y;
2898 x = y;
2899 y = r;
2902 return x;
2905 /// Calculates the minimum enclosing frame size for the given values.
2906 u_long
2907 ACE::minimum_frame_size (u_long period1, u_long period2)
2909 // if one of the periods is zero, treat it as though it as
2910 // uninitialized and return the other period as the frame size
2911 if (0 == period1)
2913 return period2;
2915 if (0 == period2)
2917 return period1;
2920 // if neither is zero, find the greatest common divisor of the two periods
2921 u_long greatest_common_divisor = ACE::gcd (period1, period2);
2923 // explicitly consider cases to reduce risk of possible overflow errors
2924 if (greatest_common_divisor == 1)
2926 // periods are relative primes: just multiply them together
2927 return period1 * period2;
2929 else if (greatest_common_divisor == period1)
2931 // the first period divides the second: return the second
2932 return period2;
2934 else if (greatest_common_divisor == period2)
2936 // the second period divides the first: return the first
2937 return period1;
2939 else
2941 // the current frame size and the entry's effective period
2942 // have a non-trivial greatest common divisor: return the
2943 // product of factors divided by those in their gcd.
2944 return (period1 * period2) / greatest_common_divisor;
2948 u_long
2949 ACE::is_prime (const u_long n,
2950 const u_long min_factor,
2951 const u_long max_factor)
2953 if (n > 3)
2954 for (u_long factor = min_factor;
2955 factor <= max_factor;
2956 ++factor)
2957 if (n / factor * factor == n)
2958 return factor;
2960 return 0;
2963 const ACE_TCHAR *
2964 ACE::sock_error (int error)
2966 #if defined (ACE_WIN32)
2967 static ACE_TCHAR unknown_msg[64];
2969 switch (error)
2971 case WSAVERNOTSUPPORTED:
2972 return ACE_TEXT ("version of WinSock not supported");
2973 /* NOTREACHED */
2974 case WSASYSNOTREADY:
2975 return ACE_TEXT ("WinSock not present or not responding");
2976 /* NOTREACHED */
2977 case WSAEINVAL:
2978 return ACE_TEXT ("app version not supported by DLL");
2979 /* NOTREACHED */
2980 case WSAHOST_NOT_FOUND:
2981 return ACE_TEXT ("Authoritive: Host not found");
2982 /* NOTREACHED */
2983 case WSATRY_AGAIN:
2984 return ACE_TEXT ("Non-authoritive: host not found or server failure");
2985 /* NOTREACHED */
2986 case WSANO_RECOVERY:
2987 return ACE_TEXT ("Non-recoverable: refused or not implemented");
2988 /* NOTREACHED */
2989 case WSANO_DATA:
2990 return ACE_TEXT ("Valid name, no data record for type");
2991 /* NOTREACHED */
2993 case WSANO_ADDRESS:
2994 return "Valid name, no MX record";
2996 case WSANOTINITIALISED:
2997 return ACE_TEXT ("WSA Startup not initialized");
2998 /* NOTREACHED */
2999 case WSAENETDOWN:
3000 return ACE_TEXT ("Network subsystem failed");
3001 /* NOTREACHED */
3002 case WSAEINPROGRESS:
3003 return ACE_TEXT ("Blocking operation in progress");
3004 /* NOTREACHED */
3005 case WSAEINTR:
3006 return ACE_TEXT ("Blocking call cancelled");
3007 /* NOTREACHED */
3008 case WSAEAFNOSUPPORT:
3009 return ACE_TEXT ("address family not supported");
3010 /* NOTREACHED */
3011 case WSAEMFILE:
3012 return ACE_TEXT ("no file handles available");
3013 /* NOTREACHED */
3014 case WSAENOBUFS:
3015 return ACE_TEXT ("no buffer space available");
3016 /* NOTREACHED */
3017 case WSAEPROTONOSUPPORT:
3018 return ACE_TEXT ("specified protocol not supported");
3019 /* NOTREACHED */
3020 case WSAEPROTOTYPE:
3021 return ACE_TEXT ("protocol wrong type for this socket");
3022 /* NOTREACHED */
3023 case WSAESOCKTNOSUPPORT:
3024 return ACE_TEXT ("socket type not supported for address family");
3025 /* NOTREACHED */
3026 case WSAENOTSOCK:
3027 return ACE_TEXT ("handle is not a socket");
3028 /* NOTREACHED */
3029 case WSAEWOULDBLOCK:
3030 return ACE_TEXT ("resource temporarily unavailable");
3031 /* NOTREACHED */
3032 case WSAEADDRINUSE:
3033 return ACE_TEXT ("address already in use");
3034 /* NOTREACHED */
3035 case WSAECONNABORTED:
3036 return ACE_TEXT ("connection aborted");
3037 /* NOTREACHED */
3038 case WSAECONNRESET:
3039 return ACE_TEXT ("connection reset");
3040 /* NOTREACHED */
3041 case WSAENOTCONN:
3042 return ACE_TEXT ("not connected");
3043 /* NOTREACHED */
3044 case WSAETIMEDOUT:
3045 return ACE_TEXT ("connection timed out");
3046 /* NOTREACHED */
3047 case WSAECONNREFUSED:
3048 return ACE_TEXT ("connection refused");
3049 /* NOTREACHED */
3050 case WSAEHOSTDOWN:
3051 return ACE_TEXT ("host down");
3052 /* NOTREACHED */
3053 case WSAEHOSTUNREACH:
3054 return ACE_TEXT ("host unreachable");
3055 /* NOTREACHED */
3056 case WSAEADDRNOTAVAIL:
3057 return ACE_TEXT ("address not available");
3058 /* NOTREACHED */
3059 case WSAEISCONN:
3060 return ACE_TEXT ("socket is already connected");
3061 /* NOTREACHED */
3062 case WSAENETRESET:
3063 return ACE_TEXT ("network dropped connection on reset");
3064 /* NOTREACHED */
3065 case WSAEMSGSIZE:
3066 return ACE_TEXT ("message too long");
3067 /* NOTREACHED */
3068 case WSAENETUNREACH:
3069 return ACE_TEXT ("network is unreachable");
3070 /* NOTREACHED */
3071 case WSAEFAULT:
3072 return ACE_TEXT ("bad address");
3073 /* NOTREACHED */
3074 case WSAEDISCON:
3075 return ACE_TEXT ("graceful shutdown in progress");
3076 /* NOTREACHED */
3077 case WSAEACCES:
3078 return ACE_TEXT ("permission denied");
3079 /* NOTREACHED */
3080 case WSAESHUTDOWN:
3081 return ACE_TEXT ("cannot send after socket shutdown");
3082 /* NOTREACHED */
3083 case WSAEPROCLIM:
3084 return ACE_TEXT ("too many processes");
3085 /* NOTREACHED */
3086 case WSAEALREADY:
3087 return ACE_TEXT ("operation already in progress");
3088 /* NOTREACHED */
3089 case WSAEPFNOSUPPORT:
3090 return ACE_TEXT ("protocol family not supported");
3091 /* NOTREACHED */
3092 case WSAENOPROTOOPT:
3093 return ACE_TEXT ("bad protocol option");
3094 /* NOTREACHED */
3095 case WSATYPE_NOT_FOUND:
3096 return ACE_TEXT ("class type not found");
3097 /* NOTREACHED */
3098 case WSAEOPNOTSUPP:
3099 return ACE_TEXT ("operation not supported");
3100 /* NOTREACHED */
3101 case WSAEDESTADDRREQ:
3102 return ACE_TEXT ("destination address required");
3103 /* NOTREACHED */
3104 default:
3105 ACE_OS::snprintf (unknown_msg,
3106 sizeof unknown_msg / sizeof unknown_msg[0],
3107 ACE_TEXT ("unknown error: %d"), error);
3108 return unknown_msg;
3109 /* NOTREACHED */
3111 #else
3112 ACE_UNUSED_ARG (error);
3113 ACE_NOTSUP_RETURN (0);
3114 #endif /* ACE_WIN32 */
3117 bool
3118 ACE::is_sock_error (int error)
3120 #if defined (ACE_WIN32)
3121 switch (error)
3123 case WSAVERNOTSUPPORTED:
3124 case WSASYSNOTREADY:
3125 case WSAEINVAL:
3126 case WSAHOST_NOT_FOUND:
3127 case WSATRY_AGAIN:
3128 case WSANO_RECOVERY:
3129 case WSANO_DATA:
3131 case WSANO_ADDRESS:
3133 case WSANOTINITIALISED:
3134 case WSAENETDOWN:
3135 case WSAEINPROGRESS:
3136 case WSAEINTR:
3137 case WSAEAFNOSUPPORT:
3138 case WSAEMFILE:
3139 case WSAENOBUFS:
3140 case WSAEPROTONOSUPPORT:
3141 case WSAEPROTOTYPE:
3142 case WSAESOCKTNOSUPPORT:
3143 case WSAENOTSOCK:
3144 case WSAEWOULDBLOCK:
3145 case WSAEADDRINUSE:
3146 case WSAECONNABORTED:
3147 case WSAECONNRESET:
3148 case WSAENOTCONN:
3149 case WSAETIMEDOUT:
3150 case WSAECONNREFUSED:
3151 case WSAEHOSTDOWN:
3152 case WSAEHOSTUNREACH:
3153 case WSAEADDRNOTAVAIL:
3154 case WSAEISCONN:
3155 case WSAENETRESET:
3156 case WSAEMSGSIZE:
3157 case WSAENETUNREACH:
3158 case WSAEFAULT:
3159 case WSAEDISCON:
3160 case WSAEACCES:
3161 case WSAESHUTDOWN:
3162 case WSAEPROCLIM:
3163 case WSAEALREADY:
3164 case WSAEPFNOSUPPORT:
3165 case WSAENOPROTOOPT:
3166 case WSATYPE_NOT_FOUND:
3167 case WSAEOPNOTSUPP:
3168 return true;
3170 #else
3171 ACE_UNUSED_ARG (error);
3172 #endif /* ACE_WIN32 */
3173 return false;
3176 char *
3177 ACE::strndup (const char *str, size_t n)
3179 const char *t = str;
3180 size_t len;
3182 // Figure out how long this string is (remember, it might not be
3183 // NUL-terminated).
3185 for (len = 0;
3186 len < n && *t++ != '\0';
3187 len++)
3188 continue;
3190 char *s;
3191 #if defined (ACE_HAS_ALLOC_HOOKS)
3192 ACE_ALLOCATOR_RETURN (s,
3193 (char *) ACE_Allocator::instance()->malloc (len + 1),
3195 #else
3196 ACE_ALLOCATOR_RETURN (s,
3197 (char *) ACE_OS::malloc (len + 1),
3199 #endif /* ACE_HAS_ALLOC_HOOKS */
3200 return ACE_OS::strsncpy (s, str, len + 1);
3203 #if defined (ACE_HAS_WCHAR)
3204 wchar_t *
3205 ACE::strndup (const wchar_t *str, size_t n)
3207 const wchar_t *t = str;
3208 size_t len;
3210 // Figure out how long this string is (remember, it might not be
3211 // NUL-terminated).
3213 for (len = 0;
3214 len < n && *t++ != '\0';
3215 len++)
3216 continue;
3218 size_t const size = (len + 1) * sizeof (wchar_t);
3219 wchar_t *s = 0;
3220 #if defined (ACE_HAS_ALLOC_HOOKS)
3221 ACE_ALLOCATOR_RETURN (s,
3222 static_cast<wchar_t*> (
3223 ACE_Allocator::instance ()->malloc (size)),
3225 #else
3226 ACE_ALLOCATOR_RETURN (s,
3227 static_cast<wchar_t*> (ACE_OS::malloc (size)),
3229 #endif /* ACE_HAS_ALLOC_HOOKS */
3230 return ACE_OS::strsncpy (s, str, len + 1);
3232 #endif /* ACE_HAS_WCHAR */
3234 char *
3235 ACE::strnnew (const char *str, size_t n)
3237 const char *t = str;
3238 size_t len;
3240 // Figure out how long this string is (remember, it might not be
3241 // NUL-terminated).
3243 for (len = 0;
3244 len < n && *t++ != L'\0';
3245 len++)
3246 continue;
3248 char *s;
3250 #if defined (ACE_HAS_ALLOC_HOOKS)
3251 ACE_ALLOCATOR_RETURN (s,
3252 static_cast<char*> (ACE_Allocator::instance ()->malloc (sizeof (char) * (len + 1))),
3254 #else
3255 ACE_NEW_RETURN (s,
3256 char[len + 1],
3258 #endif /* ACE_HAS_ALLOC_HOOKS */
3260 return ACE_OS::strsncpy (s, str, len + 1);
3263 #if defined (ACE_HAS_WCHAR)
3264 wchar_t *
3265 ACE::strnnew (const wchar_t *str, size_t n)
3267 const wchar_t *t = str;
3268 size_t len;
3270 // Figure out how long this string is (remember, it might not be
3271 // NUL-terminated).
3273 for (len = 0;
3274 len < n && *t++ != ACE_TEXT_WIDE ('\0');
3275 len++)
3276 continue;
3278 wchar_t *s;
3279 ACE_NEW_RETURN (s,
3280 wchar_t[len + 1],
3282 return ACE_OS::strsncpy (s, str, len + 1);
3284 #endif /* ACE_HAS_WCHAR */
3286 const char *
3287 ACE::strend (const char *s)
3289 while (*s++ != '\0')
3290 continue;
3292 return s;
3295 #if defined ACE_HAS_WCHAR
3296 const wchar_t *
3297 ACE::strend (const wchar_t *s)
3299 while (*s++ != ACE_TEXT_WIDE ('\0'))
3300 continue;
3302 return s;
3304 #endif
3306 char *
3307 ACE::strnew (const char *s)
3309 if (s == 0)
3310 return 0;
3311 char *t = 0;
3312 #if defined (ACE_HAS_ALLOC_HOOKS)
3313 ACE_ALLOCATOR_RETURN (t,
3314 static_cast<char*> (ACE_Allocator::instance ()->malloc (sizeof (char) * (ACE_OS::strlen (s) + 1))),
3316 #else
3317 ACE_NEW_RETURN (t,
3318 char [ACE_OS::strlen (s) + 1],
3320 #endif /* ACE_HAS_ALLOC_HOOKS */
3322 return ACE_OS::strcpy (t, s);
3325 #if defined (ACE_HAS_WCHAR)
3326 wchar_t *
3327 ACE::strnew (const wchar_t *s)
3329 if (s == 0)
3330 return 0;
3332 size_t const n = ACE_OS::strlen (s) + 1;
3333 wchar_t *t = 0;
3334 #if defined (ACE_HAS_ALLOC_HOOKS)
3335 ACE_ALLOCATOR_RETURN (t,
3336 static_cast<wchar_t*> (
3337 ACE_Allocator::instance ()->malloc (
3338 sizeof (wchar_t) * (n))),
3340 #else
3341 ACE_NEW_RETURN (t, wchar_t[n], 0);
3342 #endif /* ACE_HAS_ALLOC_HOOKS */
3344 return ACE_OS::strcpy (t, s);
3346 #endif /* ACE_HAS_WCHAR */
3348 // helper functions for ACE::wild_match()
3349 namespace
3351 inline bool equal_char (char a, char b, bool case_sensitive)
3353 if (case_sensitive)
3354 return a == b;
3355 return ACE_OS::ace_tolower (a) == ACE_OS::ace_tolower (b);
3358 // precond: *p == '[' start of char class
3359 // postcond: *p == ']' end of the char class
3360 inline bool equal_class (char s, const char *&p, bool case_sensitive)
3362 ++p;
3363 bool negate = false;
3364 if (*p == '!')
3366 negate = true;
3367 ++p;
3369 // ] and - are regular in 1st position
3370 for (bool first = true; *p && (first || *p != ']'); ++p)
3372 if (!first && *p == '-' && p[1] != ']')
3374 if (!p[1] || p[1] <= p[-1]) // invalid range
3376 continue;
3378 // Since we are in the POSIX locale, only the basic ASCII
3379 // characters are allowed as the range endpoints. These characters
3380 // are the same values in both signed and unsigned chars so we
3381 // don't have to account for any "pathological cases."
3382 for (char range = static_cast<char> (p[-1] + 1); range <= p[1]; ++range)
3384 if (equal_char (s, range, case_sensitive))
3386 while (*++p != ']') {}
3387 return !negate;
3390 ++p; // consume the character 1 past the -
3392 else if (equal_char (s, *p, case_sensitive))
3394 while (*++p != ']') {}
3395 return !negate;
3397 first = false;
3399 return negate;
3403 bool
3404 ACE::wild_match(const char *str, const char *pat, bool case_sensitive,
3405 bool character_classes)
3407 if (str == pat)
3408 return true;
3409 if (pat == 0 || str == 0)
3410 return false;
3412 bool star = false, escape = false;
3413 const char *s = str;
3414 const char *p = pat;
3415 while (*s != '\0')
3417 if (!escape && *p == '\\')
3419 ++p;
3420 escape = true;
3422 else if (!escape && *p == '*')
3424 star = true;
3425 pat = p;
3426 while (*++pat == '*') {}
3428 if (*pat == '\0')
3429 return true;
3430 p = pat;
3432 else if (!escape && *p == '?')
3434 ++s;
3435 ++p;
3437 else if (!escape && character_classes && *p == '[')
3439 if (equal_class (*s, p, case_sensitive))
3441 ++p;
3443 else
3445 if (!star)
3446 return false;
3447 p = pat;
3449 ++s;
3451 else if (!equal_char (*s, *p, case_sensitive))
3453 if (!star)
3454 return false;
3455 ++s;
3456 p = pat;
3457 escape = false;
3459 else
3461 ++s;
3462 ++p;
3463 escape = false;
3466 if (*p == '*')
3467 while (*++p == '*') {}
3469 return *p == '\0';
3472 // Close versioned namespace, if enabled by the user.
3473 ACE_END_VERSIONED_NAMESPACE_DECL