Classes | |
struct | If_Then_Else< true, Ta, Tb > |
struct | If_Then_Else< false, Ta, Tb > |
struct | VP_traits |
Value_Ptr traits template structure. More... | |
class | Value_Ptr |
Smart pointer implementation designed for use as a class member. More... | |
Namespaces | |
namespace | Monitor_Control |
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, If timeout != 0, the call will wait until the relative time specified in *timeout elapses.
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 The return values for the "*_n()" methods match the return values from the non "_n()" methods and are specified as follows:
On partial transfers, i.e., if any data is transferred before timeout / error / Methods with iovec parameter are I/O vector variants of the I/O operations.
Methods with the extra flags argument will always result in | |
ssize_t | recv (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout) |
ssize_t | recv (ACE_HANDLE handle, void *buf, size_t n, const ACE_Time_Value *timeout) |
ssize_t | recvmsg (ACE_HANDLE handle, struct msghdr *msg, int flags, const ACE_Time_Value *timeout) |
ssize_t | recvfrom (ACE_HANDLE handle, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen, const ACE_Time_Value *timeout) |
ssize_t | recv (ACE_HANDLE handle, size_t n,...) |
Receive into a variable number of pieces. | |
ssize_t | recvv (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout) |
ssize_t | recv_n (ACE_HANDLE handle, ACE_Message_Block *message_block, const ACE_Time_Value *timeout, size_t *bt) |
ssize_t | send (ACE_HANDLE handle, const void *buf, size_t n, int flags, const ACE_Time_Value *timeout) |
ssize_t | send (ACE_HANDLE handle, const void *buf, size_t n, const ACE_Time_Value *timeout) |
ssize_t | sendmsg (ACE_HANDLE handle, const struct msghdr *msg, int flags, const ACE_Time_Value *timeout) |
ssize_t | sendto (ACE_HANDLE handle, const char *buf, int len, int flags, const struct sockaddr *addr, int addrlen, const ACE_Time_Value *timeout) |
ssize_t | send (ACE_HANDLE handle, size_t n,...) |
Varargs variant. | |
ssize_t | sendv (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout) |
ssize_t | write_n (ACE_HANDLE handle, const ACE_Message_Block *message_block, size_t *bt) |
ssize_t | send_n (ACE_HANDLE handle, const ACE_Message_Block *message_block, const ACE_Time_Value *timeout, size_t *bt) |
ssize_t | readv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, size_t *bt) |
ssize_t | writev_n (ACE_HANDLE handle, const iovec *i, int iovcnt, size_t *bt) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | recv_n (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | recv_n (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | recvv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | send_n (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | send_n (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | sendv_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | read_n (ACE_HANDLE handle, void *buf, size_t len, size_t *bytes_transferred=0) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | write_n (ACE_HANDLE handle, const void *buf, size_t len, size_t *bytes_transferred=0) |
Functions | |
int | out_of_handles (int error) |
u_int | major_version (void) |
e.g., the "5" in ACE 5.1.12. | |
u_int | minor_version (void) |
e.g., the "1" in ACE 5.1.12. | |
u_int | beta_version (void) |
const ACE_TCHAR * | compiler_name (void) |
E.g., the "SunPro C++" in SunPro C++ 4.32.0. | |
u_int | compiler_major_version (void) |
E.g., the "4" in SunPro C++ 4.32.0. | |
u_int | compiler_minor_version (void) |
E.g., the "32" in SunPro C++ 4.32.0. | |
u_int | compiler_beta_version (void) |
E.g., the "0" in SunPro C++ 4.32.0. | |
bool | debug (void) |
void | debug (bool onoff) |
int | select (int width, ACE_Handle_Set *readfds, ACE_Handle_Set *writefds=0, ACE_Handle_Set *exceptfds=0, const ACE_Time_Value *timeout=0) |
Wrapper facade for select that uses ACE_Handle_Sets . | |
int | select (int width, ACE_Handle_Set &readfds, const ACE_Time_Value *timeout) |
int | terminate_process (pid_t pid) |
int | process_active (pid_t pid) |
const ACE_TCHAR * | execname (const ACE_TCHAR *old_name) |
u_long | hash_pjw (const char *str, size_t len) |
Computes the hash value of {str} using the "Hash PJW" routine. | |
u_long | hash_pjw (const char *str) |
Computes the hash value of {str} using the "Hash PJW" routine. | |
ACE_TCHAR * | strenvdup (const ACE_TCHAR *str) |
const ACE_TCHAR * | basename (const ACE_TCHAR *pathname, ACE_TCHAR delim) |
const ACE_TCHAR * | dirname (const ACE_TCHAR *pathname, ACE_TCHAR delim) |
ssize_t | recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, size_t *bt) |
ssize_t | recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bt) |
ssize_t | recv_n_i (ACE_HANDLE handle, void *buf, size_t len, size_t *bt) |
ssize_t | recv_n_i (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bt) |
ssize_t | recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, size_t *bt) |
ssize_t | recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bt) |
ssize_t | send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, size_t *bt) |
ssize_t | send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bt) |
ssize_t | send_n_i (ACE_HANDLE handle, const void *buf, size_t len, size_t *bt) |
ssize_t | send_n_i (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bt) |
ssize_t | sendv_n_i (ACE_HANDLE handle, const iovec *i, int iovcnt, size_t *bt) |
ssize_t | sendv_n_i (ACE_HANDLE handle, const iovec *i, int iovcnt, const ACE_Time_Value *timeout, size_t *bt) |
int | handle_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout, int read_ready, int write_ready, int exception_ready) |
Timed wait for handle to get read, write, or exception ready. | |
int | enter_recv_timedwait (ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val) |
int | enter_send_timedwait (ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val) |
void | record_and_set_non_blocking_mode (ACE_HANDLE handle, int &val) |
void | restore_non_blocking_mode (ACE_HANDLE handle, int val) |
size_t | format_hexdump (const char *buffer, size_t size, ACE_TCHAR *obuf, size_t obuf_sz) |
ACE_TCHAR * | timestamp (ACE_TCHAR date_and_time[], int date_and_timelen, int return_pointer_to_first_digit) |
size_t | round_to_pagesize (size_t len) |
Rounds the request to a multiple of the page size. | |
size_t | round_to_allocation_granularity (size_t len) |
Rounds the request to a multiple of the allocation granularity. | |
ACE_HANDLE | handle_timed_complete (ACE_HANDLE h, const ACE_Time_Value *timeout, int is_tli) |
int | handle_timed_accept (ACE_HANDLE listener, ACE_Time_Value *timeout, int restart) |
int | daemonize (const ACE_TCHAR pathname[], bool close_all_handles, const ACE_TCHAR program_name[]) |
pid_t | fork (const ACE_TCHAR *program_name, int avoid_zombies) |
int | max_handles (void) |
int | set_handle_limit (int new_limit, int increase_limit_only) |
u_long | gcd (u_long x, u_long y) |
Euclid's greatest common divisor algorithm. | |
u_long | minimum_frame_size (u_long period1, u_long period2) |
Calculates the minimum enclosing frame size for the given values. | |
u_long | is_prime (const u_long n, const u_long min_factor, const u_long max_factor) |
const ACE_TCHAR * | sock_error (int error) |
bool | is_sock_error (int error) |
char * | strndup (const char *str, size_t n) |
char * | strnnew (const char *str, size_t n) |
const char * | strend (const char *s) |
char * | strnew (const char *s) |
bool | wild_match (const char *str, const char *pat, bool case_sensitive) |
ACE_NAMESPACE_INLINE_FUNCTION void | strdelete (char *s) |
Delete the memory allocated by strnew . | |
ACE_Export ACE_UINT16 | crc_ccitt (const char *str) |
Computes CRC-CCITT for the string. | |
ACE_Export ACE_UINT16 | crc_ccitt (const void *buf, size_t len, ACE_UINT16 crc=0) |
Computes CRC-CCITT for the buffer. | |
ACE_Export ACE_UINT16 | crc_ccitt (const iovec *iov, int len, ACE_UINT16 crc=0) |
Computes CRC-CCITT for the @ len iovec buffers. | |
ACE_Export ACE_UINT32 | crc32 (const char *str) |
Computes the ISO 8802-3 standard 32 bits CRC for the string. | |
ACE_Export ACE_UINT32 | crc32 (const void *buf, size_t len, ACE_UINT32 crc=0) |
Computes the ISO 8802-3 standard 32 bits CRC for the buffer. | |
ACE_Export ACE_UINT32 | crc32 (const iovec *iov, int len, ACE_UINT32 crc=0) |
ACE_Export int | map_errno (int error) |
ACE_NAMESPACE_INLINE_FUNCTION void | unique_name (const void *object, ACE_TCHAR *name, size_t length) |
ACE_NAMESPACE_INLINE_FUNCTION u_long | log2 (u_long num) |
Computes the base 2 logarithm of {num}. | |
ACE_NAMESPACE_INLINE_FUNCTION ACE_TCHAR | nibble2hex (u_int n) |
Hex conversion utility. | |
ACE_NAMESPACE_INLINE_FUNCTION u_char | hex2byte (ACE_TCHAR c) |
Convert a hex character to its byte representation. | |
ACE_NAMESPACE_INLINE_FUNCTION int | handle_read_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
Timed wait for handle to get read ready. | |
ACE_NAMESPACE_INLINE_FUNCTION int | handle_write_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
Timed wait for handle to get write ready. | |
ACE_NAMESPACE_INLINE_FUNCTION int | handle_exception_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
Timed wait for handle to get exception ready. | |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | recv_i (ACE_HANDLE handle, void *buf, size_t len) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | send_i (ACE_HANDLE handle, const void *buf, size_t len) |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ssize_t | read_n (ACE_HANDLE handle, void *buf, size_t len, size_t *bytes_transferred) |
ACE_INLINE ssize_t | write_n (ACE_HANDLE handle, const void *buf, size_t len, size_t *bytes_transferred) |
ACE_INLINE ssize_t | recv_n (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_INLINE ssize_t | recv_n (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_INLINE ssize_t | recvv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_INLINE ssize_t | send_n (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_INLINE ssize_t | send_n (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_INLINE ssize_t | sendv_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_INLINE ssize_t | send_i (ACE_HANDLE handle, const void *buf, size_t len) |
ACE_INLINE ssize_t | recv_i (ACE_HANDLE handle, void *buf, size_t len) |
ACE_INLINE int | handle_read_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
Timed wait for handle to get read ready. | |
ACE_INLINE int | handle_write_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
Timed wait for handle to get write ready. | |
ACE_INLINE int | handle_exception_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
Timed wait for handle to get exception ready. | |
ACE_INLINE void | strdelete (char *s) |
Delete the memory allocated by strnew . | |
ACE_INLINE void | unique_name (const void *object, ACE_TCHAR *name, size_t length) |
ACE_INLINE u_long | log2 (u_long num) |
Computes the base 2 logarithm of {num}. | |
ACE_INLINE ACE_TCHAR | nibble2hex (u_int n) |
Hex conversion utility. | |
ACE_INLINE int | map_errno (int error) |
ACE_INLINE u_char | hex2byte (ACE_TCHAR c) |
Convert a hex character to its byte representation. | |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_UINT32 | crc32 (const char *string) |
Computes the ISO 8802-3 standard 32 bits CRC for the string. | |
ACE_UINT32 | crc32 (const void *buffer, size_t len, ACE_UINT32 crc) |
Computes the ISO 8802-3 standard 32 bits CRC for the buffer. | |
ACE_UINT32 | crc32 (const iovec *iov, int len, ACE_UINT32 crc) |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_UINT16 | crc_ccitt (const char *string) |
Computes CRC-CCITT for the string. | |
ACE_UINT16 | crc_ccitt (const void *buffer, size_t len, ACE_UINT16 crc) |
Computes CRC-CCITT for the buffer. | |
ACE_UINT16 | crc_ccitt (const iovec *iov, int len, ACE_UINT16 crc) |
Computes CRC-CCITT for the @ len iovec buffers. | |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL int | set_flags (ACE_HANDLE handle, int flags) |
Set flags associated with handle. | |
int | clr_flags (ACE_HANDLE handle, int flags) |
Clear flags associated with handle. | |
ACE_NAMESPACE_INLINE_FUNCTION int | get_flags (ACE_HANDLE handle) |
Return the current setting of flags associated with handle. | |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int | get_flags (ACE_HANDLE handle) |
Return the current setting of flags associated with handle. | |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_HANDLE | handle_timed_open (ACE_Time_Value *timeout, const ACE_TCHAR *name, int flags, int perms, LPSECURITY_ATTRIBUTES sa) |
int | init (void) |
int | fini (void) |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL int | ldfind (const ACE_TCHAR *filename, ACE_TCHAR pathname[], size_t maxpathnamelen) |
FILE * | ldopen (const ACE_TCHAR *filename, const ACE_TCHAR *type) |
ACE_TCHAR * | ldname (const ACE_TCHAR *entry_point) |
int | get_temp_dir (ACE_TCHAR *buffer, size_t buffer_len) |
ACE_HANDLE | open_temp_file (const ACE_TCHAR *name, int mode, int perm) |
size_t | strrepl (char *s, char search, char replace) |
char * | strsplit_r (char *str, const char *token, char *&next_start) |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL int | bind_port (ACE_HANDLE handle, ACE_UINT32 ip_addr=INADDR_ANY, int address_family=AF_UNSPEC) |
Bind a new unused port to handle. | |
int | get_bcast_addr (ACE_UINT32 &bcast_addr, const ACE_TCHAR *host_name, ACE_UINT32 host_addr, ACE_HANDLE handle) |
int | get_fqdn (ACE_INET_Addr const &addr, char hostname[], size_t len) |
Get fully qualified host/domain name. | |
int | get_ip_interfaces (size_t &count, ACE_INET_Addr *&addrs) |
int | count_interfaces (ACE_HANDLE handle, size_t &how_many) |
ACE_HANDLE | get_handle (void) |
bool | ipv4_enabled (void) |
int | ipv6_enabled (void) |
Variables | |
size_t | allocation_granularity_ = 0 |
size_t | pagesize_ = 0 |
char | debug_ |
unsigned int | init_fini_count_ = 0 |
The ACE namespace contains all types (classes, structures, typedefs, etc), and global functions and variables in the ACE framework.
ACE_Export int ACE::out_of_handles | ( | int | error | ) |
Check if error indicates the process being out of handles (file descriptors).
Definition at line 66 of file ACE.cpp.
References ENFILE, ENOSYS, and ENOTSUP.
Referenced by ACE_Cached_Connect_Strategy_Ex< SVC_HANDLER,, CACHING_STRATEGY, ATTRIBUTES, MUTEX >::cached_connect(), and ACE_Handle_Gobbler::consume_handles().
00067 { 00068 // EMFILE is common to all platforms. 00069 if (error == EMFILE || 00070 #if defined (ACE_WIN32) 00071 // On Win32, we need to check for ENOBUFS also. 00072 error == ENOBUFS || 00073 #elif defined (HPUX) 00074 // On HPUX, we need to check for EADDRNOTAVAIL also. 00075 error == EADDRNOTAVAIL || 00076 #elif defined (linux) 00077 // On linux, we need to check for ENOENT also. 00078 error == ENOENT || 00079 // For RedHat5.2, need to check for EINVAL too. 00080 error == EINVAL || 00081 // Without threads check for EOPNOTSUPP 00082 error == EOPNOTSUPP || 00083 #elif defined (sun) 00084 // On sun, we need to check for ENOSR also. 00085 error == ENOSR || 00086 // Without threads check for ENOTSUP 00087 error == ENOTSUP || 00088 #elif defined (__FreeBSD__) 00089 // On FreeBSD we need to check for EOPNOTSUPP (LinuxThreads) or 00090 // ENOSYS (libc_r threads) also. 00091 error == EOPNOTSUPP || 00092 error == ENOSYS || 00093 #elif defined (__OpenBSD__) 00094 // OpenBSD appears to return EBADF. 00095 error == EBADF || 00096 #elif defined (__sgi) // irix 00097 error == ENOTSUP || 00098 #elif defined (DIGITAL_UNIX) // osf1 00099 error == ENOTSUP || 00100 #endif /* ACE_WIN32 */ 00101 error == ENFILE) 00102 return 1; 00103 else 00104 return 0; 00105 }
ACE_Export u_int ACE::major_version | ( | void | ) |
e.g., the "5" in ACE 5.1.12.
Definition at line 108 of file ACE.cpp.
References ACE_MAJOR_VERSION.
00109 { 00110 return ACE_MAJOR_VERSION; 00111 }
ACE_Export u_int ACE::minor_version | ( | void | ) |
e.g., the "1" in ACE 5.1.12.
Definition at line 114 of file ACE.cpp.
References ACE_MINOR_VERSION.
00115 { 00116 return ACE_MINOR_VERSION; 00117 }
ACE_Export u_int ACE::beta_version | ( | void | ) |
e.g., the "12" in ACE 5.1.12. Returns 0 for "stable" (non-beta) releases.
Definition at line 120 of file ACE.cpp.
References ACE_BETA_VERSION.
00121 { 00122 return ACE_BETA_VERSION; 00123 }
ACE_Export const ACE_TCHAR * ACE::compiler_name | ( | void | ) |
ACE_Export u_int ACE::compiler_major_version | ( | void | ) |
ACE_Export u_int ACE::compiler_minor_version | ( | void | ) |
ACE_Export u_int ACE::compiler_beta_version | ( | void | ) |
ACE_Export bool ACE::debug | ( | void | ) |
Definition at line 166 of file ACE.cpp.
References debug_, and ACE_OS::getenv().
Referenced by ACE_DLL::ACE_DLL(), ACE_DLL_Manager::ACE_DLL_Manager(), ACE_Service_Config_Guard::ACE_Service_Config_Guard(), ACE_Service_Gestalt::ACE_Service_Gestalt(), ACE_Service_Type_Dynamic_Guard::ACE_Service_Type_Dynamic_Guard(), ACE_Service_Gestalt::add_processed_static_svc(), ACE_Service_Repository::close(), ACE_Service_Gestalt::close(), ACE_DLL_Handle::close(), ACE_Local_Name_Space<, ACE_LOCK >::create_manager_i(), ACE_Service_Repository::fini(), ACE_Service_Type::fini(), ACE_Naming_Context::fini(), ACE_Service_Config::fini_svcs(), get_fqdn(), ACE_DLL_Handle::get_handle(), ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_2 >::handle_input(), ACE_Naming_Context::init(), ACE_Dynamic_Service_Dependency::init(), ACE_Service_Gestalt::init_svc_conf_file_queue(), ACE_Service_Gestalt::initialize(), ACE_Service_Gestalt::initialize_i(), ACE_Service_Repository::insert(), ACE_Dynamic_Service_Base::instance(), ACE_SOCK_Dgram_Bcast::mk_broadcast(), ACE_DLL_Handle::open(), ACE_DLL_Manager::open_dll(), ACE_Service_Gestalt::open_i(), ACE_Service_Config::open_i(), ACE_DLL::open_i(), ACE_Service_Gestalt::parse_args_i(), ACE_Service_Gestalt::process_directive(), ACE_Service_Gestalt::process_directive_i(), ACE_Service_Gestalt::process_directives_i(), ACE_Service_Gestalt::process_file(), ACE_Service_Config::reconfigure(), ACE_Service_Repository::relocate_i(), ACE_Framework_Repository::remove_dll_components_i(), ACE_DLL_Handle::symbol(), ACE_DLL_Manager::unload_dll(), ACE_DLL_Manager::~ACE_DLL_Manager(), ACE_Dynamic_Service_Dependency::~ACE_Dynamic_Service_Dependency(), ACE_Service_Config_Guard::~ACE_Service_Config_Guard(), ACE_Service_Gestalt::~ACE_Service_Gestalt(), ACE_Service_Repository::~ACE_Service_Repository(), and ACE_Service_Type_Dynamic_Guard::~ACE_Service_Type_Dynamic_Guard().
00167 { 00168 static const char* debug = ACE_OS::getenv ("ACE_DEBUG"); 00169 return (ACE::debug_ != 0) ? ACE::debug_ : (debug != 0 ? (*debug != '0'): false); 00170 }
ACE_Export void ACE::debug | ( | bool | onoff | ) |
Definition at line 173 of file ACE.cpp.
References debug_.
00174 { 00175 ACE::debug_ = onoff; 00176 }
ACE_Export int ACE::select | ( | int | width, | |
ACE_Handle_Set * | readfds, | |||
ACE_Handle_Set * | writefds = 0 , |
|||
ACE_Handle_Set * | exceptfds = 0 , |
|||
const ACE_Time_Value * | timeout = 0 | |||
) |
Wrapper facade for select
that uses ACE_Handle_Sets
.
Definition at line 179 of file ACE.cpp.
References ACE_Handle_Set::fdset(), ACE_OS::select(), and ACE_Handle_Set::sync().
00184 { 00185 int result = ACE_OS::select (width, 00186 readfds ? readfds->fdset () : 0, 00187 writefds ? writefds->fdset () : 0, 00188 exceptfds ? exceptfds->fdset () : 0, 00189 timeout); 00190 if (result > 0) 00191 { 00192 # if !defined (ACE_WIN32) 00193 // This isn't needed for Windows... it's a no-op anyway. 00194 if (readfds) 00195 readfds->sync ((ACE_HANDLE) width); 00196 if (writefds) 00197 writefds->sync ((ACE_HANDLE) width); 00198 if (exceptfds) 00199 exceptfds->sync ((ACE_HANDLE) width); 00200 #endif /* ACE_WIN32 */ 00201 } 00202 return result; 00203 }
ACE_Export int ACE::select | ( | int | width, | |
ACE_Handle_Set & | readfds, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Wrapper facade for the most common use of select
that uses ACE_Handle_Sets
.
Definition at line 206 of file ACE.cpp.
References ACE_Handle_Set::fdset(), ACE_OS::select(), and ACE_Handle_Set::sync().
00209 { 00210 int result = ACE_OS::select (width, 00211 readfds.fdset (), 00212 0, 00213 0, 00214 timeout); 00215 00216 #if !defined (ACE_WIN32) 00217 if (result > 0) 00218 readfds.sync ((ACE_HANDLE) width); 00219 #endif /* ACE_WIN32 */ 00220 return result; 00221 }
ACE_Export int ACE::terminate_process | ( | pid_t | pid | ) |
Terminate the process abruptly with id pid. On Win32 platforms this uses {TerminateProcess} and on POSIX platforms is uses {kill} with the -9 (SIGKILL) signal, which cannot be caught or ignored. 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.
Definition at line 224 of file ACE.cpp.
References ACE_NOTSUP_RETURN, ACE_OS::close(), and ACE_OS::kill().
Referenced by ACE_Process_Manager::terminate(), and ACE_Process::terminate().
00225 { 00226 #if defined (ACE_HAS_PHARLAP) 00227 ACE_UNUSED_ARG (pid); 00228 ACE_NOTSUP_RETURN (-1); 00229 #elif defined (ACE_WIN32) 00230 // Create a handle for the given process id. 00231 ACE_HANDLE process_handle = 00232 ::OpenProcess (PROCESS_TERMINATE, 00233 FALSE, // New handle is not inheritable. 00234 pid); 00235 00236 if (process_handle == ACE_INVALID_HANDLE 00237 || process_handle == 0) 00238 return -1; 00239 else 00240 { 00241 // Kill the process associated with process_handle. 00242 BOOL terminate_result = 00243 ::TerminateProcess (process_handle, 0); 00244 // Free up the kernel resources. 00245 ACE_OS::close (process_handle); 00246 return terminate_result ? 0 : -1; 00247 } 00248 #else 00249 return ACE_OS::kill (pid, 9); 00250 #endif /* ACE_HAS_PHARLAP */ 00251 }
ACE_Export int ACE::process_active | ( | pid_t | pid | ) |
Checks if process with {pid} is still alive. Returns 1 if it is still alive, 0 if it isn't alive, and -1 if something weird happened.
Definition at line 254 of file ACE.cpp.
References ACE_OS::kill().
00255 { 00256 #if !defined(ACE_WIN32) 00257 if (ACE_OS::kill (pid, 0) == 0) 00258 return 1; 00259 else if (errno == ESRCH) 00260 return 0; 00261 else 00262 return -1; 00263 #else 00264 // Create a handle for the given process id. 00265 ACE_HANDLE process_handle = 00266 ::OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid); 00267 if (process_handle == ACE_INVALID_HANDLE || process_handle == 0) 00268 return 0; 00269 else 00270 { 00271 DWORD status; 00272 int result = 1; 00273 if (::GetExitCodeProcess (process_handle, 00274 &status) == 0 00275 || status != STILL_ACTIVE) 00276 result = 0; 00277 00278 ::CloseHandle (process_handle); 00279 return result; 00280 } 00281 #endif /* !ACE_WIN32 */ 00282 }
On Windows, determines if a specified pathname ends with ".exe" (not case sensitive). If on Windows and there is no ".exe" suffix, a new ACE_TCHAR array is allocated and a copy of pathname
with the ".exe" suffix is copied into it. In this case, the caller is responsible for calling delete [] on the returned pointer.
pathname | The name to check for a proper suffix. |
@c | pathname if there is a proper suffix for Windows. This is always the return value for non-Windows platforms. | |
If | a suffix needs to be added, returns a pointer to new[] allocated memory containing the original pathname plus a ".exe" suffix. The caller is responsible for freeing the memory using delete []. |
Definition at line 285 of file ACE.cpp.
References ACE_NEW_RETURN, ACE_TEXT, ACE_OS::strcasecmp(), ACE_OS::strcpy(), ACE_OS::strecpy(), ACE_OS::strlen(), and ACE_OS::strrchr().
00286 { 00287 #if defined (ACE_WIN32) 00288 const ACE_TCHAR *suffix = ACE_OS::strrchr (old_name, ACE_TEXT ('.')); 00289 if (suffix == 0 || ACE_OS::strcasecmp (suffix, ACE_TEXT (".exe")) != 0) 00290 { 00291 ACE_TCHAR *new_name = 0; 00292 00293 size_t size = 00294 ACE_OS::strlen (old_name) 00295 + ACE_OS::strlen (ACE_TEXT (".exe")) 00296 + 1; 00297 00298 ACE_NEW_RETURN (new_name, 00299 ACE_TCHAR[size], 00300 0); 00301 ACE_TCHAR *end = new_name; 00302 00303 end = ACE_OS::strecpy (new_name, old_name); 00304 00305 // Concatenate the .exe suffix onto the end of the executable. 00306 // end points _after_ the terminating nul. 00307 ACE_OS::strcpy (end - 1, ACE_TEXT (".exe")); 00308 00309 return new_name; 00310 } 00311 #endif /* ACE_WIN32 */ 00312 return old_name; 00313 }
ACE_Export u_long ACE::hash_pjw | ( | const char * | str, | |
size_t | len | |||
) |
Computes the hash value of {str} using the "Hash PJW" routine.
Definition at line 316 of file ACE.cpp.
Referenced by ACE_Filecache::create(), ACE_Filecache::fetch(), ACE_Filecache::finish(), ACE_UNIX_Addr::hash(), ACE_String_Base< CHAR >::hash(), ACE_SString::hash(), ACE_NS_String::hash(), hash_pjw(), ACE_Hash< char * >::operator()(), ACE_Hash< const char * >::operator()(), and ACE_Filecache::remove().
00317 { 00318 u_long hash = 0; 00319 00320 for (size_t i = 0; i < len; i++) 00321 { 00322 const char temp = str[i]; 00323 hash = (hash << 4) + (temp * 13); 00324 00325 u_long g = hash & 0xf0000000; 00326 00327 if (g) 00328 { 00329 hash ^= (g >> 24); 00330 hash ^= g; 00331 } 00332 } 00333 00334 return hash; 00335 }
ACE_Export u_long ACE::hash_pjw | ( | const char * | str | ) |
Computes the hash value of {str} using the "Hash PJW" routine.
Definition at line 338 of file ACE.cpp.
References hash_pjw(), and ACE_OS::strlen().
00339 { 00340 return ACE::hash_pjw (str, ACE_OS::strlen (str)); 00341 }
Return a dynamically allocated duplicate of 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
.
Definition at line 377 of file ACE.cpp.
References ACE_TRACE, and ACE_OS::strenvdup().
00378 { 00379 ACE_TRACE ("ACE::strenvdup"); 00380 00381 return ACE_OS::strenvdup (str); 00382 }
ACE_Export const ACE_TCHAR * ACE::basename | ( | const ACE_TCHAR * | pathname, | |
ACE_TCHAR | delim = ACE_DIRECTORY_SEPARATOR_CHAR | |||
) |
Returns the "basename" of a pathname separated by delim. For instance, the basename of "/tmp/foo.cpp" is "foo.cpp" when delim is '/'.
Definition at line 404 of file ACE.cpp.
References ACE_TRACE, and ACE_OS::strrchr().
Referenced by ACE_Malloc_Lock_Adapter_T< ACE_Process_Semaphore >::operator()(), ACE_Malloc_Lock_Adapter_T< ACE_LOCK >::operator()(), and ACE_Name_Options::process_name().
00405 { 00406 ACE_TRACE ("ACE::basename"); 00407 const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim); 00408 00409 if (temp == 0) 00410 return pathname; 00411 else 00412 return temp + 1; 00413 }
ACE_Export const ACE_TCHAR * ACE::dirname | ( | const ACE_TCHAR * | pathname, | |
ACE_TCHAR | delim = ACE_DIRECTORY_SEPARATOR_CHAR | |||
) |
Returns the "dirname" of a pathname. For instance, the dirname of "/tmp/foo.cpp" is "/tmp" when delim is '/'. If pathname has no delim ".\0" is returned. This method does not modify pathname and is not reentrant.
Definition at line 416 of file ACE.cpp.
References ACE_TRACE, MAXPATHLEN, ACE_OS::strrchr(), and ACE_OS::strsncpy().
00417 { 00418 ACE_TRACE ("ACE::dirname"); 00419 static ACE_TCHAR return_dirname[MAXPATHLEN + 1]; 00420 00421 const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim); 00422 00423 if (temp == 0) 00424 { 00425 return_dirname[0] = '.'; 00426 return_dirname[1] = '\0'; 00427 00428 return return_dirname; 00429 } 00430 else 00431 { 00432 // When the len is truncated, there are problems! This should 00433 // not happen in normal circomstances 00434 size_t len = temp - pathname + 1; 00435 if (len > (sizeof return_dirname / sizeof (ACE_TCHAR))) 00436 len = sizeof return_dirname / sizeof (ACE_TCHAR); 00437 00438 ACE_OS::strsncpy (return_dirname, 00439 pathname, 00440 len); 00441 return return_dirname; 00442 } 00443 }
ACE_Export ssize_t ACE::recv | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 446 of file ACE.cpp.
References enter_recv_timedwait(), ACE_OS::recv(), and restore_non_blocking_mode().
Referenced by ACE_MEM_Acceptor::accept(), handle_timed_complete(), ACE_Select_Reactor_Notify::read_notify_pipe(), ACE_SOCK_IO::recv(), ACE_SOCK_Dgram_SC< STREAM >::recv(), ACE_SOCK_Stream::recv_urg(), and ACE_SOCK_SEQPACK_Association::recv_urg().
00451 { 00452 if (timeout == 0) 00453 return ACE_OS::recv (handle, (char *) buf, len, flags); 00454 else 00455 { 00456 int val = 0; 00457 if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1) 00458 return -1; 00459 else 00460 { 00461 ssize_t bytes_transferred = 00462 ACE_OS::recv (handle, (char *) buf, len, flags); 00463 ACE::restore_non_blocking_mode (handle, val); 00464 return bytes_transferred; 00465 } 00466 } 00467 }
ACE_Export ssize_t ACE::recv | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | n, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 498 of file ACE.cpp.
References enter_recv_timedwait(), recv_i(), and restore_non_blocking_mode().
00502 { 00503 if (timeout == 0) 00504 return ACE::recv_i (handle, buf, n); 00505 else 00506 { 00507 int val = 0; 00508 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1) 00509 return -1; 00510 else 00511 { 00512 ssize_t bytes_transferred = ACE::recv_i (handle, buf, n); 00513 ACE::restore_non_blocking_mode (handle, val); 00514 return bytes_transferred; 00515 } 00516 } 00517 }
ACE_Export ssize_t ACE::recvmsg | ( | ACE_HANDLE | handle, | |
struct msghdr * | msg, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 520 of file ACE.cpp.
References enter_recv_timedwait(), ACE_OS::recvmsg(), and restore_non_blocking_mode().
00524 { 00525 if (timeout == 0) 00526 return ACE_OS::recvmsg (handle, msg, flags); 00527 else 00528 { 00529 int val = 0; 00530 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1) 00531 return -1; 00532 else 00533 { 00534 ssize_t bytes_transferred = ACE_OS::recvmsg (handle, msg, flags); 00535 ACE::restore_non_blocking_mode (handle, val); 00536 return bytes_transferred; 00537 } 00538 } 00539 }
ACE_Export ssize_t ACE::recvfrom | ( | ACE_HANDLE | handle, | |
char * | buf, | |||
int | len, | |||
int | flags, | |||
struct sockaddr * | addr, | |||
int * | addrlen, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 542 of file ACE.cpp.
References enter_recv_timedwait(), ACE_OS::recvfrom(), and restore_non_blocking_mode().
00549 { 00550 if (timeout == 0) 00551 return ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen); 00552 else 00553 { 00554 int val = 0; 00555 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1) 00556 return -1; 00557 else 00558 { 00559 ssize_t bytes_transferred = 00560 ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen); 00561 ACE::restore_non_blocking_mode (handle, val); 00562 return bytes_transferred; 00563 } 00564 } 00565 }
ACE_Export ssize_t ACE::recv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int | flags, | |||
size_t * | bt | |||
) |
Definition at line 568 of file ACE.cpp.
References handle_read_ready(), and ACE_OS::recv().
Referenced by recv_n().
00573 { 00574 size_t temp; 00575 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00576 ssize_t n; 00577 00578 for (bytes_transferred = 0; 00579 bytes_transferred < len; 00580 bytes_transferred += n) 00581 { 00582 // Try to transfer as much of the remaining data as possible. 00583 n = ACE_OS::recv (handle, 00584 static_cast <char *> (buf) + bytes_transferred, 00585 len - bytes_transferred, 00586 flags); 00587 // Check EOF. 00588 if (n == 0) 00589 return 0; 00590 00591 // Check for other errors. 00592 if (n == -1) 00593 { 00594 // Check for possible blocking. 00595 if (errno == EWOULDBLOCK) 00596 { 00597 // Wait for the blocking to subside. 00598 int result = ACE::handle_read_ready (handle, 00599 0); 00600 00601 // Did select() succeed? 00602 if (result != -1) 00603 { 00604 // Blocking subsided. Continue data transfer. 00605 n = 0; 00606 continue; 00607 } 00608 } 00609 00610 // Other data transfer or select() failures. 00611 return -1; 00612 } 00613 } 00614 00615 return static_cast<ssize_t> (bytes_transferred); 00616 }
ACE_Export ssize_t ACE::recv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bt | |||
) |
Definition at line 619 of file ACE.cpp.
References handle_read_ready(), record_and_set_non_blocking_mode(), ACE_OS::recv(), and restore_non_blocking_mode().
00625 { 00626 size_t temp; 00627 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00628 ssize_t n; 00629 ssize_t result = 0; 00630 int error = 0; 00631 00632 int val = 0; 00633 ACE::record_and_set_non_blocking_mode (handle, val); 00634 00635 for (bytes_transferred = 0; 00636 bytes_transferred < len; 00637 bytes_transferred += n) 00638 { 00639 // Try to transfer as much of the remaining data as possible. 00640 // Since the socket is in non-blocking mode, this call will not 00641 // block. 00642 n = ACE_OS::recv (handle, 00643 static_cast <char *> (buf) + bytes_transferred, 00644 len - bytes_transferred, 00645 flags); 00646 00647 // Check for errors. 00648 if (n == 0 || 00649 n == -1) 00650 { 00651 // Check for possible blocking. 00652 if (n == -1 && 00653 errno == EWOULDBLOCK) 00654 { 00655 // Wait upto <timeout> for the blocking to subside. 00656 int rtn = ACE::handle_read_ready (handle, 00657 timeout); 00658 00659 // Did select() succeed? 00660 if (rtn != -1) 00661 { 00662 // Blocking subsided in <timeout> period. Continue 00663 // data transfer. 00664 n = 0; 00665 continue; 00666 } 00667 } 00668 00669 // Wait in select() timed out or other data transfer or 00670 // select() failures. 00671 error = 1; 00672 result = n; 00673 break; 00674 } 00675 } 00676 00677 ACE::restore_non_blocking_mode (handle, val); 00678 00679 if (error) 00680 return result; 00681 else 00682 return static_cast<ssize_t> (bytes_transferred); 00683 }
ACE_Export ssize_t ACE::recv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
size_t * | bt | |||
) |
Definition at line 808 of file ACE.cpp.
References handle_read_ready(), and recv_i().
00812 { 00813 size_t temp; 00814 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00815 ssize_t n; 00816 00817 for (bytes_transferred = 0; 00818 bytes_transferred < len; 00819 bytes_transferred += n) 00820 { 00821 // Try to transfer as much of the remaining data as possible. 00822 n = ACE::recv_i (handle, 00823 static_cast <char *> (buf) + bytes_transferred, 00824 len - bytes_transferred); 00825 // Check EOF. 00826 if (n == 0) 00827 { 00828 return 0; 00829 } 00830 // Check for other errors. 00831 if (n == -1) 00832 { 00833 // Check for possible blocking. 00834 if (errno == EWOULDBLOCK) 00835 { 00836 // Wait for the blocking to subside. 00837 int result = ACE::handle_read_ready (handle, 00838 0); 00839 00840 // Did select() succeed? 00841 if (result != -1) 00842 { 00843 // Blocking subsided. Continue data transfer. 00844 n = 0; 00845 continue; 00846 } 00847 } 00848 00849 // Other data transfer or select() failures. 00850 return -1; 00851 } 00852 } 00853 00854 return static_cast<ssize_t> (bytes_transferred); 00855 }
ACE_Export ssize_t ACE::recv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bt | |||
) |
Definition at line 858 of file ACE.cpp.
References handle_read_ready(), record_and_set_non_blocking_mode(), recv_i(), and restore_non_blocking_mode().
00863 { 00864 size_t temp; 00865 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00866 ssize_t n; 00867 ssize_t result = 0; 00868 int error = 0; 00869 00870 int val = 0; 00871 ACE::record_and_set_non_blocking_mode (handle, val); 00872 00873 for (bytes_transferred = 0; 00874 bytes_transferred < len; 00875 bytes_transferred += n) 00876 { 00877 // Try to transfer as much of the remaining data as possible. 00878 // Since the socket is in non-blocking mode, this call will not 00879 // block. 00880 n = ACE::recv_i (handle, 00881 static_cast <char *> (buf) + bytes_transferred, 00882 len - bytes_transferred); 00883 00884 // Check for errors. 00885 if (n == 0 || 00886 n == -1) 00887 { 00888 // Check for possible blocking. 00889 if (n == -1 && 00890 errno == EWOULDBLOCK) 00891 { 00892 // Wait upto <timeout> for the blocking to subside. 00893 int rtn = ACE::handle_read_ready (handle, 00894 timeout); 00895 00896 // Did select() succeed? 00897 if (rtn != -1) 00898 { 00899 // Blocking subsided in <timeout> period. Continue 00900 // data transfer. 00901 n = 0; 00902 continue; 00903 } 00904 } 00905 00906 // Wait in select() timed out or other data transfer or 00907 // select() failures. 00908 error = 1; 00909 result = n; 00910 break; 00911 } 00912 } 00913 00914 ACE::restore_non_blocking_mode (handle, val); 00915 00916 if (error) 00917 return result; 00918 else 00919 return static_cast<ssize_t> (bytes_transferred); 00920 }
ACE_Export ssize_t ACE::recv | ( | ACE_HANDLE | handle, | |
size_t | n, | |||
... | ||||
) |
Receive into a variable number of pieces.
Accepts a variable, caller-specified, number of pointer/length pairs. Arguments following n are char *, size_t pairs.
handle | The I/O handle to receive on | |
n | The total number of char *, size_t pairs following n. |
Definition at line 929 of file ACE.cpp.
References ACE_NEW_RETURN, and ACE_OS::recvv().
00930 { 00931 va_list argp; 00932 int total_tuples = static_cast<int> (n / 2); 00933 iovec *iovp; 00934 #if defined (ACE_HAS_ALLOCA) 00935 iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); 00936 #else 00937 ACE_NEW_RETURN (iovp, 00938 iovec[total_tuples], 00939 -1); 00940 #endif /* !defined (ACE_HAS_ALLOCA) */ 00941 00942 va_start (argp, n); 00943 00944 for (int i = 0; i < total_tuples; i++) 00945 { 00946 iovp[i].iov_base = va_arg (argp, char *); 00947 iovp[i].iov_len = va_arg (argp, int); 00948 } 00949 00950 ssize_t result = ACE_OS::recvv (handle, iovp, total_tuples); 00951 #if !defined (ACE_HAS_ALLOCA) 00952 delete [] iovp; 00953 #endif /* !defined (ACE_HAS_ALLOCA) */ 00954 va_end (argp); 00955 return result; 00956 }
ACE_Export ssize_t ACE::recvv | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 959 of file ACE.cpp.
References enter_recv_timedwait(), ACE_OS::recvv(), and restore_non_blocking_mode().
Referenced by ACE_Pipe::recv(), and ACE_SOCK_IO::recvv().
00963 { 00964 if (timeout == 0) 00965 return ACE_OS::recvv (handle, iov, iovcnt); 00966 else 00967 { 00968 int val = 0; 00969 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1) 00970 return -1; 00971 else 00972 { 00973 ssize_t bytes_transferred = ACE_OS::recvv (handle, iov, iovcnt); 00974 ACE::restore_non_blocking_mode (handle, val); 00975 return bytes_transferred; 00976 } 00977 } 00978 }
ACE_Export ssize_t ACE::recvv_n_i | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
size_t * | bt | |||
) |
Definition at line 981 of file ACE.cpp.
References handle_read_ready(), and ACE_OS::recvv().
Referenced by recvv_n().
00985 { 00986 size_t temp; 00987 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00988 bytes_transferred = 0; 00989 00990 for (int s = 0; 00991 s < iovcnt; 00992 ) 00993 { 00994 // Try to transfer as much of the remaining data as possible. 00995 ssize_t n = ACE_OS::recvv (handle, 00996 iov + s, 00997 iovcnt - s); 00998 // Check EOF. 00999 if (n == 0) 01000 return 0; 01001 01002 // Check for other errors. 01003 if (n == -1) 01004 { 01005 // Check for possible blocking. 01006 if (errno == EWOULDBLOCK) 01007 { 01008 // Wait for the blocking to subside. 01009 int result = ACE::handle_read_ready (handle, 01010 0); 01011 01012 // Did select() succeed? 01013 if (result != -1) 01014 { 01015 // Blocking subsided. Continue data transfer. 01016 n = 0; 01017 continue; 01018 } 01019 } 01020 01021 // Other data transfer or select() failures. 01022 return -1; 01023 } 01024 01025 for (bytes_transferred += n; 01026 s < iovcnt 01027 && n >= static_cast<ssize_t> (iov[s].iov_len); 01028 s++) 01029 n -= iov[s].iov_len; 01030 01031 if (n != 0) 01032 { 01033 char *base = static_cast<char *> (iov[s].iov_base); 01034 iov[s].iov_base = base + n; 01035 iov[s].iov_len = iov[s].iov_len - n; 01036 } 01037 } 01038 01039 return bytes_transferred; 01040 }
ACE_Export ssize_t ACE::recvv_n_i | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bt | |||
) |
Definition at line 1043 of file ACE.cpp.
References handle_read_ready(), record_and_set_non_blocking_mode(), ACE_OS::recvv(), and restore_non_blocking_mode().
01048 { 01049 size_t temp; 01050 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01051 bytes_transferred = 0; 01052 ssize_t result = 0; 01053 int error = 0; 01054 01055 int val = 0; 01056 ACE::record_and_set_non_blocking_mode (handle, val); 01057 01058 for (int s = 0; 01059 s < iovcnt; 01060 ) 01061 { 01062 // Try to transfer as much of the remaining data as possible. 01063 // Since the socket is in non-blocking mode, this call will not 01064 // block. 01065 ssize_t n = ACE_OS::recvv (handle, 01066 iov + s, 01067 iovcnt - s); 01068 01069 // Check for errors. 01070 if (n == 0 || 01071 n == -1) 01072 { 01073 // Check for possible blocking. 01074 if (n == -1 && 01075 errno == EWOULDBLOCK) 01076 { 01077 // Wait upto <timeout> for the blocking to subside. 01078 int rtn = ACE::handle_read_ready (handle, 01079 timeout); 01080 01081 // Did select() succeed? 01082 if (rtn != -1) 01083 { 01084 // Blocking subsided in <timeout> period. Continue 01085 // data transfer. 01086 n = 0; 01087 continue; 01088 } 01089 } 01090 01091 // Wait in select() timed out or other data transfer or 01092 // select() failures. 01093 error = 1; 01094 result = n; 01095 break; 01096 } 01097 01098 for (bytes_transferred += n; 01099 s < iovcnt 01100 && n >= static_cast<ssize_t> (iov[s].iov_len); 01101 s++) 01102 n -= iov[s].iov_len; 01103 01104 if (n != 0) 01105 { 01106 char *base = reinterpret_cast<char *> (iov[s].iov_base); 01107 iov[s].iov_base = base + n; 01108 iov[s].iov_len = iov[s].iov_len - n; 01109 } 01110 } 01111 01112 ACE::restore_non_blocking_mode (handle, val); 01113 01114 if (error) 01115 return result; 01116 else 01117 return bytes_transferred; 01118 }
ACE_Export ssize_t ACE::recv_n | ( | ACE_HANDLE | handle, | |
ACE_Message_Block * | message_block, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bt = 0 | |||
) |
Definition at line 1121 of file ACE.cpp.
References ACE_IOV_MAX, ACE_Message_Block::cont(), ACE_Message_Block::length(), ACE_Message_Block::next(), ACE_Message_Block::rd_ptr(), and recvv_n().
Referenced by ACE_SOCK_Stream::recv_n(), ACE_SOCK_SEQPACK_Association::recv_n(), ACE_Pipe::recv_n(), ACE_FIFO_Recv::recv_n(), and ACE_DEV_IO::recv_n().
01125 { 01126 size_t temp; 01127 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01128 bytes_transferred = 0; 01129 01130 iovec iov[ACE_IOV_MAX]; 01131 int iovcnt = 0; 01132 01133 while (message_block != 0) 01134 { 01135 // Our current message block chain. 01136 const ACE_Message_Block *current_message_block = message_block; 01137 01138 while (current_message_block != 0) 01139 { 01140 size_t current_message_block_length = 01141 current_message_block->length (); 01142 char *this_rd_ptr = current_message_block->rd_ptr (); 01143 01144 // Check if this block has any space for incoming data. 01145 while (current_message_block_length > 0) 01146 { 01147 u_long const this_chunk_length = 01148 ACE_Utils::truncate_cast<u_long> ( 01149 current_message_block_length); 01150 01151 // Collect the data in the iovec. 01152 iov[iovcnt].iov_base = this_rd_ptr; 01153 iov[iovcnt].iov_len = this_chunk_length; 01154 current_message_block_length -= this_chunk_length; 01155 this_rd_ptr += this_chunk_length; 01156 01157 // Increment iovec counter. 01158 ++iovcnt; 01159 01160 // The buffer is full make a OS call. @@ TODO find a way to 01161 // find ACE_IOV_MAX for platforms that do not define it rather 01162 // than simply setting ACE_IOV_MAX to some arbitrary value such 01163 // as 16. 01164 if (iovcnt == ACE_IOV_MAX) 01165 { 01166 size_t current_transfer = 0; 01167 01168 ssize_t const result = ACE::recvv_n (handle, 01169 iov, 01170 iovcnt, 01171 timeout, 01172 ¤t_transfer); 01173 01174 // Add to total bytes transferred. 01175 bytes_transferred += current_transfer; 01176 01177 // Errors. 01178 if (result == -1 || result == 0) 01179 return result; 01180 01181 // Reset iovec counter. 01182 iovcnt = 0; 01183 } 01184 } 01185 01186 // Select the next message block in the chain. 01187 current_message_block = current_message_block->cont (); 01188 } 01189 01190 // Selection of the next message block chain. 01191 message_block = message_block->next (); 01192 } 01193 01194 // Check for remaining buffers to be sent. This will happen when 01195 // ACE_IOV_MAX is not a multiple of the number of message blocks. 01196 if (iovcnt != 0) 01197 { 01198 size_t current_transfer = 0; 01199 01200 ssize_t const result = ACE::recvv_n (handle, 01201 iov, 01202 iovcnt, 01203 timeout, 01204 ¤t_transfer); 01205 01206 // Add to total bytes transferred. 01207 bytes_transferred += current_transfer; 01208 01209 // Errors. 01210 if (result == -1 || result == 0) 01211 return result; 01212 } 01213 01214 // Return total bytes transferred. 01215 return bytes_transferred; 01216 }
ACE_Export ssize_t ACE::send | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | n, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 1219 of file ACE.cpp.
References enter_send_timedwait(), restore_non_blocking_mode(), and ACE_OS::send().
Referenced by ACE_MEM_Acceptor::accept(), ACE_Select_Reactor_Notify::dispatch_notify(), ACE_Select_Reactor_Notify::notify(), ACE_SOCK_IO::send(), ACE_SOCK_Dgram_SC< STREAM >::send_n(), ACE_SOCK_Stream::send_urg(), and ACE_SOCK_SEQPACK_Association::send_urg().
01224 { 01225 if (timeout == 0) 01226 return ACE_OS::send (handle, (const char *) buf, n, flags); 01227 else 01228 { 01229 int val = 0; 01230 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01231 return -1; 01232 else 01233 { 01234 ssize_t bytes_transferred = ACE_OS::send (handle, (const char *) buf, n, flags); 01235 ACE::restore_non_blocking_mode (handle, val); 01236 return bytes_transferred; 01237 } 01238 } 01239 }
ACE_Export ssize_t ACE::send | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | n, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 1269 of file ACE.cpp.
References enter_send_timedwait(), restore_non_blocking_mode(), and send_i().
01273 { 01274 if (timeout == 0) 01275 return ACE::send_i (handle, buf, n); 01276 else 01277 { 01278 int val = 0; 01279 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01280 return -1; 01281 else 01282 { 01283 ssize_t bytes_transferred = ACE::send_i (handle, buf, n); 01284 ACE::restore_non_blocking_mode (handle, val); 01285 return bytes_transferred; 01286 } 01287 } 01288 }
ACE_Export ssize_t ACE::sendmsg | ( | ACE_HANDLE | handle, | |
const struct msghdr * | msg, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 1291 of file ACE.cpp.
References enter_send_timedwait(), restore_non_blocking_mode(), and ACE_OS::sendmsg().
01295 { 01296 if (timeout == 0) 01297 return ACE_OS::sendmsg (handle, msg, flags); 01298 else 01299 { 01300 int val = 0; 01301 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01302 return -1; 01303 else 01304 { 01305 ssize_t bytes_transferred = ACE_OS::sendmsg (handle, msg, flags); 01306 ACE::restore_non_blocking_mode (handle, val); 01307 return bytes_transferred; 01308 } 01309 } 01310 }
ACE_Export ssize_t ACE::sendto | ( | ACE_HANDLE | handle, | |
const char * | buf, | |||
int | len, | |||
int | flags, | |||
const struct sockaddr * | addr, | |||
int | addrlen, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 1313 of file ACE.cpp.
References enter_send_timedwait(), restore_non_blocking_mode(), and ACE_OS::sendto().
01320 { 01321 if (timeout == 0) 01322 return ACE_OS::sendto (handle, buf, len, flags, addr, addrlen); 01323 else 01324 { 01325 int val = 0; 01326 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01327 return -1; 01328 else 01329 { 01330 ssize_t bytes_transferred = 01331 ACE_OS::sendto (handle, buf, len, flags, addr, addrlen); 01332 ACE::restore_non_blocking_mode (handle, val); 01333 return bytes_transferred; 01334 } 01335 } 01336 }
ACE_Export ssize_t ACE::send_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
size_t * | bt | |||
) |
Definition at line 1339 of file ACE.cpp.
References handle_write_ready(), and ACE_OS::send().
Referenced by send_n().
01344 { 01345 size_t temp; 01346 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01347 ssize_t n; 01348 01349 for (bytes_transferred = 0; 01350 bytes_transferred < len; 01351 bytes_transferred += n) 01352 { 01353 // Try to transfer as much of the remaining data as possible. 01354 n = ACE_OS::send (handle, 01355 (char *) buf + bytes_transferred, 01356 len - bytes_transferred, 01357 flags); 01358 // Check EOF. 01359 if (n == 0) 01360 return 0; 01361 01362 // Check for other errors. 01363 if (n == -1) 01364 { 01365 // Check for possible blocking. 01366 #if defined (ACE_WIN32) 01367 if (errno == EWOULDBLOCK) // If enobufs no need to loop 01368 #else 01369 if (errno == EWOULDBLOCK || errno == ENOBUFS) 01370 #endif /* ACE_WIN32 */ 01371 { 01372 // Wait for the blocking to subside. 01373 int result = ACE::handle_write_ready (handle, 01374 0); 01375 01376 // Did select() succeed? 01377 if (result != -1) 01378 { 01379 // Blocking subsided. Continue data transfer. 01380 n = 0; 01381 continue; 01382 } 01383 } 01384 01385 // Other data transfer or select() failures. 01386 return -1; 01387 } 01388 } 01389 01390 return bytes_transferred; 01391 }
ACE_Export ssize_t ACE::send_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bt | |||
) |
Definition at line 1394 of file ACE.cpp.
References handle_write_ready(), record_and_set_non_blocking_mode(), restore_non_blocking_mode(), and ACE_OS::send().
01400 { 01401 size_t temp; 01402 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01403 ssize_t n; 01404 ssize_t result = 0; 01405 int error = 0; 01406 01407 int val = 0; 01408 ACE::record_and_set_non_blocking_mode (handle, val); 01409 01410 for (bytes_transferred = 0; 01411 bytes_transferred < len; 01412 bytes_transferred += n) 01413 { 01414 // Try to transfer as much of the remaining data as possible. 01415 // Since the socket is in non-blocking mode, this call will not 01416 // block. 01417 n = ACE_OS::send (handle, 01418 (char *) buf + bytes_transferred, 01419 len - bytes_transferred, 01420 flags); 01421 01422 // Check for errors. 01423 if (n == 0 || 01424 n == -1) 01425 { 01426 // Check for possible blocking. 01427 if (n == -1 && 01428 errno == EWOULDBLOCK || errno == ENOBUFS) 01429 { 01430 // Wait upto <timeout> for the blocking to subside. 01431 int rtn = ACE::handle_write_ready (handle, 01432 timeout); 01433 01434 // Did select() succeed? 01435 if (rtn != -1) 01436 { 01437 // Blocking subsided in <timeout> period. Continue 01438 // data transfer. 01439 n = 0; 01440 continue; 01441 } 01442 } 01443 01444 // Wait in select() timed out or other data transfer or 01445 // select() failures. 01446 error = 1; 01447 result = n; 01448 break; 01449 } 01450 } 01451 01452 ACE::restore_non_blocking_mode (handle, val); 01453 01454 if (error) 01455 return result; 01456 else 01457 return bytes_transferred; 01458 }
ACE_Export ssize_t ACE::send_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
size_t * | bt | |||
) |
Definition at line 1583 of file ACE.cpp.
References handle_write_ready(), and send_i().
01587 { 01588 size_t temp; 01589 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01590 ssize_t n; 01591 01592 for (bytes_transferred = 0; 01593 bytes_transferred < len; 01594 bytes_transferred += n) 01595 { 01596 // Try to transfer as much of the remaining data as possible. 01597 n = ACE::send_i (handle, 01598 (char *) buf + bytes_transferred, 01599 len - bytes_transferred); 01600 // Check EOF. 01601 if (n == 0) 01602 return 0; 01603 01604 // Check for other errors. 01605 if (n == -1) 01606 { 01607 // Check for possible blocking. 01608 if (errno == EWOULDBLOCK || errno == ENOBUFS) 01609 { 01610 // Wait for the blocking to subside. 01611 int result = ACE::handle_write_ready (handle, 01612 0); 01613 01614 // Did select() succeed? 01615 if (result != -1) 01616 { 01617 // Blocking subsided. Continue data transfer. 01618 n = 0; 01619 continue; 01620 } 01621 } 01622 01623 // Other data transfer or select() failures. 01624 return -1; 01625 } 01626 } 01627 01628 return bytes_transferred; 01629 }
ACE_Export ssize_t ACE::send_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bt | |||
) |
Definition at line 1632 of file ACE.cpp.
References handle_write_ready(), record_and_set_non_blocking_mode(), restore_non_blocking_mode(), and send_i().
01637 { 01638 size_t temp; 01639 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01640 ssize_t n; 01641 ssize_t result = 0; 01642 int error = 0; 01643 01644 int val = 0; 01645 ACE::record_and_set_non_blocking_mode (handle, val); 01646 01647 for (bytes_transferred = 0; 01648 bytes_transferred < len; 01649 bytes_transferred += n) 01650 { 01651 // Try to transfer as much of the remaining data as possible. 01652 // Since the socket is in non-blocking mode, this call will not 01653 // block. 01654 n = ACE::send_i (handle, 01655 (char *) buf + bytes_transferred, 01656 len - bytes_transferred); 01657 01658 // Check for errors. 01659 if (n == 0 || 01660 n == -1) 01661 { 01662 // Check for possible blocking. 01663 if (n == -1 && 01664 errno == EWOULDBLOCK || errno == ENOBUFS) 01665 { 01666 // Wait upto <timeout> for the blocking to subside. 01667 int rtn = ACE::handle_write_ready (handle, 01668 timeout); 01669 01670 // Did select() succeed? 01671 if (rtn != -1) 01672 { 01673 // Blocking subsided in <timeout> period. Continue 01674 // data transfer. 01675 n = 0; 01676 continue; 01677 } 01678 } 01679 01680 // Wait in select() timed out or other data transfer or 01681 // select() failures. 01682 error = 1; 01683 result = n; 01684 break; 01685 } 01686 } 01687 01688 ACE::restore_non_blocking_mode (handle, val); 01689 01690 if (error) 01691 return result; 01692 else 01693 return bytes_transferred; 01694 }
ACE_Export ssize_t ACE::send | ( | ACE_HANDLE | handle, | |
size_t | n, | |||
... | ||||
) |
Varargs variant.
Definition at line 1702 of file ACE.cpp.
References ACE_NEW_RETURN, and ACE_OS::sendv().
01703 { 01704 va_list argp; 01705 int total_tuples = static_cast<int> (n / 2); 01706 iovec *iovp; 01707 #if defined (ACE_HAS_ALLOCA) 01708 iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); 01709 #else 01710 ACE_NEW_RETURN (iovp, 01711 iovec[total_tuples], 01712 -1); 01713 #endif /* !defined (ACE_HAS_ALLOCA) */ 01714 01715 va_start (argp, n); 01716 01717 for (int i = 0; i < total_tuples; i++) 01718 { 01719 iovp[i].iov_base = va_arg (argp, char *); 01720 iovp[i].iov_len = va_arg (argp, int); 01721 } 01722 01723 ssize_t result = ACE_OS::sendv (handle, iovp, total_tuples); 01724 #if !defined (ACE_HAS_ALLOCA) 01725 delete [] iovp; 01726 #endif /* !defined (ACE_HAS_ALLOCA) */ 01727 va_end (argp); 01728 return result; 01729 }
ACE_Export ssize_t ACE::sendv | ( | ACE_HANDLE | handle, | |
const iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
Definition at line 1732 of file ACE.cpp.
References enter_send_timedwait(), restore_non_blocking_mode(), and ACE_OS::sendv().
Referenced by ACE_Pipe::send(), and ACE_SOCK_IO::sendv().
01736 { 01737 if (timeout == 0) 01738 return ACE_OS::sendv (handle, iov, iovcnt); 01739 else 01740 { 01741 int val = 0; 01742 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01743 return -1; 01744 else 01745 { 01746 ssize_t bytes_transferred = ACE_OS::sendv (handle, iov, iovcnt); 01747 ACE::restore_non_blocking_mode (handle, val); 01748 return bytes_transferred; 01749 } 01750 } 01751 }
ACE_Export ssize_t ACE::sendv_n_i | ( | ACE_HANDLE | handle, | |
const iovec * | i, | |||
int | iovcnt, | |||
size_t * | bt | |||
) |
Definition at line 1754 of file ACE.cpp.
References handle_write_ready(), and ACE_OS::sendv().
Referenced by sendv_n().
01758 { 01759 size_t temp; 01760 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01761 bytes_transferred = 0; 01762 01763 iovec *iov = const_cast<iovec *> (i); 01764 01765 for (int s = 0; 01766 s < iovcnt; 01767 ) 01768 { 01769 // Try to transfer as much of the remaining data as possible. 01770 ssize_t n = ACE_OS::sendv (handle, 01771 iov + s, 01772 iovcnt - s); 01773 // Check EOF. 01774 if (n == 0) 01775 return 0; 01776 01777 // Check for other errors. 01778 if (n == -1) 01779 { 01780 // Check for possible blocking. 01781 if (errno == EWOULDBLOCK || errno == ENOBUFS) 01782 { 01783 // Wait for the blocking to subside. 01784 int result = ACE::handle_write_ready (handle, 01785 0); 01786 01787 // Did select() succeed? 01788 if (result != -1) 01789 { 01790 // Blocking subsided. Continue data transfer. 01791 n = 0; 01792 continue; 01793 } 01794 } 01795 01796 // Other data transfer or select() failures. 01797 return -1; 01798 } 01799 01800 for (bytes_transferred += n; 01801 s < iovcnt 01802 && n >= static_cast<ssize_t> (iov[s].iov_len); 01803 s++) 01804 n -= iov[s].iov_len; 01805 01806 if (n != 0) 01807 { 01808 char *base = reinterpret_cast<char *> (iov[s].iov_base); 01809 iov[s].iov_base = base + n; 01810 iov[s].iov_len = iov[s].iov_len - n; 01811 } 01812 } 01813 01814 return bytes_transferred; 01815 }
ACE_Export ssize_t ACE::sendv_n_i | ( | ACE_HANDLE | handle, | |
const iovec * | i, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bt | |||
) |
Definition at line 1818 of file ACE.cpp.
References handle_write_ready(), record_and_set_non_blocking_mode(), restore_non_blocking_mode(), and ACE_OS::sendv().
01823 { 01824 size_t temp; 01825 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01826 bytes_transferred = 0; 01827 ssize_t result = 0; 01828 int error = 0; 01829 01830 int val = 0; 01831 ACE::record_and_set_non_blocking_mode (handle, val); 01832 01833 iovec *iov = const_cast<iovec *> (i); 01834 01835 for (int s = 0; 01836 s < iovcnt; 01837 ) 01838 { 01839 // Try to transfer as much of the remaining data as possible. 01840 // Since the socket is in non-blocking mode, this call will not 01841 // block. 01842 ssize_t n = ACE_OS::sendv (handle, 01843 iov + s, 01844 iovcnt - s); 01845 01846 // Check for errors. 01847 if (n == 0 || 01848 n == -1) 01849 { 01850 // Check for possible blocking. 01851 if (n == -1 && 01852 errno == EWOULDBLOCK || errno == ENOBUFS) 01853 { 01854 // Wait upto <timeout> for the blocking to subside. 01855 int rtn = ACE::handle_write_ready (handle, 01856 timeout); 01857 01858 // Did select() succeed? 01859 if (rtn != -1) 01860 { 01861 // Blocking subsided in <timeout> period. Continue 01862 // data transfer. 01863 n = 0; 01864 continue; 01865 } 01866 } 01867 01868 // Wait in select() timed out or other data transfer or 01869 // select() failures. 01870 error = 1; 01871 result = n; 01872 break; 01873 } 01874 01875 for (bytes_transferred += n; 01876 s < iovcnt 01877 && n >= static_cast<ssize_t> (iov[s].iov_len); 01878 s++) 01879 n -= iov[s].iov_len; 01880 01881 if (n != 0) 01882 { 01883 char *base = reinterpret_cast<char *> (iov[s].iov_base); 01884 iov[s].iov_base = base + n; 01885 iov[s].iov_len = iov[s].iov_len - n; 01886 } 01887 } 01888 01889 ACE::restore_non_blocking_mode (handle, val); 01890 01891 if (error) 01892 return result; 01893 else 01894 return bytes_transferred; 01895 }
ACE_Export ssize_t ACE::write_n | ( | ACE_HANDLE | handle, | |
const ACE_Message_Block * | message_block, | |||
size_t * | bytes_transferred = 0 | |||
) |
Write all the message_blocks chained through their next
and cont
pointers. This call uses the underlying OS gather-write operation to reduce the domain-crossing penalty.
Definition at line 1898 of file ACE.cpp.
References ACE_IOV_MAX, ACE_Message_Block::cont(), ACE_Message_Block::length(), ACE_Message_Block::next(), ACE_Message_Block::rd_ptr(), and writev_n().
Referenced by ACE_SPIPE_Stream::send_n(), ACE_Pipe::send_n(), ACE_FILE_IO::send_n(), and ACE_DEV_IO::send_n().
01901 { 01902 size_t temp; 01903 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01904 bytes_transferred = 0; 01905 01906 iovec iov[ACE_IOV_MAX]; 01907 int iovcnt = 0; 01908 01909 while (message_block != 0) 01910 { 01911 // Our current message block chain. 01912 const ACE_Message_Block *current_message_block = message_block; 01913 01914 while (current_message_block != 0) 01915 { 01916 size_t current_message_block_length = 01917 current_message_block->length (); 01918 char *this_block_ptr = current_message_block->rd_ptr (); 01919 01920 // Check if this block has any data to be sent. 01921 while (current_message_block_length > 0) 01922 { 01923 u_long const this_chunk_length = 01924 ACE_Utils::truncate_cast<u_long> ( 01925 current_message_block_length); 01926 01927 // Collect the data in the iovec. 01928 iov[iovcnt].iov_base = this_block_ptr; 01929 iov[iovcnt].iov_len = this_chunk_length; 01930 current_message_block_length -= this_chunk_length; 01931 this_block_ptr += this_chunk_length; 01932 01933 // Increment iovec counter. 01934 ++iovcnt; 01935 01936 // The buffer is full make a OS call. @@ TODO find a way to 01937 // find ACE_IOV_MAX for platforms that do not define it rather 01938 // than simply setting ACE_IOV_MAX to some arbitrary value such 01939 // as 16. 01940 if (iovcnt == ACE_IOV_MAX) 01941 { 01942 size_t current_transfer = 0; 01943 01944 ssize_t const result = ACE::writev_n (handle, 01945 iov, 01946 iovcnt, 01947 ¤t_transfer); 01948 01949 // Add to total bytes transferred. 01950 bytes_transferred += current_transfer; 01951 01952 // Errors. 01953 if (result == -1 || result == 0) 01954 return result; 01955 01956 // Reset iovec counter. 01957 iovcnt = 0; 01958 } 01959 } 01960 01961 // Select the next message block in the chain. 01962 current_message_block = current_message_block->cont (); 01963 } 01964 01965 // Selection of the next message block chain. 01966 message_block = message_block->next (); 01967 } 01968 01969 // Check for remaining buffers to be sent. This will happen when 01970 // ACE_IOV_MAX is not a multiple of the number of message blocks. 01971 if (iovcnt != 0) 01972 { 01973 size_t current_transfer = 0; 01974 01975 ssize_t const result = ACE::writev_n (handle, 01976 iov, 01977 iovcnt, 01978 ¤t_transfer); 01979 01980 // Add to total bytes transferred. 01981 bytes_transferred += current_transfer; 01982 01983 // Errors. 01984 if (result == -1 || result == 0) 01985 return result; 01986 } 01987 01988 // Return total bytes transferred. 01989 return bytes_transferred; 01990 }
ACE_Export ssize_t ACE::send_n | ( | ACE_HANDLE | handle, | |
const ACE_Message_Block * | message_block, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) |
Send all the message_blocks chained through their next
and cont
pointers. This call uses the underlying OS gather-write operation to reduce the domain-crossing penalty.
Definition at line 1993 of file ACE.cpp.
References ACE_IOV_MAX, ACE_Message_Block::cont(), ACE_Message_Block::length(), ACE_Message_Block::next(), ACE_Message_Block::rd_ptr(), and sendv_n().
Referenced by ACE_SOCK_Stream::send_n(), ACE_SOCK_SEQPACK_Association::send_n(), ACE_Pipe::send_n(), and ACE_FIFO_Send::send_n().
01997 { 01998 size_t temp; 01999 size_t &bytes_transferred = bt == 0 ? temp : *bt; 02000 bytes_transferred = 0; 02001 02002 iovec iov[ACE_IOV_MAX]; 02003 int iovcnt = 0; 02004 02005 while (message_block != 0) 02006 { 02007 // Our current message block chain. 02008 const ACE_Message_Block *current_message_block = message_block; 02009 02010 while (current_message_block != 0) 02011 { 02012 char *this_block_ptr = current_message_block->rd_ptr (); 02013 size_t current_message_block_length = 02014 current_message_block->length (); 02015 02016 // Check if this block has any data to be sent. 02017 while (current_message_block_length > 0) 02018 { 02019 u_long const this_chunk_length = 02020 ACE_Utils::truncate_cast<u_long> ( 02021 current_message_block_length); 02022 02023 // Collect the data in the iovec. 02024 iov[iovcnt].iov_base = this_block_ptr; 02025 iov[iovcnt].iov_len = this_chunk_length; 02026 current_message_block_length -= this_chunk_length; 02027 this_block_ptr += this_chunk_length; 02028 02029 // Increment iovec counter. 02030 ++iovcnt; 02031 02032 // The buffer is full make a OS call. @@ TODO find a way to 02033 // find ACE_IOV_MAX for platforms that do not define it rather 02034 // than simply setting ACE_IOV_MAX to some arbitrary value such 02035 // as 16. 02036 if (iovcnt == ACE_IOV_MAX) 02037 { 02038 size_t current_transfer = 0; 02039 02040 ssize_t const result = ACE::sendv_n (handle, 02041 iov, 02042 iovcnt, 02043 timeout, 02044 ¤t_transfer); 02045 02046 // Add to total bytes transferred. 02047 bytes_transferred += current_transfer; 02048 02049 // Errors. 02050 if (result == -1 || result == 0) 02051 return result; 02052 02053 // Reset iovec counter. 02054 iovcnt = 0; 02055 } 02056 } 02057 02058 // Select the next message block in the chain. 02059 current_message_block = current_message_block->cont (); 02060 } 02061 02062 // Selection of the next message block chain. 02063 message_block = message_block->next (); 02064 } 02065 02066 // Check for remaining buffers to be sent. This will happen when 02067 // ACE_IOV_MAX is not a multiple of the number of message blocks. 02068 if (iovcnt != 0) 02069 { 02070 size_t current_transfer = 0; 02071 02072 ssize_t const result = ACE::sendv_n (handle, 02073 iov, 02074 iovcnt, 02075 timeout, 02076 ¤t_transfer); 02077 02078 // Add to total bytes transferred. 02079 bytes_transferred += current_transfer; 02080 02081 // Errors. 02082 if (result == -1 || result == 0) 02083 return result; 02084 } 02085 02086 // Return total bytes transferred. 02087 return bytes_transferred; 02088 }
ACE_Export ssize_t ACE::readv_n | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
size_t * | bt = 0 | |||
) |
Definition at line 2091 of file ACE.cpp.
References ACE_OS::readv().
02095 { 02096 size_t temp; 02097 size_t &bytes_transferred = bt == 0 ? temp : *bt; 02098 bytes_transferred = 0; 02099 02100 for (int s = 0; 02101 s < iovcnt; 02102 ) 02103 { 02104 ssize_t n = ACE_OS::readv (handle, 02105 iov + s, 02106 iovcnt - s); 02107 02108 if (n == -1 || n == 0) 02109 return n; 02110 02111 for (bytes_transferred += n; 02112 s < iovcnt 02113 && n >= static_cast<ssize_t> (iov[s].iov_len); 02114 s++) 02115 n -= iov[s].iov_len; 02116 02117 if (n != 0) 02118 { 02119 char *base = reinterpret_cast<char *> (iov[s].iov_base); 02120 iov[s].iov_base = base + n; 02121 iov[s].iov_len = iov[s].iov_len - n; 02122 } 02123 } 02124 02125 return bytes_transferred; 02126 }
ACE_Export ssize_t ACE::writev_n | ( | ACE_HANDLE | handle, | |
const iovec * | i, | |||
int | iovcnt, | |||
size_t * | bt = 0 | |||
) |
Definition at line 2129 of file ACE.cpp.
References ACE_OS::writev().
Referenced by ACE_SPIPE_Stream::sendv_n(), ACE_Pipe::sendv_n(), ACE_FILE_IO::sendv_n(), and write_n().
02133 { 02134 size_t temp; 02135 size_t &bytes_transferred = bt == 0 ? temp : *bt; 02136 bytes_transferred = 0; 02137 02138 iovec *iov = const_cast<iovec *> (i); 02139 02140 for (int s = 0; 02141 s < iovcnt; 02142 ) 02143 { 02144 ssize_t n = ACE_OS::writev (handle, 02145 iov + s, 02146 iovcnt - s); 02147 if (n == -1 || n == 0) 02148 return n; 02149 02150 for (bytes_transferred += n; 02151 s < iovcnt 02152 && n >= static_cast<ssize_t> (iov[s].iov_len); 02153 s++) 02154 n -= iov[s].iov_len; 02155 02156 if (n != 0) 02157 { 02158 char *base = reinterpret_cast<char *> (iov[s].iov_base); 02159 iov[s].iov_base = base + n; 02160 iov[s].iov_len = iov[s].iov_len - n; 02161 } 02162 } 02163 02164 return bytes_transferred; 02165 }
ACE_Export int ACE::handle_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout, | |||
int | read_ready, | |||
int | write_ready, | |||
int | exception_ready | |||
) |
Timed wait for handle to get read, write, or exception ready.
Definition at line 2168 of file ACE.cpp.
References ACE_Handle_Set::fdset(), ACE_OS::poll(), ACE_OS::select(), and ACE_Handle_Set::set_bit().
Referenced by handle_exception_ready(), handle_read_ready(), and handle_write_ready().
02173 { 02174 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) 02175 ACE_UNUSED_ARG (write_ready); 02176 ACE_UNUSED_ARG (exception_ready); 02177 02178 struct pollfd fds; 02179 02180 fds.fd = handle; 02181 fds.events = read_ready ? POLLIN : POLLOUT; 02182 fds.revents = 0; 02183 02184 int result = ACE_OS::poll (&fds, 1, timeout); 02185 #else 02186 ACE_Handle_Set handle_set; 02187 handle_set.set_bit (handle); 02188 02189 // Wait for data or for the timeout to elapse. 02190 int select_width; 02191 # if defined (ACE_WIN32) 02192 // This arg is ignored on Windows and causes pointer truncation 02193 // warnings on 64-bit compiles. 02194 select_width = 0; 02195 # else 02196 select_width = int (handle) + 1; 02197 # endif /* ACE_WIN64 */ 02198 int result = ACE_OS::select (select_width, 02199 read_ready ? handle_set.fdset () : 0, // read_fds. 02200 write_ready ? handle_set.fdset () : 0, // write_fds. 02201 exception_ready ? handle_set.fdset () : 0, // exception_fds. 02202 timeout); 02203 02204 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ 02205 02206 switch (result) 02207 { 02208 case 0: // Timer expired. 02209 errno = ETIME; 02210 /* FALLTHRU */ 02211 case -1: // we got here directly - select() returned -1. 02212 return -1; 02213 case 1: // Handle has data. 02214 /* FALLTHRU */ 02215 default: // default is case result > 0; return a 02216 // ACE_ASSERT (result == 1); 02217 return result; 02218 } 02219 }
ACE_Export int ACE::enter_recv_timedwait | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout, | |||
int & | val | |||
) |
Wait for timeout before proceeding to a recv
operation. val keeps track of whether we're in non-blocking mode or not.
Definition at line 2222 of file ACE.cpp.
References handle_read_ready(), and record_and_set_non_blocking_mode().
Referenced by recv(), recvfrom(), recvmsg(), and recvv().
02225 { 02226 int result = ACE::handle_read_ready (handle, 02227 timeout); 02228 02229 if (result == -1) 02230 return -1; 02231 02232 ACE::record_and_set_non_blocking_mode (handle, 02233 val); 02234 02235 return result; 02236 }
ACE_Export int ACE::enter_send_timedwait | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout, | |||
int & | val | |||
) |
Wait for timeout before proceeding to a send
operation. val keeps track of whether we're in non-blocking mode or not.
Definition at line 2239 of file ACE.cpp.
References handle_write_ready(), and record_and_set_non_blocking_mode().
Referenced by send(), sendmsg(), sendto(), and sendv().
02242 { 02243 int result = ACE::handle_write_ready (handle, 02244 timeout); 02245 02246 if (result == -1) 02247 return -1; 02248 02249 ACE::record_and_set_non_blocking_mode (handle, 02250 val); 02251 02252 return result; 02253 }
ACE_Export void ACE::record_and_set_non_blocking_mode | ( | ACE_HANDLE | handle, | |
int & | val | |||
) |
This makes sure that handle is set into non-blocking mode. val keeps track of whether were in non-blocking mode or not.
Definition at line 2256 of file ACE.cpp.
References ACE_BIT_DISABLED, ACE_NONBLOCK, get_flags(), and set_flags().
Referenced by enter_recv_timedwait(), enter_send_timedwait(), recv_n_i(), recvv_n_i(), send_n_i(), and sendv_n_i().
02258 { 02259 // We need to record whether we are already *in* nonblocking mode, 02260 // so that we can correctly reset the state when we're done. 02261 val = ACE::get_flags (handle); 02262 02263 if (ACE_BIT_DISABLED (val, ACE_NONBLOCK)) 02264 // Set the handle into non-blocking mode if it's not already in 02265 // it. 02266 ACE::set_flags (handle, ACE_NONBLOCK); 02267 }
ACE_Export void ACE::restore_non_blocking_mode | ( | ACE_HANDLE | handle, | |
int | val | |||
) |
Cleanup after a timed operation, restore the appropriate non-blocking status of handle.
Definition at line 2270 of file ACE.cpp.
References ACE_BIT_DISABLED, ACE_NONBLOCK, and clr_flags().
Referenced by recv(), recv_n_i(), recvfrom(), recvmsg(), recvv(), recvv_n_i(), send(), send_n_i(), sendmsg(), sendto(), sendv(), and sendv_n_i().
02272 { 02273 if (ACE_BIT_DISABLED (val, 02274 ACE_NONBLOCK)) 02275 { 02276 // Save/restore errno. 02277 ACE_Errno_Guard error (errno); 02278 // Only disable ACE_NONBLOCK if we weren't in non-blocking mode 02279 // originally. 02280 ACE::clr_flags (handle, ACE_NONBLOCK); 02281 } 02282 }
ACE_Export size_t ACE::format_hexdump | ( | const char * | buffer, | |
size_t | size, | |||
ACE_TCHAR * | obuf, | |||
size_t | obuf_sz | |||
) |
Format buffer into printable format. This is useful for debugging.
Definition at line 2290 of file ACE.cpp.
References ACE_OS::ace_isprint(), ACE_TEXT, ACE_TRACE, and ACE_OS::sprintf().
Referenced by ACE_Log_Msg::log_hexdump().
02294 { 02295 ACE_TRACE ("ACE::format_hexdump"); 02296 02297 u_char c; 02298 ACE_TCHAR textver[16 + 1]; 02299 02300 // We can fit 16 bytes output in text mode per line, 4 chars per byte. 02301 size_t maxlen = (obuf_sz / 68) * 16; 02302 02303 if (size > maxlen) 02304 size = maxlen; 02305 02306 size_t i; 02307 02308 size_t lines = size / 16; 02309 for (i = 0; i < lines; i++) 02310 { 02311 size_t j; 02312 02313 for (j = 0 ; j < 16; j++) 02314 { 02315 c = (u_char) buffer[(i << 4) + j]; // or, buffer[i*16+j] 02316 ACE_OS::sprintf (obuf, 02317 ACE_TEXT ("%02x "), 02318 c); 02319 obuf += 3; 02320 if (j == 7) 02321 { 02322 ACE_OS::sprintf (obuf, 02323 ACE_TEXT (" ")); 02324 ++obuf; 02325 } 02326 textver[j] = ACE_OS::ace_isprint (c) ? c : '.'; 02327 } 02328 02329 textver[j] = 0; 02330 02331 ACE_OS::sprintf (obuf, 02332 ACE_TEXT (" %s\n"), 02333 textver); 02334 02335 while (*obuf != '\0') 02336 ++obuf; 02337 } 02338 02339 if (size % 16) 02340 { 02341 for (i = 0 ; i < size % 16; i++) 02342 { 02343 c = (u_char) buffer[size - size % 16 + i]; 02344 ACE_OS::sprintf (obuf, 02345 ACE_TEXT ("%02x "), 02346 c); 02347 obuf += 3; 02348 if (i == 7) 02349 { 02350 ACE_OS::sprintf (obuf, 02351 ACE_TEXT (" ")); 02352 ++obuf; 02353 } 02354 textver[i] = ACE_OS::ace_isprint (c) ? c : '.'; 02355 } 02356 02357 for (i = size % 16; i < 16; i++) 02358 { 02359 ACE_OS::sprintf (obuf, 02360 ACE_TEXT (" ")); 02361 obuf += 3; 02362 if (i == 7) 02363 { 02364 ACE_OS::sprintf (obuf, 02365 ACE_TEXT (" ")); 02366 ++obuf; 02367 } 02368 textver[i] = ' '; 02369 } 02370 02371 textver[i] = 0; 02372 ACE_OS::sprintf (obuf, 02373 ACE_TEXT (" %s\n"), 02374 textver); 02375 } 02376 return size; 02377 }
ACE_Export ACE_TCHAR * ACE::timestamp | ( | ACE_TCHAR | date_and_time[], | |
int | time_len, | |||
int | return_pointer_to_first_digit = 0 | |||
) |
Returns the current timestamp in the form "hour:minute:second:microsecond." The month, day, and year are also stored in the beginning of the date_and_time array, which is a user-supplied array of size time_len> ACE_TCHARs
. Returns 0 if unsuccessful, else returns pointer to beginning of the "time" portion of date_and_time. If return_pointer_to_first_digit is 0 then return a pointer to the space before the time, else return a pointer to the beginning of the time portion.
Definition at line 2384 of file ACE.cpp.
References ACE_TEXT, ACE_OS::ctime_r(), ACE_OS::gettimeofday(), ACE_Time_Value::sec(), ACE_OS::sprintf(), ACE_OS::strsncpy(), and ACE_Time_Value::usec().
Referenced by ACE_Log_Msg::ACE_Log_Msg(), ACE_Log_Record::format_msg(), ACE_Utils::UUID_Generator::generate_UUID(), ACE_Log_Msg_UNIX_Syslog::log(), and ACE_Log_Msg::log().
02387 { 02388 //ACE_TRACE ("ACE::timestamp"); 02389 02390 if (date_and_timelen < 35) 02391 { 02392 errno = EINVAL; 02393 return 0; 02394 } 02395 02396 #if defined (WIN32) 02397 // Emulate Unix. Win32 does NOT support all the UNIX versions 02398 // below, so DO we need this ifdef. 02399 static const ACE_TCHAR *day_of_week_name[] = 02400 { 02401 ACE_TEXT ("Sun"), 02402 ACE_TEXT ("Mon"), 02403 ACE_TEXT ("Tue"), 02404 ACE_TEXT ("Wed"), 02405 ACE_TEXT ("Thu"), 02406 ACE_TEXT ("Fri"), 02407 ACE_TEXT ("Sat") 02408 }; 02409 02410 static const ACE_TCHAR *month_name[] = 02411 { 02412 ACE_TEXT ("Jan"), 02413 ACE_TEXT ("Feb"), 02414 ACE_TEXT ("Mar"), 02415 ACE_TEXT ("Apr"), 02416 ACE_TEXT ("May"), 02417 ACE_TEXT ("Jun"), 02418 ACE_TEXT ("Jul"), 02419 ACE_TEXT ("Aug"), 02420 ACE_TEXT ("Sep"), 02421 ACE_TEXT ("Oct"), 02422 ACE_TEXT ("Nov"), 02423 ACE_TEXT ("Dec") 02424 }; 02425 02426 SYSTEMTIME local; 02427 ::GetLocalTime (&local); 02428 02429 ACE_OS::sprintf (date_and_time, 02430 ACE_TEXT ("%3s %3s %2d %04d %02d:%02d:%02d.%06d"), 02431 day_of_week_name[local.wDayOfWeek], 02432 month_name[local.wMonth - 1], 02433 (int) local.wDay, 02434 (int) local.wYear, 02435 (int) local.wHour, 02436 (int) local.wMinute, 02437 (int) local.wSecond, 02438 (int) (local.wMilliseconds * 1000)); 02439 return &date_and_time[15 + (return_pointer_to_first_digit != 0)]; 02440 #else /* UNIX */ 02441 ACE_TCHAR timebuf[26]; // This magic number is based on the ctime(3c) man page. 02442 ACE_Time_Value cur_time = ACE_OS::gettimeofday (); 02443 time_t secs = cur_time.sec (); 02444 02445 ACE_OS::ctime_r (&secs, 02446 timebuf, 02447 sizeof timebuf); 02448 // date_and_timelen > sizeof timebuf! 02449 ACE_OS::strsncpy (date_and_time, 02450 timebuf, 02451 date_and_timelen); 02452 ACE_TCHAR yeartmp[5]; 02453 ACE_OS::strsncpy (yeartmp, 02454 &date_and_time[20], 02455 5); 02456 ACE_TCHAR timetmp[9]; 02457 ACE_OS::strsncpy (timetmp, 02458 &date_and_time[11], 02459 9); 02460 ACE_OS::sprintf (&date_and_time[11], 02461 # if defined (ACE_USES_WCHAR) 02462 ACE_TEXT ("%ls %ls.%06ld"), 02463 # else 02464 ACE_TEXT ("%s %s.%06ld"), 02465 # endif /* ACE_USES_WCHAR */ 02466 yeartmp, 02467 timetmp, 02468 cur_time.usec ()); 02469 date_and_time[33] = '\0'; 02470 return &date_and_time[15 + (return_pointer_to_first_digit != 0)]; 02471 #endif /* WIN32 */ 02472 }
ACE_Export size_t ACE::round_to_pagesize | ( | size_t | len | ) |
Rounds the request to a multiple of the page size.
Definition at line 2477 of file ACE.cpp.
References ACE_TRACE, ACE_OS::getpagesize(), and pagesize_.
Referenced by ACE_Shared_Memory_Pool::init_acquire(), ACE_Shared_Memory_Pool::round_up(), ACE_Sbrk_Memory_Pool::round_up(), ACE_MMAP_Memory_Pool::round_up(), and ACE_Local_Memory_Pool::round_up().
02478 { 02479 ACE_TRACE ("ACE::round_to_pagesize"); 02480 02481 if (ACE::pagesize_ == 0) 02482 ACE::pagesize_ = ACE_OS::getpagesize (); 02483 02484 return (len + (ACE::pagesize_ - 1)) & ~(ACE::pagesize_ - 1); 02485 }
ACE_Export size_t ACE::round_to_allocation_granularity | ( | size_t | len | ) |
Rounds the request to a multiple of the allocation granularity.
Definition at line 2488 of file ACE.cpp.
References ACE_TRACE, ACE_OS::allocation_granularity(), and allocation_granularity_.
02489 { 02490 ACE_TRACE ("ACE::round_to_allocation_granularity"); 02491 02492 if (ACE::allocation_granularity_ == 0) 02493 ACE::allocation_granularity_ = ACE_OS::allocation_granularity (); 02494 02495 return (len + (ACE::allocation_granularity_ - 1)) & ~(ACE::allocation_granularity_ - 1); 02496 }
ACE_Export ACE_HANDLE ACE::handle_timed_complete | ( | ACE_HANDLE | listener, | |
const ACE_Time_Value * | timeout, | |||
int | is_tli = 0 | |||
) |
Wait up to 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).
Definition at line 2499 of file ACE.cpp.
References ACE_TRACE, ACE_OS::getsockopt(), ACE_Handle_Set::is_set(), MSG_PEEK, ACE_OS::poll(), recv(), ACE_OS::select(), ACE_Handle_Set::set_bit(), SO_ERROR, and SOL_SOCKET.
Referenced by ACE_SOCK_SEQPACK_Connector::complete(), ACE_SOCK_Connector::complete(), and ACE_SOCK_Connector::shared_connect_finish().
02502 { 02503 ACE_TRACE ("ACE::handle_timed_complete"); 02504 02505 #if !defined (ACE_WIN32) && defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) 02506 02507 struct pollfd fds; 02508 02509 fds.fd = h; 02510 fds.events = POLLIN | POLLOUT; 02511 fds.revents = 0; 02512 02513 #else 02514 ACE_Handle_Set rd_handles; 02515 ACE_Handle_Set wr_handles; 02516 02517 rd_handles.set_bit (h); 02518 wr_handles.set_bit (h); 02519 #endif /* !ACE_WIN32 && ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ 02520 02521 #if defined (ACE_WIN32) 02522 // Winsock is different - it sets the exception bit for failed connect, 02523 // unlike other platforms, where the read bit is set. 02524 ACE_Handle_Set ex_handles; 02525 ex_handles.set_bit (h); 02526 #endif /* ACE_WIN32 */ 02527 02528 bool need_to_check = false; 02529 bool known_failure = false; 02530 02531 #if defined (ACE_WIN32) 02532 int n = ACE_OS::select (0, // Ignored on Windows: int (h) + 1, 02533 0, 02534 wr_handles, 02535 ex_handles, 02536 timeout); 02537 #else 02538 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) 02539 02540 int n = ACE_OS::poll (&fds, 1, timeout); 02541 02542 # else 02543 int n = ACE_OS::select (int (h) + 1, 02544 rd_handles, 02545 wr_handles, 02546 0, 02547 timeout); 02548 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ 02549 #endif /* ACE_WIN32 */ 02550 02551 // If we failed to connect within the time period allocated by the 02552 // caller, then we fail (e.g., the remote host might have been too 02553 // busy to accept our call). 02554 if (n <= 0) 02555 { 02556 if (n == 0 && timeout != 0) 02557 errno = ETIME; 02558 return ACE_INVALID_HANDLE; 02559 } 02560 02561 // Usually, a ready-for-write handle is successfully connected, and 02562 // ready-for-read (exception on Win32) is a failure. On fails, we 02563 // need to grab the error code via getsockopt. On possible success for 02564 // any platform where we can't tell just from select() (e.g. AIX), 02565 // we also need to check for success/fail. 02566 #if defined (ACE_WIN32) 02567 ACE_UNUSED_ARG (is_tli); 02568 02569 // On Win32, ex_handle set indicates a failure. We'll do the check 02570 // to try and get an errno value, but the connect failed regardless of 02571 // what getsockopt says about the error. 02572 if (ex_handles.is_set (h)) 02573 { 02574 need_to_check = true; 02575 known_failure = true; 02576 } 02577 #elif defined (ACE_VXWORKS) 02578 ACE_UNUSED_ARG (is_tli); 02579 02580 // Force the check on VxWorks. The read handle for "h" is not set, 02581 // so "need_to_check" is false at this point. The write handle is 02582 // set, for what it's worth. 02583 need_to_check = true; 02584 #else 02585 if (is_tli) 02586 02587 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) 02588 need_to_check = (fds.revents & POLLIN) && !(fds.revents & POLLOUT); 02589 # else 02590 need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h); 02591 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ 02592 02593 else 02594 #if defined(AIX) 02595 // AIX is broken... both success and failed connect will set the 02596 // write handle only, so always check. 02597 need_to_check = true; 02598 #else 02599 # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) 02600 need_to_check = (fds.revents & POLLIN); 02601 # else 02602 need_to_check = rd_handles.is_set (h); 02603 # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ 02604 #endif /* AIX */ 02605 #endif /* ACE_WIN32 */ 02606 02607 if (need_to_check) 02608 { 02609 #if defined (SOL_SOCKET) && defined (SO_ERROR) 02610 int sock_err = 0; 02611 int sock_err_len = sizeof (sock_err); 02612 int sockopt_ret = ACE_OS::getsockopt (h, SOL_SOCKET, SO_ERROR, 02613 (char *)&sock_err, &sock_err_len); 02614 if (sockopt_ret < 0) 02615 { 02616 h = ACE_INVALID_HANDLE; 02617 } 02618 02619 if (sock_err != 0 || known_failure) 02620 { 02621 h = ACE_INVALID_HANDLE; 02622 errno = sock_err; 02623 } 02624 #else 02625 char dummy; 02626 02627 // The following recv() won't block provided that the 02628 // ACE_NONBLOCK flag has not been turned off . 02629 n = ACE::recv (h, &dummy, 1, MSG_PEEK); 02630 02631 // If no data was read/peeked at, check to see if it's because 02632 // of a non-connected socket (and therefore an error) or there's 02633 // just no data yet. 02634 if (n <= 0) 02635 { 02636 if (n == 0) 02637 { 02638 errno = ECONNREFUSED; 02639 h = ACE_INVALID_HANDLE; 02640 } 02641 else if (errno != EWOULDBLOCK && errno != EAGAIN) 02642 h = ACE_INVALID_HANDLE; 02643 } 02644 #endif 02645 } 02646 02647 // 1. The HANDLE is ready for writing and doesn't need to be checked or 02648 // 2. recv() returned an indication of the state of the socket - if there is 02649 // either data present, or a recv is legit but there's no data yet, 02650 // the connection was successfully established. 02651 return h; 02652 }
ACE_Export int ACE::handle_timed_accept | ( | ACE_HANDLE | listener, | |
ACE_Time_Value * | timeout, | |||
int | restart | |||
) |
Wait up to timeout amount of time to passively establish a connection. This method doesn't perform the accept
, it just does the timed wait.
Definition at line 2657 of file ACE.cpp.
References ACE_TRACE, ACE_OS::poll(), ACE_Time_Value::sec(), ACE_OS::select(), ACE_Handle_Set::set_bit(), and ACE_Time_Value::usec().
Referenced by ACE_SPIPE_Acceptor::accept(), ACE_SOCK_SEQPACK_Acceptor::shared_accept_start(), and ACE_SOCK_Acceptor::shared_accept_start().
02660 { 02661 ACE_TRACE ("ACE::handle_timed_accept"); 02662 // Make sure we don't bomb out on erroneous values. 02663 if (listener == ACE_INVALID_HANDLE) 02664 return -1; 02665 02666 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) 02667 02668 struct pollfd fds; 02669 02670 fds.fd = listener; 02671 fds.events = POLLIN; 02672 fds.revents = 0; 02673 02674 #else 02675 // Use the select() implementation rather than poll(). 02676 ACE_Handle_Set rd_handle; 02677 rd_handle.set_bit (listener); 02678 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ 02679 02680 // We need a loop here if <restart> is enabled. 02681 02682 for (;;) 02683 { 02684 #if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) 02685 02686 int n = ACE_OS::poll (&fds, 1, timeout); 02687 02688 #else 02689 int select_width; 02690 # if defined (ACE_WIN32) 02691 // This arg is ignored on Windows and causes pointer truncation 02692 // warnings on 64-bit compiles. 02693 select_width = 0; 02694 # else 02695 select_width = int (listener) + 1; 02696 # endif /* ACE_WIN32 */ 02697 int n = ACE_OS::select (select_width, 02698 rd_handle, 0, 0, 02699 timeout); 02700 #endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ 02701 02702 switch (n) 02703 { 02704 case -1: 02705 if (errno == EINTR && restart) 02706 continue; 02707 else 02708 return -1; 02709 /* NOTREACHED */ 02710 case 0: 02711 if (timeout != 0 02712 && timeout->sec () == 0 02713 && timeout->usec () == 0) 02714 errno = EWOULDBLOCK; 02715 else 02716 errno = ETIMEDOUT; 02717 return -1; 02718 /* NOTREACHED */ 02719 case 1: 02720 return 0; 02721 /* NOTREACHED */ 02722 default: 02723 errno = EINVAL; 02724 return -1; 02725 /* NOTREACHED */ 02726 } 02727 } 02728 }
ACE_Export int ACE::daemonize | ( | const ACE_TCHAR | pathname[] = ACE_TEXT("/") , |
|
bool | close_all_handles = ACE_DEFAULT_CLOSE_ALL_HANDLES , |
|||
const ACE_TCHAR | program_name[] = ACE_TEXT("<unknown>") | |||
) |
Become a daemon process using the algorithm in Richard Stevens "Advanced Programming in the UNIX Environment." If close_all_handles is non-zero then all open file handles are closed.
Definition at line 2734 of file ACE.cpp.
References ACE_NOTSUP_RETURN, ACE_TRACE, ACE_OS::chdir(), ACE_OS::close(), ACE_OS::exit(), ACE_OS::fork(), max_handles(), ACE_OS::setsid(), SIG_IGN, SIGHUP, ACE_OS::signal(), and ACE_OS::umask().
Referenced by ACE_Service_Config::open_i().
02737 { 02738 ACE_TRACE ("ACE::daemonize"); 02739 #if !defined (ACE_LACKS_FORK) 02740 pid_t pid = ACE_OS::fork (); 02741 02742 if (pid == -1) 02743 return -1; 02744 else if (pid != 0) 02745 ACE_OS::exit (0); // Parent exits. 02746 02747 // 1st child continues. 02748 ACE_OS::setsid (); // Become session leader. 02749 02750 ACE_OS::signal (SIGHUP, SIG_IGN); 02751 02752 pid = ACE_OS::fork (program_name); 02753 02754 if (pid != 0) 02755 ACE_OS::exit (0); // First child terminates. 02756 02757 // Second child continues. 02758 02759 if (pathname != 0) 02760 // change working directory. 02761 ACE_OS::chdir (pathname); 02762 02763 ACE_OS::umask (0); // clear our file mode creation mask. 02764 02765 // Close down the I/O handles. 02766 if (close_all_handles) 02767 for (int i = ACE::max_handles () - 1; i >= 0; i--) 02768 ACE_OS::close (i); 02769 02770 return 0; 02771 #else 02772 ACE_UNUSED_ARG (pathname); 02773 ACE_UNUSED_ARG (close_all_handles); 02774 ACE_UNUSED_ARG (program_name); 02775 02776 ACE_NOTSUP_RETURN (-1); 02777 #endif /* ACE_LACKS_FORK */ 02778 }
ACE_Export pid_t ACE::fork | ( | const ACE_TCHAR * | program_name = ACE_TEXT("<unknown>") , |
|
int | avoid_zombies = 0 | |||
) |
if avoid_zombies == 0 call ACE_OS::fork
directly, else create an orphan process that's inherited by the init process; init cleans up when the orphan process terminates so we don't create zombies. Returns -1 on failure and either the child PID on success if avoid_zombies == 0 or 1 on success if avoid_zombies != 0 (this latter behavior is a known bug that needs to be fixed).
Definition at line 2781 of file ACE.cpp.
References ACE_OS::_exit(), ACE_OS::fork(), ACE_OS::waitpid(), WEXITSTATUS, and WIFEXITED.
Referenced by ACE_Process_Strategy< SVC_HANDLER >::activate_svc_handler(), and ACE_Process::spawn().
02783 { 02784 if (avoid_zombies == 0) 02785 return ACE_OS::fork (program_name); 02786 else 02787 { 02788 // This algorithm is adapted from an example in the Stevens book 02789 // "Advanced Programming in the Unix Environment" and an item in 02790 // Andrew Gierth's Unix Programming FAQ. It creates an orphan 02791 // process that's inherited by the init process; init cleans up 02792 // when the orphan process terminates. 02793 // 02794 // Another way to avoid zombies is to ignore or catch the 02795 // SIGCHLD signal; we don't use that approach here. 02796 02797 pid_t pid = ACE_OS::fork (); 02798 if (pid == 0) 02799 { 02800 // The child process forks again to create a grandchild. 02801 switch (ACE_OS::fork (program_name)) 02802 { 02803 case 0: // grandchild returns 0. 02804 return 0; 02805 case -1: // assumes all errnos are < 256 02806 ACE_OS::_exit (errno); 02807 default: // child terminates, orphaning grandchild 02808 ACE_OS::_exit (0); 02809 } 02810 } 02811 02812 // Parent process waits for child to terminate. 02813 ACE_exitcode status; 02814 if (pid < 0 || ACE_OS::waitpid (pid, &status, 0) < 0) 02815 return -1; 02816 02817 // child terminated by calling exit()? 02818 if (WIFEXITED ((status))) 02819 { 02820 // child terminated normally? 02821 if (WEXITSTATUS ((status)) == 0) 02822 return 1; 02823 else 02824 errno = WEXITSTATUS ((status)); 02825 } 02826 else 02827 // child didn't call exit(); perhaps it received a signal? 02828 errno = EINTR; 02829 02830 return -1; 02831 } 02832 }
ACE_Export int ACE::max_handles | ( | void | ) |
Returns the maximum number of open handles currently permitted in this process. This maximum may be extended using ACE::set_handle_limit
.
Definition at line 2835 of file ACE.cpp.
References ACE_NOTSUP_RETURN, ACE_TRACE, ACE_OS::getrlimit(), and ACE_OS::sysconf().
Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::ACE_Select_Reactor_T(), daemonize(), and set_handle_limit().
02836 { 02837 ACE_TRACE ("ACE::max_handles"); 02838 #if defined (RLIMIT_NOFILE) && !defined (ACE_LACKS_RLIMIT) 02839 rlimit rl; 02840 int const r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl); 02841 # if !defined (RLIM_INFINITY) 02842 if (r == 0) 02843 return rl.rlim_cur; 02844 # else 02845 if (r == 0 && rl.rlim_cur != RLIM_INFINITY) 02846 return rl.rlim_cur; 02847 // If == RLIM_INFINITY, fall through to the ACE_LACKS_RLIMIT sections 02848 # endif /* RLIM_INFINITY */ 02849 #endif /* RLIMIT_NOFILE && !ACE_LACKS_RLIMIT */ 02850 02851 #if defined (_SC_OPEN_MAX) 02852 return ACE_OS::sysconf (_SC_OPEN_MAX); 02853 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x620) 02854 return maxFiles; 02855 #elif defined (FD_SETSIZE) 02856 return FD_SETSIZE; 02857 #else 02858 ACE_NOTSUP_RETURN (-1); 02859 #endif /* _SC_OPEN_MAX */ 02860 }
ACE_Export int ACE::set_handle_limit | ( | int | new_limit = -1 , |
|
int | increase_limit_only = 0 | |||
) |
Reset the limit on the number of open handles. If new_limit == -1 set the limit to the maximum allowable. Otherwise, set the limit value to new_limit. If increase_limit_only is non-0 then only allow increases to the limit.
Definition at line 2868 of file ACE.cpp.
References ACE_NOTSUP_RETURN, ACE_TRACE, ACE_OS::getrlimit(), max_handles(), ACE_OS::memset(), and ACE_OS::setrlimit().
02870 { 02871 ACE_TRACE ("ACE::set_handle_limit"); 02872 int cur_limit = ACE::max_handles (); 02873 int max_limit = cur_limit; 02874 02875 if (cur_limit == -1) 02876 return -1; 02877 02878 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE) 02879 struct rlimit rl; 02880 02881 ACE_OS::memset ((void *) &rl, 0, sizeof rl); 02882 int r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl); 02883 if (r == 0) 02884 max_limit = rl.rlim_max; 02885 #endif /* ACE_LACKS_RLIMIT */ 02886 02887 if (new_limit == -1) 02888 new_limit = max_limit; 02889 02890 if (new_limit < 0) 02891 { 02892 errno = EINVAL; 02893 return -1; 02894 } 02895 else if (new_limit > cur_limit) 02896 { 02897 // Increase the limit. 02898 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE) 02899 rl.rlim_cur = new_limit; 02900 return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl); 02901 #elif defined (ACE_LACKS_RLIMIT_NOFILE) 02902 return 0; 02903 #else 02904 // Must return EINVAL errno. 02905 ACE_NOTSUP_RETURN (-1); 02906 #endif /* ACE_LACKS_RLIMIT */ 02907 } 02908 else if (increase_limit_only == 0) 02909 { 02910 // Decrease the limit. 02911 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE) 02912 rl.rlim_cur = new_limit; 02913 return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl); 02914 #else 02915 // We give a chance to platforms without RLIMIT to work. 02916 // Instead of ACE_NOTSUP_RETURN (0), just return 0 because 02917 // new_limit is <= cur_limit, so it's a no-op. 02918 return 0; 02919 #endif /* ACE_LACKS_RLIMIT */ 02920 } 02921 02922 return 0; 02923 }
ACE_Export u_long ACE::gcd | ( | u_long | x, | |
u_long | y | |||
) |
Euclid's greatest common divisor algorithm.
Definition at line 2927 of file ACE.cpp.
Referenced by minimum_frame_size(), and ACE_Get_Opt::permute_args().
02928 { 02929 while (y != 0) 02930 { 02931 u_long r = x % y; 02932 x = y; 02933 y = r; 02934 } 02935 02936 return x; 02937 }
ACE_Export u_long ACE::minimum_frame_size | ( | u_long | period1, | |
u_long | period2 | |||
) |
Calculates the minimum enclosing frame size for the given values.
Definition at line 2942 of file ACE.cpp.
References gcd().
02943 { 02944 // if one of the periods is zero, treat it as though it as 02945 // uninitialized and return the other period as the frame size 02946 if (0 == period1) 02947 { 02948 return period2; 02949 } 02950 if (0 == period2) 02951 { 02952 return period1; 02953 } 02954 02955 // if neither is zero, find the greatest common divisor of the two periods 02956 u_long greatest_common_divisor = ACE::gcd (period1, period2); 02957 02958 // explicitly consider cases to reduce risk of possible overflow errors 02959 if (greatest_common_divisor == 1) 02960 { 02961 // periods are relative primes: just multiply them together 02962 return period1 * period2; 02963 } 02964 else if (greatest_common_divisor == period1) 02965 { 02966 // the first period divides the second: return the second 02967 return period2; 02968 } 02969 else if (greatest_common_divisor == period2) 02970 { 02971 // the second period divides the first: return the first 02972 return period1; 02973 } 02974 else 02975 { 02976 // the current frame size and the entry's effective period 02977 // have a non-trivial greatest common divisor: return the 02978 // product of factors divided by those in their gcd. 02979 return (period1 * period2) / greatest_common_divisor; 02980 } 02981 }
ACE_Export u_long ACE::is_prime | ( | const u_long | n, | |
const u_long | min_factor, | |||
const u_long | max_factor | |||
) |
Function that can burn up noticeable CPU time: brute-force determination of whether number n is prime. Returns 0 if it is prime, or the smallest factor if it is not prime. min_factor and max_factor can be used to partition the work among threads. For just one thread, typical values are 2 and n/2.
Definition at line 2985 of file ACE.cpp.
02988 { 02989 if (n > 3) 02990 for (u_long factor = min_factor; 02991 factor <= max_factor; 02992 ++factor) 02993 if (n / factor * factor == n) 02994 return factor; 02995 02996 return 0; 02997 }
ACE_Export const ACE_TCHAR * ACE::sock_error | ( | int | error | ) |
Returns a string containing the error message corresponding to a WinSock error. This works around an omission in the Win32 API.
For internal use only.
Definition at line 3000 of file ACE.cpp.
References ACE_NOTSUP_RETURN, ACE_TEXT, and ACE_OS::sprintf().
Referenced by ACE_Log_Msg::log(), and ACE_OS::strerror().
03001 { 03002 #if defined (ACE_WIN32) 03003 static ACE_TCHAR unknown_msg[64]; 03004 03005 switch (error) 03006 { 03007 case WSAVERNOTSUPPORTED: 03008 return ACE_TEXT ("version of WinSock not supported"); 03009 /* NOTREACHED */ 03010 case WSASYSNOTREADY: 03011 return ACE_TEXT ("WinSock not present or not responding"); 03012 /* NOTREACHED */ 03013 case WSAEINVAL: 03014 return ACE_TEXT ("app version not supported by DLL"); 03015 /* NOTREACHED */ 03016 case WSAHOST_NOT_FOUND: 03017 return ACE_TEXT ("Authoritive: Host not found"); 03018 /* NOTREACHED */ 03019 case WSATRY_AGAIN: 03020 return ACE_TEXT ("Non-authoritive: host not found or server failure"); 03021 /* NOTREACHED */ 03022 case WSANO_RECOVERY: 03023 return ACE_TEXT ("Non-recoverable: refused or not implemented"); 03024 /* NOTREACHED */ 03025 case WSANO_DATA: 03026 return ACE_TEXT ("Valid name, no data record for type"); 03027 /* NOTREACHED */ 03028 /* 03029 case WSANO_ADDRESS: 03030 return "Valid name, no MX record"; 03031 */ 03032 case WSANOTINITIALISED: 03033 return ACE_TEXT ("WSA Startup not initialized"); 03034 /* NOTREACHED */ 03035 case WSAENETDOWN: 03036 return ACE_TEXT ("Network subsystem failed"); 03037 /* NOTREACHED */ 03038 case WSAEINPROGRESS: 03039 return ACE_TEXT ("Blocking operation in progress"); 03040 /* NOTREACHED */ 03041 case WSAEINTR: 03042 return ACE_TEXT ("Blocking call cancelled"); 03043 /* NOTREACHED */ 03044 case WSAEAFNOSUPPORT: 03045 return ACE_TEXT ("address family not supported"); 03046 /* NOTREACHED */ 03047 case WSAEMFILE: 03048 return ACE_TEXT ("no file handles available"); 03049 /* NOTREACHED */ 03050 case WSAENOBUFS: 03051 return ACE_TEXT ("no buffer space available"); 03052 /* NOTREACHED */ 03053 case WSAEPROTONOSUPPORT: 03054 return ACE_TEXT ("specified protocol not supported"); 03055 /* NOTREACHED */ 03056 case WSAEPROTOTYPE: 03057 return ACE_TEXT ("protocol wrong type for this socket"); 03058 /* NOTREACHED */ 03059 case WSAESOCKTNOSUPPORT: 03060 return ACE_TEXT ("socket type not supported for address family"); 03061 /* NOTREACHED */ 03062 case WSAENOTSOCK: 03063 return ACE_TEXT ("handle is not a socket"); 03064 /* NOTREACHED */ 03065 case WSAEWOULDBLOCK: 03066 return ACE_TEXT ("resource temporarily unavailable"); 03067 /* NOTREACHED */ 03068 case WSAEADDRINUSE: 03069 return ACE_TEXT ("address already in use"); 03070 /* NOTREACHED */ 03071 case WSAECONNABORTED: 03072 return ACE_TEXT ("connection aborted"); 03073 /* NOTREACHED */ 03074 case WSAECONNRESET: 03075 return ACE_TEXT ("connection reset"); 03076 /* NOTREACHED */ 03077 case WSAENOTCONN: 03078 return ACE_TEXT ("not connected"); 03079 /* NOTREACHED */ 03080 case WSAETIMEDOUT: 03081 return ACE_TEXT ("connection timed out"); 03082 /* NOTREACHED */ 03083 case WSAECONNREFUSED: 03084 return ACE_TEXT ("connection refused"); 03085 /* NOTREACHED */ 03086 case WSAEHOSTDOWN: 03087 return ACE_TEXT ("host down"); 03088 /* NOTREACHED */ 03089 case WSAEHOSTUNREACH: 03090 return ACE_TEXT ("host unreachable"); 03091 /* NOTREACHED */ 03092 case WSAEADDRNOTAVAIL: 03093 return ACE_TEXT ("address not available"); 03094 /* NOTREACHED */ 03095 case WSAEISCONN: 03096 return ACE_TEXT ("socket is already connected"); 03097 /* NOTREACHED */ 03098 case WSAENETRESET: 03099 return ACE_TEXT ("network dropped connection on reset"); 03100 /* NOTREACHED */ 03101 case WSAEMSGSIZE: 03102 return ACE_TEXT ("message too long"); 03103 /* NOTREACHED */ 03104 case WSAENETUNREACH: 03105 return ACE_TEXT ("network is unreachable"); 03106 /* NOTREACHED */ 03107 case WSAEFAULT: 03108 return ACE_TEXT ("bad address"); 03109 /* NOTREACHED */ 03110 case WSAEDISCON: 03111 return ACE_TEXT ("graceful shutdown in progress"); 03112 /* NOTREACHED */ 03113 case WSAEACCES: 03114 return ACE_TEXT ("permission denied"); 03115 /* NOTREACHED */ 03116 case WSAESHUTDOWN: 03117 return ACE_TEXT ("cannot send after socket shutdown"); 03118 /* NOTREACHED */ 03119 case WSAEPROCLIM: 03120 return ACE_TEXT ("too many processes"); 03121 /* NOTREACHED */ 03122 case WSAEALREADY: 03123 return ACE_TEXT ("operation already in progress"); 03124 /* NOTREACHED */ 03125 case WSAEPFNOSUPPORT: 03126 return ACE_TEXT ("protocol family not supported"); 03127 /* NOTREACHED */ 03128 case WSAENOPROTOOPT: 03129 return ACE_TEXT ("bad protocol option"); 03130 /* NOTREACHED */ 03131 case WSATYPE_NOT_FOUND: 03132 return ACE_TEXT ("class type not found"); 03133 /* NOTREACHED */ 03134 case WSAEOPNOTSUPP: 03135 return ACE_TEXT ("operation not supported"); 03136 /* NOTREACHED */ 03137 case WSAEDESTADDRREQ: 03138 return ACE_TEXT ("destination address required"); 03139 /* NOTREACHED */ 03140 default: 03141 ACE_OS::sprintf (unknown_msg, ACE_TEXT ("unknown error: %d"), error); 03142 return unknown_msg; 03143 /* NOTREACHED */ 03144 } 03145 #else 03146 ACE_UNUSED_ARG (error); 03147 ACE_NOTSUP_RETURN (0); 03148 #endif /* ACE_WIN32 */ 03149 }
ACE_Export bool ACE::is_sock_error | ( | int | error | ) |
Determins whether the given error code corresponds to to a WinSock error. If so returns true, false otherwise.
For internal use only.
Definition at line 3152 of file ACE.cpp.
Referenced by ACE_OS::strerror().
03153 { 03154 #if defined (ACE_WIN32) 03155 switch (error) 03156 { 03157 case WSAVERNOTSUPPORTED: 03158 case WSASYSNOTREADY: 03159 case WSAEINVAL: 03160 case WSAHOST_NOT_FOUND: 03161 case WSATRY_AGAIN: 03162 case WSANO_RECOVERY: 03163 case WSANO_DATA: 03164 /* 03165 case WSANO_ADDRESS: 03166 */ 03167 case WSANOTINITIALISED: 03168 case WSAENETDOWN: 03169 case WSAEINPROGRESS: 03170 case WSAEINTR: 03171 case WSAEAFNOSUPPORT: 03172 case WSAEMFILE: 03173 case WSAENOBUFS: 03174 case WSAEPROTONOSUPPORT: 03175 case WSAEPROTOTYPE: 03176 case WSAESOCKTNOSUPPORT: 03177 case WSAENOTSOCK: 03178 case WSAEWOULDBLOCK: 03179 case WSAEADDRINUSE: 03180 case WSAECONNABORTED: 03181 case WSAECONNRESET: 03182 case WSAENOTCONN: 03183 case WSAETIMEDOUT: 03184 case WSAECONNREFUSED: 03185 case WSAEHOSTDOWN: 03186 case WSAEHOSTUNREACH: 03187 case WSAEADDRNOTAVAIL: 03188 case WSAEISCONN: 03189 case WSAENETRESET: 03190 case WSAEMSGSIZE: 03191 case WSAENETUNREACH: 03192 case WSAEFAULT: 03193 case WSAEDISCON: 03194 case WSAEACCES: 03195 case WSAESHUTDOWN: 03196 case WSAEPROCLIM: 03197 case WSAEALREADY: 03198 case WSAEPFNOSUPPORT: 03199 case WSAENOPROTOOPT: 03200 case WSATYPE_NOT_FOUND: 03201 case WSAEOPNOTSUPP: 03202 return true; 03203 } 03204 #else 03205 ACE_UNUSED_ARG (error); 03206 #endif /* ACE_WIN32 */ 03207 return false; 03208 }
ACE_Export char * ACE::strndup | ( | const char * | str, | |
size_t | n | |||
) |
Create a fresh new copy of str, up to n chars long. Uses ACE_OS::malloc
to allocate the new string.
Definition at line 3211 of file ACE.cpp.
References ACE_ALLOCATOR_RETURN, ACE_OS::malloc(), and ACE_OS::strsncpy().
03212 { 03213 const char *t = str; 03214 size_t len; 03215 03216 // Figure out how long this string is (remember, it might not be 03217 // NUL-terminated). 03218 03219 for (len = 0; 03220 len < n && *t++ != '\0'; 03221 len++) 03222 continue; 03223 03224 char *s; 03225 ACE_ALLOCATOR_RETURN (s, 03226 (char *) ACE_OS::malloc (len + 1), 03227 0); 03228 return ACE_OS::strsncpy (s, str, len + 1); 03229 }
ACE_Export char * ACE::strnnew | ( | const char * | str, | |
size_t | n | |||
) |
Create a fresh new copy of str, up to n chars long. Uses ACE_OS::malloc
to allocate the new string.
Definition at line 3256 of file ACE.cpp.
References ACE_NEW_RETURN, and ACE_OS::strsncpy().
03257 { 03258 const char *t = str; 03259 size_t len; 03260 03261 // Figure out how long this string is (remember, it might not be 03262 // NUL-terminated). 03263 03264 for (len = 0; 03265 len < n && *t++ != L'\0'; 03266 len++) 03267 continue; 03268 03269 char *s; 03270 ACE_NEW_RETURN (s, 03271 char[len + 1], 03272 0); 03273 return ACE_OS::strsncpy (s, str, len + 1); 03274 }
ACE_Export const char * ACE::strend | ( | const char * | s | ) |
ACE_Export char * ACE::strnew | ( | const char * | s | ) |
This method is just like strdup
, except that it uses operator
new
rather than malloc
. If s is NULL returns NULL rather than segfaulting.
Definition at line 3320 of file ACE.cpp.
References ACE_NEW_RETURN, ACE_OS::strcpy(), and ACE_OS::strlen().
Referenced by ACE_Logging_Strategy::ACE_Logging_Strategy(), ACE_Process_Options::command_line_argv(), ACE_MEM_Acceptor::mmap_prefix(), ACE_Service_Type_Impl::name(), ACE_Service_Type::name(), ACE_DLL_Handle::open(), ACE_DLL::open_i(), and ACE_Logging_Strategy::parse_args().
03321 { 03322 if (s == 0) 03323 return 0; 03324 char *t = 0; 03325 ACE_NEW_RETURN (t, 03326 char [ACE_OS::strlen (s) + 1], 03327 0); 03328 if (t == 0) 03329 return 0; 03330 else 03331 return ACE_OS::strcpy (t, s); 03332 }
ACE_Export bool ACE::wild_match | ( | const char * | s, | |
const char * | pattern, | |||
bool | case_sensitive = true | |||
) |
Simple wildcard matching function supporting '*' and '?' return true if string s matches pattern.
Definition at line 3359 of file ACE.cpp.
References equal_char().
03360 { 03361 if (str == pat) 03362 return true; 03363 if (pat == 0 || str == 0) 03364 return false; 03365 03366 bool star = false; 03367 const char* s = str; 03368 const char* p = pat; 03369 while (*s != '\0') 03370 { 03371 if (*p == '*') 03372 { 03373 star = true; 03374 pat = p; 03375 while (*++pat == '*'); 03376 03377 if (*pat == '\0') 03378 return true; 03379 p = pat; 03380 } 03381 else if (*p == '?') 03382 { 03383 ++s; 03384 ++p; 03385 } 03386 else if (! equal_char(*s, *p, case_sensitive)) 03387 { 03388 if (!star) 03389 return false; 03390 s = ++str; 03391 p = pat; 03392 } 03393 else 03394 { 03395 ++s; 03396 ++p; 03397 } 03398 } 03399 if (*p == '*') 03400 while (*++p == '*'); 03401 03402 return *p == '\0'; 03403 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::recv_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) |
Definition at line 41 of file ACE.inl.
00047 { 00048 if (timeout == 0) 00049 return ACE::recv_n_i (handle, 00050 buf, 00051 len, 00052 flags, 00053 bytes_transferred); 00054 else 00055 return ACE::recv_n_i (handle, 00056 buf, 00057 len, 00058 flags, 00059 timeout, 00060 bytes_transferred); 00061 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::recv_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) |
Definition at line 91 of file ACE.inl.
References recv_n_i().
00096 { 00097 if (timeout == 0) 00098 return ACE::recv_n_i (handle, 00099 buf, 00100 len, 00101 bytes_transferred); 00102 else 00103 return ACE::recv_n_i (handle, 00104 buf, 00105 len, 00106 timeout, 00107 bytes_transferred); 00108 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::recvv_n | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) |
Definition at line 111 of file ACE.inl.
References recvv_n_i().
Referenced by recv_n(), ACE_SOCK_Stream::recvv_n(), and ACE_SOCK_SEQPACK_Association::recvv_n().
00116 { 00117 if (timeout == 0) 00118 return ACE::recvv_n_i (handle, 00119 iov, 00120 iovcnt, 00121 bytes_transferred); 00122 else 00123 return ACE::recvv_n_i (handle, 00124 iov, 00125 iovcnt, 00126 timeout, 00127 bytes_transferred); 00128 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::send_n | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) |
Definition at line 131 of file ACE.inl.
00137 { 00138 if (timeout == 0) 00139 return ACE::send_n_i (handle, 00140 buf, 00141 len, 00142 flags, 00143 bytes_transferred); 00144 else 00145 return ACE::send_n_i (handle, 00146 buf, 00147 len, 00148 flags, 00149 timeout, 00150 bytes_transferred); 00151 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::send_n | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) |
Definition at line 181 of file ACE.inl.
References send_n_i().
00186 { 00187 if (timeout == 0) 00188 return ACE::send_n_i (handle, 00189 buf, 00190 len, 00191 bytes_transferred); 00192 else 00193 return ACE::send_n_i (handle, 00194 buf, 00195 len, 00196 timeout, 00197 bytes_transferred); 00198 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::sendv_n | ( | ACE_HANDLE | handle, | |
const iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) |
Definition at line 201 of file ACE.inl.
References sendv_n_i().
Referenced by send_n(), ACE_SOCK_Stream::sendv_n(), ACE_SOCK_SEQPACK_Association::sendv_n(), and ACE_Pipe::sendv_n().
00206 { 00207 if (timeout == 0) 00208 return ACE::sendv_n_i (handle, 00209 iov, 00210 iovcnt, 00211 bytes_transferred); 00212 else 00213 return ACE::sendv_n_i (handle, 00214 iov, 00215 iovcnt, 00216 timeout, 00217 bytes_transferred); 00218 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::read_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
size_t * | bytes_transferred = 0 | |||
) |
Receive 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 errors occur, -1 is returned. If EOF occurs, 0 is returned. Whatever data has been read will be returned to the caller through<bytes_transferred>.
Definition at line 17 of file ACE.inl.
References ACE_OS::read().
Referenced by read_n(), ACE_SPIPE_Stream::recv_n(), ACE_Pipe::recv_n(), ACE_FILE_IO::recv_n(), and ACE_DEV_IO::recv_n().
00021 { 00022 return ACE_OS::read_n (handle, 00023 buf, 00024 len, 00025 bytes_transferred); 00026 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::write_n | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
size_t * | bytes_transferred = 0 | |||
) |
Send 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 errors occur, -1 is returned. If EOF occurs, 0 is returned. Whatever data has been transmitted will be returned to the caller through <bytes_transferred>.
Definition at line 29 of file ACE.inl.
References ACE_OS::write().
Referenced by write_n().
00033 { 00034 return ACE_OS::write_n (handle, 00035 buf, 00036 len, 00037 bytes_transferred); 00038 }
ACE_NAMESPACE_INLINE_FUNCTION void ACE::strdelete | ( | char * | s | ) |
Delete the memory allocated by strnew
.
Definition at line 274 of file ACE.inl.
Referenced by ACE_Process_Options::command_line_argv(), ACE_Service_Type_Impl::name(), ACE_Framework_Component::~ACE_Framework_Component(), and ACE_Process_Options::~ACE_Process_Options().
ACE_Export ACE_UINT16 ACE::crc_ccitt | ( | const char * | str | ) |
Computes CRC-CCITT for the string.
Definition at line 78 of file ACE_crc_ccitt.cpp.
00079 { 00080 ACE_UINT16 crc = 0xFFFF; 00081 00082 for (const char *p = string; 00083 *p != 0; 00084 ++p) 00085 { 00086 COMPUTE (crc, *p); 00087 } 00088 00089 return ~crc; 00090 }
ACE_Export ACE_UINT16 ACE::crc_ccitt | ( | const void * | buf, | |
size_t | len, | |||
ACE_UINT16 | crc = 0 | |||
) |
Computes CRC-CCITT for the buffer.
Definition at line 93 of file ACE_crc_ccitt.cpp.
00094 { 00095 crc = ~crc; 00096 00097 for (const char *p = (const char *) buffer, 00098 *e = (const char *) buffer + len; 00099 p != e; 00100 ++p) 00101 { 00102 COMPUTE (crc, *p); 00103 } 00104 00105 return ~crc; 00106 }
ACE_Export ACE_UINT16 ACE::crc_ccitt | ( | const iovec * | iov, | |
int | len, | |||
ACE_UINT16 | crc = 0 | |||
) |
Computes CRC-CCITT for the @ len iovec buffers.
Definition at line 109 of file ACE_crc_ccitt.cpp.
References COMPUTE.
00110 { 00111 crc = ~crc; 00112 00113 for (int i = 0; i < len; ++i) 00114 { 00115 for (const char *p = (const char *) iov[i].iov_base, 00116 *e = (const char *) iov[i].iov_base + iov[i].iov_len; 00117 p != e; 00118 ++p) 00119 COMPUTE (crc, *p); 00120 } 00121 00122 return ~crc; 00123 }
ACE_Export ACE_UINT32 ACE::crc32 | ( | const char * | str | ) |
Computes the ISO 8802-3 standard 32 bits CRC for the string.
Definition at line 111 of file ACE_crc32.cpp.
Referenced by ACE_Shared_Memory_Pool::ACE_Shared_Memory_Pool(), and ACE_SV_Semaphore_Simple::name_2_key().
00112 { 00113 ACE_UINT32 crc = 0xFFFFFFFF; 00114 00115 for (const char *p = string; 00116 *p != 0; 00117 ++p) 00118 { 00119 COMPUTE (crc, *p); 00120 } 00121 00122 return ~crc; 00123 }
ACE_Export ACE_UINT32 ACE::crc32 | ( | const void * | buf, | |
size_t | len, | |||
ACE_UINT32 | crc = 0 | |||
) |
Computes the ISO 8802-3 standard 32 bits CRC for the buffer.
Definition at line 126 of file ACE_crc32.cpp.
00127 { 00128 crc = ~crc; 00129 00130 for (const char *p = (const char *) buffer, 00131 *e = (const char *) buffer + len; 00132 p != e; 00133 ++p) 00134 { 00135 COMPUTE (crc, *p); 00136 } 00137 00138 return ~crc; 00139 }
ACE_Export ACE_UINT32 ACE::crc32 | ( | const iovec * | iov, | |
int | len, | |||
ACE_UINT32 | crc = 0 | |||
) |
Computes the ISO 8802-3 standard 32 bits CRC for the @ len iovec buffers.
Definition at line 142 of file ACE_crc32.cpp.
References COMPUTE.
00143 { 00144 crc = ~crc; 00145 00146 for (int i = 0; i < len; ++i) 00147 { 00148 for (const char *p = (const char *) iov[i].iov_base, 00149 *e = (const char *) iov[i].iov_base + iov[i].iov_len; 00150 p != e; 00151 ++p) 00152 COMPUTE (crc, *p); 00153 } 00154 00155 return ~crc; 00156 }
ACE_Export int ACE::map_errno | ( | int | error | ) |
Map troublesome win32 errno values to values that standard C strerr function understands. Thank you Microsoft.
Definition at line 325 of file ACE.inl.
Referenced by ACE_Log_Msg::log().
00326 { 00327 #if defined (ACE_WIN32) 00328 switch (error) 00329 { 00330 case WSAEWOULDBLOCK: 00331 return EAGAIN; // Same as UNIX errno EWOULDBLOCK. 00332 } 00333 #endif /* ACE_WIN32 */ 00334 00335 return error; 00336 }
ACE_NAMESPACE_INLINE_FUNCTION void ACE::unique_name | ( | const void * | object, | |
ACE_TCHAR * | name, | |||
size_t | length | |||
) |
This method uses process id and object pointer to come up with a machine wide unique name. The process ID will provide uniqueness between processes on the same machine. The "this" pointer of the 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.
Definition at line 288 of file ACE.inl.
References ACE_UNIQUE_NAME_LEN, ACE_OS::getpid(), ACE_OS::sprintf(), and ACE_OS::strsncpy().
Referenced by ACE_MEM_Acceptor::accept(), ACE_Semaphore::ACE_Semaphore(), ACE_OS::rwlock_init(), ACE_OS::sema_init(), ACE_DLL::set_handle(), unique_name(), ACE_RW_Process_Mutex::unique_name(), and ACE_Process_Mutex::unique_name().
00291 { 00292 ACE_OS::unique_name (object, name, length); 00293 }
ACE_NAMESPACE_INLINE_FUNCTION u_long ACE::log2 | ( | u_long | num | ) |
Computes the base 2 logarithm of {num}.
Definition at line 296 of file ACE.inl.
Referenced by ace_log2_helper(), ACE_Log_Record::priority(), and ACE_Log_Record::priority_name().
00297 { 00298 u_long log = 0; 00299 00300 for (; num > 1; ++log) 00301 num >>= 1; 00302 00303 return log; 00304 }
ACE_NAMESPACE_INLINE_FUNCTION ACE_TCHAR ACE::nibble2hex | ( | u_int | n | ) |
Hex conversion utility.
Definition at line 307 of file ACE.inl.
References ACE_TEXT.
00308 { 00309 // Hexadecimal characters. 00310 #if defined (ACE_VXWORKS) && !defined (__DCPLUSPLUS__) 00311 // temporary solution to prevent Windriver GNU toolchains from spewing 00312 // loads of warnings when inlining. 00313 // problem (incorrect warning leftover from older GNU) has been reported as 00314 // TSR to Windriver. 00315 const ACE_TCHAR hex_chars[] = ACE_TEXT ("0123456789abcdef"); 00316 #else 00317 static const ACE_TCHAR hex_chars[] = ACE_TEXT ("0123456789abcdef"); 00318 #endif 00319 00320 // Yes, this works for UNICODE 00321 return hex_chars[n & 0x0f]; 00322 }
ACE_NAMESPACE_INLINE_FUNCTION u_char ACE::hex2byte | ( | ACE_TCHAR | c | ) |
Convert a hex character to its byte representation.
Definition at line 339 of file ACE.inl.
References ACE_OS::ace_isdigit(), ACE_OS::ace_islower(), and ACE_TEXT.
00340 { 00341 if (ACE_OS::ace_isdigit (c)) 00342 return (u_char) (c - ACE_TEXT ('0')); 00343 else if (ACE_OS::ace_islower (c)) 00344 return (u_char) (10 + c - ACE_TEXT ('a')); 00345 else 00346 return (u_char) (10 + c - ACE_TEXT ('A')); 00347 }
ACE_NAMESPACE_INLINE_FUNCTION int ACE::handle_read_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) |
Timed wait for handle to get read ready.
Definition at line 241 of file ACE.inl.
References handle_ready().
Referenced by enter_recv_timedwait(), recv_n_i(), and recvv_n_i().
00243 { 00244 return ACE::handle_ready (handle, 00245 timeout, 00246 1, 00247 0, 00248 0); 00249 }
ACE_NAMESPACE_INLINE_FUNCTION int ACE::handle_write_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) |
Timed wait for handle to get write ready.
Definition at line 252 of file ACE.inl.
References handle_ready().
Referenced by enter_send_timedwait(), send_n_i(), and sendv_n_i().
00254 { 00255 return ACE::handle_ready (handle, 00256 timeout, 00257 0, 00258 1, 00259 0); 00260 }
ACE_NAMESPACE_INLINE_FUNCTION int ACE::handle_exception_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) |
Timed wait for handle to get exception ready.
Definition at line 263 of file ACE.inl.
References handle_ready().
00265 { 00266 return ACE::handle_ready (handle, 00267 timeout, 00268 0, 00269 0, 00270 1); 00271 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::recv_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len | |||
) |
Definition at line 231 of file ACE.inl.
References ACE_OS::read(), and ACE_OS::recv().
Referenced by recv(), and recv_n_i().
00232 { 00233 #if defined (ACE_WIN32) || defined (ACE_OPENVMS) || defined (ACE_TANDEM_T1248_PTHREADS) 00234 return ACE_OS::recv (handle, (char *) buf, len); 00235 #else 00236 return ACE_OS::read (handle, (char *) buf, len); 00237 #endif /* ACE_WIN32 */ 00238 }
ACE_NAMESPACE_INLINE_FUNCTION ssize_t ACE::send_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len | |||
) |
Definition at line 221 of file ACE.inl.
References ACE_OS::send(), and ACE_OS::write().
Referenced by send(), and send_n_i().
00222 { 00223 #if defined (ACE_WIN32) || defined (HPUX) 00224 return ACE_OS::send (handle, (const char *) buf, len); 00225 #else 00226 return ACE_OS::write (handle, (const char *) buf, len); 00227 #endif /* ACE_WIN32 */ 00228 }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ssize_t ACE::read_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 17 of file ACE.inl.
References ACE_OS::read_n().
00021 { 00022 return ACE_OS::read_n (handle, 00023 buf, 00024 len, 00025 bytes_transferred); 00026 }
ACE_INLINE ssize_t ACE::write_n | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 29 of file ACE.inl.
References ACE_OS::write_n().
00033 { 00034 return ACE_OS::write_n (handle, 00035 buf, 00036 len, 00037 bytes_transferred); 00038 }
ACE_INLINE ssize_t ACE::recv_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 41 of file ACE.inl.
References recv_n_i().
00047 { 00048 if (timeout == 0) 00049 return ACE::recv_n_i (handle, 00050 buf, 00051 len, 00052 flags, 00053 bytes_transferred); 00054 else 00055 return ACE::recv_n_i (handle, 00056 buf, 00057 len, 00058 flags, 00059 timeout, 00060 bytes_transferred); 00061 }
ACE_INLINE ssize_t ACE::recv_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 91 of file ACE.inl.
References recv_n_i().
00096 { 00097 if (timeout == 0) 00098 return ACE::recv_n_i (handle, 00099 buf, 00100 len, 00101 bytes_transferred); 00102 else 00103 return ACE::recv_n_i (handle, 00104 buf, 00105 len, 00106 timeout, 00107 bytes_transferred); 00108 }
ACE_INLINE ssize_t ACE::recvv_n | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 111 of file ACE.inl.
References recvv_n_i().
Referenced by recv_n(), ACE_SOCK_SEQPACK_Association::recvv_n(), and ACE_SOCK_Stream::recvv_n().
00116 { 00117 if (timeout == 0) 00118 return ACE::recvv_n_i (handle, 00119 iov, 00120 iovcnt, 00121 bytes_transferred); 00122 else 00123 return ACE::recvv_n_i (handle, 00124 iov, 00125 iovcnt, 00126 timeout, 00127 bytes_transferred); 00128 }
ACE_INLINE ssize_t ACE::send_n | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 131 of file ACE.inl.
References send_n_i().
00137 { 00138 if (timeout == 0) 00139 return ACE::send_n_i (handle, 00140 buf, 00141 len, 00142 flags, 00143 bytes_transferred); 00144 else 00145 return ACE::send_n_i (handle, 00146 buf, 00147 len, 00148 flags, 00149 timeout, 00150 bytes_transferred); 00151 }
ACE_INLINE ssize_t ACE::send_n | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 181 of file ACE.inl.
References send_n_i().
00186 { 00187 if (timeout == 0) 00188 return ACE::send_n_i (handle, 00189 buf, 00190 len, 00191 bytes_transferred); 00192 else 00193 return ACE::send_n_i (handle, 00194 buf, 00195 len, 00196 timeout, 00197 bytes_transferred); 00198 }
ACE_INLINE ssize_t ACE::sendv_n | ( | ACE_HANDLE | handle, | |
const iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 201 of file ACE.inl.
References sendv_n_i().
Referenced by send_n(), ACE_Pipe::sendv_n(), ACE_SOCK_SEQPACK_Association::sendv_n(), and ACE_SOCK_Stream::sendv_n().
00206 { 00207 if (timeout == 0) 00208 return ACE::sendv_n_i (handle, 00209 iov, 00210 iovcnt, 00211 bytes_transferred); 00212 else 00213 return ACE::sendv_n_i (handle, 00214 iov, 00215 iovcnt, 00216 timeout, 00217 bytes_transferred); 00218 }
ACE_INLINE ssize_t ACE::send_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len | |||
) |
Definition at line 221 of file ACE.inl.
References ACE_OS::send(), and ACE_OS::write().
Referenced by send(), and send_n_i().
00222 { 00223 #if defined (ACE_WIN32) || defined (HPUX) 00224 return ACE_OS::send (handle, (const char *) buf, len); 00225 #else 00226 return ACE_OS::write (handle, (const char *) buf, len); 00227 #endif /* ACE_WIN32 */ 00228 }
ACE_INLINE ssize_t ACE::recv_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len | |||
) |
Definition at line 231 of file ACE.inl.
References ACE_OS::read(), and ACE_OS::recv().
Referenced by recv(), and recv_n_i().
00232 { 00233 #if defined (ACE_WIN32) || defined (ACE_OPENVMS) || defined (ACE_TANDEM_T1248_PTHREADS) 00234 return ACE_OS::recv (handle, (char *) buf, len); 00235 #else 00236 return ACE_OS::read (handle, (char *) buf, len); 00237 #endif /* ACE_WIN32 */ 00238 }
ACE_INLINE int ACE::handle_read_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) |
Timed wait for handle to get read ready.
Definition at line 241 of file ACE.inl.
References handle_ready().
Referenced by enter_recv_timedwait(), recv_n_i(), and recvv_n_i().
00243 { 00244 return ACE::handle_ready (handle, 00245 timeout, 00246 1, 00247 0, 00248 0); 00249 }
ACE_INLINE int ACE::handle_write_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) |
Timed wait for handle to get write ready.
Definition at line 252 of file ACE.inl.
References handle_ready().
Referenced by enter_send_timedwait(), send_n_i(), and sendv_n_i().
00254 { 00255 return ACE::handle_ready (handle, 00256 timeout, 00257 0, 00258 1, 00259 0); 00260 }
ACE_INLINE int ACE::handle_exception_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) |
Timed wait for handle to get exception ready.
Definition at line 263 of file ACE.inl.
References handle_ready().
00265 { 00266 return ACE::handle_ready (handle, 00267 timeout, 00268 0, 00269 0, 00270 1); 00271 }
ACE_INLINE void ACE::strdelete | ( | char * | s | ) |
Delete the memory allocated by strnew
.
Definition at line 274 of file ACE.inl.
Referenced by ACE_Process_Options::command_line_argv(), ACE_Service_Type_Impl::name(), ACE_Framework_Component::~ACE_Framework_Component(), and ACE_Process_Options::~ACE_Process_Options().
ACE_INLINE void ACE::unique_name | ( | const void * | object, | |
ACE_TCHAR * | name, | |||
size_t | length | |||
) |
This method uses process id and object pointer to come up with a machine wide unique name. The process ID will provide uniqueness between processes on the same machine. The "this" pointer of the {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}.
Definition at line 288 of file ACE.inl.
References ACE_OS::unique_name().
00291 { 00292 ACE_OS::unique_name (object, name, length); 00293 }
ACE_INLINE u_long ACE::log2 | ( | u_long | num | ) |
ACE_INLINE ACE_TCHAR ACE::nibble2hex | ( | u_int | n | ) |
Hex conversion utility.
Definition at line 307 of file ACE.inl.
References ACE_TEXT.
00308 { 00309 // Hexadecimal characters. 00310 #if defined (ACE_VXWORKS) && !defined (__DCPLUSPLUS__) 00311 // temporary solution to prevent Windriver GNU toolchains from spewing 00312 // loads of warnings when inlining. 00313 // problem (incorrect warning leftover from older GNU) has been reported as 00314 // TSR to Windriver. 00315 const ACE_TCHAR hex_chars[] = ACE_TEXT ("0123456789abcdef"); 00316 #else 00317 static const ACE_TCHAR hex_chars[] = ACE_TEXT ("0123456789abcdef"); 00318 #endif 00319 00320 // Yes, this works for UNICODE 00321 return hex_chars[n & 0x0f]; 00322 }
ACE_INLINE int ACE::map_errno | ( | int | error | ) |
Map troublesome win32 errno values to values that standard C strerr function understands. Thank you Microsoft.
Definition at line 325 of file ACE.inl.
Referenced by ACE_Log_Msg::log().
00326 { 00327 #if defined (ACE_WIN32) 00328 switch (error) 00329 { 00330 case WSAEWOULDBLOCK: 00331 return EAGAIN; // Same as UNIX errno EWOULDBLOCK. 00332 } 00333 #endif /* ACE_WIN32 */ 00334 00335 return error; 00336 }
ACE_INLINE u_char ACE::hex2byte | ( | ACE_TCHAR | c | ) |
Convert a hex character to its byte representation.
Definition at line 339 of file ACE.inl.
References ACE_OS::ace_isdigit(), ACE_OS::ace_islower(), and ACE_TEXT.
00340 { 00341 if (ACE_OS::ace_isdigit (c)) 00342 return (u_char) (c - ACE_TEXT ('0')); 00343 else if (ACE_OS::ace_islower (c)) 00344 return (u_char) (10 + c - ACE_TEXT ('a')); 00345 else 00346 return (u_char) (10 + c - ACE_TEXT ('A')); 00347 }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_UINT32 ACE::crc32 | ( | const char * | string | ) |
Computes the ISO 8802-3 standard 32 bits CRC for the string.
Definition at line 111 of file ACE_crc32.cpp.
References COMPUTE.
00112 { 00113 ACE_UINT32 crc = 0xFFFFFFFF; 00114 00115 for (const char *p = string; 00116 *p != 0; 00117 ++p) 00118 { 00119 COMPUTE (crc, *p); 00120 } 00121 00122 return ~crc; 00123 }
ACE_UINT32 ACE::crc32 | ( | const void * | buffer, | |
size_t | len, | |||
ACE_UINT32 | crc | |||
) |
Computes the ISO 8802-3 standard 32 bits CRC for the buffer.
Definition at line 126 of file ACE_crc32.cpp.
References COMPUTE.
00127 { 00128 crc = ~crc; 00129 00130 for (const char *p = (const char *) buffer, 00131 *e = (const char *) buffer + len; 00132 p != e; 00133 ++p) 00134 { 00135 COMPUTE (crc, *p); 00136 } 00137 00138 return ~crc; 00139 }
ACE_UINT32 ACE::crc32 | ( | const iovec * | iov, | |
int | len, | |||
ACE_UINT32 | crc = 0 | |||
) |
Computes the ISO 8802-3 standard 32 bits CRC for the @ len iovec buffers.
Definition at line 142 of file ACE_crc32.cpp.
References COMPUTE.
00143 { 00144 crc = ~crc; 00145 00146 for (int i = 0; i < len; ++i) 00147 { 00148 for (const char *p = (const char *) iov[i].iov_base, 00149 *e = (const char *) iov[i].iov_base + iov[i].iov_len; 00150 p != e; 00151 ++p) 00152 COMPUTE (crc, *p); 00153 } 00154 00155 return ~crc; 00156 }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_UINT16 ACE::crc_ccitt | ( | const char * | string | ) |
Computes CRC-CCITT for the string.
Definition at line 78 of file ACE_crc_ccitt.cpp.
References COMPUTE.
00079 { 00080 ACE_UINT16 crc = 0xFFFF; 00081 00082 for (const char *p = string; 00083 *p != 0; 00084 ++p) 00085 { 00086 COMPUTE (crc, *p); 00087 } 00088 00089 return ~crc; 00090 }
ACE_UINT16 ACE::crc_ccitt | ( | const void * | buffer, | |
size_t | len, | |||
ACE_UINT16 | crc | |||
) |
Computes CRC-CCITT for the buffer.
Definition at line 93 of file ACE_crc_ccitt.cpp.
References COMPUTE.
00094 { 00095 crc = ~crc; 00096 00097 for (const char *p = (const char *) buffer, 00098 *e = (const char *) buffer + len; 00099 p != e; 00100 ++p) 00101 { 00102 COMPUTE (crc, *p); 00103 } 00104 00105 return ~crc; 00106 }
ACE_UINT16 ACE::crc_ccitt | ( | const iovec * | iov, | |
int | len, | |||
ACE_UINT16 | crc | |||
) |
Computes CRC-CCITT for the @ len iovec buffers.
Definition at line 109 of file ACE_crc_ccitt.cpp.
References COMPUTE.
00110 { 00111 crc = ~crc; 00112 00113 for (int i = 0; i < len; ++i) 00114 { 00115 for (const char *p = (const char *) iov[i].iov_base, 00116 *e = (const char *) iov[i].iov_base + iov[i].iov_len; 00117 p != e; 00118 ++p) 00119 COMPUTE (crc, *p); 00120 } 00121 00122 return ~crc; 00123 }
ACE_Export int ACE::set_flags | ( | ACE_HANDLE | handle, | |
int | flags | |||
) |
Set flags associated with handle.
Definition at line 27 of file Flag_Manip.cpp.
References ACE_NONBLOCK, ACE_NOTSUP_RETURN, ACE_SET_BITS, ACE_TRACE, F_GETFL, ACE_OS::fcntl(), and ACE_OS::ioctl().
Referenced by ACE_IPC_SAP::enable(), ACE_IO_SAP::enable(), ACE_Select_Reactor_Notify::open(), record_and_set_non_blocking_mode(), ACE_SOCK_SEQPACK_Acceptor::shared_accept_start(), and ACE_SOCK_Acceptor::shared_accept_start().
00028 { 00029 ACE_TRACE ("ACE::set_flags"); 00030 #if defined (ACE_LACKS_FCNTL) 00031 switch (flags) 00032 { 00033 case ACE_NONBLOCK: 00034 // nonblocking argument (1) 00035 // blocking: (0) 00036 { 00037 int nonblock = 1; 00038 return ACE_OS::ioctl (handle, FIONBIO, &nonblock); 00039 } 00040 default: 00041 ACE_NOTSUP_RETURN (-1); 00042 } 00043 #else 00044 int val = ACE_OS::fcntl (handle, F_GETFL, 0); 00045 00046 if (val == -1) 00047 return -1; 00048 00049 // Turn on flags. 00050 ACE_SET_BITS (val, flags); 00051 00052 if (ACE_OS::fcntl (handle, F_SETFL, val) == -1) 00053 return -1; 00054 else 00055 return 0; 00056 #endif /* ACE_LACKS_FCNTL */ 00057 }
ACE_Export int ACE::clr_flags | ( | ACE_HANDLE | handle, | |
int | flags | |||
) |
Clear flags associated with handle.
Definition at line 62 of file Flag_Manip.cpp.
References ACE_CLR_BITS, ACE_NONBLOCK, ACE_NOTSUP_RETURN, ACE_TRACE, F_GETFL, ACE_OS::fcntl(), and ACE_OS::ioctl().
Referenced by ACE_IPC_SAP::disable(), ACE_IO_SAP::disable(), restore_non_blocking_mode(), ACE_SOCK_SEQPACK_Acceptor::shared_accept_finish(), ACE_SOCK_Acceptor::shared_accept_finish(), and ACE_MEM_Acceptor::shared_accept_finish().
00063 { 00064 ACE_TRACE ("ACE::clr_flags"); 00065 00066 #if defined (ACE_LACKS_FCNTL) 00067 switch (flags) 00068 { 00069 case ACE_NONBLOCK: 00070 // nonblocking argument (1) 00071 // blocking: (0) 00072 { 00073 int nonblock = 0; 00074 return ACE_OS::ioctl (handle, FIONBIO, &nonblock); 00075 } 00076 default: 00077 ACE_NOTSUP_RETURN (-1); 00078 } 00079 #else 00080 int val = ACE_OS::fcntl (handle, F_GETFL, 0); 00081 00082 if (val == -1) 00083 return -1; 00084 00085 // Turn flags off. 00086 ACE_CLR_BITS (val, flags); 00087 00088 if (ACE_OS::fcntl (handle, F_SETFL, val) == -1) 00089 return -1; 00090 else 00091 return 0; 00092 #endif /* ACE_LACKS_FCNTL */ 00093 }
ACE_NAMESPACE_INLINE_FUNCTION int ACE::get_flags | ( | ACE_HANDLE | handle | ) |
Return the current setting of flags associated with handle.
Definition at line 11 of file Flag_Manip.inl.
References ACE_TRACE, F_GETFL, and ACE_OS::fcntl().
Referenced by record_and_set_non_blocking_mode(), ACE_SOCK_SEQPACK_Acceptor::shared_accept_start(), and ACE_SOCK_Acceptor::shared_accept_start().
00012 { 00013 ACE_TRACE ("ACE::get_flags"); 00014 00015 #if defined (ACE_LACKS_FCNTL) 00016 // ACE_OS::fcntl is not supported. It 00017 // would be better to store ACE's notion of the flags 00018 // associated with the handle, but this works for now. 00019 ACE_UNUSED_ARG (handle); 00020 return 0; 00021 #else 00022 return ACE_OS::fcntl (handle, F_GETFL, 0); 00023 #endif /* ACE_LACKS_FCNTL */ 00024 }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE::get_flags | ( | ACE_HANDLE | handle | ) |
Return the current setting of flags associated with handle.
Definition at line 11 of file Flag_Manip.inl.
References ACE_TRACE, F_GETFL, and ACE_OS::fcntl().
Referenced by record_and_set_non_blocking_mode(), ACE_SOCK_Acceptor::shared_accept_start(), and ACE_SOCK_SEQPACK_Acceptor::shared_accept_start().
00012 { 00013 ACE_TRACE ("ACE::get_flags"); 00014 00015 #if defined (ACE_LACKS_FCNTL) 00016 // ACE_OS::fcntl is not supported. It 00017 // would be better to store ACE's notion of the flags 00018 // associated with the handle, but this works for now. 00019 ACE_UNUSED_ARG (handle); 00020 return 0; 00021 #else 00022 return ACE_OS::fcntl (handle, F_GETFL, 0); 00023 #endif /* ACE_LACKS_FCNTL */ 00024 }
ACE_Export ACE_HANDLE ACE::handle_timed_open | ( | ACE_Time_Value * | timeout, | |
const ACE_TCHAR * | name, | |||
int | flags, | |||
int | perms, | |||
LPSECURITY_ATTRIBUTES | sa = 0 | |||
) |
Wait up to timeout amount of time to actively open a device. This method doesn't perform the connect
, it just does the timed wait.
Definition at line 17 of file Handle_Ops.cpp.
References ACE_NONBLOCK, ACE_TRACE, and ACE_OS::open().
Referenced by ACE_SPIPE_Connector::connect(), ACE_FILE_Connector::connect(), and ACE_DEV_Connector::connect().
00022 { 00023 ACE_TRACE ("ACE::handle_timed_open"); 00024 00025 if (timeout != 0) 00026 { 00027 #if !defined (ACE_WIN32) 00028 // On Win32, ACE_NONBLOCK gets recognized as O_WRONLY so we 00029 // don't use it there 00030 flags |= ACE_NONBLOCK; 00031 #endif /* ACE_WIN32 */ 00032 00033 // Open the named pipe or file using non-blocking mode... 00034 ACE_HANDLE const handle = ACE_OS::open (name, flags, perms, sa); 00035 00036 if (handle == ACE_INVALID_HANDLE 00037 && (errno == EWOULDBLOCK 00038 && (timeout->sec () > 0 || timeout->usec () > 0))) 00039 // This expression checks if we were polling. 00040 errno = ETIMEDOUT; 00041 00042 return handle; 00043 } 00044 else 00045 return ACE_OS::open (name, flags, perms, sa); 00046 }
ACE_Export int ACE::init | ( | void | ) |
This class implements the functions for the initialization and shutting down ACE. These functions are called only once per ACE invokation.
Definition at line 15 of file Init_ACE.cpp.
References ACE_Object_Manager::init(), init_fini_count_, and ACE_Object_Manager::instance().
Referenced by ACE_Arg_Shifter_T< CHAR_TYPE >::ACE_Arg_Shifter_T(), ACE_Dynamic_Service_Dependency::ACE_Dynamic_Service_Dependency(), ACE_IOStream< STREAM >::ACE_IOStream(), ACE_OS_Object_Manager::init(), ACE_Control_Block::ACE_Name_Node::init_ptr(), and ACE_Control_Block::ACE_Malloc_Header::init_ptr().
00016 { 00017 // Don't use ACE_TRACE, because Object_Manager might not have been 00018 // instantiated yet. 00019 // ACE_TRACE ("ACE::init"); 00020 00021 ++ACE::init_fini_count_; 00022 00023 return ACE_Object_Manager::instance ()->init (); 00024 }
ACE_Export int ACE::fini | ( | void | ) |
Shut down ACE library services. Can be called only once per program invocation.
Definition at line 27 of file Init_ACE.cpp.
References ACE_TRACE, ACE_Object_Manager::fini(), init_fini_count_, and ACE_Object_Manager::instance().
Referenced by ACE_OS_Object_Manager::fini().
00028 { 00029 ACE_TRACE ("ACE::fini"); 00030 00031 if (ACE::init_fini_count_ > 0) 00032 { 00033 if (--ACE::init_fini_count_ == 0) 00034 return ACE_Object_Manager::instance ()->fini (); 00035 else 00036 // Wait for remaining fini () calls. 00037 return 1; 00038 } 00039 else 00040 // More ACE::fini () calls than ACE::init () calls. Bad 00041 // application! 00042 return -1; 00043 }
ACE_Export int ACE::ldfind | ( | const ACE_TCHAR * | filename, | |
ACE_TCHAR | pathname[], | |||
size_t | maxpathnamelen | |||
) |
Finds the file 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 the directories scaned by Win32 API SearchPath 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.
Definition at line 117 of file Lib_Find.cpp.
References ACE_OS::access(), ACE_DIRECTORY_SEPARATOR_CHAR, ACE_DLL_PREFIX, ACE_DLL_SUFFIX, ACE_ERROR, ACE_LD_SEARCH_PATH, ACE_LD_SEARCH_PATH_SEPARATOR_STR, ACE_TEXT, ACE_TEXT_ALWAYS_CHAR, ACE_TRACE, F_OK, ACE_OS::free(), ACE_OS::getenv(), LM_WARNING, ACE_OS::malloc(), MAXPATHLEN, ACE_OS::sprintf(), ACE_OS::strcasecmp(), ACE_OS::strcat(), ACE_OS::strcmp(), ACE_OS::strcpy(), ACE_OS::strdup(), ACE_OS::strlen(), ACE_OS::strrchr(), strrepl(), and strsplit_r().
Referenced by ldopen(), and ACE_DLL_Handle::open().
00120 { 00121 ACE_TRACE ("ACE::ldfind"); 00122 #if defined (ACE_OPENVMS) 00123 if (ACE_OS::strlen(filename) >= maxpathnamelen) 00124 { 00125 errno = ENOMEM; 00126 return -1; 00127 } 00128 00129 dsc$descriptor nameDsc; 00130 nameDsc.dsc$b_class = DSC$K_CLASS_S; 00131 nameDsc.dsc$b_dtype = DSC$K_DTYPE_T; 00132 nameDsc.dsc$w_length = ACE_OS::strlen(filename); 00133 nameDsc.dsc$a_pointer = (char*)filename; 00134 00135 char symbol[] = "NULL"; 00136 dsc$descriptor symbolDsc; 00137 symbolDsc.dsc$b_class = DSC$K_CLASS_S; 00138 symbolDsc.dsc$b_dtype = DSC$K_DTYPE_T; 00139 symbolDsc.dsc$w_length = ACE_OS::strlen(symbol); 00140 symbolDsc.dsc$a_pointer = symbol; 00141 00142 int symbolValue; 00143 int result; 00144 try 00145 { 00146 result = LIB$FIND_IMAGE_SYMBOL(&nameDsc, &symbolDsc, &symbolValue, 0, 0); 00147 } 00148 catch (chf$signal_array& sig) 00149 { 00150 result = sig.chf$l_sig_name; 00151 } 00152 00153 int severity = result & STS$M_SEVERITY; 00154 int conditionId = result & STS$M_COND_ID; 00155 if (severity == STS$K_SUCCESS || severity == STS$K_WARNING || severity == STS$K_INFO || 00156 (severity == STS$K_ERROR && conditionId == (LIB$_KEYNOTFOU & STS$M_COND_ID))) 00157 { 00158 ACE_OS::strcpy(pathname, filename); 00159 return 0; 00160 } 00161 00162 if (ACE_OS::strlen(filename) + ACE_OS::strlen(ACE_DLL_PREFIX) >= maxpathnamelen) 00163 { 00164 errno = ENOMEM; 00165 return -1; 00166 } 00167 00168 00169 ACE_OS::strcpy(pathname, ACE_DLL_PREFIX); 00170 ACE_OS::strcat(pathname, filename); 00171 nameDsc.dsc$w_length = ACE_OS::strlen(pathname); 00172 nameDsc.dsc$a_pointer = pathname; 00173 try 00174 { 00175 result = LIB$FIND_IMAGE_SYMBOL(&nameDsc, &symbolDsc, &symbolValue, 0, 0); 00176 } 00177 catch (chf$signal_array& sig) 00178 { 00179 result = sig.chf$l_sig_name; 00180 } 00181 00182 severity = result & STS$M_SEVERITY; 00183 conditionId = result & STS$M_COND_ID; 00184 if (severity == STS$K_SUCCESS || severity == STS$K_WARNING || severity == STS$K_INFO || 00185 (severity == STS$K_ERROR && conditionId == (LIB$_KEYNOTFOU & STS$M_COND_ID))) 00186 { 00187 return 0; 00188 } 00189 errno = ENOENT; 00190 return -1; 00191 #endif /* ACE_OPENVMS */ 00192 00193 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && \ 00194 !defined (ACE_HAS_PHARLAP) 00195 ACE_TCHAR expanded_filename[MAXPATHLEN]; 00196 if (ACE_TEXT_ExpandEnvironmentStrings (filename, 00197 expanded_filename, 00198 sizeof expanded_filename 00199 / sizeof (ACE_TCHAR))) 00200 filename = expanded_filename; 00201 #endif /* ACE_WIN32 && !ACE_HAS_WINCE && !ACE_HAS_PHARLAP */ 00202 00203 ACE_TCHAR tempcopy[MAXPATHLEN + 1]; 00204 ACE_TCHAR searchpathname[MAXPATHLEN + 1]; 00205 #if defined (ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) 00206 ACE_TCHAR decorator[] = ACE_LD_DECORATOR_STR; 00207 ACE_TCHAR searchfilename[MAXPATHLEN + sizeof(decorator) / sizeof (ACE_TCHAR)]; 00208 #else 00209 ACE_TCHAR searchfilename[MAXPATHLEN + 1]; 00210 #endif /* ACE_WIN32 && ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */ 00211 00212 // Create a copy of filename to work with. 00213 if (ACE_OS::strlen (filename) + 1 00214 > (sizeof tempcopy / sizeof (ACE_TCHAR))) 00215 { 00216 errno = ENOMEM; 00217 return -1; 00218 } 00219 else 00220 ACE_OS::strcpy (tempcopy, filename); 00221 00222 // Insert canonical directory separators. 00223 ACE_TCHAR *separator_ptr; 00224 00225 #if (ACE_DIRECTORY_SEPARATOR_CHAR != '/') 00226 // Make all the directory separators "canonical" to simplify 00227 // subsequent code. 00228 ACE::strrepl (tempcopy, ACE_DIRECTORY_SEPARATOR_CHAR, '/'); 00229 #endif /* ACE_DIRECTORY_SEPARATOR_CHAR */ 00230 00231 // Separate filename from pathname. 00232 separator_ptr = ACE_OS::strrchr (tempcopy, '/'); 00233 00234 // This is a relative path. 00235 if (separator_ptr == 0) 00236 { 00237 searchpathname[0] = '\0'; 00238 ACE_OS::strcpy (searchfilename, tempcopy); 00239 } 00240 else // This is an absolute path. 00241 { 00242 ACE_OS::strcpy (searchfilename, separator_ptr + 1); 00243 separator_ptr[1] = '\0'; 00244 ACE_OS::strcpy (searchpathname, tempcopy); 00245 } 00246 00247 bool has_suffix = false; 00248 00249 // Check to see if this has an appropriate DLL suffix for the OS 00250 // platform. 00251 ACE_TCHAR *s = ACE_OS::strrchr (searchfilename, '.'); 00252 00253 const ACE_TCHAR *dll_suffix = ACE_DLL_SUFFIX; 00254 00255 if (s != 0) 00256 { 00257 // If we have a dot, we have a suffix 00258 has_suffix = true; 00259 00260 // Check whether this matches the appropriate platform-specific 00261 // suffix. 00262 #if defined (ACE_WIN32) 00263 // Use <ACE_OS::strcasecmp> on any platform with 00264 // case-insensitive filenames. 00265 if (ACE_OS::strcasecmp (s, dll_suffix) != 0) 00266 #else 00267 if (ACE_OS::strcmp (s, dll_suffix) != 0) 00268 #endif /* ACE_WIN32 */ 00269 { 00270 ACE_ERROR ((LM_WARNING, 00271 ACE_TEXT ("Warning: improper suffix for a ") 00272 ACE_TEXT ("shared library on this platform: %s\n"), 00273 s)); 00274 } 00275 } 00276 00277 // Make sure we've got enough space in searchfilename. 00278 if (ACE_OS::strlen (searchfilename) 00279 + ACE_OS::strlen (ACE_DLL_PREFIX) 00280 + (has_suffix ? 0 : ACE_OS::strlen (dll_suffix)) 00281 >= (sizeof searchfilename / sizeof (ACE_TCHAR))) 00282 { 00283 errno = ENOMEM; 00284 return -1; 00285 } 00286 00287 #if defined (ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) 00288 size_t len_searchfilename = ACE_OS::strlen (searchfilename); 00289 if (! has_suffix) 00290 ACE_OS::strcpy (searchfilename + len_searchfilename, 00291 decorator); 00292 00293 for (int tag = 1; tag >= 0; tag --) 00294 { 00295 if (tag == 0) 00296 searchfilename [len_searchfilename] = 0; 00297 00298 #endif /* ACE_WIN32 && ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */ 00299 // Use absolute pathname if there is one. 00300 if (ACE_OS::strlen (searchpathname) > 0) 00301 { 00302 if (ACE_OS::strlen (searchfilename) 00303 + ACE_OS::strlen (searchpathname) >= maxpathnamelen) 00304 { 00305 errno = ENOMEM; 00306 return -1; 00307 } 00308 else 00309 { 00310 #if (ACE_DIRECTORY_SEPARATOR_CHAR != '/') 00311 // Revert to native path name separators. 00312 ACE::strrepl (searchpathname, 00313 '/', 00314 ACE_DIRECTORY_SEPARATOR_CHAR); 00315 #endif /* ACE_DIRECTORY_SEPARATOR_CHAR */ 00316 // First, try matching the filename *without* adding a 00317 // prefix. 00318 ACE_OS::sprintf (pathname, 00319 ACE_TEXT ("%s%s%s"), 00320 searchpathname, 00321 searchfilename, 00322 has_suffix ? ACE_TEXT ("") : dll_suffix); 00323 if (ACE_OS::access (pathname, F_OK) == 0) 00324 return 0; 00325 00326 // Second, try matching the filename *with* adding a prefix. 00327 ACE_OS::sprintf (pathname, 00328 ACE_TEXT ("%s%s%s%s"), 00329 searchpathname, 00330 ACE_DLL_PREFIX, 00331 searchfilename, 00332 has_suffix ? ACE_TEXT ("") : dll_suffix); 00333 if (ACE_OS::access (pathname, F_OK) == 0) 00334 return 0; 00335 } 00336 } 00337 00338 // Use relative filenames via LD_LIBRARY_PATH or PATH (depending on 00339 // OS platform). 00340 else 00341 { 00342 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) 00343 ACE_TCHAR *file_component = 0; 00344 DWORD pathlen = 00345 ACE_TEXT_SearchPath (0, 00346 searchfilename, 00347 dll_suffix, 00348 static_cast<DWORD> (maxpathnamelen), 00349 pathname, 00350 &file_component); 00351 if (pathlen >= maxpathnamelen) 00352 { 00353 errno = ENOMEM; 00354 return -1; 00355 } 00356 else if (pathlen > 0) 00357 return 0; 00358 00359 // In case not found we should try again with the ACE_DLL_PREFIX 00360 // prefixed 00361 ACE_OS::strcpy (searchfilename, ACE_DLL_PREFIX); 00362 ACE_OS::strcat (searchfilename, tempcopy); 00363 pathlen = 00364 ACE_TEXT_SearchPath (0, 00365 searchfilename, 00366 dll_suffix, 00367 static_cast<DWORD> (maxpathnamelen), 00368 pathname, 00369 &file_component); 00370 if (pathlen >= maxpathnamelen) 00371 { 00372 errno = ENOMEM; 00373 return -1; 00374 } 00375 else if (pathlen > 0) 00376 return 0; 00377 #else 00378 ACE_TCHAR *ld_path; 00379 # if defined ACE_DEFAULT_LD_SEARCH_PATH 00380 ld_path = ACE_DEFAULT_LD_SEARCH_PATH; 00381 # else 00382 # if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) 00383 ld_path = ACE_OS::getenv (ACE_LD_SEARCH_PATH); 00384 # else 00385 // Wide-char, non-Windows only offers char * getenv. So capture 00386 // it, translate to wide-char, and continue. 00387 ACE_Ascii_To_Wide wide_ldpath 00388 (ACE_OS::getenv (ACE_TEXT_ALWAYS_CHAR (ACE_LD_SEARCH_PATH))); 00389 ld_path = wide_ldpath.wchar_rep (); 00390 # endif /* ACE_WIN32 || !ACE_USES_WCHAR */ 00391 # endif /* ACE_DEFAULT_LD_SEARCH_PATH */ 00392 00393 #if defined (ACE_HAS_WINCE) 00394 ACE_TCHAR *ld_path_temp = 0; 00395 if (ld_path != 0) 00396 { 00397 ld_path_temp = (ACE_TCHAR *) 00398 ACE_OS::malloc ((ACE_OS::strlen (ld_path) + 2) 00399 * sizeof (ACE_TCHAR)); 00400 if (ld_path_temp != 0) 00401 { 00402 ACE_OS::strcpy (ld_path_temp, 00403 ACE_LD_SEARCH_PATH_SEPARATOR_STR); 00404 00405 ACE_OS::strcat (ld_path_temp, ld_path); 00406 ld_path = ld_path_temp; 00407 } 00408 else 00409 { 00410 ACE_OS::free ((void *) ld_path_temp); 00411 ld_path = ld_path_temp = 0; 00412 } 00413 } 00414 #endif /* ACE_HAS_WINCE */ 00415 00416 if (ld_path != 0 00417 && (ld_path = ACE_OS::strdup (ld_path)) != 0) 00418 { 00419 // strtok has the strange behavior of not separating the 00420 // string ":/foo:/bar" into THREE tokens. One would expect 00421 // that the first iteration the token would be an empty 00422 // string, the second iteration would be "/foo", and the 00423 // third iteration would be "/bar". However, this is not 00424 // the case; one only gets two iterations: "/foo" followed 00425 // by "/bar". 00426 00427 // This is especially a problem in parsing Unix paths 00428 // because it is permissible to specify 'the current 00429 // directory' as an empty entry. So, we introduce the 00430 // following special code to cope with this: 00431 00432 // Look at each dynamic lib directory in the search path. 00433 00434 ACE_TCHAR *nextholder = 0; 00435 const ACE_TCHAR *path_entry = 00436 ACE::strsplit_r (ld_path, 00437 ACE_LD_SEARCH_PATH_SEPARATOR_STR, 00438 nextholder); 00439 int result = 0; 00440 00441 for (;;) 00442 { 00443 // Check if at end of search path. 00444 if (path_entry == 0) 00445 { 00446 errno = ENOENT; 00447 result = -1; 00448 break; 00449 } 00450 else if (ACE_OS::strlen (path_entry) 00451 + 1 00452 + ACE_OS::strlen (searchfilename) 00453 >= maxpathnamelen) 00454 { 00455 errno = ENOMEM; 00456 result = -1; 00457 break; 00458 } 00459 // This works around the issue where a path might have 00460 // an empty component indicating 'current directory'. 00461 // We need to do it here rather than anywhere else so 00462 // that the loop condition will still work. 00463 else if (path_entry[0] == '\0') 00464 path_entry = ACE_TEXT ("."); 00465 00466 // First, try matching the filename *without* adding a 00467 // prefix. 00468 ACE_OS::sprintf (pathname, 00469 ACE_TEXT ("%s%c%s%s"), 00470 path_entry, 00471 ACE_DIRECTORY_SEPARATOR_CHAR, 00472 searchfilename, 00473 has_suffix ? ACE_TEXT ("") : dll_suffix); 00474 if (ACE_OS::access (pathname, F_OK) == 0) 00475 break; 00476 00477 // Second, try matching the filename *with* adding a 00478 // prefix. 00479 ACE_OS::sprintf (pathname, 00480 ACE_TEXT ("%s%c%s%s%s"), 00481 path_entry, 00482 ACE_DIRECTORY_SEPARATOR_CHAR, 00483 ACE_DLL_PREFIX, 00484 searchfilename, 00485 has_suffix ? ACE_TEXT ("") : dll_suffix); 00486 if (ACE_OS::access (pathname, F_OK) == 0) 00487 break; 00488 00489 // Fetch the next item in the path 00490 path_entry = 00491 ACE::strsplit_r (0, 00492 ACE_LD_SEARCH_PATH_SEPARATOR_STR, 00493 nextholder); 00494 } 00495 00496 #if defined (ACE_HAS_WINCE) 00497 if (ld_path_temp != 0) 00498 ACE_OS::free (ld_path_temp); 00499 #endif /* ACE_HAS_WINCE */ 00500 ACE_OS::free ((void *) ld_path); 00501 #if defined (ACE_HAS_WINCE) && defined (ACE_LD_DECORATOR_STR) && \ 00502 !defined (ACE_DISABLE_DEBUG_DLL_CHECK) 00503 if (result == 0 || tag == 0) 00504 #endif /* ACE_HAS_WINCE && ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */ 00505 return result; 00506 } 00507 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */ 00508 } 00509 #if defined (ACE_WIN32) && defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) 00510 } 00511 #endif /* ACE_WIN32 && ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */ 00512 00513 errno = ENOENT; 00514 return -1; 00515 }
Uses ldfind
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.
Definition at line 518 of file Lib_Find.cpp.
References ACE_TRACE, ACE_OS::fopen(), ldfind(), and MAXPATHLEN.
00520 { 00521 ACE_TRACE ("ACE::ldopen"); 00522 00523 ACE_TCHAR buf[MAXPATHLEN + 1]; 00524 if (ACE::ldfind (filename, 00525 buf, 00526 sizeof (buf) /sizeof (ACE_TCHAR)) == -1) 00527 return 0; 00528 else 00529 return ACE_OS::fopen (buf, type); 00530 }
Transforms entry_point into a form that can be located in a dynamic library using <dlsym>. For example, with Win32/Borland extern "C" functions which use the default calling convention have a '_' prepended. Always returns a buffer that has been dynamically allocated using <operator new>="">.
Definition at line 533 of file Lib_Find.cpp.
References ACE_NEW_RETURN, ACE_TEXT, ACE_TRACE, ACE_OS::strcat(), ACE_OS::strcpy(), and ACE_OS::strlen().
Referenced by ACE_DLL_Handle::symbol().
00534 { 00535 ACE_TRACE ("ACE::ldname"); 00536 00537 #if defined(ACE_NEEDS_DL_UNDERSCORE) 00538 size_t size = 00539 1 // leading '_' 00540 + ACE_OS::strlen (entry_point) 00541 + 1; 00542 00543 ACE_TCHAR *new_name; 00544 ACE_NEW_RETURN (new_name, 00545 ACE_TCHAR[size], 00546 0); 00547 00548 ACE_OS::strcpy (new_name, ACE_TEXT ("_")); 00549 ACE_OS::strcat (new_name, entry_point); 00550 00551 return new_name; 00552 #else /* ACE_NEEDS_DL_UNDERSCORE */ 00553 size_t size = 00554 ACE_OS::strlen (entry_point) 00555 + 1; 00556 00557 ACE_TCHAR *new_name; 00558 ACE_NEW_RETURN (new_name, 00559 ACE_TCHAR[size], 00560 0); 00561 00562 ACE_OS::strcpy (new_name, entry_point); 00563 return new_name; 00564 #endif /* ACE_NEEDS_DL_UNDERSCORE */ 00565 }
ACE_Export int ACE::get_temp_dir | ( | ACE_TCHAR * | buffer, | |
size_t | buffer_len | |||
) |
Returns the temporary directory including the trailing slash in buffer. Returns -1 for an error or if the buffer_len is not long enough.
Definition at line 589 of file Lib_Find.cpp.
References ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, ACE_OS::getenv(), ACE_OS::strcpy(), and ACE_OS::strlen().
Referenced by ACE_MEM_Acceptor::accept(), ACE_Logging_Strategy::ACE_Logging_Strategy(), ACE_MMAP_Memory_Pool::ACE_MMAP_Memory_Pool(), ACE_Name_Options::ACE_Name_Options(), ACE_System_Time::ACE_System_Time(), and ACE_FILE_Addr::set().
00590 { 00591 int result; 00592 #if defined (ACE_WIN32) 00593 result = ACE_TEXT_GetTempPath (static_cast<DWORD> (buffer_len), 00594 buffer); 00595 00596 // Make sure to return -1 if there is an error 00597 if (result == 0 && ::GetLastError () != ERROR_SUCCESS 00598 || result > static_cast<int> (buffer_len)) 00599 result = -1; 00600 00601 #else /* ACE_WIN32 */ 00602 00603 // NOTE! Non-Windows platforms don't deal with wide chars for env. 00604 // variables, so do this narrow-char and convert to wide for the 00605 // caller if necessary. 00606 00607 // On non-win32 platforms, check to see what the TMPDIR environment 00608 // variable is defined to be. If it doesn't exist, just use /tmp 00609 const char *tmpdir = ACE_OS::getenv ("TMPDIR"); 00610 00611 if (tmpdir == 0) 00612 tmpdir = "/tmp"; 00613 00614 size_t len = ACE_OS::strlen (tmpdir); 00615 00616 // Check to see if the buffer is large enough for the string, 00617 // another /, and its null character (hence the + 2) 00618 if ((len + 2) > buffer_len) 00619 { 00620 result = -1; 00621 } 00622 else 00623 { 00624 ACE_OS::strcpy (buffer, ACE_TEXT_CHAR_TO_TCHAR (tmpdir)); 00625 00626 // Add a trailing slash because we cannot assume there is already one 00627 // at the end. And having an extra one should not cause problems. 00628 buffer[len] = ACE_TEXT ('/'); 00629 buffer[len + 1] = 0; 00630 result = 0; 00631 } 00632 #endif /* ACE_WIN32 */ 00633 return result; 00634 }
ACE_Export ACE_HANDLE ACE::open_temp_file | ( | const ACE_TCHAR * | name, | |
int | mode, | |||
int | perm = 0 | |||
) |
Opening the temp file. File is automagically unlinked when it is closed. This is useful for have temp files.
Definition at line 637 of file Lib_Find.cpp.
References FILE_SHARE_READ, ACE_OS::open(), and ACE_OS::unlink().
00638 { 00639 #if defined (ACE_WIN32) 00640 ACE_UNUSED_ARG (perm); 00641 ACE_HANDLE handle = ACE_OS::open (name, 00642 mode, 00643 FILE_SHARE_READ 00644 | FILE_SHARE_WRITE 00645 | FILE_SHARE_DELETE); 00646 #else 00647 // Open it. 00648 ACE_HANDLE handle = ACE_OS::open (name, mode, perm); 00649 #endif /* ACE_WIN32 */ 00650 00651 if (handle == ACE_INVALID_HANDLE) 00652 return ACE_INVALID_HANDLE; 00653 00654 // Unlink it so that the file will be removed automatically when the 00655 // process goes away. 00656 if (ACE_OS::unlink (name) == -1) 00657 return ACE_INVALID_HANDLE; 00658 else 00659 // Return the handle. 00660 return handle; 00661 }
ACE_Export size_t ACE::strrepl | ( | char * | s, | |
char | search, | |||
char | replace | |||
) |
Replace all instances of search in s with replace. Returns the number of replacements made.
Definition at line 664 of file Lib_Find.cpp.
References ACE_TRACE.
Referenced by ldfind().
00665 { 00666 ACE_TRACE ("ACE::strrepl"); 00667 00668 size_t replaced = 0; 00669 00670 for (size_t i = 0; s[i] != '\0'; i++) 00671 if (s[i] == search) 00672 { 00673 s[i] = replace; 00674 ++replaced; 00675 } 00676 00677 return replaced; 00678 }
ACE_Export char * ACE::strsplit_r | ( | char * | s, | |
const char * | token, | |||
char *& | next_start | |||
) |
Splits string <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.
Definition at line 685 of file Lib_Find.cpp.
References ACE_OS::strlen(), and ACE_OS::strstr().
Referenced by ldfind().
00688 { 00689 char *result = 0; 00690 00691 if (str != 0) 00692 next_start = str; 00693 00694 if (next_start != 0) 00695 { 00696 char *tok_loc = ACE_OS::strstr (next_start, token); 00697 00698 if (tok_loc != 0) 00699 { 00700 // Return the beginning of the string. 00701 result = next_start; 00702 00703 // Insure it's terminated. 00704 *tok_loc = '\0'; 00705 next_start = tok_loc + ACE_OS::strlen (token); 00706 } 00707 else 00708 { 00709 result = next_start; 00710 next_start = (char *) 0; 00711 } 00712 } 00713 00714 return result; 00715 }
ACE_Export int ACE::bind_port | ( | ACE_HANDLE | handle, | |
ACE_UINT32 | ip_addr = INADDR_ANY , |
|||
int | address_family = AF_UNSPEC | |||
) |
Bind a new unused port to handle.
Definition at line 171 of file Sock_Connect.cpp.
References ACE_MAX_DEFAULT_PORT, ACE_TRACE, ACE_OS::bind(), ACE_INET_Addr::get_addr(), ACE_Addr::get_size(), INADDR_ANY, IPPORT_RESERVED, and ACE_INET_Addr::set().
Referenced by ACE_SOCK_CODgram::open(), ACE_SOCK_SEQPACK_Acceptor::shared_open(), ACE_SOCK_Dgram::shared_open(), and ACE_SOCK_Acceptor::shared_open().
00172 { 00173 ACE_TRACE ("ACE::bind_port"); 00174 00175 ACE_INET_Addr addr; 00176 00177 #if defined (ACE_HAS_IPV6) 00178 if (address_family != PF_INET6) 00179 // What do we do if it is PF_"INET6? Since it's 4 bytes, it must be an 00180 // IPV4 address. Is there a difference? Why is this test done? dhinton 00181 #else /* ACE_HAS_IPV6 */ 00182 ACE_UNUSED_ARG (address_family); 00183 #endif /* !ACE_HAS_IPV6 */ 00184 addr = ACE_INET_Addr ((u_short)0, ip_addr); 00185 #if defined (ACE_HAS_IPV6) 00186 else if (ip_addr != INADDR_ANY) 00187 // address_family == PF_INET6 and a non default IP address means to bind 00188 // to the IPv4-mapped IPv6 address 00189 addr.set ((u_short)0, ip_addr, 1, 1); 00190 #endif /* ACE_HAS_IPV6 */ 00191 00192 #if !defined (ACE_LACKS_WILDCARD_BIND) 00193 // The OS kernel should select a free port for us. 00194 return ACE_OS::bind (handle, 00195 (sockaddr*)addr.get_addr(), 00196 addr.get_size()); 00197 #else 00198 static u_short upper_limit = ACE_MAX_DEFAULT_PORT; 00199 int round_trip = upper_limit; 00200 int lower_limit = IPPORT_RESERVED; 00201 00202 // We have to select the port explicitly. 00203 00204 for (;;) 00205 { 00206 addr.set((u_short)upper_limit,ip_addr); 00207 00208 if (ACE_OS::bind (handle, 00209 (sockaddr*)addr.get_addr() 00210 addr.get_size()) >= 0) 00211 { 00212 #if defined (ACE_WIN32) 00213 upper_limit--; 00214 #endif /* ACE_WIN32 */ 00215 return 0; 00216 } 00217 else if (errno != EADDRINUSE) 00218 return -1; 00219 else 00220 { 00221 upper_limit--; 00222 00223 // Wrap back around when we reach the bottom. 00224 if (upper_limit <= lower_limit) 00225 upper_limit = ACE_MAX_DEFAULT_PORT; 00226 00227 // See if we have already gone around once! 00228 if (upper_limit == round_trip) 00229 { 00230 errno = EAGAIN; 00231 return -1; 00232 } 00233 } 00234 } 00235 #endif /* ACE_HAS_WILDCARD_BIND */ 00236 }
ACE_Export int ACE::get_bcast_addr | ( | ACE_UINT32 & | bcast_addr, | |
const ACE_TCHAR * | hostname = 0 , |
|||
ACE_UINT32 | host_addr = 0 , |
|||
ACE_HANDLE | handle = ACE_INVALID_HANDLE | |||
) |
Get our broadcast address based on our 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.
Definition at line 239 of file Sock_Connect.cpp.
References ACE_BIT_DISABLED, ACE_BIT_ENABLED, ACE_ERROR, ACE_ERROR_RETURN, ACE_NOTSUP_RETURN, ACE_TEXT, ACE_TEXT_ALWAYS_CHAR, ACE_TRACE, AF_INET, ACE_OS::close(), ACE_OS::gethostbyname(), IFF_BROADCAST, IFF_LOOPBACK, IFF_UP, ACE_OS::ioctl(), LM_ERROR, ACE_OS::memcpy(), ACE_OS::memset(), SIOCGIFBRDADDR, SIOCGIFCONF_CMD, SOCK_STREAM, and ACE_OS::socket().
00243 { 00244 ACE_TRACE ("ACE::get_bcast_addr"); 00245 00246 #if defined (ACE_LACKS_GET_BCAST_ADDR) 00247 ACE_UNUSED_ARG (bcast_addr); 00248 ACE_UNUSED_ARG (host_name); 00249 ACE_UNUSED_ARG (host_addr); 00250 ACE_UNUSED_ARG (handle); 00251 ACE_NOTSUP_RETURN (-1); 00252 #elif !defined(ACE_WIN32) && !defined(__INTERIX) 00253 ACE_HANDLE s = handle; 00254 00255 if (s == ACE_INVALID_HANDLE) 00256 s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0); 00257 00258 if (s == ACE_INVALID_HANDLE) 00259 ACE_ERROR_RETURN ((LM_ERROR, 00260 ACE_TEXT ("%p\n"), 00261 ACE_TEXT ("ACE_OS::socket")), 00262 -1); 00263 00264 struct ifconf ifc; 00265 char buf[BUFSIZ]; 00266 00267 ifc.ifc_len = sizeof buf; 00268 ifc.ifc_buf = buf; 00269 00270 // Get interface structure and initialize the addresses using UNIX 00271 // techniques 00272 if (ACE_OS::ioctl (s, SIOCGIFCONF_CMD, (char *) &ifc) == -1) 00273 ACE_ERROR_RETURN ((LM_ERROR, 00274 ACE_TEXT ("%p\n"), 00275 ACE_TEXT ("ACE::get_bcast_addr:") 00276 ACE_TEXT ("ioctl (get interface configuration)")), 00277 -1); 00278 00279 struct ifreq *ifr = ifc.ifc_req; 00280 00281 struct sockaddr_in ip_addr; 00282 00283 // Get host ip address if necessary. 00284 if (host_name) 00285 { 00286 hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name)); 00287 00288 if (hp == 0) 00289 return -1; 00290 else 00291 #if !defined(_UNICOS) 00292 ACE_OS::memcpy ((char *) &ip_addr.sin_addr.s_addr, 00293 (char *) hp->h_addr, 00294 hp->h_length); 00295 #else /* _UNICOS */ 00296 { 00297 ACE_UINT64 haddr; // a place to put the address 00298 char * haddrp = (char *) &haddr; // convert to char pointer 00299 ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length); 00300 ip_addr.sin_addr.s_addr = haddr; 00301 } 00302 #endif /* ! _UNICOS */ 00303 } 00304 else 00305 { 00306 ACE_OS::memset ((void *) &ip_addr, 0, sizeof ip_addr); 00307 #if !defined(_UNICOS) 00308 ACE_OS::memcpy ((void *) &ip_addr.sin_addr, 00309 (void*) &host_addr, 00310 sizeof ip_addr.sin_addr); 00311 #else /* _UNICOS */ 00312 ip_addr.sin_addr.s_addr = host_addr; // just copy to the bitfield 00313 #endif /* ! _UNICOS */ 00314 } 00315 00316 #if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) 00317 for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0; 00318 n--, ifr++) 00319 #else 00320 // see mk_broadcast@SOCK_Dgram_Bcast.cpp 00321 for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) && 00322 ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ? 00323 (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1); 00324 ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ? 00325 (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len, 00326 ifr = (struct ifreq *) 00327 ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) : 00328 (nbytes -= sizeof (struct ifreq), ifr++))) 00329 #endif /* !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) */ 00330 { 00331 struct sockaddr_in if_addr; 00332 00333 // Compare host ip address with interface ip address. 00334 ACE_OS::memcpy (&if_addr, 00335 &ifr->ifr_addr, 00336 sizeof if_addr); 00337 00338 if (ip_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr) 00339 continue; 00340 00341 if (ifr->ifr_addr.sa_family != AF_INET) 00342 { 00343 ACE_ERROR ((LM_ERROR, 00344 ACE_TEXT ("%p\n"), 00345 ACE_TEXT ("ACE::get_bcast_addr:") 00346 ACE_TEXT ("Not AF_INET"))); 00347 continue; 00348 } 00349 00350 struct ifreq flags = *ifr; 00351 struct ifreq if_req = *ifr; 00352 00353 if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1) 00354 { 00355 ACE_ERROR ((LM_ERROR, 00356 ACE_TEXT ("%p\n"), 00357 ACE_TEXT ("ACE::get_bcast_addr:") 00358 ACE_TEXT (" ioctl (get interface flags)"))); 00359 continue; 00360 } 00361 00362 if (ACE_BIT_DISABLED (flags.ifr_flags, IFF_UP)) 00363 { 00364 ACE_ERROR ((LM_ERROR, 00365 ACE_TEXT ("%p\n"), 00366 ACE_TEXT ("ACE::get_bcast_addr:") 00367 ACE_TEXT ("Network interface is not up"))); 00368 continue; 00369 } 00370 00371 if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_LOOPBACK)) 00372 continue; 00373 00374 if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_BROADCAST)) 00375 { 00376 if (ACE_OS::ioctl (s, 00377 SIOCGIFBRDADDR, 00378 (char *) &if_req) == -1) 00379 ACE_ERROR ((LM_ERROR, 00380 ACE_TEXT ("%p\n"), 00381 ACE_TEXT ("ACE::get_bcast_addr:") 00382 ACE_TEXT ("ioctl (get broadaddr)"))); 00383 else 00384 { 00385 ACE_OS::memcpy (&ip_addr, 00386 &if_req.ifr_broadaddr, 00387 sizeof if_req.ifr_broadaddr); 00388 00389 ACE_OS::memcpy ((void *) &host_addr, 00390 (void *) &ip_addr.sin_addr, 00391 sizeof host_addr); 00392 00393 if (handle == ACE_INVALID_HANDLE) 00394 ACE_OS::close (s); 00395 00396 bcast_addr = host_addr; 00397 return 0; 00398 } 00399 } 00400 else 00401 ACE_ERROR ((LM_ERROR, 00402 ACE_TEXT ("%p\n"), 00403 ACE_TEXT ("ACE::get_bcast_addr:") 00404 ACE_TEXT ("Broadcast is not enable for this interface."))); 00405 00406 if (handle == ACE_INVALID_HANDLE) 00407 ACE_OS::close (s); 00408 00409 bcast_addr = host_addr; 00410 return 0; 00411 } 00412 00413 return 0; 00414 #else 00415 ACE_UNUSED_ARG (handle); 00416 ACE_UNUSED_ARG (host_addr); 00417 ACE_UNUSED_ARG (host_name); 00418 bcast_addr = (ACE_UINT32 (INADDR_BROADCAST)); 00419 return 0; 00420 #endif /* !ACE_WIN32 && !__INTERIX */ 00421 }
ACE_Export int ACE::get_fqdn | ( | ACE_INET_Addr const & | addr, | |
char | hostname[], | |||
size_t | len | |||
) |
Get fully qualified host/domain name.
Definition at line 424 of file Sock_Connect.cpp.
References ACE_DEBUG, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, AF_INET, debug(), ACE_INET_Addr::get_addr(), ACE_Addr::get_type(), ACE_OS::gethostbyaddr_r(), LM_DEBUG, ACE_OS::strchr(), ACE_OS::strcpy(), and ACE_OS::strlen().
00427 { 00428 int h_error; // Not the same as errno! 00429 hostent hentry; 00430 ACE_HOSTENT_DATA buf; 00431 00432 char * ip_addr = 0; 00433 int ip_addr_size = 0; 00434 if (addr.get_type () == AF_INET) 00435 { 00436 sockaddr_in * const sock_addr = 00437 reinterpret_cast<sockaddr_in *> (addr.get_addr ()); 00438 ip_addr_size = sizeof sock_addr->sin_addr; 00439 ip_addr = (char*) &sock_addr->sin_addr; 00440 } 00441 #ifdef ACE_HAS_IPV6 00442 else 00443 { 00444 sockaddr_in6 * sock_addr = 00445 reinterpret_cast<sockaddr_in6 *> (addr.get_addr ()); 00446 00447 ip_addr_size = sizeof sock_addr->sin6_addr; 00448 ip_addr = (char*) &sock_addr->sin6_addr; 00449 } 00450 #endif /* ACE_HAS_IPV6 */ 00451 00452 // get the host entry for the address in question 00453 hostent * const hp = ACE_OS::gethostbyaddr_r (ip_addr, 00454 ip_addr_size, 00455 addr.get_type (), 00456 &hentry, 00457 buf, 00458 &h_error); 00459 00460 // if it's not found in the host file or the DNS datase, there is nothing 00461 // much we can do. embed the IP address 00462 if (hp == 0 || hp->h_name == 0) 00463 return -1; 00464 00465 if (ACE::debug()) 00466 ACE_DEBUG ((LM_DEBUG, 00467 ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ") 00468 ACE_TEXT ("canonical host name is %s\n"), 00469 ACE_TEXT_CHAR_TO_TCHAR (hp->h_name))); 00470 00471 // check if the canonical name is the FQDN 00472 if (!ACE_OS::strchr(hp->h_name, '.')) 00473 { 00474 // list of address 00475 char** p; 00476 // list of aliases 00477 char** q; 00478 00479 // for every address and for every alias within the address, check and 00480 // see if we can locate a FQDN 00481 for (p = hp->h_addr_list; *p != 0; ++p) 00482 { 00483 for (q = hp->h_aliases; *q != 0; ++q) 00484 { 00485 if (ACE_OS::strchr(*q, '.')) 00486 { 00487 // we got an FQDN from an alias. use this 00488 if (ACE_OS::strlen (*q) >= len) 00489 // the hostname is too huge to fit into a 00490 // buffer of size MAXHOSTNAMELEN 00491 // should we check other aliases as well 00492 // before bailing out prematurely? 00493 // for right now, let's do it. this (short name) 00494 // is atleast better than embedding the IP 00495 // address in the profile 00496 continue; 00497 00498 if (ACE::debug ()) 00499 ACE_DEBUG ((LM_DEBUG, 00500 ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ") 00501 ACE_TEXT ("found fqdn within alias as %s\n"), 00502 ACE_TEXT_CHAR_TO_TCHAR(*q))); 00503 ACE_OS::strcpy (hostname, *q); 00504 00505 return 0; 00506 } 00507 } 00508 } 00509 } 00510 00511 // The canonical name may be an FQDN when we reach here. 00512 // Alternatively, the canonical name (a non FQDN) may be the best 00513 // we can do. 00514 if (ACE_OS::strlen (hp->h_name) >= len) 00515 { 00516 // The hostname is too large to fit into a buffer of size 00517 // MAXHOSTNAMELEN. 00518 return -2; 00519 } 00520 else 00521 { 00522 ACE_OS::strcpy (hostname, hp->h_name); 00523 } 00524 00525 return 0; 00526 }
ACE_Export int ACE::get_ip_interfaces | ( | size_t & | count, | |
ACE_INET_Addr *& | addr_array | |||
) |
Return count and array of all configured IP interfaces on this host, rc = 0 on success (count == number of interfaces else -1). Caller is responsible for calling delete [] on addr_array.
Definition at line 1221 of file Sock_Connect.cpp.
References ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_TEXT, ACE_TRACE, AF_INET, AF_UNSPEC, ACE_OS::close(), count_interfaces(), ACE_Auto_Basic_Array_Ptr< X >::get(), get_handle(), IFCONF, IFREQ, ACE_OS::ioctl(), ACE_OS::memcpy(), ACE_OS::memset(), ACE_INET_Addr::set(), and SIOCGIFCONF_CMD.
Referenced by ACE_SOCK_Dgram_Mcast::subscribe_ifs(), and ACE_SOCK_Dgram_Mcast::unsubscribe_ifs().
01223 { 01224 ACE_TRACE ("ACE::get_ip_interfaces"); 01225 01226 count = 0; 01227 addrs = 0; 01228 01229 #if defined (ACE_WIN32) 01230 return get_ip_interfaces_win32 (count, addrs); 01231 #elif defined (ACE_HAS_GETIFADDRS) 01232 return get_ip_interfaces_getifaddrs (count, addrs); 01233 #elif defined (__hpux) 01234 return get_ip_interfaces_hpux (count, addrs); 01235 #elif defined (_AIX) 01236 return get_ip_interfaces_aix (count, addrs); 01237 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x600) && !defined (ACE_HAS_VXWORKS551_MEDUSA) 01238 return get_ip_interfaces_vxworks_lt600 (count, addrs); 01239 #elif (defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (ACE_OPENVMS) || (defined (ACE_VXWORKS) && (ACE_VXWORKS == 0x650)) || defined (ACE_HAS_RTEMS)) && !defined (ACE_LACKS_NETWORKING) 01240 // COMMON (SVR4 and BSD) UNIX CODE 01241 01242 // Call specific routine as necessary. 01243 ACE_HANDLE handle = ACE::get_handle(); 01244 01245 if (handle == ACE_INVALID_HANDLE) 01246 ACE_ERROR_RETURN ((LM_ERROR, 01247 ACE_TEXT ("%p\n"), 01248 ACE_TEXT ("ACE::get_ip_interfaces:open")), 01249 -1); 01250 01251 size_t num_ifs, num_ifs_found; 01252 01253 if (ACE::count_interfaces (handle, num_ifs)) 01254 { 01255 ACE_OS::close (handle); 01256 return -1; 01257 } 01258 01259 // ioctl likes to have an extra ifreq structure to mark the end of 01260 // what it returned, so increase the num_ifs by one. 01261 ++num_ifs; 01262 01263 struct IFREQ *ifs = 0; 01264 ACE_NEW_RETURN (ifs, 01265 struct IFREQ[num_ifs], 01266 -1); 01267 ACE_OS::memset (ifs, 0, num_ifs * sizeof (struct IFREQ)); 01268 01269 ACE_Auto_Array_Ptr<struct IFREQ> p_ifs (ifs); 01270 01271 if (p_ifs.get() == 0) 01272 { 01273 ACE_OS::close (handle); 01274 errno = ENOMEM; 01275 return -1; 01276 } 01277 01278 struct IFCONF ifcfg; 01279 ACE_OS::memset (&ifcfg, 0, sizeof (struct IFCONF)); 01280 01281 # ifdef SETFAMILY 01282 ifcfg.IFC_FAMILY = AF_UNSPEC; // request all families be returned 01283 ifcfg.IFC_FLAGS = 0; 01284 # endif 01285 01286 ifcfg.IFC_REQ = p_ifs.get (); 01287 ifcfg.IFC_LEN = num_ifs * sizeof (struct IFREQ); 01288 01289 if (ACE_OS::ioctl (handle, 01290 SIOCGIFCONF_CMD, 01291 (caddr_t) &ifcfg) == -1) 01292 { 01293 ACE_OS::close (handle); 01294 ACE_ERROR_RETURN ((LM_ERROR, 01295 ACE_TEXT ("%p\n"), 01296 ACE_TEXT ("ACE::get_ip_interfaces:") 01297 ACE_TEXT ("ioctl - SIOCGIFCONF failed")), 01298 -1); 01299 } 01300 01301 ACE_OS::close (handle); 01302 01303 // Now create and initialize output array. 01304 01305 ACE_NEW_RETURN (addrs, 01306 ACE_INET_Addr[num_ifs], 01307 -1); // caller must free 01308 01309 struct IFREQ *pcur = p_ifs.get (); 01310 num_ifs_found = ifcfg.IFC_LEN / sizeof (struct IFREQ); // get the number of returned ifs 01311 01312 // Pull the address out of each INET interface. Not every interface 01313 // is for IP, so be careful to count properly. When setting the 01314 // INET_Addr, note that the 3rd arg (0) says to leave the byte order 01315 // (already in net byte order from the interface structure) as is. 01316 count = 0; 01317 01318 for (size_t i = 0; 01319 i < num_ifs_found; 01320 i++) 01321 { 01322 if (pcur->IFR_ADDR.SA_FAMILY == AF_INET 01323 # if defined (ACE_HAS_IPV6) 01324 || pcur->IFR_ADDR.SA_FAMILY == AF_INET6 01325 # endif 01326 ) 01327 01328 { 01329 # if !defined(_UNICOS) 01330 struct sockaddr_in *addr = 01331 reinterpret_cast<sockaddr_in *> (&pcur->IFR_ADDR); 01332 01333 // Sometimes the kernel returns 0.0.0.0 as an IPv4 interface 01334 // address; skip those... 01335 if (addr->sin_addr.s_addr != 0 01336 # if defined (ACE_HAS_IPV6) 01337 || (addr->sin_family == AF_INET6 && 01338 !IN6_IS_ADDR_UNSPECIFIED(&reinterpret_cast<sockaddr_in6 *>(addr)->sin6_addr)) 01339 # endif 01340 ) 01341 { 01342 int addrlen = static_cast<int> (sizeof (struct sockaddr_in)); 01343 # if defined (ACE_HAS_IPV6) 01344 if (addr->sin_family == AF_INET6) 01345 addrlen = static_cast<int> (sizeof (struct sockaddr_in6)); 01346 # endif 01347 addrs[count].set (addr, addrlen); 01348 ++count; 01349 } 01350 # else /* ! _UNICOS */ 01351 // need to explicitly copy on the Cray, since the bitfields kinda 01352 // screw things up here 01353 struct sockaddr_in inAddr; 01354 01355 inAddr.sin_len = pcur->IFR_ADDR.sa_len; 01356 inAddr.sin_family = pcur->IFR_ADDR.sa_family; 01357 memcpy((void *)&(inAddr.sin_addr), 01358 (const void *)&(pcur->IFR_ADDR.sa_data[8]), 01359 sizeof(struct in_addr)); 01360 01361 if (inAddr.sin_addr.s_addr != 0) 01362 { 01363 addrs[count].set(&inAddr, sizeof(struct sockaddr_in)); 01364 ++count; 01365 } 01366 # endif /* ! _UNICOS */ 01367 } 01368 01369 #if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) 01370 ++pcur; 01371 #else 01372 if (pcur->ifr_addr.sa_len <= sizeof (struct sockaddr)) 01373 { 01374 ++pcur; 01375 } 01376 else 01377 { 01378 pcur = (struct ifreq *) 01379 (pcur->ifr_addr.sa_len + (caddr_t) &pcur->ifr_addr); 01380 } 01381 #endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) */ 01382 } 01383 01384 # if defined (ACE_HAS_IPV6) 01385 // Retrieve IPv6 local interfaces by scanning /proc/net/if_inet6 if 01386 // it exists. If we cannot open it then ignore possible IPv6 01387 // interfaces, we did our best;-) 01388 FILE* fp; 01389 char addr_p[8][5]; 01390 char s_ipaddr[64]; 01391 int scopeid; 01392 struct addrinfo hints, *res0; 01393 int error; 01394 01395 ACE_OS::memset (&hints, 0, sizeof (hints)); 01396 hints.ai_flags = AI_NUMERICHOST; 01397 hints.ai_family = AF_INET6; 01398 01399 if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0) 01400 { 01401 while (fscanf (fp, 01402 "%4s%4s%4s%4s%4s%4s%4s%4s %02x %*02x %*02x %*02x %*8s\n", 01403 addr_p[0], addr_p[1], addr_p[2], addr_p[3], 01404 addr_p[4], addr_p[5], addr_p[6], addr_p[7], &scopeid) != EOF) 01405 { 01406 // Format the address intoa proper IPv6 decimal address specification and 01407 // resolve the resulting text using getaddrinfo(). 01408 01409 const char* ip_fmt = "%s:%s:%s:%s:%s:%s:%s:%s%%%d"; 01410 ACE_OS::sprintf (s_ipaddr, 01411 ip_fmt, 01412 addr_p[0], addr_p[1], addr_p[2], addr_p[3], 01413 addr_p[4], addr_p[5], addr_p[6], addr_p[7], scopeid); 01414 01415 error = getaddrinfo (s_ipaddr, 0, &hints, &res0); 01416 if (error) 01417 continue; 01418 01419 if (res0->ai_family == AF_INET6 && 01420 !IN6_IS_ADDR_UNSPECIFIED (&reinterpret_cast<sockaddr_in6 *> (res0->ai_addr)->sin6_addr)) 01421 { 01422 addrs[count].set(reinterpret_cast<sockaddr_in *> (res0->ai_addr), res0->ai_addrlen); 01423 ++count; 01424 } 01425 freeaddrinfo (res0); 01426 01427 } 01428 ACE_OS::fclose (fp); 01429 } 01430 # endif /* ACE_HAS_IPV6 */ 01431 01432 return 0; 01433 #else 01434 ACE_UNUSED_ARG (count); 01435 ACE_UNUSED_ARG (addrs); 01436 ACE_NOTSUP_RETURN (-1); // no implementation 01437 #endif /* ACE_WIN32 */ 01438 }
ACE_Export int ACE::count_interfaces | ( | ACE_HANDLE | handle, | |
size_t & | how_many | |||
) |
Helper routine for get_ip_interfaces, differs by UNIX platform so put into own subroutine. perform some ioctls to retrieve ifconf list of ifreq structs.
Definition at line 1445 of file Sock_Connect.cpp.
References ACE_ERROR_RETURN, ACE_NOTSUP_RETURN, AF_UNSPEC, ACE_OS::fclose(), ACE_OS::fopen(), ACE_OS::free(), ACE_OS::ioctl(), ACE_OS::malloc(), ACE_OS::memset(), and SIOCGIFCONF_CMD.
Referenced by get_ip_interfaces().
01447 { 01448 #if defined (ACE_WIN32) || defined (ACE_HAS_GETIFADDRS) || defined (__hpux) || defined (_AIX) || (defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x600)) 01449 // none of these platforms make use of count_interfaces 01450 ACE_UNUSED_ARG (handle); 01451 ACE_UNUSED_ARG (how_many); 01452 ACE_NOTSUP_RETURN (-1); // no implementation 01453 01454 #elif defined (SIOCGIFNUM) 01455 # if defined (SIOCGLIFNUM) 01456 int cmd = SIOCGLIFNUM; 01457 struct lifnum if_num = {AF_UNSPEC,0,0}; 01458 # else 01459 int cmd = SIOCGIFNUM; 01460 int if_num = 0; 01461 # endif /* SIOCGLIFNUM */ 01462 if (ACE_OS::ioctl (handle, cmd, (caddr_t)&if_num) == -1) 01463 ACE_ERROR_RETURN ((LM_ERROR, 01464 ACE_TEXT ("%p\n"), 01465 ACE_TEXT ("ACE::count_interfaces:") 01466 ACE_TEXT ("ioctl - SIOCGLIFNUM failed")), 01467 -1); 01468 # if defined (SIOCGLIFNUM) 01469 how_many = if_num.lifn_count; 01470 # else 01471 how_many = if_num; 01472 # endif /* SIOCGLIFNUM */ 01473 return 0; 01474 01475 #elif (defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS)) && !defined (ACE_LACKS_NETWORKING) 01476 // Note: DEC CXX doesn't define "unix". BSD compatible OS: HP UX, 01477 // AIX, SunOS 4.x perform some ioctls to retrieve ifconf list of 01478 // ifreq structs no SIOCGIFNUM on SunOS 4.x, so use guess and scan 01479 // algorithm 01480 01481 // Probably hard to put this many ifs in a unix box.. 01482 const int MAX_IF = 50; 01483 01484 // HACK - set to an unreasonable number 01485 int num_ifs = MAX_IF; 01486 01487 struct ifconf ifcfg; 01488 size_t ifreq_size = num_ifs * sizeof (struct ifreq); 01489 struct ifreq *p_ifs = 01490 (struct ifreq *) ACE_OS::malloc (ifreq_size); 01491 01492 if (!p_ifs) 01493 { 01494 errno = ENOMEM; 01495 return -1; 01496 } 01497 01498 ACE_OS::memset (p_ifs, 0, ifreq_size); 01499 ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf)); 01500 01501 ifcfg.ifc_req = p_ifs; 01502 ifcfg.ifc_len = ifreq_size; 01503 01504 if (ACE_OS::ioctl (handle, 01505 SIOCGIFCONF_CMD, 01506 (caddr_t) &ifcfg) == -1) 01507 { 01508 ACE_OS::free (ifcfg.ifc_req); 01509 ACE_ERROR_RETURN ((LM_ERROR, 01510 ACE_TEXT ("%p\n"), 01511 ACE_TEXT ("ACE::count_interfaces:") 01512 ACE_TEXT ("ioctl - SIOCGIFCONF failed")), 01513 -1); 01514 } 01515 01516 int if_count = 0, i; 01517 01518 // get if address out of ifreq buffers. ioctl puts a blank-named 01519 // interface to mark the end of the returned interfaces. 01520 for (i = 0; 01521 i < num_ifs; 01522 i++) 01523 { 01524 /* In OpenBSD, the length of the list is returned. */ 01525 ifcfg.ifc_len -= sizeof (struct ifreq); 01526 if (ifcfg.ifc_len < 0) 01527 break; 01528 01529 ++if_count; 01530 #if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) 01531 ++p_ifs; 01532 #else 01533 if (p_ifs->ifr_addr.sa_len <= sizeof (struct sockaddr)) 01534 { 01535 ++p_ifs; 01536 } 01537 else 01538 { 01539 p_ifs = (struct ifreq *) 01540 (p_ifs->ifr_addr.sa_len + (caddr_t) &p_ifs->ifr_addr); 01541 } 01542 #endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) */ 01543 } 01544 01545 ACE_OS::free (ifcfg.ifc_req); 01546 01547 # if defined (ACE_HAS_IPV6) 01548 FILE* fp = 0; 01549 01550 if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0) 01551 { 01552 // Scan the lines according to the expected format but don't really read any input 01553 while (fscanf (fp, "%*32s %*02x %*02x %*02x %*02x %*8s\n") != EOF) 01554 { 01555 ++if_count; 01556 } 01557 ACE_OS::fclose (fp); 01558 } 01559 # endif /* ACE_HAS_IPV6 */ 01560 01561 how_many = if_count; 01562 return 0; 01563 #else 01564 ACE_UNUSED_ARG (handle); 01565 ACE_UNUSED_ARG (how_many); 01566 ACE_NOTSUP_RETURN (-1); // no implementation 01567 #endif /* sparc && SIOCGIFNUM */ 01568 }
ACE_Export ACE_HANDLE ACE::get_handle | ( | void | ) |
Routine to return a handle from which ioctl
requests can be made. Caller must close the handle.
Definition at line 1573 of file Sock_Connect.cpp.
References ACE_OS::open(), PF_INET, SOCK_DGRAM, and ACE_OS::socket().
Referenced by get_ip_interfaces(), and ACE_SOCK_Dgram_SC< STREAM >::recv().
01574 { 01575 // Solaris 2.x 01576 ACE_HANDLE handle = ACE_INVALID_HANDLE; 01577 #if defined (sparc) 01578 handle = ACE_OS::open ("/dev/udp", O_RDONLY); 01579 #elif defined (__unix) || defined (__unix__) || defined (__Lynx__) || defined (_AIX) || defined (__hpux) || (defined (ACE_VXWORKS) && (ACE_VXWORKS >= 0x600)) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS) 01580 // Note: DEC CXX doesn't define "unix" BSD compatible OS: HP UX, 01581 // AIX, SunOS 4.x 01582 01583 handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, 0); 01584 #endif /* sparc */ 01585 return handle; 01586 }
ACE_Export bool ACE::ipv4_enabled | ( | void | ) |
This is an execution-time check. If ACE has not been compiled with ACE_HAS_IPV6
, it always returns true
. This function tries to create a PF_INET
socket, returning true
if it succeeds, and false
if it fails. Caches the result so it only gets checked once.
Definition at line 1618 of file Sock_Connect.cpp.
References PF_INET.
01619 { 01620 #if defined (ACE_HAS_IPV6) 01621 return static_cast<bool> (ace_ipv4_enabled == -1 ? 01622 ::ip_check (ace_ipv4_enabled, PF_INET) : 01623 ace_ipv4_enabled); 01624 #else 01625 // Assume it's always enabled since ACE requires some version of 01626 // TCP/IP to exist. 01627 return true; 01628 #endif /* ACE_HAS_IPV6*/ 01629 }
ACE_Export int ACE::ipv6_enabled | ( | void | ) |
Returns 1 if IPv6 is enabled on the current host; 0 if not. This is an execution-time check. If ACE has not been compiled with ACE_HAS_IPV6, it always returns 0. If ACE_HAS_IPV6 is enabled, this function tries to create a PF_INET6 socket, returning 1 if it succeeds, and 0 if it fails. Caches the result so it only gets checked once.
Definition at line 1632 of file Sock_Connect.cpp.
Referenced by ACE_INET_Addr::determine_type(), ACE_SOCK_SEQPACK_Acceptor::open(), ACE_SOCK_Dgram::open(), ACE_SOCK_Acceptor::open(), and ACE_INET_Addr::set().
01633 { 01634 #if defined (ACE_HAS_IPV6) 01635 return ace_ipv6_enabled == -1 ? 01636 ::ip_check (ace_ipv6_enabled, PF_INET6) : 01637 ace_ipv6_enabled; 01638 #else /* ACE_HAS_IPV6 */ 01639 return 0; 01640 #endif /* !ACE_HAS_IPV6 */ 01641 }
size_t ACE::allocation_granularity_ = 0 |
size_t ACE::pagesize_ = 0 |
char ACE::debug_ |
ACE_BEGIN_VERSIONED_NAMESPACE_DECL unsigned int ACE::init_fini_count_ = 0 |