NAME

ACE - Contains value added ACE methods that extend the behavior of the UNIX and Win32 OS calls.

SYNOPSIS

#include <ace/ACE.h>

class ACE { public: static int init (void); static int fini (void); static u_int major_version (void); static u_int minor_version (void); static u_int beta_version (void); static const char* compiler_name (void); static u_int compiler_major_version (void); static u_int compiler_minor_version (void); static u_int compiler_beta_version (void); static int out_of_handles (int error); static ssize_t recv ( ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout = 0 ); static ssize_t recv ( ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout = 0 ); static ssize_t recvmsg ( ACE_HANDLE handle, struct msghdr *msg, int flags, const ACE_Time_Value *timeout = 0 ); static ssize_t recvfrom ( ACE_HANDLE handle, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen, const ACE_Time_Value *timeout = 0 ); static ssize_t recv_n ( ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout = 0 ); static ssize_t recv_n ( ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout = 0 ); static ssize_t recv (ACE_HANDLE handle, size_t n, ...); static ssize_t recvv ( ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout = 0 ); static ssize_t recvv_n ( ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout = 0 ); static ssize_t recv_n ( ACE_HANDLE handle, ACE_Message_Block *message_block, const ACE_Time_Value *timeout = 0 ); static ssize_t send ( ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout = 0 ); static ssize_t send ( ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout = 0 ); static ssize_t sendmsg ( ACE_HANDLE handle, const struct msghdr *msg, int flags, const ACE_Time_Value *timeout = 0 ); static ssize_t sendto ( ACE_HANDLE handle, const char *buf, int len, int flags, const struct sockaddr *addr, int addrlen, const ACE_Time_Value *timeout = 0 ); static ssize_t send_n ( ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout = 0 ); static ssize_t send_n ( ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout = 0 ); static ssize_t send (ACE_HANDLE handle, size_t n, ...); static ssize_t sendv ( ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout = 0 ); static ssize_t sendv_n ( ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout = 0 ); static ssize_t send_n ( ACE_HANDLE handle, const ACE_Message_Block *message_block, const ACE_Time_Value *timeout = 0 ); static ssize_t read_n (ACE_HANDLE handle, void *buf, size_t len); static ssize_t write_n ( ACE_HANDLE handle, const void *buf, size_t len ); static ssize_t readv_n ( ACE_HANDLE handle, iovec *iov, int iovcnt ); static ssize_t writev_n ( ACE_HANDLE handle, const iovec *iov, int iovcnt ); static int bind_port ( ACE_HANDLE handle, ACE_UINT32 ip_addr = INADDR_ANY ); static int get_bcast_addr ( ACE_UINT32 &bcast_addr, const char *hostname = 0, ACE_UINT32 host_addr = 0, ACE_HANDLE handle = ACE_INVALID_HANDLE ); static int get_ip_interfaces ( size_t &count, ACE_INET_Addr *&addr_array ); static int count_interfaces (ACE_HANDLE handle, size_t &how_many); static ACE_HANDLE get_handle (void); static int handle_timed_accept ( ACE_HANDLE listener, ACE_Time_Value *timeout, int restart ); static ACE_HANDLE handle_timed_complete ( ACE_HANDLE listener, ACE_Time_Value *timeout, int is_tli = 0 ); static ACE_HANDLE handle_timed_open ( ACE_Time_Value *timeout, LPCTSTR name, int flags, int perms ); static int set_flags (ACE_HANDLE handle, int flags); static int clr_flags (ACE_HANDLE handle, int flags); static int get_flags (ACE_HANDLE handle); static int set_handle_limit (int new_limit = -1); static int max_handles (void); static ASYS_TCHAR *strenvdup (const ASYS_TCHAR *str); static char *strecpy (char *des, const char *src); static const char *strend (const char *); static char *strnew (const char *s); static wchar_t *strnew (const wchar_t *s); static char *strndup (const char *str, size_t n); static char *strnnew (const char *str, size_t n); static char *strsplit_r ( char *s, const char *token, char *&next_start ); static size_t strrepl (char *s, char search, char replace); static const char *execname (const char *pathname); static const char *basename ( const char *pathname, char delim = ACE_DIRECTORY_SEPARATOR_CHAR_A ); static const char *dirname ( const char *pathname, char delim = ACE_DIRECTORY_SEPARATOR_CHAR_A ); static wchar_t *strecpy (wchar_t *s, const wchar_t *t); static wchar_t *strsplit_r ( wchar_t *s, const wchar_t *token, wchar_t *&next_start ); static size_t strrepl ( wchar_t *s, wchar_t search, wchar_t replace ); static const wchar_t *execname (const wchar_t *pathname); static const wchar_t *basename ( const wchar_t *pathname, wchar_t delim = ACE_DIRECTORY_SEPARATOR_CHAR_W ); static ASYS_TCHAR *timestamp ( ASYS_TCHAR date_and_time[], int time_len ); static pid_t fork ( const char *program_name = "<unknown>", int avoid_zombies = 0 ); static int daemonize ( const char pathname[] = "/", int close_all_handles = ACE_DEFAULT_CLOSE_ALL_HANDLES, const char program_name[] = "<unknown>" ); static int ldfind ( const ASYS_TCHAR *filename, ASYS_TCHAR *pathname, size_t maxlen ); static FILE *ldopen ( const ASYS_TCHAR *filename, const ASYS_TCHAR *type ); static int get_temp_dir (char *buffer, size_t buffer_len); static int get_temp_dir (wchar_t *buffer, size_t buffer_len); static ACE_HANDLE open_temp_file ( const char *name, int mode, int perm = 0 ); static size_t round_to_pagesize (off_t length); static size_t round_to_allocation_granularity (off_t len); static int format_hexdump ( const char *buffer, int size, ASYS_TCHAR *obuf, int obuf_sz ); static u_long hash_pjw (const char *str); static u_long hash_pjw (const char *str, size_t len); static u_long hash_pjw (const wchar_t *str); static u_long hash_pjw (const wchar_t *str, size_t len); static u_long hash_pjw (const ACE_USHORT16 *str); static u_long hash_pjw (const ACE_USHORT16 *str, size_t len); static u_long crc32 (const char *str); static u_long crc32 (const char *buf, ACE_UINT32 len); static u_long gcd (u_long x, u_long y); static u_long minimum_frame_size (u_long period1, u_long period2); static u_long is_prime ( const u_long n, const u_long min_factor, const u_long max_factor ); static int map_errno (int error); static const ASYS_TCHAR *sock_error (int error); static int process_active (pid_t pid); static int terminate_process (pid_t pid); static void unique_name ( const void *object, LPTSTR name, size_t length ); static u_long log2 (u_long num); static char nibble2hex (u_int n); static u_char hex2byte (char c); static char debug (void); static void debug (char d); static int handle_read_ready ( ACE_HANDLE handle, const ACE_Time_Value *timeout ); static int handle_write_ready ( ACE_HANDLE handle, const ACE_Time_Value *timeout ); static int handle_exception_ready ( ACE_HANDLE handle, const ACE_Time_Value *timeout ); static int handle_ready ( ACE_HANDLE handle, const ACE_Time_Value *timeout, int read_ready, int write_ready, int exception_ready ); static int enter_recv_timedwait ( ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val ); static int enter_send_timedwait ( ACE_HANDLE handle, const ACE_Time_Value* timeout, int &val ); static void record_and_set_non_blocking_mode ( ACE_HANDLE handle, int &val ); static void restore_non_blocking_mode ( ACE_HANDLE handle, int val ); private: ACE_CLASS_IS_NAMESPACE (ACE); = Recv_n helpers static ssize_t recv_i ( ACE_HANDLE handle, void *buf, size_t len ); static ssize_t recv_n_i ( ACE_HANDLE handle, void *buf, size_t len, int flags ); static ssize_t recv_n_i ( ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout ); static ssize_t recv_n_i ( ACE_HANDLE handle, void *buf, size_t len ); static ssize_t recv_n_i ( ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout ); static ssize_t recvv_n_i ( ACE_HANDLE handle, iovec *iov, int iovcnt ); static ssize_t recvv_n_i ( ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout ); = Send_n helpers static ssize_t send_i ( ACE_HANDLE handle, const void *buf, size_t len ); static ssize_t send_n_i ( ACE_HANDLE handle, const void *buf, size_t len, int flags ); static ssize_t send_n_i ( ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout ); static ssize_t send_n_i ( ACE_HANDLE handle, const void *buf, size_t len ); static ssize_t send_n_i ( ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout ); static ssize_t sendv_n_i ( ACE_HANDLE handle, const iovec *iov, int iovcnt ); static ssize_t sendv_n_i ( ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout ); static u_int init_fini_count_; static size_t pagesize_; static size_t allocation_granularity_; static u_long crc_table_[]; static const char hex_chars_[]; static char debug_; };

DESCRIPTION

This class consolidates all these ACE static methods in a single place in order to manage the namespace better. These methods are put here rather than in ACE_OS in order to separate concerns.

ACE version information.

static u_int major_version (void);

static u_int minor_version (void);

static u_int beta_version (void);

C++ compiler version information.

static const char* compiler_name (void);

static u_int compiler_major_version (void);

static u_int compiler_minor_version (void);

static u_int compiler_beta_version (void);

static int out_of_handles (int error);

I/O operations.

Notes on common parameters:

handle is the connected endpoint that will be used for I/O.

buf is the buffer to write from or receive into.

len is the number of bytes to transfer.

The timeout parameter in the following methods indicates how long to blocking trying to transfer data. If timeout == 0, then the call behaves as a normal send/recv call, i.e., for blocking sockets, the call will block until action is possible; for non-blocking sockets, EWOULDBLOCK will be returned if no action is immediately possible.

If timeout != 0, the call will wait until the relative time specified in *timeout elapses.

Errors are reported by -1 and 0 return values. If the operation times out, -1 is returned with errno == ETIME. If it succeeds the number of bytes transferred is returned.

The "_n" I/O methods keep looping until all the data has been transferred. These methods also work for sockets in non-blocking mode i.e., they keep looping on EWOULDBLOCK. timeout is used to make sure we keep making progress, i.e., the same timeout value is used for every I/O operation in the loop and the timeout is not counted down. If the transfer times out, the number of bytes transferred so far are returned.

Methods with iovec parameter are I/O vector variants of the I/O operations.

static ssize_t recv (
    ACE_HANDLE handle,
    void *buf,
    size_t len,
    int flags,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t recv (
    ACE_HANDLE handle,
    void *buf,
    size_t len,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t recvmsg (
    ACE_HANDLE handle,
    struct msghdr *msg,
    int flags,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t recvfrom (
    ACE_HANDLE handle,
    char *buf,
    int len,
    int flags,
    struct sockaddr *addr,
    int *addrlen,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t recv_n (
    ACE_HANDLE handle,
    void *buf,
    size_t len,
    int flags,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t recv_n (
    ACE_HANDLE handle,
    void *buf,
    size_t len,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t recv (ACE_HANDLE handle, size_t n, ...);

static ssize_t recvv (
    ACE_HANDLE handle,
    iovec *iov,
    int iovcnt,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t recvv_n (
    ACE_HANDLE handle,
    iovec *iov,
    int iovcnt,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t recv_n (
    ACE_HANDLE handle,
    ACE_Message_Block *message_block,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t send (
    ACE_HANDLE handle,
    const void *buf,
    size_t len,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t send (
    ACE_HANDLE handle,
    const void *buf,
    size_t len,
    int flags,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t sendmsg (
    ACE_HANDLE handle,
    const struct msghdr *msg,
    int flags,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t sendto (
    ACE_HANDLE handle,
    const char *buf,
    int len,
    int flags,
    const struct sockaddr *addr,
    int addrlen,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t send_n (
    ACE_HANDLE handle,
    const void *buf,
    size_t len,
    int flags,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t send_n (
    ACE_HANDLE handle,
    const void *buf,
    size_t len,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t send (ACE_HANDLE handle, size_t n, ...);

static ssize_t sendv (
    ACE_HANDLE handle,
    const iovec *iov,
    int iovcnt,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t sendv_n (
    ACE_HANDLE handle,
    const iovec *iov,
    int iovcnt,
    const ACE_Time_Value *timeout = 0
    );

static ssize_t send_n (
    ACE_HANDLE handle,
    const ACE_Message_Block *message_block,
    const ACE_Time_Value *timeout = 0
    );

File system I/O functions (these don't support timeouts).

static ssize_t read_n (ACE_HANDLE handle, void *buf, size_t len);

static ssize_t write_n (
    ACE_HANDLE handle,
    const void *buf,
    size_t len
    );

static ssize_t readv_n (ACE_HANDLE handle, iovec *iov, int iovcnt);

static ssize_t writev_n (
    ACE_HANDLE handle,
    const iovec *iov,
    int iovcnt
    );

Socket connection establishment calls.

static int bind_port (
    ACE_HANDLE handle,
    ACE_UINT32 ip_addr = INADDR_ANY
    );

static int get_bcast_addr (
    ACE_UINT32 &bcast_addr,
    const char *hostname = 0,
    ACE_UINT32 host_addr = 0,
    ACE_HANDLE handle = ACE_INVALID_HANDLE
    );

static int get_ip_interfaces (
    size_t &count,
    ACE_INET_Addr *&addr_array
    );

static int count_interfaces (ACE_HANDLE handle, size_t &how_many);

static ACE_HANDLE get_handle (void);

static int handle_timed_accept (
    ACE_HANDLE listener,
    ACE_Time_Value *timeout,
    int restart
    );

static ACE_HANDLE handle_timed_complete (
    ACE_HANDLE listener,
    ACE_Time_Value *timeout,
    int is_tli = 0
    );

Operations on HANDLEs.

static ACE_HANDLE handle_timed_open (
    ACE_Time_Value *timeout,
    LPCTSTR name,
    int flags,
    int perms
    );

Set/get/clear various flags related to I/O HANDLE.

static int set_flags (ACE_HANDLE handle, int flags);

static int clr_flags (ACE_HANDLE handle, int flags);

static int get_flags (ACE_HANDLE handle);

static int set_handle_limit (int new_limit = -1);

static int max_handles (void);

String functions

static ASYS_TCHAR *strenvdup (const ASYS_TCHAR *str);

static char *strecpy (char *des, const char *src);

static const char *strend (const char *);

static char *strnew (const char *s);

static wchar_t *strnew (const wchar_t *s);

static char *strndup (const char *str, size_t n);

static char *strnnew (const char *str, size_t n);

static char *strsplit_r (
    char *s,
    const char *token,
    char *&next_start
    );

static size_t strrepl (char *s, char search, char replace);

static const char *execname (const char *pathname);

static const char *basename (
    const char *pathname,
    char delim = ACE_DIRECTORY_SEPARATOR_CHAR_A
    );

static const char *dirname (
    const char *pathname,
    char delim = ACE_DIRECTORY_SEPARATOR_CHAR_A
    );

A collection of wide string functions. See above for details.

static wchar_t *strecpy (wchar_t *s, const wchar_t *t);

static wchar_t *strsplit_r (
    wchar_t *s,
    const wchar_t *token,
    wchar_t *&next_start
    );

static size_t strrepl (wchar_t *s, wchar_t search, wchar_t replace);

static const wchar_t *execname (const wchar_t *pathname);

static const wchar_t *basename (
    const wchar_t *pathname,
    wchar_t delim = ACE_DIRECTORY_SEPARATOR_CHAR_W
    );

static ASYS_TCHAR *timestamp (
    ASYS_TCHAR date_and_time[],
    int time_len
    );

static pid_t fork (
    const char *program_name = "<unknown>",
    int avoid_zombies = 0
    );

static int daemonize (
    const char pathname[] = "/",
    int close_all_handles = ACE_DEFAULT_CLOSE_ALL_HANDLES,
    const char program_name[] = "<unknown>"
    );

Methods for searching and opening shared libraries.

static int ldfind (
    const ASYS_TCHAR *filename,
    ASYS_TCHAR *pathname,
    size_t maxlen
    );

static FILE *ldopen (
    const ASYS_TCHAR *filename,
    const ASYS_TCHAR *type
    );

static int get_temp_dir (char *buffer, size_t buffer_len);

static int get_temp_dir (wchar_t *buffer, size_t buffer_len);

static ACE_HANDLE open_temp_file (
    const char *name,
    int mode,
    int perm = 0
    );

Shield us from Win32's inability to select on STDIN.

Miscelleous functions.

static size_t round_to_pagesize (off_t length);

static size_t round_to_allocation_granularity (off_t len);

static int format_hexdump (
    const char *buffer,
    int size,
    ASYS_TCHAR *obuf,
    int obuf_sz
    );

static u_long hash_pjw (const char *str);

static u_long hash_pjw (const char *str, size_t len);

static u_long hash_pjw (const wchar_t *str);

static u_long hash_pjw (const wchar_t *str, size_t len);

static u_long hash_pjw (const ACE_USHORT16 *str);

static u_long hash_pjw (const ACE_USHORT16 *str, size_t len);

static u_long crc32 (const char *str);

static u_long crc32 (const char *buf, ACE_UINT32 len);

static u_long gcd (u_long x, u_long y);

static u_long minimum_frame_size (u_long period1, u_long period2);

static u_long is_prime (
    const u_long n,
    const u_long min_factor,
    const u_long max_factor
    );

static int map_errno (int error);

static const ASYS_TCHAR *sock_error (int error);

static int process_active (pid_t pid);

static int terminate_process (pid_t pid);

static void unique_name (
    const void *object,
    LPTSTR name,
    size_t length
    );

static u_long log2 (u_long num);

static char nibble2hex (u_int n);

static u_char hex2byte (char c);

Set/get the debug level.

static char debug (void);

static void debug (char d);

static int handle_read_ready (
    ACE_HANDLE handle,
    const ACE_Time_Value *timeout
    );

static int handle_write_ready (
    ACE_HANDLE handle,
    const ACE_Time_Value *timeout
    );

static int handle_exception_ready (
    ACE_HANDLE handle,
    const ACE_Time_Value *timeout
    );

static int handle_ready (
    ACE_HANDLE handle,
    const ACE_Time_Value *timeout,
    int read_ready,
    int write_ready,
    int exception_ready
    );

static int enter_recv_timedwait (
    ACE_HANDLE handle,
    const ACE_Time_Value *timeout,
    int &val
    );

static int enter_send_timedwait (
    ACE_HANDLE handle,
    const ACE_Time_Value* timeout,
    int &val
    );

static void record_and_set_non_blocking_mode (
    ACE_HANDLE handle,
    int &val
    );

static void restore_non_blocking_mode (ACE_HANDLE handle, int val);

AUTHOR

Doug Schmidt

LIBRARY

ace