ACE.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  * @file    ACE.h
00006  *
00007  * $Id: ACE.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  * This file contains value added ACE functions that extend the
00010  * behavior of the UNIX and Win32 OS calls.
00011  *
00012  * All these ACE static functions are consolidated in a single place
00013  * in order to manage the namespace better.  These functions are put
00014  * here rather than in @c ACE_OS in order to separate concerns.
00015  *
00016  * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00017  */
00018 //=============================================================================
00019 
00020 #ifndef ACE_ACE_H
00021 #define ACE_ACE_H
00022 
00023 #include /**/ "ace/pre.h"
00024 
00025 #include "ace/config-lite.h"
00026 
00027 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00028 # pragma once
00029 #endif /* ACE_LACKS_PRAGMA_ONCE */
00030 
00031 #include "ace/OS_NS_math.h"
00032 #include "ace/Flag_Manip.h"
00033 #include "ace/Handle_Ops.h"
00034 #include "ace/Lib_Find.h"
00035 #include "ace/Init_ACE.h"
00036 #include "ace/Sock_Connect.h"
00037 #include "ace/Default_Constants.h"
00038 
00039 #if defined (ACE_EXPORT_MACRO)
00040 #  undef ACE_EXPORT_MACRO
00041 #endif
00042 #define ACE_EXPORT_MACRO ACE_Export
00043 
00044 // Open versioned namespace, if enabled by the user.
00045 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00046 
00047 // Forward declarations.
00048 class ACE_Time_Value;
00049 class ACE_Message_Block;
00050 class ACE_Handle_Set;
00051 
00052 /**
00053  * @namespace ACE
00054  *
00055  * @brief The namespace containing the ACE framework itself.
00056  *
00057  * The ACE namespace contains all types (classes, structures,
00058  * typedefs, etc), and global functions and variables in the ACE
00059  * framework.
00060  */
00061 namespace ACE
00062 {
00063   // = ACE version information.
00064   /// e.g., the "5" in ACE 5.1.12.
00065   extern ACE_Export u_int major_version (void);
00066 
00067   /// e.g., the "1" in ACE 5.1.12.
00068   extern ACE_Export u_int minor_version (void);
00069 
00070   /// e.g., the "12" in ACE 5.1.12.
00071   /// Returns 0 for "stable" (non-beta) releases.
00072   extern ACE_Export u_int beta_version (void);
00073 
00074   // = C++ compiler version information.
00075   /// E.g., the "SunPro C++" in SunPro C++ 4.32.0
00076   extern ACE_Export const ACE_TCHAR * compiler_name (void);
00077 
00078   /// E.g., the "4" in SunPro C++ 4.32.0
00079   extern ACE_Export u_int compiler_major_version (void);
00080 
00081   /// E.g., the "32" in SunPro C++ 4.32.0
00082   extern ACE_Export u_int compiler_minor_version (void);
00083 
00084   /// E.g., the "0" in SunPro C++ 4.32.0
00085   extern ACE_Export u_int compiler_beta_version (void);
00086 
00087   /// Check if error indicates the process being out of handles (file
00088   /// descriptors).
00089   extern ACE_Export int out_of_handles (int error);
00090 
00091   /// Simple wildcard matching function supporting '*' and '?'
00092   /// return true if string s matches pattern.
00093   extern ACE_Export bool wild_match(const char* s, const char* pattern, bool case_sensitive = true);
00094 
00095   /**
00096    * @name I/O operations
00097    *
00098    * Notes on common parameters:
00099    *
00100    * @a handle is the connected endpoint that will be used for I/O.
00101    *
00102    * @a buf is the buffer to write from or receive into.
00103    *
00104    * @a len is the number of bytes to transfer.
00105    *
00106    * The @a timeout parameter in the following methods indicates how
00107    * long to blocking trying to transfer data.  If @a timeout == 0,
00108    * then the call behaves as a normal send/recv call, i.e., for
00109    * blocking sockets, the call will block until action is possible;
00110    * for non-blocking sockets, @c EWOULDBLOCK will be returned if no
00111    * action is immediately possible.
00112    *
00113    * If @a timeout != 0, the call will wait until the relative time
00114    * specified in  @a *timeout elapses.
00115    *
00116    * The "_n()" I/O methods keep looping until all the data has been
00117    * transferred.  These methods also work for sockets in non-blocking
00118    * mode i.e., they keep looping on @c EWOULDBLOCK.  @a timeout is
00119    * used to make sure we keep making progress, i.e., the same timeout
00120    * value is used for every I/O operation in the loop and the timeout
00121    * is not counted down.
00122    *
00123    * The return values for the "*_n()" methods match the return values
00124    * from the non "_n()" methods and are specified as follows:
00125    *
00126    * - On complete transfer, the number of bytes transferred is returned.
00127    * - On timeout, -1 is returned, @c errno == @c ETIME.
00128    * - On error, -1 is returned, @c errno is set to appropriate error.
00129    * - On @c EOF, 0 is returned, @c errno is irrelevant.
00130    *
00131    * On partial transfers, i.e., if any data is transferred before
00132    * timeout / error / @c EOF, @a bytes_transferred> will contain the
00133    * number of bytes transferred.
00134    *
00135    * Methods with @a iovec parameter are I/O vector variants of the
00136    * I/O operations.
00137    *
00138    * Methods with the extra @a flags argument will always result in
00139    * @c send getting called. Methods without the extra @a flags
00140    * argument will result in @c send getting called on Win32
00141    * platforms, and @c write getting called on non-Win32 platforms.
00142    */
00143   //@{
00144   extern ACE_Export ssize_t recv (ACE_HANDLE handle,
00145                                   void *buf,
00146                                   size_t len,
00147                                   int flags,
00148                                   const ACE_Time_Value *timeout = 0);
00149 
00150 #if defined (ACE_HAS_TLI)
00151 
00152   extern ACE_Export ssize_t t_rcv (ACE_HANDLE handle,
00153                                    void *buf,
00154                                    size_t len,
00155                                    int *flags,
00156                                    const ACE_Time_Value *timeout = 0);
00157 
00158 #endif /* ACE_HAS_TLI */
00159 
00160   extern ACE_Export ssize_t recv (ACE_HANDLE handle,
00161                                   void *buf,
00162                                   size_t len,
00163                                   const ACE_Time_Value *timeout = 0);
00164 
00165   extern ACE_Export ssize_t recvmsg (ACE_HANDLE handle,
00166                                      struct msghdr *msg,
00167                                      int flags,
00168                                      const ACE_Time_Value *timeout = 0);
00169 
00170   extern ACE_Export ssize_t recvfrom (ACE_HANDLE handle,
00171                                       char *buf,
00172                                       int len,
00173                                       int flags,
00174                                       struct sockaddr *addr,
00175                                       int *addrlen,
00176                                       const ACE_Time_Value *timeout = 0);
00177 
00178   ACE_NAMESPACE_INLINE_FUNCTION
00179   ssize_t recv_n (ACE_HANDLE handle,
00180                   void *buf,
00181                   size_t len,
00182                   int flags,
00183                   const ACE_Time_Value *timeout = 0,
00184                   size_t *bytes_transferred = 0);
00185 
00186 #if defined (ACE_HAS_TLI)
00187 
00188   ACE_NAMESPACE_INLINE_FUNCTION
00189   ssize_t t_rcv_n (ACE_HANDLE handle,
00190                    void *buf,
00191                    size_t len,
00192                    int *flags,
00193                    const ACE_Time_Value *timeout = 0,
00194                    size_t *bytes_transferred = 0);
00195 
00196 #endif /* ACE_HAS_TLI */
00197 
00198   ACE_NAMESPACE_INLINE_FUNCTION
00199   ssize_t recv_n (ACE_HANDLE handle,
00200                   void *buf,
00201                   size_t len,
00202                   const ACE_Time_Value *timeout = 0,
00203                   size_t *bytes_transferred = 0);
00204 
00205   /// Receive into a variable number of pieces.
00206   /**
00207    * Accepts a variable, caller-specified, number of pointer/length
00208    * pairs. Arguments following @a n are char *, size_t pairs.
00209    *
00210    * @param handle The I/O handle to receive on
00211    * @param n      The total number of char *, size_t pairs following @a n.
00212    *
00213    * @return -1 on error, else total number of bytes received.
00214    */
00215   extern ACE_Export ssize_t recv (ACE_HANDLE handle, size_t n, ...);
00216 
00217   extern ACE_Export ssize_t recvv (ACE_HANDLE handle,
00218                                    iovec *iov,
00219                                    int iovcnt,
00220                                    const ACE_Time_Value *timeout = 0);
00221 
00222   ACE_NAMESPACE_INLINE_FUNCTION
00223   ssize_t recvv_n (ACE_HANDLE handle,
00224                    iovec *iov,
00225                    int iovcnt,
00226                    const ACE_Time_Value *timeout = 0,
00227                    size_t *bytes_transferred = 0);
00228 
00229   extern ACE_Export ssize_t recv_n (ACE_HANDLE handle,
00230                                     ACE_Message_Block *message_block,
00231                                     const ACE_Time_Value *timeout = 0,
00232                                     size_t *bytes_transferred = 0);
00233 
00234   extern ACE_Export ssize_t send (ACE_HANDLE handle,
00235                                   const void *buf,
00236                                   size_t len,
00237                                   int flags,
00238                                   const ACE_Time_Value *timeout = 0);
00239 
00240 #if defined (ACE_HAS_TLI)
00241 
00242   extern ACE_Export ssize_t t_snd (ACE_HANDLE handle,
00243                                    const void *buf,
00244                                    size_t len,
00245                                    int flags,
00246                                    const ACE_Time_Value *timeout = 0);
00247 
00248 #endif /* ACE_HAS_TLI */
00249 
00250   extern ACE_Export ssize_t send (ACE_HANDLE handle,
00251                                   const void *buf,
00252                                   size_t len,
00253                                   const ACE_Time_Value *timeout = 0);
00254 
00255   extern ACE_Export ssize_t sendmsg (ACE_HANDLE handle,
00256                                      const struct msghdr *msg,
00257                                      int flags,
00258                                      const ACE_Time_Value *timeout = 0);
00259 
00260   extern ACE_Export ssize_t sendto (ACE_HANDLE handle,
00261                                     const char *buf,
00262                                     int len,
00263                                     int flags,
00264                                     const struct sockaddr *addr,
00265                                     int addrlen,
00266                                     const ACE_Time_Value *timeout = 0);
00267 
00268   ACE_NAMESPACE_INLINE_FUNCTION
00269   ssize_t send_n (ACE_HANDLE handle,
00270                   const void *buf,
00271                   size_t len,
00272                   int flags,
00273                   const ACE_Time_Value *timeout = 0,
00274                   size_t *bytes_transferred = 0);
00275 
00276 #if defined (ACE_HAS_TLI)
00277 
00278   ACE_NAMESPACE_INLINE_FUNCTION
00279   ssize_t t_snd_n (ACE_HANDLE handle,
00280                    const void *buf,
00281                    size_t len,
00282                    int flags,
00283                    const ACE_Time_Value *timeout = 0,
00284                    size_t *bytes_transferred = 0);
00285 
00286 #endif /* ACE_HAS_TLI */
00287 
00288   ACE_NAMESPACE_INLINE_FUNCTION
00289   ssize_t send_n (ACE_HANDLE handle,
00290                   const void *buf,
00291                   size_t len,
00292                   const ACE_Time_Value *timeout = 0,
00293                   size_t *bytes_transferred = 0);
00294 
00295   /// Varargs variant.
00296   extern ACE_Export ssize_t send (ACE_HANDLE handle, size_t n, ...);
00297 
00298   extern ACE_Export ssize_t sendv (ACE_HANDLE handle,
00299                                    const iovec *iov,
00300                                    int iovcnt,
00301                                    const ACE_Time_Value *timeout = 0);
00302 
00303   ACE_NAMESPACE_INLINE_FUNCTION
00304   ssize_t sendv_n (ACE_HANDLE handle,
00305                    const iovec *iov,
00306                    int iovcnt,
00307                    const ACE_Time_Value *timeout = 0,
00308                    size_t *bytes_transferred = 0);
00309 
00310   /// Send all the @a message_blocks chained through their @c next and
00311   /// @c cont pointers.  This call uses the underlying OS gather-write
00312   /// operation to reduce the domain-crossing penalty.
00313   extern ACE_Export ssize_t send_n (ACE_HANDLE handle,
00314                                     const ACE_Message_Block *message_block,
00315                                     const ACE_Time_Value *timeout = 0,
00316                                     size_t *bytes_transferred = 0);
00317 
00318   // = File system I/O functions (these don't support timeouts).
00319 
00320   ACE_NAMESPACE_INLINE_FUNCTION
00321   ssize_t read_n (ACE_HANDLE handle,
00322                   void *buf,
00323                   size_t len,
00324                   size_t *bytes_transferred = 0);
00325 
00326   ACE_NAMESPACE_INLINE_FUNCTION
00327   ssize_t write_n (ACE_HANDLE handle,
00328                    const void *buf,
00329                    size_t len,
00330                    size_t *bytes_transferred = 0);
00331 
00332   /// Write all the @a message_blocks chained through their @c next
00333   /// and @c cont pointers.  This call uses the underlying OS
00334   /// gather-write operation to reduce the domain-crossing penalty.
00335   extern ACE_Export ssize_t write_n (ACE_HANDLE handle,
00336                                      const ACE_Message_Block *message_block,
00337                                      size_t *bytes_transferred = 0);
00338 
00339   extern ACE_Export ssize_t readv_n (ACE_HANDLE handle,
00340                                      iovec *iov,
00341                                      int iovcnt,
00342                                      size_t *bytes_transferred = 0);
00343 
00344   extern ACE_Export ssize_t writev_n (ACE_HANDLE handle,
00345                                       const iovec *iov,
00346                                       int iovcnt,
00347                                       size_t *bytes_transferred = 0);
00348   //@}
00349 
00350   /**
00351    * Wait up to @a timeout amount of time to passively establish a
00352    * connection.  This method doesn't perform the @c accept, it just
00353    * does the timed wait.
00354    */
00355   extern ACE_Export int handle_timed_accept (ACE_HANDLE listener,
00356                                              ACE_Time_Value *timeout,
00357                                              int restart);
00358 
00359   /**
00360    * Wait up to @a timeout amount of time to complete an actively
00361    * established non-blocking connection.  If @a is_tli is non-0 then
00362    * we are being called by a TLI wrapper (which behaves slightly
00363    * differently from a socket wrapper).
00364    */
00365   extern ACE_Export ACE_HANDLE handle_timed_complete (
00366     ACE_HANDLE listener,
00367     const ACE_Time_Value *timeout,
00368     int is_tli = 0);
00369 
00370   /**
00371    * Reset the limit on the number of open handles.  If @a new_limit
00372    * == -1 set the limit to the maximum allowable.  Otherwise, set
00373    * the limit value to @a new_limit.  If @a increase_limit_only is
00374    * non-0 then only allow increases to the limit.
00375    */
00376   extern ACE_Export int set_handle_limit (int new_limit = -1,
00377                                           int increase_limit_only = 0);
00378 
00379   /**
00380    * Returns the maximum number of open handles currently permitted in
00381    * this process.  This maximum may be extended using
00382    * @c ACE::set_handle_limit.
00383    */
00384   extern ACE_Export int max_handles (void);
00385 
00386   // = String functions
00387 #if !defined (ACE_HAS_WINCE)
00388   /**
00389    * Return a dynamically allocated duplicate of @a str, substituting
00390    * the environment variable if @c str[0] @c == @c '$'.  Note that
00391    * the pointer is allocated with @c ACE_OS::malloc and must be freed
00392    * by @c ACE_OS::free.
00393    */
00394   extern ACE_Export ACE_TCHAR *strenvdup (const ACE_TCHAR *str);
00395 #endif /* ACE_HAS_WINCE */
00396 
00397   /// Returns a pointer to the "end" of the string, i.e., the character
00398   /// past the '\0'.
00399   extern ACE_Export const char *strend (const char *s);
00400 
00401   /// This method is just like @c strdup, except that it uses
00402   /// @c operator @c new rather than @c malloc.  If @a s is NULL
00403   /// returns NULL rather than segfaulting.
00404   extern ACE_Export char *strnew (const char *s);
00405 
00406   /// Delete the memory allocated by @c strnew.
00407   ACE_NAMESPACE_INLINE_FUNCTION void strdelete (char *s);
00408 
00409   /// Create a fresh new copy of @a str, up to @a n chars long.  Uses
00410   /// @c ACE_OS::malloc to allocate the new string.
00411   extern ACE_Export char *strndup (const char *str, size_t n);
00412 
00413   /// Create a fresh new copy of @a str, up to @a n chars long.  Uses
00414   /// @c ACE_OS::malloc to allocate the new string.
00415   extern ACE_Export char *strnnew (const char *str, size_t n);
00416 
00417 #if defined (ACE_HAS_WCHAR)
00418   extern ACE_Export const wchar_t *strend (const wchar_t *s);
00419 
00420   extern ACE_Export wchar_t *strnew (const wchar_t *s);
00421 
00422   ACE_NAMESPACE_INLINE_FUNCTION void strdelete (wchar_t *s);
00423 
00424   extern ACE_Export wchar_t *strndup (const wchar_t *str, size_t n);
00425 
00426   extern ACE_Export wchar_t *strnnew (const wchar_t *str, size_t n);
00427 
00428 #endif /* ACE_HAS_WCHAR */
00429 
00430   /**
00431    * On Windows, determines if a specified pathname ends with ".exe"
00432    * (not case sensitive). If on Windows and there is no ".exe" suffix,
00433    * a new ACE_TCHAR array is allocated and a copy of @c pathname with
00434    * the ".exe" suffix is copied into it. In this case, the caller is
00435    * responsible for calling delete [] on the returned pointer.
00436    *
00437    * @param pathname  The name to check for a proper suffix.
00438    *
00439    * @retval @c pathname if there is a proper suffix for Windows. This is
00440    *         always the return value for non-Windows platforms.
00441    * @retval If a suffix needs to be added, returns a pointer to new[]
00442    *         allocated memory containing the original @c pathname plus
00443    *         a ".exe" suffix. The caller is responsible for freeing the
00444    *         memory using delete [].
00445    */
00446   extern ACE_Export const ACE_TCHAR *execname (const ACE_TCHAR *pathname);
00447 
00448   /**
00449    * Returns the "basename" of a @a pathname separated by @a delim.
00450    * For instance, the basename of "/tmp/foo.cpp" is "foo.cpp" when
00451    * @a delim is @a '/'.
00452    */
00453   extern ACE_Export const ACE_TCHAR *basename (const ACE_TCHAR *pathname,
00454                                                ACE_TCHAR delim =
00455                                                ACE_DIRECTORY_SEPARATOR_CHAR);
00456 
00457   /**
00458    * Returns the "dirname" of a @a pathname.  For instance, the
00459    * dirname of "/tmp/foo.cpp" is "/tmp" when @a delim is @a '/'.  If
00460    * @a pathname has no @a delim ".\0" is returned.  This method does
00461    * not modify @a pathname and is not reentrant.
00462    */
00463   extern ACE_Export const ACE_TCHAR *dirname (const ACE_TCHAR *pathname,
00464                                               ACE_TCHAR delim =
00465                                               ACE_DIRECTORY_SEPARATOR_CHAR);
00466 
00467   /**
00468    * Returns the current timestamp in the form
00469    * "hour:minute:second:microsecond."  The month, day, and year are
00470    * also stored in the beginning of the @a date_and_time array, which
00471    * is a user-supplied array of size @a time_len> @c ACE_TCHARs.
00472    * Returns 0 if unsuccessful, else returns pointer to beginning of the
00473    * "time" portion of @a date_and_time.  If @a
00474    * return_pointer_to_first_digit is 0 then return a pointer to the
00475    * space before the time, else return a pointer to the beginning of
00476    * the time portion.
00477    */
00478   extern ACE_Export ACE_TCHAR *timestamp (ACE_TCHAR date_and_time[],
00479                                           int time_len,
00480                                           int return_pointer_to_first_digit =
00481                                             0);
00482 
00483   /**
00484    * if @a avoid_zombies == 0 call @c ACE_OS::fork directly, else
00485    * create an orphan process that's inherited by the init process;
00486    * init cleans up when the orphan process terminates so we don't
00487    * create zombies.  Returns -1 on failure and either the child PID
00488    * on success if @a avoid_zombies == 0 or 1 on success if @a
00489    * avoid_zombies != 0 (this latter behavior is a known bug that
00490    * needs to be fixed).
00491    */
00492   extern ACE_Export pid_t fork (
00493     const ACE_TCHAR *program_name = ACE_TEXT ("<unknown>"),
00494     int avoid_zombies = 0);
00495 
00496   /**
00497    * Become a daemon process using the algorithm in Richard Stevens
00498    * "Advanced Programming in the UNIX Environment."  If
00499    * @a close_all_handles is non-zero then all open file handles are
00500    * closed.
00501    */
00502   extern ACE_Export int daemonize (
00503     const ACE_TCHAR pathname[] = ACE_TEXT ("/"),
00504     bool close_all_handles = ACE_DEFAULT_CLOSE_ALL_HANDLES,
00505     const ACE_TCHAR program_name[] = ACE_TEXT ("<unknown>"));
00506 
00507   // = Miscellaneous functions.
00508   /// Rounds the request to a multiple of the page size.
00509   extern ACE_Export size_t round_to_pagesize (size_t len);
00510 
00511   /// Rounds the request to a multiple of the allocation granularity.
00512   extern ACE_Export size_t round_to_allocation_granularity (size_t len);
00513 
00514   // @@ UNICODE what about buffer?
00515   /// Format buffer into printable format.  This is useful for
00516   /// debugging.
00517   extern ACE_Export size_t format_hexdump (const char *buffer, size_t size,
00518                                            ACE_TCHAR *obuf, size_t obuf_sz);
00519 
00520   /// Computes the hash value of {str} using the "Hash PJW" routine.
00521   extern ACE_Export u_long hash_pjw (const char *str);
00522 
00523   /// Computes the hash value of {str} using the "Hash PJW" routine.
00524   extern ACE_Export u_long hash_pjw (const char *str, size_t len);
00525 
00526 #if defined (ACE_HAS_WCHAR)
00527   /// Computes the hash value of {str} using the "Hash PJW" routine.
00528   extern ACE_Export u_long hash_pjw (const wchar_t *str);
00529 
00530   /// Computes the hash value of {str} using the "Hash PJW" routine.
00531   extern ACE_Export u_long hash_pjw (const wchar_t *str, size_t len);
00532 #endif /* ACE_HAS_WCHAR */
00533 
00534   /// Computes CRC-CCITT for the string.
00535   extern ACE_Export ACE_UINT16 crc_ccitt(const char *str);
00536 
00537   /// Computes CRC-CCITT for the buffer.
00538   extern ACE_Export ACE_UINT16 crc_ccitt(const void *buf, size_t len,
00539            ACE_UINT16 crc = 0);
00540 
00541   /// Computes CRC-CCITT for the @ len iovec buffers.
00542   extern ACE_Export ACE_UINT16 crc_ccitt(const iovec *iov, int len,
00543            ACE_UINT16 crc = 0);
00544 
00545   /// Computes the ISO 8802-3 standard 32 bits CRC for the string.
00546   extern ACE_Export ACE_UINT32 crc32 (const char *str);
00547 
00548   /// Computes the ISO 8802-3 standard 32 bits CRC for the buffer.
00549   extern ACE_Export ACE_UINT32 crc32 (const void *buf, size_t len,
00550               ACE_UINT32 crc = 0);
00551 
00552   /// Computes the ISO 8802-3 standard 32 bits CRC for the
00553   /// @ len iovec buffers.
00554   extern ACE_Export ACE_UINT32 crc32 (const iovec *iov, int len,
00555               ACE_UINT32 crc = 0);
00556 
00557   /// Euclid's greatest common divisor algorithm.
00558   extern ACE_Export u_long gcd (u_long x, u_long y);
00559 
00560   /// Calculates the minimum enclosing frame size for the given values.
00561   extern ACE_Export u_long minimum_frame_size (u_long period1, u_long period2);
00562 
00563   /**
00564    * Function that can burn up noticeable CPU time:  brute-force
00565    * determination of whether number @a n is prime.  Returns 0 if
00566    * it is prime, or the smallest factor if it is not prime.
00567    * @a min_factor and @a max_factor can be used to partition the work
00568    * among threads. For just one thread, typical values are 2 and
00569    * n/2.
00570    */
00571   extern ACE_Export u_long is_prime (const u_long n,
00572                                      const u_long min_factor,
00573                                      const u_long max_factor);
00574 
00575   /// Map troublesome win32 errno values to values that standard C
00576   /// strerr function understands.  Thank you Microsoft.
00577   extern ACE_Export int map_errno (int error);
00578 
00579   /// Returns a string containing the error message corresponding to a
00580   /// WinSock error.  This works around an omission in the Win32 API.
00581   /// @internal
00582   extern ACE_Export const ACE_TCHAR * sock_error (int error);
00583 
00584   /// Determins whether the given error code corresponds to to a
00585   /// WinSock error. If so returns true, false otherwise.
00586   /// @internal
00587   extern ACE_Export bool is_sock_error (int error);
00588 
00589   /**
00590    * Checks if process with {pid} is still alive.  Returns 1 if it is
00591    * still alive, 0 if it isn't alive, and -1 if something weird
00592    * happened.
00593    */
00594   extern ACE_Export int process_active (pid_t pid);
00595 
00596   /**
00597    * Terminate the process abruptly with id @a pid.  On Win32 platforms
00598    * this uses {TerminateProcess} and on POSIX platforms is uses
00599    * {kill} with the -9 (SIGKILL) signal, which cannot be caught or
00600    * ignored.  Note that this call is potentially dangerous to use
00601    * since the process being terminated may not have a chance to
00602    * cleanup before it shuts down.
00603    */
00604   extern ACE_Export int terminate_process (pid_t pid);
00605 
00606   /**
00607    * This method uses process id and object pointer to come up with a
00608    * machine wide unique name.  The process ID will provide uniqueness
00609    * between processes on the same machine. The "this" pointer of the
00610    * {object} will provide uniqueness between other "live" objects in
00611    * the same process. The uniqueness of this name is therefore only
00612    * valid for the life of {object}.
00613    */
00614   ACE_NAMESPACE_INLINE_FUNCTION void unique_name (const void *object,
00615                                                   ACE_TCHAR *name,
00616                                                   size_t length);
00617 
00618   /// Computes the base 2 logarithm of {num}.
00619   ACE_NAMESPACE_INLINE_FUNCTION u_long log2 (u_long num);
00620 
00621   /// Hex conversion utility.
00622   ACE_NAMESPACE_INLINE_FUNCTION ACE_TCHAR nibble2hex (u_int n);
00623 
00624   /// Convert a hex character to its byte representation.
00625   ACE_NAMESPACE_INLINE_FUNCTION u_char hex2byte (ACE_TCHAR c);
00626 
00627   // = Set/get the debug level.
00628   extern ACE_Export bool debug (void);
00629   extern ACE_Export void debug (bool onoff);
00630 
00631   /// Wrapper facade for @c select that uses @c ACE_Handle_Sets.
00632   extern ACE_Export int select (int width,
00633                                 ACE_Handle_Set *readfds,
00634                                 ACE_Handle_Set *writefds = 0,
00635                                 ACE_Handle_Set *exceptfds = 0,
00636                                 const ACE_Time_Value *timeout = 0);
00637 
00638   /// Wrapper facade for the most common use of @c select that uses
00639   /// @c ACE_Handle_Sets.
00640   extern ACE_Export int select (int width,
00641                                 ACE_Handle_Set &readfds,
00642                                 const ACE_Time_Value *timeout = 0);
00643 
00644   /// Timed wait for handle to get read ready.
00645   ACE_NAMESPACE_INLINE_FUNCTION
00646   int handle_read_ready (ACE_HANDLE handle,
00647                          const ACE_Time_Value *timeout);
00648 
00649   /// Timed wait for handle to get write ready.
00650   ACE_NAMESPACE_INLINE_FUNCTION
00651   int handle_write_ready (ACE_HANDLE handle,
00652                           const ACE_Time_Value *timeout);
00653 
00654   /// Timed wait for handle to get exception ready.
00655   ACE_NAMESPACE_INLINE_FUNCTION
00656   int handle_exception_ready (ACE_HANDLE handle,
00657                               const ACE_Time_Value *timeout);
00658 
00659   /// Timed wait for handle to get read, write, or exception ready.
00660   extern ACE_Export int handle_ready (ACE_HANDLE handle,
00661                                       const ACE_Time_Value *timeout,
00662                                       int read_ready,
00663                                       int write_ready,
00664                                       int exception_ready);
00665 
00666   /// Wait for @a timeout before proceeding to a @c recv operation.
00667   /// @a val keeps track of whether we're in non-blocking mode or
00668   /// not.
00669   extern ACE_Export int enter_recv_timedwait (ACE_HANDLE handle,
00670                                               const ACE_Time_Value *timeout,
00671                                               int &val);
00672 
00673   /// Wait for @a timeout before proceeding to a @c send operation.
00674   /// @a val keeps track of whether we're in non-blocking mode or
00675   /// not.
00676   extern ACE_Export int enter_send_timedwait (ACE_HANDLE handle,
00677                                               const ACE_Time_Value* timeout,
00678                                               int &val);
00679 
00680   /// This makes sure that @a handle is set into non-blocking mode.
00681   /// @a val keeps track of whether were in non-blocking mode or not.
00682   extern ACE_Export void record_and_set_non_blocking_mode (ACE_HANDLE handle,
00683                                                            int &val);
00684 
00685   /// Cleanup after a timed operation, restore the appropriate
00686   /// non-blocking status of @a handle.
00687   extern ACE_Export void restore_non_blocking_mode (ACE_HANDLE handle,
00688                                                     int val);
00689 
00690   // private:
00691   //   These functions aren't meant to be used internally, so they are
00692   //   not exported.
00693 
00694   //
00695   // = Recv_n helpers
00696   //
00697 
00698   ACE_NAMESPACE_INLINE_FUNCTION ssize_t recv_i (ACE_HANDLE handle,
00699                                                 void *buf,
00700                                                 size_t len);
00701 
00702   extern ACE_Export ssize_t recv_n_i (ACE_HANDLE handle,
00703                                       void *buf,
00704                                       size_t len,
00705                                       int flags,
00706                                       size_t *bytes_transferred);
00707 
00708   extern ACE_Export ssize_t recv_n_i (ACE_HANDLE handle,
00709                                       void *buf,
00710                                       size_t len,
00711                                       int flags,
00712                                       const ACE_Time_Value *timeout,
00713                                       size_t *bytes_transferred);
00714 
00715 #if defined (ACE_HAS_TLI)
00716 
00717   extern ACE_Export ssize_t t_rcv_n_i (ACE_HANDLE handle,
00718                                        void *buf,
00719                                        size_t len,
00720                                        int *flags,
00721                                        size_t *bytes_transferred);
00722 
00723   extern ACE_Export ssize_t t_rcv_n_i (ACE_HANDLE handle,
00724                                        void *buf,
00725                                        size_t len,
00726                                        int *flags,
00727                                        const ACE_Time_Value *timeout,
00728                                        size_t *bytes_transferred);
00729 
00730 #endif /* ACE_HAS_TLI */
00731 
00732   extern ACE_Export ssize_t recv_n_i (ACE_HANDLE handle,
00733                                       void *buf,
00734                                       size_t len,
00735                                       size_t *bytes_transferred);
00736 
00737   extern ACE_Export ssize_t recv_n_i (ACE_HANDLE handle,
00738                                       void *buf,
00739                                       size_t len,
00740                                       const ACE_Time_Value *timeout,
00741                                       size_t *bytes_transferred);
00742 
00743   extern ACE_Export ssize_t recvv_n_i (ACE_HANDLE handle,
00744                                        iovec *iov,
00745                                        int iovcnt,
00746                                        size_t *bytes_transferred);
00747 
00748   extern ACE_Export ssize_t recvv_n_i (ACE_HANDLE handle,
00749                                        iovec *iov,
00750                                        int iovcnt,
00751                                        const ACE_Time_Value *timeout,
00752                                        size_t *bytes_transferred);
00753 
00754   //
00755   // = Send_n helpers
00756   //
00757 
00758   ACE_NAMESPACE_INLINE_FUNCTION ssize_t send_i (ACE_HANDLE handle,
00759                                                 const void *buf,
00760                                                 size_t len);
00761 
00762   extern ACE_Export ssize_t send_n_i (ACE_HANDLE handle,
00763                                       const void *buf,
00764                                       size_t len,
00765                                       int flags,
00766                                       size_t *bytes_transferred);
00767 
00768   extern ACE_Export ssize_t send_n_i (ACE_HANDLE handle,
00769                                       const void *buf,
00770                                       size_t len,
00771                                       int flags,
00772                                       const ACE_Time_Value *timeout,
00773                                       size_t *bytes_transferred);
00774 
00775 #if defined (ACE_HAS_TLI)
00776 
00777   extern ACE_Export ssize_t t_snd_n_i (ACE_HANDLE handle,
00778                                        const void *buf,
00779                                        size_t len,
00780                                        int flags,
00781                                        size_t *bytes_transferred);
00782 
00783   extern ACE_Export ssize_t t_snd_n_i (ACE_HANDLE handle,
00784                                        const void *buf,
00785                                        size_t len,
00786                                        int flags,
00787                                        const ACE_Time_Value *timeout,
00788                                        size_t *bytes_transferred);
00789 
00790 #endif /* ACE_HAS_TLI */
00791 
00792   extern ACE_Export ssize_t send_n_i (ACE_HANDLE handle,
00793                                       const void *buf,
00794                                       size_t len,
00795                                       size_t *bytes_transferred);
00796 
00797   extern ACE_Export ssize_t send_n_i (ACE_HANDLE handle,
00798                                       const void *buf,
00799                                       size_t len,
00800                                       const ACE_Time_Value *timeout,
00801                                       size_t *bytes_transferred);
00802 
00803   extern ACE_Export ssize_t sendv_n_i (ACE_HANDLE handle,
00804                                        const iovec *iov,
00805                                        int iovcnt,
00806                                        size_t *bytes_transferred);
00807 
00808   extern ACE_Export ssize_t sendv_n_i (ACE_HANDLE handle,
00809                                        const iovec *iov,
00810                                        int iovcnt,
00811                                        const ACE_Time_Value *timeout,
00812                                        size_t *bytes_transferred);
00813 
00814 }
00815 
00816 // Close versioned namespace, if enabled by the user.
00817 ACE_END_VERSIONED_NAMESPACE_DECL
00818 
00819 #if defined (__ACE_INLINE__)
00820 #include "ace/ACE.inl"
00821 #endif /* __ACE_INLINE__ */
00822 
00823 #include /**/ "ace/post.h"
00824 
00825 #endif  /* ACE_ACE_H */

Generated on Tue Feb 2 17:18:38 2010 for ACE by  doxygen 1.4.7