/* -*- C++ -*- */ // ============================================================================ // // = LIBRARY // ace // // = FILENAME // OS.h // // = AUTHOR // Doug Schmidt , Jesper S. M|ller // , and a cast of thousands... // // ============================================================================ #if !defined (ACE_OS_H) #define ACE_OS_H // This file should be a link to the platform/compiler-specific // configuration file (e.g., config-sunos5-sunc++-4.x.h). #include "ace/config.h" #if defined (ACE_HAS_4_4BSD_SENDMSG_RECVMSG) // control message size to pass a file descriptor #define ACE_BSD_CONTROL_MSG_LEN sizeof (struct cmsghdr) + sizeof (ACE_HANDLE) #endif /* ACE_HAS_4_4BSD_SENDMSG_RECVMSG */ // Define the default constants for ACE. Many of these are used for // the ACE tests and applications. You can change these values by // defining the macros in your config.h file. #if !defined (ACE_DEFAULT_TIMEOUT) #define ACE_DEFAULT_TIMEOUT 5 #endif /* ACE_DEFAULT_TIMEOUT */ #if !defined (ACE_DEFAULT_THREADS) #define ACE_DEFAULT_THREADS 1 #endif /* ACE_DEFAULT_THREADS */ // The following 3 defines are used in the IP multicast and broadcast tests. #if !defined (ACE_DEFAULT_BROADCAST_PORT) #define ACE_DEFAULT_BROADCAST_PORT 10000 #endif /* ACE_DEFAULT_BROADCAST_PORT */ #if !defined (ACE_DEFAULT_MULTICAST_PORT) #define ACE_DEFAULT_MULTICAST_PORT 10001 #endif /* ACE_DEFAULT_MULTICAST_PORT */ #if !defined (ACE_DEFAULT_MULTICAST_ADDR) #define ACE_DEFAULT_MULTICAST_ADDR "224.9.9.2" #endif /* ACE_DEFAULT_MULTICAST_ADDR */ // Default port number for HTTP. #if !defined (ACE_DEFAULT_HTTP_SERVER_PORT) #define ACE_DEFAULT_HTTP_SERVER_PORT 80 #endif /* ACE_DEFAULT_HTTP_SERVER_PORT */ // Used in many IPC_SAP tests #if !defined (ACE_DEFAULT_SERVER_PORT) #define ACE_DEFAULT_SERVER_PORT 10002 #endif /* ACE_DEFAULT_SERVER_PORT */ // Used in Acceptor tests #if !defined (ACE_DEFAULT_SERVER_PORT_STR) #define ACE_DEFAULT_SERVER_PORT_STR "10002" #endif /* ACE_DEFAULT_SERVER_PORT_STR */ // Used for the Service_Directory test #if !defined (ACE_DEFAULT_SERVICE_PORT) #define ACE_DEFAULT_SERVICE_PORT 10003 #endif /* ACE_DEFAULT_SERVICE_PORT */ // Used for the ACE_Thread_Spawn test #if !defined (ACE_DEFAULT_THR_PORT ) #define ACE_DEFAULT_THR_PORT 10004 #endif /* ACE_DEFAULT_THR_PORT */ // Used for SOCK_Connect::connect() tests #if !defined (ACE_DEFAULT_LOCAL_PORT) #define ACE_DEFAULT_LOCAL_PORT 10005 #endif /* ACE_DEFAULT_LOCAL_PORT */ // Used for Connector tests #if !defined (ACE_DEFAULT_LOCAL_PORT_STR) #define ACE_DEFAULT_LOCAL_PORT_STR "10005" #endif /* ACE_DEFAULT_LOCAL_PORT_STR */ // Used for the name server. #if !defined (ACE_DEFAULT_NAME_SERVER_PORT) #define ACE_DEFAULT_NAME_SERVER_PORT 10006 #endif /* ACE_DEFAULT_NAME_SERVER_PORT */ #if !defined (ACE_DEFAULT_NAME_SERVER_PORT_STR) #define ACE_DEFAULT_NAME_SERVER_PORT_STR "10006" #endif /* ACE_DEFAULT_NAME_SERVER_PORT_STR */ // Used for the token server. #if !defined (ACE_DEFAULT_TOKEN_SERVER_PORT) #define ACE_DEFAULT_TOKEN_SERVER_PORT 10007 #endif /* ACE_DEFAULT_TOKEN_SERVER_PORT */ #if !defined (ACE_DEFAULT_TOKEN_SERVER_PORT_STR) #define ACE_DEFAULT_TOKEN_SERVER_PORT_STR "10007" #endif /* ACE_DEFAULT_TOKEN_SERVER_PORT_STR */ // Used for the logging server. #if !defined (ACE_DEFAULT_LOGGING_SERVER_PORT) #define ACE_DEFAULT_LOGGING_SERVER_PORT 10008 #endif /* ACE_DEFAULT_LOGGING_SERVER_PORT */ #if !defined (ACE_DEFAULT_LOGGING_SERVER_PORT_STR) #define ACE_DEFAULT_LOGGING_SERVER_PORT_STR "10008" #endif /* ACE_DEFAULT_LOGGING_SERVER_PORT_STR */ // Used for the logging server. #if !defined (ACE_DEFAULT_THR_LOGGING_SERVER_PORT) #define ACE_DEFAULT_THR_LOGGING_SERVER_PORT 10008 #endif /* ACE_DEFAULT_THR_LOGGING_SERVER_PORT */ #if !defined (ACE_DEFAULT_THR_LOGGING_SERVER_PORT_STR) #define ACE_DEFAULT_THR_LOGGING_SERVER_PORT_STR "10008" #endif /* ACE_DEFAULT_THR_LOGGING_SERVER_PORT_STR */ // Used for the gateway server. #if !defined (ACE_DEFAULT_GATEWAY_SERVER_PORT) #define ACE_DEFAULT_GATEWAY_SERVER_PORT 10009 #endif /* ACE_DEFAULT_GATEWAY_SERVER_PORT */ #if !defined (ACE_DEFAULT_GATEWAY_SERVER_PORT_STR) #define ACE_DEFAULT_GATEWAY_SERVER_PORT_STR "10009" #endif /* ACE_DEFAULT_GATEWAY_SERVER_PORT_STR */ // Used for the peer server. #if !defined (ACE_DEFAULT_PEER_SERVER_PORT) #define ACE_DEFAULT_PEER_SERVER_PORT 10010 #endif /* ACE_DEFAULT_PEER_SERVER_PORT */ #if !defined (ACE_DEFAULT_PEER_SERVER_PORT_STR) #define ACE_DEFAULT_PEER_SERVER_PORT_STR "10010" #endif /* ACE_DEFAULT_PEER_SERVER_PORT_STR */ // Used for the time server. #if !defined (ACE_DEFAULT_TIME_SERVER_PORT) #define ACE_DEFAULT_TIME_SERVER_PORT 10011 #endif /* ACE_DEFAULT_TIME_SERVER_PORT */ #if !defined (ACE_DEFAULT_TIME_SERVER_PORT_STR) #define ACE_DEFAULT_TIME_SERVER_PORT_STR "10011" #endif /* ACE_DEFAULT_TIME_SERVER_PORT_STR */ #if !defined (ACE_DEFAULT_TIME_SERVER_STR) #define ACE_DEFAULT_TIME_SERVER_STR "ACE_TS_TIME" #endif /* ACE_DEFAULT_TIME_SERVER_STR */ #if !defined (ACE_DEFAULT_SERVER_HOST) #define ACE_DEFAULT_SERVER_HOST "localhost" #endif /* ACE_DEFAULT_SERVER_HOST */ // Default shared memory key #if !defined (ACE_DEFAULT_SHM_KEY) #define ACE_DEFAULT_SHM_KEY 1234 #endif /* ACE_DEFAULT_SHM_KEY */ // Default segment size used by SYSV shared memory (128 K) #if !defined (ACE_DEFAULT_SEGMENT_SIZE) #define ACE_DEFAULT_SEGMENT_SIZE 1024 * 128 #endif /* ACE_DEFAULT_SEGMENT_SIZE */ // Maximum number of SYSV shared memory segments // (does anyone know how to figure out the right values?!) #if !defined (ACE_DEFAULT_MAX_SEGMENTS) #define ACE_DEFAULT_MAX_SEGMENTS 6 #endif /* ACE_DEFAULT_MAX_SEGMENTS */ // Used by the FIFO tests. #if !defined (ACE_DEFAULT_RENDEZVOUS) #define ACE_DEFAULT_RENDEZVOUS "/tmp/fifo.ace" #endif /* ACE_DEFAULT_RENDEZVOUS */ // Name of the map that's stored in shared memory. #if !defined (ACE_NAME_SERVER_MAP) #define ACE_NAME_SERVER_MAP "Name Server Map" #endif /* ACE_NAME_SERVER_MAP */ // Default file permissions. #if !defined (ACE_DEFAULT_FILE_PERMS) #define ACE_DEFAULT_FILE_PERMS 0666 #endif /* ACE_DEFAULT_FILE_PERMS */ // Default directory permissions. #if !defined (ACE_DEFAULT_DIR_PERMS) #define ACE_DEFAULT_DIR_PERMS 0777 #endif /* ACE_DEFAULT_DIR_PERMS */ // Default size of the ACE Reactor. #if !defined (ACE_DEFAULT_REACTOR_SIZE) #define ACE_DEFAULT_REACTOR_SIZE FD_SETSIZE #endif /* ACE_DEFAULT_REACTOR_SIZE */ // Default size of the ACE Map_Manager. #if !defined (ACE_DEFAULT_MAP_SIZE) #define ACE_DEFAULT_MAP_SIZE 1024 #endif /* ACE_DEFAULT_MAP_SIZE */ // Defaults for ACE Timer Wheel #if !defined (ACE_DEFAULT_TIMER_WHEEL_SIZE) #define ACE_DEFAULT_TIMER_WHEEL_SIZE 1024 #endif /* ACE_DEFAULT_TIMER_WHEEL_SIZE */ #if !defined (ACE_DEFAULT_TIMER_WHEEL_RESOLUTION) #define ACE_DEFAULT_TIMER_WHEEL_RESOLUTION 100 #endif /* ACE_DEFAULT_TIMER_WHEEL_RESOLUTION */ // Default size for ACE Timer Hash table #if !defined (ACE_DEFAULT_TIMER_HASH_TABLE_SIZE) #define ACE_DEFAULT_TIMER_HASH_TABLE_SIZE 1024 #endif /* ACE_DEFAULT_TIMER_HASH_TABLE_SIZE */ // Defaults for the ACE Free List #if !defined (ACE_DEFAULT_FREE_LIST_PREALLOC) #define ACE_DEFAULT_FREE_LIST_PREALLOC 0 #endif /* ACE_DEFAULT_FREE_LIST_PREALLOC */ #if !defined (ACE_DEFAULT_FREE_LIST_LWM) #define ACE_DEFAULT_FREE_LIST_LWM 0 #endif /* ACE_DEFAULT_FREE_LIST_LWM */ #if !defined (ACE_DEFAULT_FREE_LIST_HWM) #define ACE_DEFAULT_FREE_LIST_HWM 25000 #endif /* ACE_DEFAULT_FREE_LIST_HWM */ #if !defined (ACE_DEFAULT_FREE_LIST_INC) #define ACE_DEFAULT_FREE_LIST_INC 100 #endif /* ACE_DEFAULT_FREE_LIST_INC */ // Here are all ACE-specific global declarations needed throughout // ACE. // Helpful dump macros. #define ACE_BEGIN_DUMP "\n====\n(%P|%t|%x)" #define ACE_END_DUMP "====\n" // This is used to indicate that a platform doesn't support a // particular feature. #define ACE_NOTSUP_RETURN(FAILVALUE) do { errno = ENOTSUP ; return FAILVALUE; } while (0) #if defined (ACE_NDEBUG) #define ACE_DB(X) #else #define ACE_DB(X) X #endif /* ACE_NDEBUG */ // ACE_NO_HEAP_CHECK macro can be used to suppress false report of // memory leaks. It turns off the built-in heap checking until the // block is left. The old state will then be restored Only used for // Win32 (in the moment). #if defined (ACE_WIN32) #if defined (_DEBUG) class ACE_No_Heap_Check { public: ACE_No_Heap_Check (void) : old_state (_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG)) { _CrtSetDbgFlag (old_state & ~_CRTDBG_ALLOC_MEM_DF);} ~ACE_No_Heap_Check (void) { _CrtSetDbgFlag (old_state);} private: int old_state; }; #define ACE_NO_HEAP_CHECK ACE_No_Heap_Check ____no_heap; #else /* !_DEBUG*/ #define ACE_NO_HEAP_CHECK #endif /* _DEBUG*/ #else /* !ACE_WIN32 */ #define ACE_NO_HEAP_CHECK #endif /* ACE_WIN32 */ // Increase the range of "address families". #define AF_SPIPE (AF_MAX + 1) #define AF_FILE (AF_MAX + 2) #define AF_DEV (AF_MAX + 3) #define AF_UPIPE (AF_SPIPE) // Turn a number into a string. #define ACE_ITOA(X) #X // Create a string of a server address with a "host:port" format. #define ACE_SERVER_ADDRESS(H,P) H":"P // A couple useful inline functions for checking whether bits are // enabled or disabled. // Efficiently returns the least power of two >= X... #define ACE_POW(X) ((!X)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X))) #define ACE_EVEN(NUM) (((NUM) & 1) == 0) #define ACE_ODD(NUM) (((NUM) & 1) == 1) #define ACE_BIT_ENABLED(WORD, BIT) (((WORD) & (BIT)) != 0) #define ACE_BIT_DISABLED(WORD, BIT) (((WORD) & (BIT)) == 0) #define ACE_SET_BITS(WORD, BITS) (WORD |= (BITS)) #define ACE_CLR_BITS(WORD, BITS) (WORD &= ~(BITS)) #define ACE_MAX(x,y) (((x)>(y))?(x):(y)) #define ACE_MIN(x,y) (((x)<(y))?(x):(y)) // keep the compiler from complaining of // parameters which are not used. #if defined (ghs) // GreenHills C++ 1.8.8 complains that the (a) expression has no effect. But, // it doesn't complain about unused args, so don't bother with them. #define ACE_UNUSED_ARG(a) #elif defined (__GNUC__) || defined (__sgi) || defined (__hpux) // Some compilers complain about "statement with no effect" with (a). // This eliminates the warnings, and no code is generated for the null // conditional statement. #define ACE_UNUSED_ARG(a) {if (&a) /* null */ ;} #else #define ACE_UNUSED_ARG(a) (a) #endif /* ghs */ // These hooks enable ACE to have all dynamic memory management // automatically handled on a per-object basis. #if defined (ACE_HAS_ALLOC_HOOKS) #define ACE_ALLOC_HOOK_DECLARE \ void *operator new (size_t bytes); \ void operator delete (void *ptr); // Note that these are just place holders for now. They'll // be replaced by the ACE_Malloc stuff shortly... #define ACE_ALLOC_HOOK_DEFINE(CLASS) \ void *CLASS::operator new (size_t bytes) { return ::new char[bytes]; } \ void CLASS::operator delete (void *ptr) { delete (ptr); } #else #define ACE_ALLOC_HOOK_DECLARE struct __Ace {} /* Just need a dummy... */ #define ACE_ALLOC_HOOK_DEFINE(CLASS) #endif /* ACE_HAS_ALLOC_HOOKS */ #if defined (ACE_LACKS_KEY_T) #if defined (ACE_WIN32) // Win32 doesn't use numeric values to name its semaphores, it uses // strings! typedef char *key_t; #else typedef int key_t; #endif /* ACE_WIN32 */ #endif /* ACE_LACKS_KEY_T */ #if defined (VXWORKS) // GreenHills 1.8.8 needs the stdarg.h #include before #include of vxWorks.h. // Also, be sure that these #includes come _after_ the key_t typedef, and // before the #include of time.h. #include /**/ #include /**/ #if defined (__GNUC__) // This horrible hack works around a problem with the that // is distributed with Tornado 1.0.1/VxWorks 5.3.1. Some of the prototypes // in that file "conflicts with [their] built-in declaration" in g++ 2.7.2. // They use size_t, but the built-in declarations apparently use unsigned // long. So, temporarily #define size_t to be u_long. #define size_t u_long #include /**/ #undef size_t // At this point, size_t reverts to its original: // typedef unsigned int size_t; #endif /* __GNUC__ */ #endif /* VXWORKS */ #if defined (ACE_HAS_CHARPTR_SPRINTF) #define ACE_SPRINTF_ADAPTER(X) ::strlen (X) #else #define ACE_SPRINTF_ADAPTER(X) X #endif /* ACE_HAS_CHARPTR_SPRINTF */ #if defined (__ACE_INLINE__) #define ACE_INLINE inline #if !defined (ACE_HAS_INLINED_OSCALLS) #define ACE_HAS_INLINED_OSCALLS #endif /* !ACE_HAS_INLINED_OSCALLS */ #else #define ACE_INLINE #endif /* __ACE_INLINE__ */ // Default address for shared memory mapped files and SYSV shared memory // (defaults to 64 M). #if !defined (ACE_DEFAULT_BASE_ADDR) #define ACE_DEFAULT_BASE_ADDR ((char *) (64 * 1024 * 1024)) #endif /* ACE_DEFAULT_BASE_ADDR */ // This fudge factor can be overriden for timers that need it, such as on // Solaris, by defining the ACE_TIMER_SKEW symbol in the appropriate config // header. #if !defined (ACE_TIMER_SKEW) #define ACE_TIMER_SKEW 0 #endif /* ACE_TIMER_SKEW */ // Nasty macro stuff to account for Microsoft Win32 DLL nonsense. We // use these macros so that we don't end up with ACE software // hard-coded to Microsoft proprietary extensions to C++. #if defined (ACE_HAS_DLL) #if defined (ACE_BUILD_DLL) #if !defined (_MSC_VER) /* Mark classes as exported, Borland. */ #define ACE_Export _export #else /* Microsoft: */ #define ACE_Export __declspec (dllexport) #endif /* !_MSC_VER */ #else /* Using the DLL. */ #if !defined _MSC_VER #define ACE_Export _import #else #define ACE_Export __declspec (dllimport) #endif /* !_MSC_VER */ #endif /* ACE_BUILD_DLL */ #else /* We're not building a DLL! */ #define ACE_Export #endif /* ACE_HAS_DLL */ #if defined (ACE_HAS_SVC_DLL) #if defined (ACE_BUILD_SVC_DLL) #if !defined (_MSC_VER) /* Mark classes as exported, Borland. */ #define ACE_Svc_Export _export #else /* Microsoft: */ #define ACE_Svc_Export __declspec (dllexport) #endif /* !_MSC_VER */ #else /* Using the DLL. */ #if !defined _MSC_VER #define ACE_Svc_Export _import #else #define ACE_Svc_Export __declspec (dllimport) #endif /* !_MSC_VER */ #endif /* ACE_BUILD_DLL || ACE_BUILD_SVC_DLL */ #else /* We're not building a DLL! */ #define ACE_Svc_Export #endif /* ACE_HAS_SVC_DLL */ // This needs to go here *first* to avoid problems with AIX. // Just to be safe we'll do it with pthreads, too -- jwr #if defined (ACE_HAS_DCETHREADS) || defined (ACE_HAS_PTHREADS) extern "C" { #include /**/ #if defined (DIGITAL_UNIX) #define pthread_self __pthread_self extern "C" pthread_t pthread_self (void); #endif /* DIGITAL_UNIX */ } #endif /* ACE_HAS_DCETHREADS */ #if (ACE_NTRACE == 1) #define ACE_TRACE(X) #else #define ACE_TRACE(X) ACE_Trace ____ (X, __LINE__, __FILE__) #endif /* ACE_NTRACE */ #include /**/ #if defined (ACE_NEEDS_SYSTIME_H) // Some platforms may need to include this, but I suspect that most // will get it from #if defined (VXWORKS) #include /**/ #else #include /**/ #endif /* VXWORKS */ #endif /* ACE_NEEDS_SYSTIME_H */ #if !defined (ACE_HAS_POSIX_TIME) // Definition per POSIX. typedef struct timespec { time_t tv_sec; // Seconds long tv_nsec; // Nanoseconds } timespec_t; #elif defined (ACE_HAS_BROKEN_POSIX_TIME) // OSF/1 defines struct timespec in - Tom Marrs #include /**/ #endif /* !ACE_HAS_POSIX_TIME */ #if !defined (ACE_HAS_CLOCK_GETTIME) && !defined (_CLOCKID_T) typedef int clockid_t; #if !defined (CLOCK_REALTIME) #define CLOCK_REALTIME 0 #endif /* CLOCK_REALTIME */ #endif /* ! ACE_HAS_CLOCK_GETTIME && ! _CLOCKID_T */ // #if (!defined (timespec) && !defined (m88k)) // #define timestruc_t struct timespec // #endif /* timespec */ #if !defined (ACE_HAS_SVR4_TIME) // Definition per SVr4. typedef struct timespec timestruc_t; #endif /* ACE_HAS_SVR4_TIME */ class ACE_Export ACE_Time_Value // = TITLE // Operations on "timeval" structures. // // = DESCRIPTION // This class centralizes all the time-related processing in // ACE. These timers are typically used in conjunction with // lower-level OS mechanisms like