#include <ace/ACE.h>
class ACE {
public:
static u_int major_version (void);
static u_int minor_version (void);
static u_int beta_version (void);
static ssize_t recv ( ACE_HANDLE handle, void *buf, size_t len, int flags );
static ssize_t recv (ACE_HANDLE handle, void *buf, size_t len);
static ssize_t recv_n ( ACE_HANDLE handle, void *buf, size_t len, int flags );
static ssize_t recv_n (ACE_HANDLE handle, void *buf, size_t len);
static ssize_t recv ( ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout );
static ssize_t recv ( ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout );
static ssize_t recvmsg ( ACE_HANDLE handle, struct msghdr *msg, int flags, const ACE_Time_Value *timeout );
static ssize_t recvfrom ( ACE_HANDLE handle, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen, const ACE_Time_Value *timeout );
static ssize_t recv_n ( ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout );
static ssize_t send ( ACE_HANDLE handle, const void *buf, size_t len, int flags );
static ssize_t send ( ACE_HANDLE handle, const void *buf, size_t len );
static ssize_t send_n ( ACE_HANDLE handle, const void *buf, size_t len, int flags );
static ssize_t send_n ( ACE_HANDLE handle, const void *buf, size_t len );
static ssize_t send ( ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout );
static ssize_t send ( ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout );
static ssize_t sendmsg ( ACE_HANDLE handle, const struct msghdr *msg, int flags, const ACE_Time_Value *timeout );
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 );
static ssize_t send_n ( ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout );
static ssize_t writev ( ACE_HANDLE handle, const struct iovec* iov, int iovcnt, const ACE_Time_Value *timeout );
static ssize_t readv ( ACE_HANDLE handle, struct iovec *iov, int iovcnt, const ACE_Time_Value *timeout );
static ssize_t send (ACE_HANDLE handle, size_t n, ...);
static ssize_t recv (ACE_HANDLE handle, size_t n, ...);
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 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 char *strenvdup (const char *str);
static char *strecpy (char *s, const char *t);
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);
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 );
static ASYS_TCHAR *timestamp ( ASYS_TCHAR date_and_time[], int time_len );
static int daemonize ( const char pathname[] = "/", int close_all_handles = ACE_DEFAULT_CLOSE_ALL_HANDLES );
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 void *read_adapter (void *event_handler);
static int register_stdin_handler ( ACE_Event_Handler *eh, ACE_Reactor *reactor, ACE_Thread_Manager *thr_mgr, int flags = THR_DETACHED );
static int remove_stdin_handler ( ACE_Reactor *reactor, ACE_Thread_Manager *thr_mgr );
static size_t round_to_pagesize (off_t length);
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 ACE_USHORT16 *str);
static u_long crc32 (const char* str);
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);
private:
ACE_CLASS_IS_NAMESPACE (ACE);
static int enter_recv_timedwait ( ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val );
static void leave_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 leave_send_timedwait ( ACE_HANDLE handle, const ACE_Time_Value *timeout, int val );
static size_t pagesize_;
static u_long crc_table_[];
static const char hex_chars_[];
};
static u_int major_version (void);
static u_int minor_version (void);
static u_int beta_version (void);
static ssize_t recv (
ACE_HANDLE handle,
void *buf,
size_t len,
int flags
);
len
bytes into buf
from handle
(uses the
ACE_OS::recv
call).
static ssize_t recv (ACE_HANDLE handle, void *buf, size_t len);
len
bytes into buf
from handle
(uses the
ACE_OS::read
system call on UNIX and the ACE_OS::recv
call on
Win32).
static ssize_t recv_n (
ACE_HANDLE handle,
void *buf,
size_t len,
int flags
);
len
bytes into buf
from handle
(uses the
ACE_OS::recv
call). If handle
is set to non-blocking mode
this call will poll until all len
bytes are received.
static ssize_t recv_n (ACE_HANDLE handle, void *buf, size_t len);
len
bytes into buf
from handle
(uses the
ACE_OS::read
system call on UNIX and the ACE_OS::recv
call on
Win32). If handle
is set to non-blocking mode this call will
poll until all len
bytes are received.
= Timed recv
operations.
static ssize_t recv (
ACE_HANDLE handle,
void *buf,
size_t len,
int flags,
const ACE_Time_Value *timeout
);
timeout
amount of time to receive up to len
bytes
into buf
from handle
(uses the ACE_OS::recv
call). The
timeout
indicates how long to blocking trying to receive. If
timeout
== 0, the caller will block until action is possible,
else will wait until the relative time specified in *timeout
elapses). If recv
times out a -1 is returned with errno ==
ETIME
. If it succeeds the number of bytes received is returned.
static ssize_t recv (
ACE_HANDLE handle,
void *buf,
size_t len,
const ACE_Time_Value *timeout
);
timeout
amount of time to receive up to len
bytes
into buf
from handle
(uses the ACE_OS::read
call). The
timeout
indicates how long to blocking trying to receive. If
timeout
== 0, the caller will block until action is possible,
else will wait until the relative time specified in *timeout
elapses). If recv
times out a -1 is returned with errno ==
ETIME
. If it succeeds the number of bytes received is returned.
static ssize_t recvmsg (
ACE_HANDLE handle,
struct msghdr *msg,
int flags,
const ACE_Time_Value *timeout
);
timeout
amount of time to receive msg
from
handle
(uses the ACE_OS::recvmsg
call). The timeout
indicates how long to blocking trying to receive. If timeout
== 0, the caller will block until action is possible, else will
wait until the relative time specified in *timeout
elapses).
If recvmsg
times out a -1 is returned with errno == ETIME
.
If it succeeds the number of bytes received is returned.
static ssize_t recvfrom (
ACE_HANDLE handle,
char *buf,
int len,
int flags,
struct sockaddr *addr,
int *addrlen,
const ACE_Time_Value *timeout
);
timeout
amount of time to recv up to len
bytes
into buf
from handle
(uses the ACE_OS::recvfrom
call). The
timeout
indicates how long to blocking trying to recv. If
timeout
== 0, the caller will block until action is possible,
else will wait until the relative time specified in *timeout
elapses). If recvfrom
times out a -1 is returned with errno
== ETIME
. If it succeeds the number of bytes received is
returned.
static ssize_t recv_n (
ACE_HANDLE handle,
void *buf,
size_t len,
int flags,
const ACE_Time_Value *timeout
);
len
bytes into buf
from handle
(uses
the ACE_OS::recv
call). The timeout
indicates how long to
blocking trying to receive. If timeout
== 0, the caller will
block until action is possible, else will wait until the relative
time specified in *timeout
elapses). If recv
blocks for
longer than timeout
the number of bytes actually read is
returned with errno == ETIME
. If a timeout does not occur,
recv_n
return len
(i.e., the number of bytes requested to be
read).
static ssize_t send (
ACE_HANDLE handle,
const void *buf,
size_t len,
int flags
);
len
bytes into buf
from handle
(uses the
ACE_OS::send
call).
static ssize_t send (ACE_HANDLE handle, const void *buf, size_t len);
len
bytes into buf
from handle
(uses the
ACE_OS::write
system call on UNIX and the ACE_OS::send
call
on Win32).
static ssize_t send_n (
ACE_HANDLE handle,
const void *buf,
size_t len,
int flags
);
len
bytes from buf
to handle
(uses the ACE_OS::send
system call). If handle
is set to non-blocking mode this call
will poll until all len
bytes are sent.
static ssize_t send_n (
ACE_HANDLE handle,
const void *buf,
size_t len
);
len
bytes from buf
to handle
(uses the ACE_OS::write
system call on UNIX and the ACE_OS::recv
call on Win32). If
handle
is set to non-blocking mode this call will poll until
all len
bytes are sent.
= Timed send
operations.
static ssize_t send (
ACE_HANDLE handle,
const void *buf,
size_t len,
const ACE_Time_Value *timeout
);
timeout
amount of time to send up to len
bytes
into buf
from handle
(uses the ACE_OS::write
system call on
UNIX and the ACE_OS::send
call on Win32). The timeout
indicates how long to blocking trying to send. If timeout
==
0, the caller will block until action is possible, else will wait
until the relative time specified in *timeout
elapses). If
send
times out a -1 is returned with errno == ETIME
. If it
succeeds the number of bytes sent is returned.
static ssize_t send (
ACE_HANDLE handle,
const void *buf,
size_t len,
int flags,
const ACE_Time_Value *timeout
);
timeout
amount of time to send up to len
bytes
into buf
from handle
(uses the ACE_OS::send
call). The
timeout
indicates how long to blocking trying to send. If
timeout
== 0, the caller will block until action is possible,
else will wait until the relative time specified in *timeout
elapses). If send
times out a -1 is returned with errno ==
ETIME
. If it succeeds the number of bytes sent is returned.
static ssize_t sendmsg (
ACE_HANDLE handle,
const struct msghdr *msg,
int flags,
const ACE_Time_Value *timeout
);
timeout
amount of time to send the msg
to handle
(uses the ACE_OS::sendmsg
call). The timeout
indicates how
long to blocking trying to send. If timeout
== 0, the caller
will block until action is possible, else will wait until the
relative time specified in *timeout
elapses). If sendmsg
times out a -1 is returned with errno == ETIME
. If it succeeds
the number of bytes sent is returned.
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
);
timeout
amount of time to send up to len
bytes
into buf
from handle
(uses the ACE_OS::sendto
call). The
timeout
indicates how long to blocking trying to send. If
timeout
== 0, the caller will block until action is possible,
else will wait until the relative time specified in *timeout
elapses). If sendto
times out a -1 is returned with errno ==
ETIME
. If it succeeds the number of bytes sent is returned.
static ssize_t send_n (
ACE_HANDLE handle,
const void *buf,
size_t len,
int flags,
const ACE_Time_Value *timeout
);
len
bytes into buf
from handle
(uses
the ACE_OS::send
call). The timeout
indicates how long to
blocking trying to send. If timeout
== 0, the caller will
block until action is possible, else will wait until the relative
time specified in *timeout
elapses). If send
blocks for
longer than timeout
the number of bytes actually sent is
returned with errno == ETIME
. If a timeout does not occur,
send_n
return len
(i.e., the number of bytes requested to be
sent).
static ssize_t writev (
ACE_HANDLE handle,
const struct iovec* iov,
int iovcnt,
const ACE_Time_Value *timeout
);
iovcnt
iovec
structs to handle
(uses the
ACE_OS::writev
call). If timeout
== 0, the caller will block
until action is possible, else will wait until the relative time
specified in *timeout
elapses). If writev
times out a -1 is
returned with errno == ETIME
. If it succeeds the number of
bytes written is returned.
static ssize_t readv (
ACE_HANDLE handle,
struct iovec *iov,
int iovcnt,
const ACE_Time_Value *timeout
);
iovcnt
iovec
structs from handle
(uses the
ACE_OS::readv
call). If timeout
== 0, the caller will block
until action is possible, else will wait until the relative time
specified in *timeout
elapses). If readv
times out a -1 is
returned with errno == ETIME
. If it succeeds the number of
bytes receieved is returned.
static ssize_t send (ACE_HANDLE handle, size_t n, ...);
handle
using writev
.
static ssize_t recv (ACE_HANDLE handle, size_t n, ...);
handle
using readv
.
static ssize_t read_n (ACE_HANDLE handle, void *buf, size_t len);
len
bytes into buf
from handle
(uses the
ACE_OS::read
call, which uses the read
system call on UNIX
and the ReadFile
call on Win32). If handle
is set to
non-blocking mode this call will poll until all len
bytes are
received.
static ssize_t write_n (
ACE_HANDLE handle,
const void *buf,
size_t len
);
len
bytes from buf
to handle
(uses the ACE_OS::write
calls, which is uses the write
system call on UNIX and the
WriteFile
call on Win32). If handle
is set to non-blocking
mode this call will poll until all len
bytes are sent.
static int bind_port (
ACE_HANDLE handle,
ACE_UINT32 ip_addr = INADDR_ANY
);
handle
.
static int get_bcast_addr (
ACE_UINT32 &bcast_addr,
const char *hostname = 0,
ACE_UINT32 host_addr = 0,
ACE_HANDLE handle = ACE_INVALID_HANDLE
);
host_addr
. If
hostname
is non-0 we'll use it to determine our IP address. If
handle
is not ACE_INVALID_HANDLE
then we'll use this to
determine our broadcast address, otherwise we'll have to create a
socket internally (and free it). Returns -1 on failure and 0 on
success.
static int get_ip_interfaces (
size_t &count,
ACE_INET_Addr *&addr_array
);
addr_array
.
static int count_interfaces (ACE_HANDLE handle, size_t &how_many);
static ACE_HANDLE get_handle (void);
ioctl
requests can be
made. Caller must close
the handle.
static int handle_timed_accept (
ACE_HANDLE listener,
ACE_Time_Value *timeout,
int restart
);
timeout
amount of time to passively establish a
connection. This method doesn't perform the accept
, it just
does the timed wait...
static ACE_HANDLE handle_timed_complete (
ACE_HANDLE listener,
ACE_Time_Value *timeout,
int is_tli = 0
);
timeout
amount of time to complete an actively
established non-blocking connection. If is_tli
is non-0 then
we are being called by a TLI wrapper (which behaves slightly
differently from a socket wrapper).
static ACE_HANDLE handle_timed_open (
ACE_Time_Value *timeout,
LPCTSTR name,
int flags,
int perms
);
timeout
amount of time to actively open a device.
This method doesn't perform the connect
, it just does the timed
wait...
static int set_flags (ACE_HANDLE handle, int flags);
handle
.
static int clr_flags (ACE_HANDLE handle, int flags);
handle
.
static int get_flags (ACE_HANDLE handle);
handle
.
static int set_handle_limit (int new_limit = -1);
new_limit
==
-1 set the limit to the maximum allowable. Otherwise, set it to
be the value of new_limit
.
static int max_handles (void);
ACE::set_handle_limit
.
static char *strenvdup (const char *str);
str
, substituting
the environment variable if str[0] == '$'
. Note that the
pointer is allocated with ACE_OS::malloc
and must be freed by
ACE_OS::free
static char *strecpy (char *s, const char *t);
t
to s
, returning a pointer to the end of the copied
region (rather than the beginning, a la strcpy
.
static char *strsplit_r (
char *s,
const char *token,
char *&next_start
);
s
into pieces separated by the string token
.
next_start
is an opaque cookie handed back by the call to store
its state for the next invocation, thus making it re-entrant.
This operates very similar to Perl's split
function except that
it returns pieces one at a time instead of into an array.
static size_t strrepl (char *s, char search, char replace);
search
in s
with replace
. Returns
the number of replacements made.
static const char *execname (const char *pathname);
pathname
if it already ends in ".exe,"
otherwise returns a dynamically allocated buffer containing
"pathname
.exe". Always returns pathname
on UNIX.
static const char *basename (const char *pathname, char delim);
pathname
.
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
);
pathname
.
static ASYS_TCHAR *timestamp (
ASYS_TCHAR date_and_time[],
int time_len
);
day_and_time
.
static int daemonize (
const char pathname[] = "/",
int close_all_handles = ACE_DEFAULT_CLOSE_ALL_HANDLES
);
close_all_handles
is non-zero then
all open file handles are closed.
static int ldfind (
const ASYS_TCHAR *filename,
ASYS_TCHAR *pathname,
size_t maxlen
);
filename
either using an absolute path or using
a relative path in conjunction with ACE_LD_SEARCH_PATH (e.g.,
$LD_LIBRARY_PATH on UNIX or $PATH on Win32). This function will
add appropriate suffix (e.g., .dll on Win32 or .so on UNIX)
according to the OS platform. In addition, this function will
apply the appropriate prefix (e.g., "lib" on UNIX and "" on
Win32) if the filename
doesn't match directly.
static FILE *ldopen (
const ASYS_TCHAR *filename,
const ASYS_TCHAR *type
);
ldopen
to locate and open the appropriate filename
and
returns a pointer to the file, else it returns a NULL
pointer. type
specifies how the file should be open.
static void *read_adapter (void *event_handler);
event_handler
must be a
subclass of ACE_Event_Handler
. If the get_handle
method of
this event handler returns ACE_INVALID_HANDLE
we default to
reading from ACE_STDIN.
static int register_stdin_handler (
ACE_Event_Handler *eh,
ACE_Reactor *reactor,
ACE_Thread_Manager *thr_mgr,
int flags = THR_DETACHED
);
static int remove_stdin_handler (
ACE_Reactor *reactor,
ACE_Thread_Manager *thr_mgr
);
register_stdin_handler
method.
static size_t round_to_pagesize (off_t length);
static int format_hexdump (
const char *buffer,
int size,
ASYS_TCHAR *obuf,
int obuf_sz
);
static u_long hash_pjw (const char *str);
str
using the ``Hash PJW'' routine.
static u_long hash_pjw (const ACE_USHORT16 *str);
str
using the ``Hash PJW'' routine
(works for UNICODE strings).
static u_long crc32 (const char* str);
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);
pid
is still alive. Returns 1 if it is
still alive, 0 if it isn't alive, and -1 if something weird
happened.
static int terminate_process (pid_t pid);
pid
. Note that this call is
potentially dangerous to use since the process being terminated
may not have a chance to cleanup before it shuts down.
static void unique_name (
const void *object,
LPTSTR name,
size_t length
);
object
will provide uniqueness between other "live" objects in
the same process. The uniqueness of this name is therefore only
valid for the life of object
.
static u_long log2 (u_long num);
num
.
static char nibble2hex (u_int n);
static u_char hex2byte (char c);