The namespace containing the ACE framework itself. More...
Namespaces | |
namespace | Monitor_Control |
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... | |
Functions | |
ACE_Export u_int | major_version (void) |
e.g., the "6" in ACE 6.3.4 | |
ACE_Export u_int | minor_version (void) |
e.g., the "3" in ACE 6.3.4 | |
ACE_Export u_int | micro_version (void) |
ACE_Export u_int | beta_version (void) |
ACE_Export const ACE_TCHAR * | compiler_name (void) |
E.g., the "SunPro C++" in SunPro C++ 4.32.0. | |
ACE_Export u_int | compiler_major_version (void) |
E.g., the "4" in SunPro C++ 4.32.0. | |
ACE_Export u_int | compiler_minor_version (void) |
E.g., the "32" in SunPro C++ 4.32.0. | |
ACE_Export u_int | compiler_beta_version (void) |
E.g., the "0" in SunPro C++ 4.32.0. | |
ACE_Export int | out_of_handles (int error) |
ACE_Export bool | wild_match (const char *s, const char *pattern, bool case_sensitive=true, bool character_classes=false) |
ACE_Export int | handle_timed_accept (ACE_HANDLE listener, ACE_Time_Value *timeout, bool restart) |
Wait up to timeout amount of time to accept a connection. | |
ACE_Export ACE_HANDLE | handle_timed_complete (ACE_HANDLE listener, const ACE_Time_Value *timeout, int is_tli=0) |
ACE_Export int | set_handle_limit (int new_limit=-1, int increase_limit_only=0) |
ACE_Export int | max_handles (void) |
ACE_Export ACE_TCHAR * | strenvdup (const ACE_TCHAR *str) |
ACE_Export const char * | strend (const char *s) |
ACE_Export char * | strnew (const char *s) |
ACE_NAMESPACE_INLINE_FUNCTION void | strdelete (char *s) |
Delete the memory allocated by strnew . | |
ACE_Export char * | strndup (const char *str, size_t n) |
ACE_Export char * | strnnew (const char *str, size_t n) |
ACE_NAMESPACE_INLINE_FUNCTION bool | isdotdir (const char *s) |
Determine if a specified pathname is "dot dir" (ie. "." or ".."). | |
ACE_Export const wchar_t * | strend (const wchar_t *s) |
ACE_Export wchar_t * | strnew (const wchar_t *s) |
ACE_NAMESPACE_INLINE_FUNCTION void | strdelete (wchar_t *s) |
ACE_Export wchar_t * | strndup (const wchar_t *str, size_t n) |
ACE_Export wchar_t * | strnnew (const wchar_t *str, size_t n) |
ACE_NAMESPACE_INLINE_FUNCTION bool | isdotdir (const wchar_t *s) |
ACE_Export const ACE_TCHAR * | execname (const ACE_TCHAR *pathname) |
ACE_Export const ACE_TCHAR * | basename (const ACE_TCHAR *pathname, ACE_TCHAR delim=ACE_DIRECTORY_SEPARATOR_CHAR) |
ACE_Export const ACE_TCHAR * | dirname (const ACE_TCHAR *pathname, ACE_TCHAR delim=ACE_DIRECTORY_SEPARATOR_CHAR) |
ACE_Export ACE_TCHAR * | timestamp (const ACE_Time_Value &time_value, ACE_TCHAR date_and_time[], size_t time_len, bool return_pointer_to_first_digit=false) |
ACE_Export ACE_TCHAR * | timestamp (ACE_TCHAR date_and_time[], size_t time_len, bool return_pointer_to_first_digit=false) |
ACE_Export pid_t | fork (const ACE_TCHAR *program_name=ACE_TEXT("<unknown>"), int avoid_zombies=0) |
ACE_Export int | daemonize (const ACE_TCHAR pathname[]=ACE_TEXT("/"), bool close_all_handles=ACE_DEFAULT_CLOSE_ALL_HANDLES, const ACE_TCHAR program_name[]=ACE_TEXT("<unknown>")) |
ACE_Export size_t | round_to_pagesize (size_t len) |
Rounds the request to a multiple of the page size. | |
ACE_Export size_t | round_to_allocation_granularity (size_t len) |
Rounds the request to a multiple of the allocation granularity. | |
ACE_Export size_t | format_hexdump (const char *buffer, size_t size, ACE_TCHAR *obuf, size_t obuf_sz) |
ACE_Export u_long | hash_pjw (const char *str) |
Computes the hash value of {str} using the "Hash PJW" routine. | |
ACE_Export u_long | hash_pjw (const char *str, size_t len) |
Computes the hash value of {str} using the "Hash PJW" routine. | |
ACE_Export u_long | hash_pjw (const wchar_t *str) |
Computes the hash value of {str} using the "Hash PJW" routine. | |
ACE_Export u_long | hash_pjw (const wchar_t *str, size_t len) |
Computes the hash value of {str} using the "Hash PJW" routine. | |
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 u_long | gcd (u_long x, u_long y) |
Euclid's greatest common divisor algorithm. | |
ACE_Export u_long | minimum_frame_size (u_long period1, u_long period2) |
Calculates the minimum enclosing frame size for the given values. | |
ACE_Export u_long | is_prime (const u_long n, const u_long min_factor, const u_long max_factor) |
ACE_Export int | map_errno (int error) |
ACE_Export const ACE_TCHAR * | sock_error (int error) |
ACE_Export bool | is_sock_error (int error) |
ACE_Export int | process_active (pid_t pid) |
ACE_Export int | terminate_process (pid_t pid) |
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}. | |
template<typename T > | |
bool | is_equal (const T &a, const T &b) |
template<typename T > | |
bool | is_inequal (const T &a, const T &b) |
ACE_Export 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_Export bool | debug (void) |
ACE_Export void | debug (bool onoff) |
ACE_Export 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 . | |
ACE_Export int | select (int width, ACE_Handle_Set &readfds, const ACE_Time_Value *timeout=0) |
ACE_NAMESPACE_INLINE_FUNCTION int | handle_read_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
ACE_NAMESPACE_INLINE_FUNCTION int | handle_write_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
ACE_NAMESPACE_INLINE_FUNCTION int | handle_exception_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout) |
ACE_Export int | handle_ready (ACE_HANDLE handle, const ACE_Time_Value *timeout, int read_ready, int write_ready, int exception_ready) |
ACE_Export int | enter_recv_timedwait (ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val) |
ACE_Export int | enter_send_timedwait (ACE_HANDLE handle, const ACE_Time_Value *timeout, int &val) |
ACE_Export void | record_and_set_non_blocking_mode (ACE_HANDLE handle, int &val) |
ACE_Export void | restore_non_blocking_mode (ACE_HANDLE handle, int val) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | recv_i (ACE_HANDLE handle, void *buf, size_t len) |
ACE_Export ssize_t | recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, size_t *bytes_transferred) |
ACE_Export ssize_t | recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_Export ssize_t | t_rcv_n_i (ACE_HANDLE handle, void *buf, size_t len, int *flags, size_t *bytes_transferred) |
ACE_Export ssize_t | t_rcv_n_i (ACE_HANDLE handle, void *buf, size_t len, int *flags, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_Export ssize_t | recv_n_i (ACE_HANDLE handle, void *buf, size_t len, size_t *bytes_transferred) |
ACE_Export ssize_t | recv_n_i (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_Export ssize_t | recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, size_t *bytes_transferred) |
ACE_Export ssize_t | recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | send_i (ACE_HANDLE handle, const void *buf, size_t len) |
ACE_Export ssize_t | send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, size_t *bytes_transferred) |
ACE_Export ssize_t | send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_Export ssize_t | t_snd_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, size_t *bytes_transferred) |
ACE_Export ssize_t | t_snd_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_Export ssize_t | send_n_i (ACE_HANDLE handle, const void *buf, size_t len, size_t *bytes_transferred) |
ACE_Export ssize_t | send_n_i (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
ACE_Export ssize_t | sendv_n_i (ACE_HANDLE handle, const iovec *iov, int iovcnt, size_t *bytes_transferred) |
ACE_Export ssize_t | sendv_n_i (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout, size_t *bytes_transferred) |
template<class T , typename = typename std::enable_if<std::is_base_of<ACE_Event_Handler, T>::value>::type, typename... Args> | |
ACE_Event_Handler_var | make_event_handler (Args &&...args) |
ACE_Export int | set_flags (ACE_HANDLE handle, int flags) |
Set flags associated with handle. | |
ACE_Export 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_Export ACE_HANDLE | handle_timed_open (ACE_Time_Value *timeout, const ACE_TCHAR *name, int flags, int perms, LPSECURITY_ATTRIBUTES sa=0) |
ACE_Export int | init (void) |
ACE_Export int | fini (void) |
ACE_Export int | ldfind (const ACE_TCHAR *filename, ACE_TCHAR pathname[], size_t maxpathnamelen) |
ACE_Export FILE * | ldopen (const ACE_TCHAR *filename, const ACE_TCHAR *type) |
ACE_Export ACE_TCHAR * | ldname (const ACE_TCHAR *entry_point) |
ACE_Export void | ldregister (const ACE_TCHAR *entry_point, void *entry_addr) |
ACE_Export void * | ldsymbol (ACE_SHLIB_HANDLE sh, const ACE_TCHAR *entry_point) |
ACE_Export int | get_temp_dir (ACE_TCHAR *buffer, size_t buffer_len) |
ACE_Export ACE_HANDLE | open_temp_file (const ACE_TCHAR *name, int mode, int perm=0) |
ACE_Export size_t | strrepl (char *s, char search, char replace) |
ACE_Export char * | strsplit_r (char *s, const char *token, char *&next_start) |
ACE_Export size_t | strrepl (wchar_t *s, wchar_t search, wchar_t replace) |
As strrepl, but for wide characters. | |
ACE_Export wchar_t * | strsplit_r (wchar_t *s, const wchar_t *token, wchar_t *&next_start) |
As strsplit_r, but for wide characters. | |
ACE_Export int | bind_port (ACE_HANDLE handle, ACE_UINT32 ip_addr=INADDR_ANY, int address_family=AF_UNSPEC) |
Bind a new unused port to handle. | |
ACE_Export int | get_bcast_addr (ACE_UINT32 &bcast_addr, const ACE_TCHAR *hostname=0, ACE_UINT32 host_addr=0, ACE_HANDLE handle=ACE_INVALID_HANDLE) |
ACE_Export int | get_fqdn (ACE_INET_Addr const &addr, char hostname[], size_t len) |
Get fully qualified host/domain name. | |
ACE_Export int | get_ip_interfaces (size_t &count, ACE_INET_Addr *&addr_array) |
ACE_Export int | count_interfaces (ACE_HANDLE handle, size_t &how_many) |
ACE_Export ACE_HANDLE | get_handle (void) |
ACE_Export bool | ipv4_enabled (void) |
ACE_Export int | ipv6_enabled (void) |
I/O operations | |
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 | |
ACE_Export ssize_t | recv (ACE_HANDLE handle, void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | t_rcv (ACE_HANDLE handle, void *buf, size_t len, int *flags, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | recv (ACE_HANDLE handle, void *buf, size_t len, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | recvmsg (ACE_HANDLE handle, struct msghdr *msg, int flags, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | recvfrom (ACE_HANDLE handle, char *buf, int len, int flags, struct sockaddr *addr, int *addrlen, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
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) |
Receive into a variable number of pieces. | |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | t_rcv_n (ACE_HANDLE handle, void *buf, size_t len, int *flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
Receive into a variable number of pieces. | |
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) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | recv (ACE_HANDLE handle, size_t n,...) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | recvv (ACE_HANDLE handle, iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
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) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | recv_n (ACE_HANDLE handle, ACE_Message_Block *message_block, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | send (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | t_snd (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | send (ACE_HANDLE handle, const void *buf, size_t len, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | sendmsg (ACE_HANDLE handle, const struct msghdr *msg, int flags, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | sendto (ACE_HANDLE handle, const char *buf, int len, int flags, const struct sockaddr *addr, int addrlen, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
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) |
Receive into a variable number of pieces. | |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | t_snd_n (ACE_HANDLE handle, const void *buf, size_t len, int flags, const ACE_Time_Value *timeout=0, size_t *bytes_transferred=0) |
Receive into a variable number of pieces. | |
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) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | send (ACE_HANDLE handle, size_t n,...) |
Varargs variant. | |
ACE_Export ssize_t | sendv (ACE_HANDLE handle, const iovec *iov, int iovcnt, const ACE_Time_Value *timeout=0) |
Receive into a variable number of pieces. | |
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) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | send_n (ACE_HANDLE handle, const ACE_Message_Block *message_block, 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) |
Receive into a variable number of pieces. | |
ACE_NAMESPACE_INLINE_FUNCTION ssize_t | write_n (ACE_HANDLE handle, const void *buf, size_t len, size_t *bytes_transferred=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | write_n (ACE_HANDLE handle, const ACE_Message_Block *message_block, size_t *bytes_transferred=0) |
ACE_Export ssize_t | readv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, size_t *bytes_transferred=0) |
Receive into a variable number of pieces. | |
ACE_Export ssize_t | writev_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, size_t *bytes_transferred=0) |
Receive into a variable number of pieces. | |
Variables | |
size_t | allocation_granularity_ = 0 |
size_t | pagesize_ = 0 |
char | debug_ |
unsigned int | init_fini_count_ = 0 |
The namespace containing the ACE framework itself.
The ACE namespace contains all types (classes, structures, typedefs, etc), and global functions and variables in the ACE framework.
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 403 of file ACE.cpp.
00404 { 00405 ACE_TRACE ("ACE::basename"); 00406 const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim); 00407 00408 if (temp == 0) 00409 return pathname; 00410 else 00411 return temp + 1; 00412 }
u_int ACE::beta_version | ( | void | ) |
e.g., the "4" in ACE 6.3.4 Returns 0 for "stable" (non-micro) releases.
Definition at line 106 of file ACE.cpp.
00107 { 00108 return ACE_BETA_VERSION; 00109 }
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 135 of file Sock_Connect.cpp.
00136 { 00137 ACE_TRACE ("ACE::bind_port"); 00138 00139 ACE_INET_Addr addr; 00140 00141 #if defined (ACE_HAS_IPV6) 00142 if (address_family != PF_INET6) 00143 // What do we do if it is PF_"INET6? Since it's 4 bytes, it must be an 00144 // IPV4 address. Is there a difference? Why is this test done? dhinton 00145 #else /* ACE_HAS_IPV6 */ 00146 ACE_UNUSED_ARG (address_family); 00147 #endif /* !ACE_HAS_IPV6 */ 00148 addr = ACE_INET_Addr ((u_short)0, ip_addr); 00149 #if defined (ACE_HAS_IPV6) 00150 else if (ip_addr != INADDR_ANY) 00151 // address_family == PF_INET6 and a non default IP address means to bind 00152 // to the IPv4-mapped IPv6 address 00153 addr.set ((u_short)0, ip_addr, 1, 1); 00154 #endif /* ACE_HAS_IPV6 */ 00155 00156 // The OS kernel should select a free port for us. 00157 return ACE_OS::bind (handle, 00158 (sockaddr*)addr.get_addr(), 00159 addr.get_size()); 00160 }
int ACE::clr_flags | ( | ACE_HANDLE | handle, | |
int | flags | |||
) |
Clear flags associated with handle.
Definition at line 66 of file Flag_Manip.cpp.
00067 { 00068 ACE_TRACE ("ACE::clr_flags"); 00069 #if defined (ACE_LACKS_FCNTL) 00070 switch (flags) 00071 { 00072 case ACE_NONBLOCK: 00073 // nonblocking argument (1) 00074 // blocking: (0) 00075 { 00076 int nonblock = 0; 00077 # if defined (ACE_LACKS_IOCTL) 00078 int dev_info; 00079 return ACE_OS::posix_devctl (handle, FIONBIO, &nonblock, 00080 sizeof nonblock, &dev_info); 00081 # else 00082 return ACE_OS::ioctl (handle, FIONBIO, &nonblock); 00083 # endif 00084 } 00085 default: 00086 ACE_NOTSUP_RETURN (-1); 00087 } 00088 #else 00089 int val = ACE_OS::fcntl (handle, F_GETFL, 0); 00090 00091 if (val == -1) 00092 return -1; 00093 00094 // Turn flags off. 00095 ACE_CLR_BITS (val, flags); 00096 00097 if (ACE_OS::fcntl (handle, F_SETFL, val) == -1) 00098 return -1; 00099 else 00100 return 0; 00101 #endif /* ACE_LACKS_FCNTL */ 00102 }
u_int ACE::compiler_beta_version | ( | void | ) |
u_int ACE::compiler_major_version | ( | void | ) |
u_int ACE::compiler_minor_version | ( | void | ) |
const ACE_TCHAR * ACE::compiler_name | ( | void | ) |
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 1311 of file Sock_Connect.cpp.
01312 { 01313 #if defined (SIOCGIFNUM) 01314 # if defined (SIOCGLIFNUM) && !defined (ACE_LACKS_STRUCT_LIFNUM) 01315 int cmd = SIOCGLIFNUM; 01316 struct lifnum if_num = {AF_UNSPEC,0,0}; 01317 # else 01318 int cmd = SIOCGIFNUM; 01319 int if_num = 0; 01320 # endif /* SIOCGLIFNUM */ 01321 if (ACE_OS::ioctl (handle, cmd, (caddr_t)&if_num) == -1) 01322 ACELIB_ERROR_RETURN ((LM_ERROR, 01323 ACE_TEXT ("%p\n"), 01324 ACE_TEXT ("ACE::count_interfaces:") 01325 ACE_TEXT ("ioctl - SIOCGLIFNUM failed")), 01326 -1); 01327 # if defined (SIOCGLIFNUM) && !defined (ACE_LACKS_STRUCT_LIFNUM) 01328 how_many = if_num.lifn_count; 01329 # else 01330 how_many = if_num; 01331 # endif /* SIOCGLIFNUM */ 01332 return 0; 01333 01334 #elif (defined (__unix) || defined (__unix__) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS) || (defined (ACE_VXWORKS) && !defined (ACE_HAS_GETIFADDRS))) && !defined (ACE_LACKS_NETWORKING) 01335 // Note: DEC CXX doesn't define "unix". BSD compatible OS: HP UX, 01336 // AIX, SunOS 4.x perform some ioctls to retrieve ifconf list of 01337 // ifreq structs no SIOCGIFNUM on SunOS 4.x, so use guess and scan 01338 // algorithm 01339 01340 // Probably hard to put this many ifs in a unix box.. 01341 int const MAX_INTERFACES = 50; 01342 01343 // HACK - set to an unreasonable number 01344 int const num_ifs = MAX_INTERFACES; 01345 01346 struct ifconf ifcfg; 01347 size_t ifreq_size = num_ifs * sizeof (struct ifreq); 01348 struct ifreq *p_ifs; 01349 01350 #if defined (ACE_HAS_ALLOC_HOOKS) 01351 p_ifs = (struct IFREQ *)ACE_Allocator::instance()->malloc (ifreq_size); 01352 #else 01353 p_ifs = (struct ifreq *) ACE_OS::malloc (ifreq_size); 01354 #endif /* ACE_HAS_ALLOC_HOOKS */ 01355 01356 if (!p_ifs) 01357 { 01358 errno = ENOMEM; 01359 return -1; 01360 } 01361 01362 ACE_OS::memset (p_ifs, 0, ifreq_size); 01363 ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf)); 01364 01365 ifcfg.ifc_req = p_ifs; 01366 ifcfg.ifc_len = ifreq_size; 01367 01368 if (ACE_OS::ioctl (handle, 01369 SIOCGIFCONF_CMD, 01370 (caddr_t) &ifcfg) == -1) 01371 { 01372 #if defined (ACE_HAS_ALLOC_HOOKS) 01373 ACE_Allocator::instance()->free (ifcfg.ifc_req); 01374 #else 01375 ACE_OS::free (ifcfg.ifc_req); 01376 #endif /* ACE_HAS_ALLOC_HOOKS */ 01377 01378 ACELIB_ERROR_RETURN ((LM_ERROR, 01379 ACE_TEXT ("%p\n"), 01380 ACE_TEXT ("ACE::count_interfaces:") 01381 ACE_TEXT ("ioctl - SIOCGIFCONF failed")), 01382 -1); 01383 } 01384 01385 int if_count = 0; 01386 int i = 0; 01387 01388 // get if address out of ifreq buffers. ioctl puts a blank-named 01389 // interface to mark the end of the returned interfaces. 01390 for (i = 0; 01391 i < num_ifs; 01392 i++) 01393 { 01394 /* In OpenBSD, the length of the list is returned. */ 01395 ifcfg.ifc_len -= sizeof (struct ifreq); 01396 if (ifcfg.ifc_len < 0) 01397 break; 01398 01399 ++if_count; 01400 # if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__) 01401 ++p_ifs; 01402 # else 01403 if (p_ifs->ifr_addr.sa_len <= sizeof (struct sockaddr)) 01404 { 01405 ++p_ifs; 01406 } 01407 else 01408 { 01409 p_ifs = (struct ifreq *) 01410 (p_ifs->ifr_addr.sa_len + (caddr_t) &p_ifs->ifr_addr); 01411 } 01412 # endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__) */ 01413 } 01414 01415 #if defined (ACE_HAS_ALLOC_HOOKS) 01416 ACE_Allocator::instance()->free (ifcfg.ifc_req); 01417 #else 01418 ACE_OS::free (ifcfg.ifc_req); 01419 #endif /* ACE_HAS_ALLOC_HOOKS */ 01420 01421 # if defined (ACE_HAS_IPV6) 01422 FILE* fp = 0; 01423 01424 if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0) 01425 { 01426 // Scan the lines according to the expected format but don't really read any input 01427 while (fscanf (fp, "%*32s %*02x %*02x %*02x %*02x %*8s\n") != EOF) 01428 { 01429 ++if_count; 01430 } 01431 ACE_OS::fclose (fp); 01432 } 01433 # endif /* ACE_HAS_IPV6 && !ACE_LACKS_FSCANF */ 01434 01435 how_many = if_count; 01436 return 0; 01437 #else 01438 ACE_UNUSED_ARG (handle); 01439 ACE_UNUSED_ARG (how_many); 01440 ACE_NOTSUP_RETURN (-1); // no implementation 01441 #endif /* sparc && SIOCGIFNUM */ 01442 }
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 135 of file ACE_crc32.cpp.
00136 { 00137 crc = ~crc; 00138 00139 for (int i = 0; i < len; ++i) 00140 { 00141 for (const char *p = (const char *) iov[i].iov_base, 00142 *e = (const char *) iov[i].iov_base + iov[i].iov_len; 00143 p != e; 00144 ++p) 00145 COMPUTE (crc, *p); 00146 } 00147 00148 return ~crc; 00149 }
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 119 of file ACE_crc32.cpp.
00120 { 00121 crc = ~crc; 00122 00123 for (const char *p = (const char *) buffer, 00124 *e = (const char *) buffer + len; 00125 p != e; 00126 ++p) 00127 { 00128 COMPUTE (crc, *p); 00129 } 00130 00131 return ~crc; 00132 }
ACE_UINT32 ACE::crc32 | ( | const char * | str | ) |
Computes the ISO 8802-3 standard 32 bits CRC for the string.
Definition at line 104 of file ACE_crc32.cpp.
00105 { 00106 ACE_UINT32 crc = 0xFFFFFFFF; 00107 00108 for (const char *p = string; 00109 *p != 0; 00110 ++p) 00111 { 00112 COMPUTE (crc, *p); 00113 } 00114 00115 return ~crc; 00116 }
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 103 of file ACE_crc_ccitt.cpp.
00104 { 00105 crc = static_cast<ACE_UINT16> (~crc); 00106 00107 for (int i = 0; i < len; ++i) 00108 { 00109 for (const char *p = (const char *) iov[i].iov_base, 00110 *e = (const char *) iov[i].iov_base + iov[i].iov_len; 00111 p != e; 00112 ++p) 00113 COMPUTE (crc, *p); 00114 } 00115 00116 return static_cast<ACE_UINT16> (~crc); 00117 }
ACE_UINT16 ACE::crc_ccitt | ( | const void * | buf, | |
size_t | len, | |||
ACE_UINT16 | crc = 0 | |||
) |
Computes CRC-CCITT for the buffer.
Definition at line 87 of file ACE_crc_ccitt.cpp.
00088 { 00089 crc = static_cast<ACE_UINT16> (~crc); 00090 00091 for (const char *p = (const char *) buffer, 00092 *e = (const char *) buffer + len; 00093 p != e; 00094 ++p) 00095 { 00096 COMPUTE (crc, *p); 00097 } 00098 00099 return static_cast<ACE_UINT16> (~crc); 00100 }
ACE_UINT16 ACE::crc_ccitt | ( | const char * | str | ) |
Computes CRC-CCITT for the string.
Definition at line 72 of file ACE_crc_ccitt.cpp.
00073 { 00074 ACE_UINT16 crc = 0xFFFF; 00075 00076 for (const char *p = string; 00077 *p != 0; 00078 ++p) 00079 { 00080 COMPUTE (crc, *p); 00081 } 00082 00083 return static_cast<ACE_UINT16> (~crc); 00084 }
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.
Make the current process a UNIX daemon. This is based on Stevens code from APUE.
Definition at line 2712 of file ACE.cpp.
02715 { 02716 ACE_TRACE ("ACE::daemonize"); 02717 #if !defined (ACE_LACKS_FORK) 02718 pid_t pid = ACE_OS::fork (); 02719 02720 if (pid == -1) 02721 return -1; 02722 else if (pid != 0) 02723 ACE_OS::exit (0); // Parent exits. 02724 02725 // 1st child continues. 02726 ACE_OS::setsid (); // Become session leader. 02727 02728 ACE_OS::signal (SIGHUP, SIG_IGN); 02729 02730 pid = ACE_OS::fork (program_name); 02731 02732 if (pid != 0) 02733 ACE_OS::exit (0); // First child terminates. 02734 02735 // Second child continues. 02736 02737 if (pathname != 0) 02738 // change working directory. 02739 ACE_OS::chdir (pathname); 02740 02741 ACE_OS::umask (0); // clear our file mode creation mask. 02742 02743 // Close down the I/O handles. 02744 if (close_all_handles) 02745 { 02746 for (int i = ACE::max_handles () - 1; i >= 0; i--) 02747 ACE_OS::close (i); 02748 02749 int fd = ACE_OS::open ("/dev/null", O_RDWR, 0); 02750 if (fd != -1) 02751 { 02752 ACE_OS::dup2 (fd, ACE_STDIN); 02753 ACE_OS::dup2 (fd, ACE_STDOUT); 02754 ACE_OS::dup2 (fd, ACE_STDERR); 02755 02756 if (fd > ACE_STDERR) 02757 ACE_OS::close (fd); 02758 } 02759 } 02760 02761 return 0; 02762 #else 02763 ACE_UNUSED_ARG (pathname); 02764 ACE_UNUSED_ARG (close_all_handles); 02765 ACE_UNUSED_ARG (program_name); 02766 02767 ACE_NOTSUP_RETURN (-1); 02768 #endif /* ACE_LACKS_FORK */ 02769 }
void ACE::debug | ( | bool | onoff | ) |
Definition at line 174 of file ACE.cpp.
00175 { 00176 ACE::debug_ = onoff; 00177 }
bool ACE::debug | ( | void | ) |
Definition at line 165 of file ACE.cpp.
00166 { 00167 //FUZZ: disable check_for_ace_log_categories 00168 static const char *debug = ACE_OS::getenv ("ACE_DEBUG"); 00169 //FUZZ: enable check_for_ace_log_categories 00170 return (ACE::debug_ != 0) ? ACE::debug_ : (debug != 0 ? (*debug != '0') : false); 00171 }
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 415 of file ACE.cpp.
00416 { 00417 ACE_TRACE ("ACE::dirname"); 00418 static ACE_TCHAR return_dirname[MAXPATHLEN + 1]; 00419 00420 const ACE_TCHAR *temp = ACE_OS::strrchr (pathname, delim); 00421 00422 if (temp == 0) 00423 { 00424 return_dirname[0] = '.'; 00425 return_dirname[1] = '\0'; 00426 00427 return return_dirname; 00428 } 00429 else 00430 { 00431 // When the len is truncated, there are problems! This should 00432 // not happen in normal circomstances 00433 size_t len = temp - pathname + 1; 00434 if (len > (sizeof return_dirname / sizeof (ACE_TCHAR))) 00435 len = sizeof return_dirname / sizeof (ACE_TCHAR); 00436 00437 ACE_OS::strsncpy (return_dirname, 00438 pathname, 00439 len); 00440 return return_dirname; 00441 } 00442 }
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 2250 of file ACE.cpp.
02253 { 02254 int const result = ACE::handle_read_ready (handle, timeout); 02255 02256 if (result == -1) 02257 return -1; 02258 02259 ACE::record_and_set_non_blocking_mode (handle, val); 02260 02261 return result; 02262 }
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 2265 of file ACE.cpp.
02268 { 02269 int const result = ACE::handle_write_ready (handle, timeout); 02270 02271 if (result == -1) 02272 return -1; 02273 02274 ACE::record_and_set_non_blocking_mode (handle, val); 02275 02276 return result; 02277 }
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 286 of file ACE.cpp.
00287 { 00288 #if defined (ACE_WIN32) 00289 const ACE_TCHAR *suffix = ACE_OS::strrchr (old_name, ACE_TEXT ('.')); 00290 if (suffix == 0 || ACE_OS::strcasecmp (suffix, ACE_TEXT (".exe")) != 0) 00291 { 00292 ACE_TCHAR *new_name = 0; 00293 00294 size_t size = 00295 ACE_OS::strlen (old_name) 00296 + ACE_OS::strlen (ACE_TEXT (".exe")) 00297 + 1; 00298 00299 ACE_NEW_RETURN (new_name, 00300 ACE_TCHAR[size], 00301 0); 00302 ACE_TCHAR *end = new_name; 00303 00304 end = ACE_OS::strecpy (new_name, old_name); 00305 00306 // Concatenate the .exe suffix onto the end of the executable. 00307 // end points _after_ the terminating nul. 00308 ACE_OS::strcpy (end - 1, ACE_TEXT (".exe")); 00309 00310 return new_name; 00311 } 00312 #endif /* ACE_WIN32 */ 00313 return old_name; 00314 }
int ACE::fini | ( | void | ) |
Finalize the ACE library services and releases ACE's internal resources. In general, do not instantiate ACE classes or call methods on objects of these classes after ACE::fini() has been called.
Definition at line 22 of file Init_ACE.cpp.
00023 { 00024 ACE_TRACE ("ACE::fini"); 00025 00026 if (ACE::init_fini_count_ > 0) 00027 { 00028 if (--ACE::init_fini_count_ == 0) 00029 return ACE_Object_Manager::instance ()->fini (); 00030 else 00031 // Wait for remaining fini () calls. 00032 return 1; 00033 } 00034 else 00035 // More ACE::fini () calls than ACE::init () calls. Bad 00036 // application! 00037 return -1; 00038 }
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 2772 of file ACE.cpp.
02774 { 02775 if (avoid_zombies == 0) 02776 return ACE_OS::fork (program_name); 02777 else 02778 { 02779 // This algorithm is adapted from an example in the Stevens book 02780 // "Advanced Programming in the Unix Environment" and an item in 02781 // Andrew Gierth's Unix Programming FAQ. It creates an orphan 02782 // process that's inherited by the init process; init cleans up 02783 // when the orphan process terminates. 02784 // 02785 // Another way to avoid zombies is to ignore or catch the 02786 // SIGCHLD signal; we don't use that approach here. 02787 02788 pid_t pid = ACE_OS::fork (); 02789 if (pid == 0) 02790 { 02791 // The child process forks again to create a grandchild. 02792 switch (ACE_OS::fork (program_name)) 02793 { 02794 case 0: // grandchild returns 0. 02795 return 0; 02796 case -1: // assumes all errnos are < 256 02797 ACE_OS::_exit (errno); 02798 default: // child terminates, orphaning grandchild 02799 ACE_OS::_exit (0); 02800 } 02801 } 02802 02803 // Parent process waits for child to terminate. 02804 ACE_exitcode status; 02805 if (pid < 0 || ACE_OS::waitpid (pid, &status, 0) < 0) 02806 return -1; 02807 02808 // child terminated by calling exit()? 02809 if (WIFEXITED ((status))) 02810 { 02811 // child terminated normally? 02812 if (WEXITSTATUS ((status)) == 0) 02813 return 1; 02814 else 02815 errno = WEXITSTATUS ((status)); 02816 } 02817 else 02818 // child didn't call exit(); perhaps it received a signal? 02819 errno = EINTR; 02820 02821 return -1; 02822 } 02823 }
Format buffer into printable format. This is useful for debugging.
Format buffer into printable format. This is useful for debugging. Portions taken from mdump by J.P. Knight (J.P.Knight@lut.ac.uk) Modifications by Todd Montgomery.
Definition at line 2309 of file ACE.cpp.
02313 { 02314 ACE_TRACE ("ACE::format_hexdump"); 02315 02316 u_char c; 02317 ACE_TCHAR textver[16 + 1]; 02318 02319 // We can fit 16 bytes output in text mode per line, 4 chars per byte. 02320 size_t maxlen = (obuf_sz / 68) * 16; 02321 const ACE_TCHAR *const obuf_start = obuf; 02322 02323 if (size > maxlen) 02324 size = maxlen; 02325 02326 size_t i; 02327 02328 size_t const lines = size / 16; 02329 for (i = 0; i < lines; i++) 02330 { 02331 size_t j; 02332 02333 for (j = 0 ; j < 16; j++) 02334 { 02335 c = (u_char) buffer[(i << 4) + j]; // or, buffer[i*16+j] 02336 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start), 02337 ACE_TEXT ("%02x "), 02338 c); 02339 obuf += 3; 02340 if (j == 7) 02341 { 02342 *obuf++ = ACE_TEXT (' '); 02343 } 02344 textver[j] = ACE_OS::ace_isprint (c) ? c : u_char ('.'); 02345 } 02346 02347 textver[j] = 0; 02348 02349 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start), 02350 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 02351 ACE_TEXT (" %ls\n"), 02352 #else 02353 ACE_TEXT (" %s\n"), 02354 #endif 02355 textver); 02356 02357 while (*obuf != '\0') 02358 ++obuf; 02359 } 02360 02361 if (size % 16) 02362 { 02363 for (i = 0 ; i < size % 16; i++) 02364 { 02365 c = (u_char) buffer[size - size % 16 + i]; 02366 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start), 02367 ACE_TEXT ("%02x "), 02368 c); 02369 obuf += 3; 02370 if (i == 7) 02371 { 02372 *obuf++ = ACE_TEXT (' '); 02373 } 02374 textver[i] = ACE_OS::ace_isprint (c) ? c : u_char ('.'); 02375 } 02376 02377 for (i = size % 16; i < 16; i++) 02378 { 02379 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start), 02380 ACE_TEXT (" ")); 02381 obuf += 3; 02382 if (i == 7) 02383 { 02384 *obuf++ = ACE_TEXT (' '); 02385 } 02386 textver[i] = ' '; 02387 } 02388 02389 textver[i] = 0; 02390 ACE_OS::snprintf (obuf, obuf_sz - (obuf - obuf_start), 02391 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 02392 ACE_TEXT (" %ls\n"), 02393 #else 02394 ACE_TEXT (" %s\n"), 02395 #endif 02396 textver); 02397 } 02398 return size; 02399 }
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 163 of file Sock_Connect.cpp.
00167 { 00168 ACE_TRACE ("ACE::get_bcast_addr"); 00169 00170 #if defined (ACE_LACKS_GET_BCAST_ADDR) 00171 ACE_UNUSED_ARG (bcast_addr); 00172 ACE_UNUSED_ARG (host_name); 00173 ACE_UNUSED_ARG (host_addr); 00174 ACE_UNUSED_ARG (handle); 00175 ACE_NOTSUP_RETURN (-1); 00176 #elif !defined(ACE_WIN32) && !defined(__INTERIX) 00177 ACE_HANDLE s = handle; 00178 00179 if (s == ACE_INVALID_HANDLE) 00180 s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0); 00181 00182 if (s == ACE_INVALID_HANDLE) 00183 ACELIB_ERROR_RETURN ((LM_ERROR, 00184 ACE_TEXT ("%p\n"), 00185 ACE_TEXT ("ACE_OS::socket")), 00186 -1); 00187 00188 struct ifconf ifc; 00189 char buf[BUFSIZ]; 00190 00191 ifc.ifc_len = sizeof buf; 00192 ifc.ifc_buf = buf; 00193 00194 // Get interface structure and initialize the addresses using UNIX 00195 // techniques 00196 if (ACE_OS::ioctl (s, SIOCGIFCONF_CMD, (char *) &ifc) == -1) 00197 ACELIB_ERROR_RETURN ((LM_ERROR, 00198 ACE_TEXT ("%p\n"), 00199 ACE_TEXT ("ACE::get_bcast_addr:") 00200 ACE_TEXT ("ioctl (get interface configuration)")), 00201 -1); 00202 00203 struct ifreq *ifr = ifc.ifc_req; 00204 00205 struct sockaddr_in ip_addr; 00206 00207 // Get host ip address if necessary. 00208 if (host_name) 00209 { 00210 hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name)); 00211 00212 if (hp == 0) 00213 return -1; 00214 else 00215 ACE_OS::memcpy ((char *) &ip_addr.sin_addr.s_addr, 00216 # ifdef ACE_HOSTENT_H_ADDR 00217 (char *) hp->ACE_HOSTENT_H_ADDR, 00218 # else 00219 (char *) hp->h_addr, 00220 # endif 00221 hp->h_length); 00222 } 00223 else 00224 { 00225 ACE_OS::memset ((void *) &ip_addr, 0, sizeof ip_addr); 00226 ACE_OS::memcpy ((void *) &ip_addr.sin_addr, 00227 (void*) &host_addr, 00228 sizeof ip_addr.sin_addr); 00229 } 00230 00231 #if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (__Lynx__) 00232 for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0; 00233 n--, ifr++) 00234 #else 00235 // see mk_broadcast@SOCK_Dgram_Bcast.cpp 00236 for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) && 00237 ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ? 00238 (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1); 00239 ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ? 00240 (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len, 00241 ifr = (struct ifreq *) 00242 ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) : 00243 (nbytes -= sizeof (struct ifreq), ifr++))) 00244 #endif /* !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (__Lynx__) */ 00245 { 00246 struct sockaddr_in if_addr; 00247 00248 // Compare host ip address with interface ip address. 00249 ACE_OS::memcpy (&if_addr, 00250 &ifr->ifr_addr, 00251 sizeof if_addr); 00252 00253 if (ip_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr) 00254 continue; 00255 00256 if (ifr->ifr_addr.sa_family != AF_INET) 00257 { 00258 ACELIB_ERROR ((LM_ERROR, 00259 ACE_TEXT ("%p\n"), 00260 ACE_TEXT ("ACE::get_bcast_addr:") 00261 ACE_TEXT ("Not AF_INET"))); 00262 continue; 00263 } 00264 00265 struct ifreq flags = *ifr; 00266 struct ifreq if_req = *ifr; 00267 00268 if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1) 00269 { 00270 ACELIB_ERROR ((LM_ERROR, 00271 ACE_TEXT ("%p\n"), 00272 ACE_TEXT ("ACE::get_bcast_addr:") 00273 ACE_TEXT (" ioctl (get interface flags)"))); 00274 continue; 00275 } 00276 00277 if (ACE_BIT_DISABLED (flags.ifr_flags, IFF_UP)) 00278 { 00279 ACELIB_ERROR ((LM_ERROR, 00280 ACE_TEXT ("%p\n"), 00281 ACE_TEXT ("ACE::get_bcast_addr:") 00282 ACE_TEXT ("Network interface is not up"))); 00283 continue; 00284 } 00285 00286 if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_LOOPBACK)) 00287 continue; 00288 00289 if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_BROADCAST)) 00290 { 00291 if (ACE_OS::ioctl (s, 00292 SIOCGIFBRDADDR, 00293 (char *) &if_req) == -1) 00294 ACELIB_ERROR ((LM_ERROR, 00295 ACE_TEXT ("%p\n"), 00296 ACE_TEXT ("ACE::get_bcast_addr:") 00297 ACE_TEXT ("ioctl (get broadaddr)"))); 00298 else 00299 { 00300 ACE_OS::memcpy (&ip_addr, 00301 &if_req.ifr_broadaddr, 00302 sizeof if_req.ifr_broadaddr); 00303 00304 ACE_OS::memcpy ((void *) &host_addr, 00305 (void *) &ip_addr.sin_addr, 00306 sizeof host_addr); 00307 00308 if (handle == ACE_INVALID_HANDLE) 00309 ACE_OS::close (s); 00310 00311 bcast_addr = host_addr; 00312 return 0; 00313 } 00314 } 00315 else 00316 ACELIB_ERROR ((LM_ERROR, 00317 ACE_TEXT ("%p\n"), 00318 ACE_TEXT ("ACE::get_bcast_addr:") 00319 ACE_TEXT ("Broadcast is not enabled for this interface."))); 00320 00321 if (handle == ACE_INVALID_HANDLE) 00322 ACE_OS::close (s); 00323 00324 bcast_addr = host_addr; 00325 return 0; 00326 } 00327 00328 return 0; 00329 #else 00330 ACE_UNUSED_ARG (handle); 00331 ACE_UNUSED_ARG (host_addr); 00332 ACE_UNUSED_ARG (host_name); 00333 bcast_addr = (ACE_UINT32 (INADDR_BROADCAST)); 00334 return 0; 00335 #endif /* !ACE_WIN32 && !__INTERIX */ 00336 }
int ACE::get_flags | ( | ACE_HANDLE | handle | ) | [inline] |
Return the current setting of flags associated with handle.
Definition at line 8 of file Flag_Manip.inl.
00009 { 00010 ACE_TRACE ("ACE::get_flags"); 00011 00012 #if defined (ACE_LACKS_FCNTL) 00013 // ACE_OS::fcntl is not supported. It 00014 // would be better to store ACE's notion of the flags 00015 // associated with the handle, but this works for now. 00016 ACE_UNUSED_ARG (handle); 00017 return 0; 00018 #else 00019 return ACE_OS::fcntl (handle, F_GETFL, 0); 00020 #endif /* ACE_LACKS_FCNTL */ 00021 }
int ACE::get_fqdn | ( | ACE_INET_Addr const & | addr, | |
char | hostname[], | |||
size_t | len | |||
) |
Get fully qualified host/domain name.
Definition at line 339 of file Sock_Connect.cpp.
00342 { 00343 #ifndef ACE_LACKS_GETNAMEINFO 00344 00345 const socklen_t addr_size = 00346 # ifdef ACE_HAS_IPV6 00347 (addr.get_type () == PF_INET6) ? sizeof (sockaddr_in6) : 00348 # endif 00349 sizeof (sockaddr_in); 00350 00351 if (ACE_OS::getnameinfo ((const sockaddr *) addr.get_addr (), 00352 addr_size, hostname, 00353 static_cast<ACE_SOCKET_LEN> (len), 00354 0, 0, NI_NAMEREQD) != 0) 00355 return -1; 00356 00357 if (ACE::debug ()) 00358 ACELIB_DEBUG ((LM_DEBUG, 00359 ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ") 00360 ACE_TEXT ("canonical host name is %C\n"), 00361 hostname)); 00362 00363 return 0; 00364 #else // below, ACE_LACKS_GETNAMEINFO 00365 int h_error; // Not the same as errno! 00366 hostent hentry; 00367 ACE_HOSTENT_DATA buf; 00368 00369 char * ip_addr = 0; 00370 int ip_addr_size = 0; 00371 if (addr.get_type () == AF_INET) 00372 { 00373 sockaddr_in * const sock_addr = 00374 reinterpret_cast<sockaddr_in *> (addr.get_addr ()); 00375 ip_addr_size = sizeof sock_addr->sin_addr; 00376 ip_addr = (char*) &sock_addr->sin_addr; 00377 } 00378 # ifdef ACE_HAS_IPV6 00379 else 00380 { 00381 sockaddr_in6 * sock_addr = 00382 reinterpret_cast<sockaddr_in6 *> (addr.get_addr ()); 00383 00384 ip_addr_size = sizeof sock_addr->sin6_addr; 00385 ip_addr = (char*) &sock_addr->sin6_addr; 00386 } 00387 # endif /* ACE_HAS_IPV6 */ 00388 00389 // get the host entry for the address in question 00390 hostent * const hp = ACE_OS::gethostbyaddr_r (ip_addr, 00391 ip_addr_size, 00392 addr.get_type (), 00393 &hentry, 00394 buf, 00395 &h_error); 00396 00397 // if it's not found in the host file or the DNS datase, there is nothing 00398 // much we can do. embed the IP address 00399 if (hp == 0 || hp->h_name == 0) 00400 return -1; 00401 00402 if (ACE::debug()) 00403 ACELIB_DEBUG ((LM_DEBUG, 00404 ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ") 00405 ACE_TEXT ("canonical host name is %C\n"), 00406 hp->h_name)); 00407 00408 // check if the canonical name is the FQDN 00409 if (!ACE_OS::strchr(hp->h_name, '.')) 00410 { 00411 // list of address 00412 char** p; 00413 // list of aliases 00414 char** q; 00415 00416 // for every address and for every alias within the address, check and 00417 // see if we can locate a FQDN 00418 for (p = hp->h_addr_list; *p != 0; ++p) 00419 { 00420 for (q = hp->h_aliases; *q != 0; ++q) 00421 { 00422 if (ACE_OS::strchr(*q, '.')) 00423 { 00424 // we got an FQDN from an alias. use this 00425 if (ACE_OS::strlen (*q) >= len) 00426 // the hostname is too huge to fit into a 00427 // buffer of size MAXHOSTNAMELEN 00428 // should we check other aliases as well 00429 // before bailing out prematurely? 00430 // for right now, let's do it. this (short name) 00431 // is atleast better than embedding the IP 00432 // address in the profile 00433 continue; 00434 00435 if (ACE::debug ()) 00436 ACELIB_DEBUG ((LM_DEBUG, 00437 ACE_TEXT ("(%P|%t) - ACE::get_fqdn, ") 00438 ACE_TEXT ("found fqdn within alias as %C\n"), 00439 *q)); 00440 ACE_OS::strcpy (hostname, *q); 00441 00442 return 0; 00443 } 00444 } 00445 } 00446 } 00447 00448 // The canonical name may be an FQDN when we reach here. 00449 // Alternatively, the canonical name (a non FQDN) may be the best 00450 // we can do. 00451 if (ACE_OS::strlen (hp->h_name) >= len) 00452 { 00453 // The hostname is too large to fit into a buffer of size 00454 // MAXHOSTNAMELEN. 00455 return -2; 00456 } 00457 else 00458 { 00459 ACE_OS::strcpy (hostname, hp->h_name); 00460 } 00461 00462 return 0; 00463 #endif /* ACE_LACKS_GETNAMEINFO */ 00464 }
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 1447 of file Sock_Connect.cpp.
01448 { 01449 // Solaris 2.x 01450 ACE_HANDLE handle = ACE_INVALID_HANDLE; 01451 #if defined (sparc) 01452 handle = ACE_OS::open ("/dev/udp", O_RDONLY); 01453 #elif defined (__unix) || defined (__unix__) || defined (_AIX) || defined (__hpux) || (defined (ACE_VXWORKS) && (ACE_VXWORKS >= 0x600)) || defined (ACE_OPENVMS) || defined (ACE_HAS_RTEMS) 01454 // Note: DEC CXX doesn't define "unix" BSD compatible OS: HP UX, 01455 // AIX, SunOS 4.x 01456 01457 handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, 0); 01458 #endif /* sparc */ 01459 return handle; 01460 }
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 1108 of file Sock_Connect.cpp.
01109 { 01110 ACE_TRACE ("ACE::get_ip_interfaces"); 01111 01112 count = 0; 01113 addrs = 0; 01114 01115 #if defined (ACE_WIN32) 01116 return get_ip_interfaces_win32 (count, addrs); 01117 #elif defined (ACE_HAS_GETIFADDRS) 01118 return get_ip_interfaces_getifaddrs (count, addrs); 01119 #elif defined (__hpux) 01120 return get_ip_interfaces_hpux (count, addrs); 01121 #elif defined (_AIX) 01122 return get_ip_interfaces_aix (count, addrs); 01123 #elif (defined (__unix) || defined (__unix__) || defined (ACE_OPENVMS) || (defined (ACE_VXWORKS) && !defined (ACE_HAS_GETIFADDRS)) || defined (ACE_HAS_RTEMS)) && !defined (ACE_LACKS_NETWORKING) 01124 // COMMON (SVR4 and BSD) UNIX CODE 01125 01126 // Call specific routine as necessary. 01127 ACE_HANDLE handle = ACE::get_handle(); 01128 01129 if (handle == ACE_INVALID_HANDLE) 01130 ACELIB_ERROR_RETURN ((LM_ERROR, 01131 ACE_TEXT ("%p\n"), 01132 ACE_TEXT ("ACE::get_ip_interfaces:open")), 01133 -1); 01134 01135 size_t num_ifs = 0; 01136 01137 if (ACE::count_interfaces (handle, num_ifs)) 01138 { 01139 ACE_OS::close (handle); 01140 return -1; 01141 } 01142 01143 // ioctl likes to have an extra ifreq structure to mark the end of 01144 // what it returned, so increase the num_ifs by one. 01145 ++num_ifs; 01146 01147 struct IFREQ *ifs = 0; 01148 ACE_NEW_RETURN (ifs, 01149 struct IFREQ[num_ifs], 01150 -1); 01151 ACE_OS::memset (ifs, 0, num_ifs * sizeof (struct IFREQ)); 01152 01153 ACE_Auto_Array_Ptr<struct IFREQ> p_ifs (ifs); 01154 01155 if (p_ifs.get() == 0) 01156 { 01157 ACE_OS::close (handle); 01158 errno = ENOMEM; 01159 return -1; 01160 } 01161 01162 struct IFCONF ifcfg; 01163 ACE_OS::memset (&ifcfg, 0, sizeof (struct IFCONF)); 01164 01165 # ifdef SETFAMILY 01166 ifcfg.IFC_FAMILY = AF_UNSPEC; // request all families be returned 01167 ifcfg.IFC_FLAGS = 0; 01168 # endif 01169 01170 ifcfg.IFC_REQ = p_ifs.get (); 01171 ifcfg.IFC_LEN = num_ifs * sizeof (struct IFREQ); 01172 01173 if (ACE_OS::ioctl (handle, 01174 SIOCGIFCONF_CMD, 01175 (caddr_t) &ifcfg) == -1) 01176 { 01177 ACE_OS::close (handle); 01178 ACELIB_ERROR_RETURN ((LM_ERROR, 01179 ACE_TEXT ("%p\n"), 01180 ACE_TEXT ("ACE::get_ip_interfaces:") 01181 ACE_TEXT ("ioctl - SIOCGIFCONF failed")), 01182 -1); 01183 } 01184 01185 ACE_OS::close (handle); 01186 01187 // Now create and initialize output array. 01188 01189 ACE_NEW_RETURN (addrs, 01190 ACE_INET_Addr[num_ifs], 01191 -1); // caller must free 01192 01193 struct IFREQ *pcur = p_ifs.get (); 01194 size_t num_ifs_found = ifcfg.IFC_LEN / sizeof (struct IFREQ); // get the number of returned ifs 01195 01196 // Pull the address out of each INET interface. Not every interface 01197 // is for IP, so be careful to count properly. When setting the 01198 // INET_Addr, note that the 3rd arg (0) says to leave the byte order 01199 // (already in net byte order from the interface structure) as is. 01200 count = 0; 01201 01202 for (size_t i = 0; 01203 i < num_ifs_found; 01204 i++) 01205 { 01206 if (pcur->IFR_ADDR.SA_FAMILY == AF_INET 01207 # if defined (ACE_HAS_IPV6) 01208 || pcur->IFR_ADDR.SA_FAMILY == AF_INET6 01209 # endif 01210 ) 01211 01212 { 01213 struct sockaddr_in *addr = 01214 reinterpret_cast<sockaddr_in *> (&pcur->IFR_ADDR); 01215 01216 // Sometimes the kernel returns 0.0.0.0 as an IPv4 interface 01217 // address; skip those... 01218 if (addr->sin_addr.s_addr != 0 01219 # if defined (ACE_HAS_IPV6) 01220 || (addr->sin_family == AF_INET6 && 01221 !IN6_IS_ADDR_UNSPECIFIED(&reinterpret_cast<sockaddr_in6 *>(addr)->sin6_addr)) 01222 # endif 01223 ) 01224 { 01225 int addrlen = static_cast<int> (sizeof (struct sockaddr_in)); 01226 # if defined (ACE_HAS_IPV6) 01227 if (addr->sin_family == AF_INET6) 01228 addrlen = static_cast<int> (sizeof (struct sockaddr_in6)); 01229 # endif 01230 addrs[count].set (addr, addrlen); 01231 ++count; 01232 } 01233 } 01234 01235 #if !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__) 01236 ++pcur; 01237 #else 01238 if (pcur->ifr_addr.sa_len <= sizeof (struct sockaddr)) 01239 { 01240 ++pcur; 01241 } 01242 else 01243 { 01244 pcur = (struct ifreq *) 01245 (pcur->ifr_addr.sa_len + (caddr_t) &pcur->ifr_addr); 01246 } 01247 #endif /* !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_HAS_RTEMS) && !defined (__Lynx__) */ 01248 } 01249 01250 # if defined (ACE_HAS_IPV6) && !defined (ACE_LACKS_FSCANF) 01251 // Retrieve IPv6 local interfaces by scanning /proc/net/if_inet6 if 01252 // it exists. If we cannot open it then ignore possible IPv6 01253 // interfaces, we did our best;-) 01254 FILE* fp = 0; 01255 char addr_p[8][5]; 01256 char s_ipaddr[64]; 01257 int scopeid; 01258 struct addrinfo hints, *res0; 01259 int error; 01260 01261 ACE_OS::memset (&hints, 0, sizeof (hints)); 01262 hints.ai_flags = AI_NUMERICHOST; 01263 hints.ai_family = AF_INET6; 01264 01265 if ((fp = ACE_OS::fopen (ACE_TEXT ("/proc/net/if_inet6"), ACE_TEXT ("r"))) != 0) 01266 { 01267 while (fscanf (fp, 01268 "%4s%4s%4s%4s%4s%4s%4s%4s %02x %*02x %*02x %*02x %*8s\n", 01269 addr_p[0], addr_p[1], addr_p[2], addr_p[3], 01270 addr_p[4], addr_p[5], addr_p[6], addr_p[7], &scopeid) != EOF) 01271 { 01272 // Format the address intoa proper IPv6 decimal address specification and 01273 // resolve the resulting text using getaddrinfo(). 01274 01275 const char* ip_fmt = "%s:%s:%s:%s:%s:%s:%s:%s%%%d"; 01276 ACE_OS::snprintf (s_ipaddr, 64, ip_fmt, 01277 addr_p[0], addr_p[1], addr_p[2], addr_p[3], 01278 addr_p[4], addr_p[5], addr_p[6], addr_p[7], 01279 scopeid); 01280 01281 error = ACE_OS::getaddrinfo (s_ipaddr, 0, &hints, &res0); 01282 if (error) 01283 continue; 01284 01285 if (res0->ai_family == AF_INET6 && 01286 !IN6_IS_ADDR_UNSPECIFIED (&reinterpret_cast<sockaddr_in6 *> (res0->ai_addr)->sin6_addr)) 01287 { 01288 addrs[count].set(reinterpret_cast<sockaddr_in *> (res0->ai_addr), res0->ai_addrlen); 01289 ++count; 01290 } 01291 ACE_OS::freeaddrinfo (res0); 01292 01293 } 01294 ACE_OS::fclose (fp); 01295 } 01296 # endif /* ACE_HAS_IPV6 && !ACE_LACKS_FSCANF */ 01297 01298 return 0; 01299 #else 01300 ACE_UNUSED_ARG (count); 01301 ACE_UNUSED_ARG (addrs); 01302 ACE_NOTSUP_RETURN (-1); // no implementation 01303 #endif /* ACE_WIN32 */ 01304 }
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 599 of file Lib_Find.cpp.
00600 { 00601 int result; 00602 #if defined (ACE_WIN32) 00603 result = ACE_TEXT_GetTempPath (static_cast<DWORD> (buffer_len), 00604 buffer); 00605 00606 // Make sure to return -1 if there is an error 00607 if ((result == 0 && ::GetLastError () != ERROR_SUCCESS) 00608 || (result > static_cast<int> (buffer_len))) 00609 result = -1; 00610 00611 #else /* ACE_WIN32 */ 00612 00613 // NOTE! Non-Windows platforms don't deal with wide chars for env. 00614 // variables, so do this narrow-char and convert to wide for the 00615 // caller if necessary. 00616 00617 // On non-win32 platforms, check to see what the TMPDIR environment 00618 // variable is defined to be. If it doesn't exist, just use /tmp 00619 const char *tmpdir = ACE_OS::getenv ("TMPDIR"); 00620 00621 if (tmpdir == 0) 00622 { 00623 #if defined (ACE_DEFAULT_TEMP_DIR) 00624 tmpdir = ACE_DEFAULT_TEMP_DIR; 00625 #else 00626 tmpdir = "/tmp"; 00627 #endif 00628 } 00629 00630 size_t len = ACE_OS::strlen (tmpdir); 00631 00632 // Check to see if the buffer is large enough for the string, 00633 // another /, and its null character (hence the + 2) 00634 if ((len + 2) > buffer_len) 00635 { 00636 result = -1; 00637 } 00638 else 00639 { 00640 ACE_OS::strcpy (buffer, ACE_TEXT_CHAR_TO_TCHAR (tmpdir)); 00641 00642 // Add a trailing slash because we cannot assume there is already one 00643 // at the end. And having an extra one should not cause problems. 00644 buffer[len] = ACE_TEXT ('/'); 00645 buffer[len + 1] = 0; 00646 result = 0; 00647 } 00648 #endif /* ACE_WIN32 */ 00649 return result; 00650 }
int ACE::handle_exception_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) | [inline] |
Timed wait for handle to get exception ready.
-1 | for error | |
0 | for timeout | |
1 | the handle is ready |
Definition at line 250 of file ACE.inl.
00251 { 00252 return ACE::handle_ready (handle, timeout, 0, 0, 1); 00253 }
int ACE::handle_read_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) | [inline] |
Timed wait for handle to get read ready.
-1 | for error | |
0 | for timeout | |
1 | the handle is ready |
Definition at line 238 of file ACE.inl.
00239 { 00240 return ACE::handle_ready (handle, timeout, 1, 0, 0); 00241 }
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.
-1 | for error | |
0 | for timeout | |
1 | the handle is ready |
Definition at line 2196 of file ACE.cpp.
02201 { 02202 #if defined (ACE_HAS_POLL) 02203 ACE_UNUSED_ARG (exception_ready); 02204 02205 struct pollfd fds; 02206 02207 fds.fd = handle; 02208 fds.events = read_ready ? POLLIN : 0; 02209 02210 if( write_ready ) 02211 { 02212 fds.events |= POLLOUT; 02213 } 02214 02215 fds.revents = 0; 02216 02217 int const result = ACE_OS::poll (&fds, 1, timeout); 02218 #else 02219 ACE_Handle_Set handle_set; 02220 handle_set.set_bit (handle); 02221 02222 // Wait for data or for the timeout to elapse. 02223 int select_width = 0; 02224 #if !defined (ACE_WIN32) 02225 select_width = int (handle) + 1; 02226 # endif /* ACE_WIN64 */ 02227 int result = ACE_OS::select (select_width, 02228 read_ready ? handle_set.fdset () : 0, // read_fds. 02229 write_ready ? handle_set.fdset () : 0, // write_fds. 02230 exception_ready ? handle_set.fdset () : 0, // exception_fds. 02231 timeout); 02232 02233 #endif /* ACE_HAS_POLL */ 02234 switch (result) 02235 { 02236 case 0: // Timer expired. 02237 errno = ETIME; 02238 /* FALLTHRU */ 02239 case -1: // we got here directly - select() returned -1. 02240 return -1; 02241 case 1: // Handle has data. 02242 /* FALLTHRU */ 02243 default: // default is case result > 0; return a 02244 // ACE_ASSERT (result == 1); 02245 return result; 02246 } 02247 }
int ACE::handle_timed_accept | ( | ACE_HANDLE | listener, | |
ACE_Time_Value * | timeout, | |||
bool | restart | |||
) |
Wait up to timeout amount of time to accept a connection.
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 2642 of file ACE.cpp.
02645 { 02646 ACE_TRACE ("ACE::handle_timed_accept"); 02647 // Make sure we don't bomb out on erroneous values. 02648 if (listener == ACE_INVALID_HANDLE) 02649 return -1; 02650 02651 #if defined (ACE_HAS_POLL) 02652 02653 struct pollfd fds; 02654 02655 fds.fd = listener; 02656 fds.events = POLLIN; 02657 fds.revents = 0; 02658 02659 #else 02660 // Use the select() implementation rather than poll(). 02661 ACE_Handle_Set rd_handle; 02662 rd_handle.set_bit (listener); 02663 #endif /* ACE_HAS_POLL */ 02664 02665 // We need a loop here if <restart> is enabled. 02666 02667 for (;;) 02668 { 02669 #if defined (ACE_HAS_POLL) 02670 02671 int n = ACE_OS::poll (&fds, 1, timeout); 02672 02673 #else 02674 int select_width = 0; 02675 # if !defined (ACE_WIN32) 02676 select_width = int (listener) + 1; 02677 # endif /* ACE_WIN32 */ 02678 int n = ACE_OS::select (select_width, 02679 rd_handle, 0, 0, 02680 timeout); 02681 #endif /* ACE_HAS_POLL */ 02682 02683 switch (n) 02684 { 02685 case -1: 02686 if (errno == EINTR && restart) 02687 continue; 02688 else 02689 return -1; 02690 /* NOTREACHED */ 02691 case 0: 02692 if (timeout != 0 && *timeout == ACE_Time_Value::zero) 02693 errno = EWOULDBLOCK; 02694 else 02695 errno = ETIMEDOUT; 02696 return -1; 02697 /* NOTREACHED */ 02698 case 1: 02699 return 0; 02700 /* NOTREACHED */ 02701 default: 02702 errno = EINVAL; 02703 return -1; 02704 /* NOTREACHED */ 02705 } 02706 } 02707 }
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 2482 of file ACE.cpp.
02485 { 02486 ACE_TRACE ("ACE::handle_timed_complete"); 02487 02488 #if !defined (ACE_WIN32) && defined (ACE_HAS_POLL) 02489 02490 struct pollfd fds; 02491 02492 fds.fd = h; 02493 fds.events = POLLIN | POLLOUT; 02494 fds.revents = 0; 02495 02496 #else 02497 ACE_Handle_Set rd_handles; 02498 ACE_Handle_Set wr_handles; 02499 rd_handles.set_bit (h); 02500 wr_handles.set_bit (h); 02501 #endif /* !ACE_WIN32 && ACE_HAS_POLL */ 02502 02503 #if defined (ACE_WIN32) 02504 // Winsock is different - it sets the exception bit for failed connect, 02505 // unlike other platforms, where the write bit is set for both success 02506 // and fail. 02507 ACE_Handle_Set ex_handles; 02508 ex_handles.set_bit (h); 02509 #endif /* ACE_WIN32 */ 02510 02511 bool need_to_check = false; 02512 bool known_failure = false; 02513 02514 #if defined (ACE_WIN32) 02515 int n = ACE_OS::select (0, // Ignored on Windows: int (h) + 1, 02516 0, 02517 wr_handles, 02518 ex_handles, 02519 timeout); 02520 #else 02521 # if defined (ACE_HAS_POLL) 02522 02523 int n = ACE_OS::poll (&fds, 1, timeout); 02524 02525 # else 02526 int n = 0; 02527 if (is_tli) 02528 n = ACE_OS::select (int (h) + 1, 02529 rd_handles, 02530 wr_handles, 02531 0, 02532 timeout); 02533 else 02534 n = ACE_OS::select (int (h) + 1, 02535 0, 02536 wr_handles, 02537 0, 02538 timeout); 02539 # endif /* ACE_HAS_POLL */ 02540 #endif /* ACE_WIN32 */ 02541 02542 // If we failed to connect within the time period allocated by the 02543 // caller, then we fail (e.g., the remote host might have been too 02544 // busy to accept our call). 02545 if (n <= 0) 02546 { 02547 if (n == 0 && timeout != 0) 02548 errno = ETIME; 02549 return ACE_INVALID_HANDLE; 02550 } 02551 02552 // On Windows, a ready-for-write handle is successfully connected, and 02553 // ready-for-exception is a failure. On fails, we need to grab the error 02554 // code via getsockopt. 02555 // On BSD sockets using select(), the handle becomes writable on 02556 // completion either success or fail, so if the select() does not time 02557 // out, we need to check for success/fail. 02558 // It is believed that TLI sockets use the readable=fail, writeable=success 02559 // but that hasn't been as well tested. 02560 #if defined (ACE_WIN32) 02561 ACE_UNUSED_ARG (is_tli); 02562 02563 // On Win32, ex_handle set indicates a failure. We'll do the check 02564 // to try and get an errno value, but the connect failed regardless of 02565 // what getsockopt says about the error. 02566 if (ex_handles.is_set (h)) 02567 { 02568 need_to_check = true; 02569 known_failure = true; 02570 } 02571 #else 02572 if (is_tli) 02573 # if defined (ACE_HAS_POLL) 02574 need_to_check = (fds.revents & POLLIN) && !(fds.revents & POLLOUT); 02575 # else 02576 need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h); 02577 # endif /* ACE_HAS_POLL */ 02578 02579 else 02580 # if defined (ACE_HAS_POLL) 02581 { 02582 // The "official" bit for failed connect is POLLIN. However, POLLERR 02583 // is often set and there are occasional cases seen with some kernels 02584 // where only POLLERR is set on a failed connect. 02585 need_to_check = (fds.revents & POLLIN) || (fds.revents & POLLERR); 02586 known_failure = (fds.revents & POLLERR); 02587 } 02588 # else 02589 need_to_check = true; 02590 # endif /* ACE_HAS_POLL */ 02591 #endif /* ACE_WIN32 */ 02592 02593 if (need_to_check) 02594 { 02595 #if defined (SOL_SOCKET) && defined (SO_ERROR) 02596 int sock_err = 0; 02597 int sock_err_len = sizeof (sock_err); 02598 int sockopt_ret = ACE_OS::getsockopt (h, SOL_SOCKET, SO_ERROR, 02599 (char *)&sock_err, &sock_err_len); 02600 if (sockopt_ret < 0) 02601 { 02602 h = ACE_INVALID_HANDLE; 02603 } 02604 02605 if (sock_err != 0 || known_failure) 02606 { 02607 h = ACE_INVALID_HANDLE; 02608 errno = sock_err; 02609 } 02610 #else 02611 char dummy; 02612 02613 // The following recv() won't block provided that the 02614 // ACE_NONBLOCK flag has not been turned off . 02615 n = ACE::recv (h, &dummy, 1, MSG_PEEK); 02616 02617 // If no data was read/peeked at, check to see if it's because 02618 // of a non-connected socket (and therefore an error) or there's 02619 // just no data yet. 02620 if (n <= 0) 02621 { 02622 if (n == 0) 02623 { 02624 errno = ECONNREFUSED; 02625 h = ACE_INVALID_HANDLE; 02626 } 02627 else if (errno != EWOULDBLOCK && errno != EAGAIN) 02628 h = ACE_INVALID_HANDLE; 02629 } 02630 #endif 02631 } 02632 02633 // 1. The HANDLE is ready for writing and doesn't need to be checked or 02634 // 2. recv() returned an indication of the state of the socket - if there is 02635 // either data present, or a recv is legit but there's no data yet, 02636 // the connection was successfully established. 02637 return h; 02638 }
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 11 of file Handle_Ops.cpp.
00016 { 00017 ACE_TRACE ("ACE::handle_timed_open"); 00018 00019 if (timeout != 0) 00020 { 00021 #if !defined (ACE_WIN32) 00022 // On Win32, ACE_NONBLOCK gets recognized as O_WRONLY so we 00023 // don't use it there 00024 flags |= ACE_NONBLOCK; 00025 #endif /* ACE_WIN32 */ 00026 00027 // Open the named pipe or file using non-blocking mode... 00028 ACE_HANDLE const handle = ACE_OS::open (name, flags, perms, sa); 00029 00030 if (handle == ACE_INVALID_HANDLE 00031 && (errno == EWOULDBLOCK 00032 && (timeout->sec () > 0 || timeout->usec () > 0))) 00033 // This expression checks if we were polling. 00034 errno = ETIMEDOUT; 00035 00036 return handle; 00037 } 00038 else 00039 return ACE_OS::open (name, flags, perms, sa); 00040 }
int ACE::handle_write_ready | ( | ACE_HANDLE | handle, | |
const ACE_Time_Value * | timeout | |||
) | [inline] |
Timed wait for handle to get write ready.
-1 | for error | |
0 | for timeout | |
1 | the handle is ready |
Definition at line 244 of file ACE.inl.
00245 { 00246 return ACE::handle_ready (handle, timeout, 0, 1, 0); 00247 }
Computes the hash value of {str} using the "Hash PJW" routine.
Definition at line 346 of file ACE.cpp.
00347 { 00348 u_long hash = 0; 00349 00350 for (size_t i = 0; i < len; i++) 00351 { 00352 // @@ UNICODE: Does this function do the correct thing with wchar's? 00353 00354 const wchar_t temp = str[i]; 00355 hash = (hash << 4) + (temp * 13); 00356 00357 u_long g = hash & 0xf0000000; 00358 00359 if (g) 00360 { 00361 hash ^= (g >> 24); 00362 hash ^= g; 00363 } 00364 } 00365 00366 return hash; 00367 }
Computes the hash value of {str} using the "Hash PJW" routine.
Definition at line 370 of file ACE.cpp.
00371 { 00372 return ACE::hash_pjw (str, ACE_OS::strlen (str)); 00373 }
Computes the hash value of {str} using the "Hash PJW" routine.
Definition at line 317 of file ACE.cpp.
00318 { 00319 u_long hash = 0; 00320 00321 for (size_t i = 0; i < len; i++) 00322 { 00323 const char temp = str[i]; 00324 hash = (hash << 4) + (temp * 13); 00325 00326 u_long g = hash & 0xf0000000; 00327 00328 if (g) 00329 { 00330 hash ^= (g >> 24); 00331 hash ^= g; 00332 } 00333 } 00334 00335 return hash; 00336 }
u_long ACE::hash_pjw | ( | const char * | str | ) |
Computes the hash value of {str} using the "Hash PJW" routine.
Definition at line 339 of file ACE.cpp.
00340 { 00341 return ACE::hash_pjw (str, ACE_OS::strlen (str)); 00342 }
Convert a hex character to its byte representation.
Definition at line 323 of file ACE.inl.
00324 { 00325 if (ACE_OS::ace_isdigit (c)) 00326 return (u_char) (c - ACE_TEXT ('0')); 00327 else if (ACE_OS::ace_islower (c)) 00328 return (u_char) (10 + c - ACE_TEXT ('a')); 00329 else 00330 return (u_char) (10 + c - ACE_TEXT ('A')); 00331 }
int ACE::init | ( | void | ) |
This method initializes the ACE library services and initializes ACE's internal resources. Applications should not instantiate ACE classes or call methods on objects of these classes until ACE::init() returns successfully.
Definition at line 10 of file Init_ACE.cpp.
00011 { 00012 // Don't use ACE_TRACE, because Object_Manager might not have been 00013 // instantiated yet. 00014 // ACE_TRACE ("ACE::init"); 00015 00016 ++ACE::init_fini_count_; 00017 00018 return ACE_Object_Manager::instance ()->init (); 00019 }
bool ACE::ipv4_enabled | ( | void | ) |
Returns true
if IPv4 is enabled on the current host; false
if not. 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 1511 of file Sock_Connect.cpp.
01512 { 01513 #if defined (ACE_HAS_IPV6) 01514 return static_cast<bool> (ace_ipv4_enabled == -1 ? 01515 ::ip_check (ace_ipv4_enabled, PF_INET) : 01516 ace_ipv4_enabled); 01517 #else 01518 // Assume it's always enabled since ACE requires some version of 01519 // TCP/IP to exist. 01520 return true; 01521 #endif /* ACE_HAS_IPV6*/ 01522 }
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 1525 of file Sock_Connect.cpp.
01526 { 01527 #if defined (ACE_HAS_IPV6) 01528 return ace_ipv6_enabled == -1 ? 01529 ::ip_check (ace_ipv6_enabled, PF_INET6) : 01530 ace_ipv6_enabled; 01531 #else /* ACE_HAS_IPV6 */ 01532 return 0; 01533 #endif /* !ACE_HAS_IPV6 */ 01534 }
bool ACE::is_equal | ( | const T & | a, | |
const T & | b | |||
) | [inline] |
bool ACE::is_inequal | ( | const T & | a, | |
const T & | b | |||
) | [inline] |
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 2974 of file ACE.cpp.
02977 { 02978 if (n > 3) 02979 for (u_long factor = min_factor; 02980 factor <= max_factor; 02981 ++factor) 02982 if (n / factor * factor == n) 02983 return factor; 02984 02985 return 0; 02986 }
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 3143 of file ACE.cpp.
03144 { 03145 #if defined (ACE_WIN32) 03146 switch (error) 03147 { 03148 case WSAVERNOTSUPPORTED: 03149 case WSASYSNOTREADY: 03150 case WSAEINVAL: 03151 case WSAHOST_NOT_FOUND: 03152 case WSATRY_AGAIN: 03153 case WSANO_RECOVERY: 03154 case WSANO_DATA: 03155 /* 03156 case WSANO_ADDRESS: 03157 */ 03158 case WSANOTINITIALISED: 03159 case WSAENETDOWN: 03160 case WSAEINPROGRESS: 03161 case WSAEINTR: 03162 case WSAEAFNOSUPPORT: 03163 case WSAEMFILE: 03164 case WSAENOBUFS: 03165 case WSAEPROTONOSUPPORT: 03166 case WSAEPROTOTYPE: 03167 case WSAESOCKTNOSUPPORT: 03168 case WSAENOTSOCK: 03169 case WSAEWOULDBLOCK: 03170 case WSAEADDRINUSE: 03171 case WSAECONNABORTED: 03172 case WSAECONNRESET: 03173 case WSAENOTCONN: 03174 case WSAETIMEDOUT: 03175 case WSAECONNREFUSED: 03176 case WSAEHOSTDOWN: 03177 case WSAEHOSTUNREACH: 03178 case WSAEADDRNOTAVAIL: 03179 case WSAEISCONN: 03180 case WSAENETRESET: 03181 case WSAEMSGSIZE: 03182 case WSAENETUNREACH: 03183 case WSAEFAULT: 03184 case WSAEDISCON: 03185 case WSAEACCES: 03186 case WSAESHUTDOWN: 03187 case WSAEPROCLIM: 03188 case WSAEALREADY: 03189 case WSAEPFNOSUPPORT: 03190 case WSAENOPROTOOPT: 03191 case WSATYPE_NOT_FOUND: 03192 case WSAEOPNOTSUPP: 03193 return true; 03194 } 03195 #else 03196 ACE_UNUSED_ARG (error); 03197 #endif /* ACE_WIN32 */ 03198 return false; 03199 }
bool ACE::isdotdir | ( | const wchar_t * | s | ) | [inline] |
bool ACE::isdotdir | ( | const char * | s | ) | [inline] |
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 119 of file Lib_Find.cpp.
00122 { 00123 ACE_TRACE ("ACE::ldfind"); 00124 #if defined (ACE_OPENVMS) 00125 if (ACE_OS::strlen (filename) >= maxpathnamelen) 00126 { 00127 errno = ENOMEM; 00128 return -1; 00129 } 00130 00131 dsc$descriptor nameDsc; 00132 nameDsc.dsc$b_class = DSC$K_CLASS_S; 00133 nameDsc.dsc$b_dtype = DSC$K_DTYPE_T; 00134 nameDsc.dsc$w_length = ACE_OS::strlen (filename); 00135 nameDsc.dsc$a_pointer = (char*)filename; 00136 00137 char symbol[] = "NULL"; 00138 dsc$descriptor symbolDsc; 00139 symbolDsc.dsc$b_class = DSC$K_CLASS_S; 00140 symbolDsc.dsc$b_dtype = DSC$K_DTYPE_T; 00141 symbolDsc.dsc$w_length = ACE_OS::strlen (symbol); 00142 symbolDsc.dsc$a_pointer = symbol; 00143 00144 int symbolValue; 00145 int result; 00146 try 00147 { 00148 result = LIB$FIND_IMAGE_SYMBOL (&nameDsc, &symbolDsc, &symbolValue, 0, 0); 00149 } 00150 catch (chf$signal_array &sig) 00151 { 00152 result = sig.chf$l_sig_name; 00153 } 00154 00155 int severity = result & STS$M_SEVERITY; 00156 int conditionId = result & STS$M_COND_ID; 00157 if (severity == STS$K_SUCCESS || severity == STS$K_WARNING || severity == STS$K_INFO || 00158 (severity == STS$K_ERROR && conditionId == (LIB$_KEYNOTFOU & STS$M_COND_ID))) 00159 { 00160 ACE_OS::strcpy (pathname, filename); 00161 return 0; 00162 } 00163 00164 if (ACE_OS::strlen (filename) + ACE_OS::strlen (ACE_DLL_PREFIX) >= maxpathnamelen) 00165 { 00166 errno = ENOMEM; 00167 return -1; 00168 } 00169 00170 00171 ACE_OS::strcpy (pathname, ACE_DLL_PREFIX); 00172 ACE_OS::strcat (pathname, filename); 00173 nameDsc.dsc$w_length = ACE_OS::strlen (pathname); 00174 nameDsc.dsc$a_pointer = pathname; 00175 try 00176 { 00177 result = LIB$FIND_IMAGE_SYMBOL (&nameDsc, &symbolDsc, &symbolValue, 0, 0); 00178 } 00179 catch (chf$signal_array &sig) 00180 { 00181 result = sig.chf$l_sig_name; 00182 } 00183 00184 severity = result & STS$M_SEVERITY; 00185 conditionId = result & STS$M_COND_ID; 00186 if (severity == STS$K_SUCCESS || severity == STS$K_WARNING || severity == STS$K_INFO || 00187 (severity == STS$K_ERROR && conditionId == (LIB$_KEYNOTFOU & STS$M_COND_ID))) 00188 { 00189 return 0; 00190 } 00191 errno = ENOENT; 00192 return -1; 00193 #endif /* ACE_OPENVMS */ 00194 00195 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && \ 00196 !defined (ACE_HAS_PHARLAP) 00197 ACE_TCHAR expanded_filename[MAXPATHLEN]; 00198 if (ACE_TEXT_ExpandEnvironmentStrings (filename, 00199 expanded_filename, 00200 sizeof expanded_filename 00201 / sizeof (ACE_TCHAR))) 00202 filename = expanded_filename; 00203 #endif /* ACE_WIN32 && !ACE_HAS_WINCE && !ACE_HAS_PHARLAP */ 00204 00205 ACE_TCHAR tempcopy[MAXPATHLEN + 1]; 00206 ACE_TCHAR searchpathname[MAXPATHLEN + 1]; 00207 #if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) 00208 ACE_TCHAR decorator[] = ACE_LD_DECORATOR_STR; 00209 ACE_TCHAR searchfilename[MAXPATHLEN + sizeof(decorator) / sizeof (ACE_TCHAR)]; 00210 #else 00211 ACE_TCHAR searchfilename[MAXPATHLEN + 1]; 00212 #endif /* ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */ 00213 00214 // Create a copy of filename to work with. 00215 if (ACE_OS::strlen (filename) + 1 00216 > (sizeof tempcopy / sizeof (ACE_TCHAR))) 00217 { 00218 errno = ENOMEM; 00219 return -1; 00220 } 00221 else 00222 ACE_OS::strcpy (tempcopy, filename); 00223 00224 // Insert canonical directory separators. 00225 ACE_TCHAR *separator_ptr; 00226 00227 #if (ACE_DIRECTORY_SEPARATOR_CHAR != '/') 00228 // Make all the directory separators "canonical" to simplify 00229 // subsequent code. 00230 ACE::strrepl (tempcopy, ACE_DIRECTORY_SEPARATOR_CHAR, '/'); 00231 #endif /* ACE_DIRECTORY_SEPARATOR_CHAR */ 00232 00233 // Separate filename from pathname. 00234 separator_ptr = ACE_OS::strrchr (tempcopy, '/'); 00235 00236 // This is a relative path. 00237 if (separator_ptr == 0) 00238 { 00239 searchpathname[0] = '\0'; 00240 ACE_OS::strcpy (searchfilename, tempcopy); 00241 } 00242 else // This is an absolute path. 00243 { 00244 ACE_OS::strcpy (searchfilename, separator_ptr + 1); 00245 separator_ptr[1] = '\0'; 00246 ACE_OS::strcpy (searchpathname, tempcopy); 00247 } 00248 00249 bool has_suffix = false; 00250 00251 // Check to see if this has an appropriate DLL suffix for the OS 00252 // platform. 00253 ACE_TCHAR *s = ACE_OS::strrchr (searchfilename, '.'); 00254 00255 const ACE_TCHAR *dll_suffix = ACE_DLL_SUFFIX; 00256 00257 if (s != 0) 00258 { 00259 // If we have a dot, we have a suffix 00260 has_suffix = true; 00261 00262 // Check whether this matches the appropriate platform-specific 00263 // suffix. 00264 #if defined (ACE_WIN32) 00265 // Use <ACE_OS::strcasecmp> on any platform with 00266 // case-insensitive filenames. 00267 if (ACE_OS::strcasecmp (s, dll_suffix) != 0) 00268 #else 00269 if (ACE_OS::strcmp (s, dll_suffix) != 0) 00270 #endif /* ACE_WIN32 */ 00271 { 00272 ACELIB_ERROR ((LM_WARNING, 00273 ACE_TEXT ("Warning: improper suffix for a ") 00274 ACE_TEXT ("shared library on this platform: %s\n"), 00275 s)); 00276 } 00277 } 00278 00279 // Make sure we've got enough space in searchfilename. 00280 if (ACE_OS::strlen (searchfilename) 00281 + ACE_OS::strlen (ACE_DLL_PREFIX) 00282 + (has_suffix ? 0 : ACE_OS::strlen (dll_suffix)) 00283 >= (sizeof searchfilename / sizeof (ACE_TCHAR))) 00284 { 00285 errno = ENOMEM; 00286 return -1; 00287 } 00288 00289 #if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) 00290 size_t const len_searchfilename = ACE_OS::strlen (searchfilename); 00291 if (!has_suffix) 00292 ACE_OS::strcpy (searchfilename + len_searchfilename, decorator); 00293 00294 for (int tag = 1; tag >= 0; tag --) 00295 { 00296 if (tag == 0) 00297 searchfilename [len_searchfilename] = 0; 00298 00299 #endif /* ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */ 00300 // Use absolute pathname if there is one. 00301 if (ACE_OS::strlen (searchpathname) > 0) 00302 { 00303 if (ACE_OS::strlen (searchfilename) 00304 + ACE_OS::strlen (searchpathname) >= maxpathnamelen) 00305 { 00306 errno = ENOMEM; 00307 return -1; 00308 } 00309 else 00310 { 00311 #if (ACE_DIRECTORY_SEPARATOR_CHAR != '/') 00312 // Revert to native path name separators. 00313 ACE::strrepl (searchpathname, 00314 '/', 00315 ACE_DIRECTORY_SEPARATOR_CHAR); 00316 #endif /* ACE_DIRECTORY_SEPARATOR_CHAR */ 00317 // First, try matching the filename *without* adding a 00318 // prefix. 00319 ACE_OS::snprintf (pathname, maxpathnamelen, 00320 ACE_TEXT ("%s%s%s"), 00321 searchpathname, 00322 searchfilename, 00323 has_suffix ? ACE_TEXT ("") : dll_suffix); 00324 if (ACE_OS::access (pathname, F_OK) == 0) 00325 return 0; 00326 00327 // Second, try matching the filename *with* adding a prefix. 00328 ACE_OS::snprintf (pathname, maxpathnamelen, 00329 ACE_TEXT ("%s%s%s%s"), 00330 searchpathname, 00331 ACE_DLL_PREFIX, 00332 searchfilename, 00333 has_suffix ? ACE_TEXT ("") : dll_suffix); 00334 if (ACE_OS::access (pathname, F_OK) == 0) 00335 return 0; 00336 } 00337 } 00338 00339 // Use relative filenames via LD_LIBRARY_PATH or PATH (depending on 00340 // OS platform). 00341 else 00342 { 00343 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) 00344 ACE_TCHAR *file_component = 0; 00345 DWORD pathlen = 00346 ACE_TEXT_SearchPath (0, 00347 searchfilename, 00348 dll_suffix, 00349 static_cast<DWORD> (maxpathnamelen), 00350 pathname, 00351 &file_component); 00352 if (pathlen >= maxpathnamelen) 00353 { 00354 errno = ENOMEM; 00355 return -1; 00356 } 00357 else if (pathlen > 0) 00358 return 0; 00359 00360 // In case not found we should try again with the ACE_DLL_PREFIX 00361 // prefixed 00362 ACE_OS::strcpy (searchfilename, ACE_DLL_PREFIX); 00363 ACE_OS::strcat (searchfilename, tempcopy); 00364 pathlen = 00365 ACE_TEXT_SearchPath (0, 00366 searchfilename, 00367 dll_suffix, 00368 static_cast<DWORD> (maxpathnamelen), 00369 pathname, 00370 &file_component); 00371 if (pathlen >= maxpathnamelen) 00372 { 00373 errno = ENOMEM; 00374 return -1; 00375 } 00376 else if (pathlen > 0) 00377 return 0; 00378 #else 00379 ACE_TCHAR *ld_path = 0; 00380 # if defined ACE_DEFAULT_LD_SEARCH_PATH 00381 ld_path = const_cast<ACE_TCHAR*> (ACE_DEFAULT_LD_SEARCH_PATH); 00382 # else 00383 # if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) 00384 ld_path = ACE_OS::getenv (ACE_LD_SEARCH_PATH); 00385 # else 00386 // Wide-char, non-Windows only offers char * getenv. So capture 00387 // it, translate to wide-char, and continue. 00388 ACE_Ascii_To_Wide wide_ldpath 00389 (ACE_OS::getenv (ACE_TEXT_ALWAYS_CHAR (ACE_LD_SEARCH_PATH))); 00390 ld_path = wide_ldpath.wchar_rep (); 00391 # endif /* ACE_WIN32 || !ACE_USES_WCHAR */ 00392 # endif /* ACE_DEFAULT_LD_SEARCH_PATH */ 00393 00394 #if defined (ACE_HAS_WINCE) 00395 ACE_TCHAR *ld_path_temp = 0; 00396 if (ld_path != 0) 00397 { 00398 ld_path_temp = (ACE_TCHAR *) 00399 ACE_OS::malloc ((ACE_OS::strlen (ld_path) + 2) 00400 * sizeof (ACE_TCHAR)); 00401 if (ld_path_temp != 0) 00402 { 00403 ACE_OS::strcpy (ld_path_temp, 00404 ACE_LD_SEARCH_PATH_SEPARATOR_STR); 00405 00406 ACE_OS::strcat (ld_path_temp, ld_path); 00407 ld_path = ld_path_temp; 00408 } 00409 else 00410 { 00411 ACE_OS::free ((void *) ld_path_temp); 00412 ld_path = ld_path_temp = 0; 00413 } 00414 } 00415 #endif /* ACE_HAS_WINCE */ 00416 00417 if (ld_path != 0 00418 && (ld_path = ACE_OS::strdup (ld_path)) != 0) 00419 { 00420 // strtok has the strange behavior of not separating the 00421 // string ":/foo:/bar" into THREE tokens. One would expect 00422 // that the first iteration the token would be an empty 00423 // string, the second iteration would be "/foo", and the 00424 // third iteration would be "/bar". However, this is not 00425 // the case; one only gets two iterations: "/foo" followed 00426 // by "/bar". 00427 00428 // This is especially a problem in parsing Unix paths 00429 // because it is permissible to specify 'the current 00430 // directory' as an empty entry. So, we introduce the 00431 // following special code to cope with this: 00432 00433 // Look at each dynamic lib directory in the search path. 00434 00435 ACE_TCHAR *nextholder = 0; 00436 const ACE_TCHAR *path_entry = 00437 ACE::strsplit_r (ld_path, 00438 ACE_LD_SEARCH_PATH_SEPARATOR_STR, 00439 nextholder); 00440 int result = 0; 00441 00442 for (;;) 00443 { 00444 // Check if at end of search path. 00445 if (path_entry == 0) 00446 { 00447 errno = ENOENT; 00448 result = -1; 00449 break; 00450 } 00451 else if (ACE_OS::strlen (path_entry) 00452 + 1 00453 + ACE_OS::strlen (searchfilename) 00454 >= maxpathnamelen) 00455 { 00456 errno = ENOMEM; 00457 result = -1; 00458 break; 00459 } 00460 // This works around the issue where a path might have 00461 // an empty component indicating 'current directory'. 00462 // We need to do it here rather than anywhere else so 00463 // that the loop condition will still work. 00464 else if (path_entry[0] == '\0') 00465 path_entry = ACE_TEXT ("."); 00466 00467 // First, try matching the filename *without* adding a 00468 // prefix. 00469 ACE_OS::snprintf (pathname, maxpathnamelen, 00470 ACE_TEXT ("%s%c%s%s"), 00471 path_entry, 00472 ACE_DIRECTORY_SEPARATOR_CHAR, 00473 searchfilename, 00474 has_suffix ? ACE_TEXT ("") : dll_suffix); 00475 if (ACE_OS::access (pathname, F_OK) == 0) 00476 break; 00477 00478 // Second, try matching the filename *with* adding a 00479 // prefix. 00480 ACE_OS::snprintf (pathname, maxpathnamelen, 00481 ACE_TEXT ("%s%c%s%s%s"), 00482 path_entry, 00483 ACE_DIRECTORY_SEPARATOR_CHAR, 00484 ACE_DLL_PREFIX, 00485 searchfilename, 00486 has_suffix ? ACE_TEXT ("") : dll_suffix); 00487 if (ACE_OS::access (pathname, F_OK) == 0) 00488 break; 00489 00490 // Fetch the next item in the path 00491 path_entry = 00492 ACE::strsplit_r (0, 00493 ACE_LD_SEARCH_PATH_SEPARATOR_STR, 00494 nextholder); 00495 } 00496 00497 #if defined (ACE_HAS_WINCE) 00498 if (ld_path_temp != 0) 00499 ACE_OS::free (ld_path_temp); 00500 #endif /* ACE_HAS_WINCE */ 00501 #if defined (ACE_HAS_ALLOC_HOOKS) 00502 ACE_Allocator::instance()->free ((void *) ld_path); 00503 #else 00504 ACE_OS::free ((void *) ld_path); 00505 #endif /* ACE_HAS_ALLOC_HOOKS */ 00506 #if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) 00507 if (result == 0 || tag == 0) 00508 #endif /* ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */ 00509 return result; 00510 } 00511 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */ 00512 } 00513 #if defined (ACE_LD_DECORATOR_STR) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) 00514 } 00515 #endif /* ACE_LD_DECORATOR_STR && !ACE_DISABLE_DEBUG_DLL_CHECK */ 00516 00517 errno = ENOENT; 00518 return -1; 00519 }
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 537 of file Lib_Find.cpp.
00538 { 00539 ACE_TRACE ("ACE::ldname"); 00540 00541 #if defined(ACE_NEEDS_DL_UNDERSCORE) 00542 size_t size = 00543 1 // leading '_' 00544 + ACE_OS::strlen (entry_point) 00545 + 1; 00546 00547 ACE_TCHAR *new_name; 00548 ACE_NEW_RETURN (new_name, 00549 ACE_TCHAR[size], 00550 0); 00551 00552 ACE_OS::strcpy (new_name, ACE_TEXT ("_")); 00553 ACE_OS::strcat (new_name, entry_point); 00554 00555 return new_name; 00556 #else /* ACE_NEEDS_DL_UNDERSCORE */ 00557 size_t size = 00558 ACE_OS::strlen (entry_point) 00559 + 1; 00560 00561 ACE_TCHAR *new_name; 00562 #if defined (ACE_HAS_ALLOC_HOOKS) 00563 ACE_ALLOCATOR_RETURN (new_name, 00564 static_cast<ACE_TCHAR *>(ACE_Allocator::instance()->malloc(sizeof(ACE_TCHAR) * size)), 00565 0); 00566 #else 00567 ACE_NEW_RETURN (new_name, 00568 ACE_TCHAR[size], 00569 0); 00570 #endif /* ACE_HAS_ALLOC_HOOKS */ 00571 00572 ACE_OS::strcpy (new_name, entry_point); 00573 return new_name; 00574 #endif /* ACE_NEEDS_DL_UNDERSCORE */ 00575 }
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 522 of file Lib_Find.cpp.
00524 { 00525 ACE_TRACE ("ACE::ldopen"); 00526 00527 ACE_TCHAR buf[MAXPATHLEN + 1]; 00528 if (ACE::ldfind (filename, 00529 buf, 00530 sizeof (buf) /sizeof (ACE_TCHAR)) == -1) 00531 return 0; 00532 else 00533 return ACE_OS::fopen (buf, type); 00534 }
ACE_Export void ACE::ldregister | ( | const ACE_TCHAR * | entry_point, | |
void * | entry_addr | |||
) |
Registers an entry_point and its address for later retrieval through the ACE::ldsymbol () method. For use in cases where the OS compiler encodes long symbolnames.
ACE_Export void* ACE::ldsymbol | ( | ACE_SHLIB_HANDLE | sh, | |
const ACE_TCHAR * | entry_point | |||
) |
Looks up an entry_point address either from previously registered symbols or through ACE_OS::dlsym (). Returns 0 in case the entry_point is not found, otherwise nonzero. For use in cases where the OS compiler encodes long symbolnames.
u_int ACE::major_version | ( | void | ) |
e.g., the "6" in ACE 6.3.4
Definition at line 94 of file ACE.cpp.
00095 { 00096 return ACE_MAJOR_VERSION; 00097 }
ACE_Event_Handler_var ACE::make_event_handler | ( | Args &&... | args | ) | [inline] |
With C++11 it is common to not use C++ new and delete, but use std::make_shared and std::make_unique. This will not work for ACE event handlers so we introduce a new ACE::make_event_handler which can be used in user code to allocate a new ACE event handler instance and directly assign it to a ACE_Event_Handler_var As user this now makes it for example possible to implement the following when Simple_Handler is derived from ACE_Event_Handler ACE_Event_Handler_var v = ACE::make_event_handler<Simple_Handler> (reactor.get());
Definition at line 386 of file Event_Handler.h.
00387 { 00388 return ACE_Event_Handler_var (new T (std::forward<Args> (args)...)); 00389 }
int ACE::map_errno | ( | int | error | ) | [inline] |
Map troublesome win32 errno values to values that standard C strerr function understands. Thank you Microsoft.
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 2826 of file ACE.cpp.
02827 { 02828 ACE_TRACE ("ACE::max_handles"); 02829 #if defined (RLIMIT_NOFILE) && !defined (ACE_LACKS_RLIMIT) 02830 rlimit rl; 02831 int const r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl); 02832 # if !defined (RLIM_INFINITY) 02833 if (r == 0) 02834 return rl.rlim_cur; 02835 # else 02836 if (r == 0 && rl.rlim_cur != RLIM_INFINITY) 02837 return rl.rlim_cur; 02838 // If == RLIM_INFINITY, fall through to the ACE_LACKS_RLIMIT sections 02839 # endif /* RLIM_INFINITY */ 02840 #endif /* RLIMIT_NOFILE && !ACE_LACKS_RLIMIT */ 02841 02842 #if defined (_SC_OPEN_MAX) && !defined (ACE_LACKS_SYSCONF) 02843 return static_cast<int> (ACE_OS::sysconf (_SC_OPEN_MAX)); 02844 #elif defined (FD_SETSIZE) 02845 return FD_SETSIZE; 02846 #else 02847 ACE_NOTSUP_RETURN (-1); 02848 #endif /* _SC_OPEN_MAX */ 02849 }
u_int ACE::micro_version | ( | void | ) |
e.g., the "4" in ACE 6.3.4 Returns 0 for "stable" (non-micro) releases.
Definition at line 112 of file ACE.cpp.
00113 { 00114 return ACE_MICRO_VERSION; 00115 }
Calculates the minimum enclosing frame size for the given values.
Definition at line 2931 of file ACE.cpp.
02932 { 02933 // if one of the periods is zero, treat it as though it as 02934 // uninitialized and return the other period as the frame size 02935 if (0 == period1) 02936 { 02937 return period2; 02938 } 02939 if (0 == period2) 02940 { 02941 return period1; 02942 } 02943 02944 // if neither is zero, find the greatest common divisor of the two periods 02945 u_long greatest_common_divisor = ACE::gcd (period1, period2); 02946 02947 // explicitly consider cases to reduce risk of possible overflow errors 02948 if (greatest_common_divisor == 1) 02949 { 02950 // periods are relative primes: just multiply them together 02951 return period1 * period2; 02952 } 02953 else if (greatest_common_divisor == period1) 02954 { 02955 // the first period divides the second: return the second 02956 return period2; 02957 } 02958 else if (greatest_common_divisor == period2) 02959 { 02960 // the second period divides the first: return the first 02961 return period1; 02962 } 02963 else 02964 { 02965 // the current frame size and the entry's effective period 02966 // have a non-trivial greatest common divisor: return the 02967 // product of factors divided by those in their gcd. 02968 return (period1 * period2) / greatest_common_divisor; 02969 } 02970 }
u_int ACE::minor_version | ( | void | ) |
e.g., the "3" in ACE 6.3.4
Definition at line 100 of file ACE.cpp.
00101 { 00102 return ACE_MINOR_VERSION; 00103 }
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 653 of file Lib_Find.cpp.
00654 { 00655 #if defined (ACE_WIN32) 00656 ACE_UNUSED_ARG (perm); 00657 ACE_HANDLE handle = ACE_OS::open (name, 00658 mode, 00659 FILE_SHARE_READ 00660 | FILE_SHARE_WRITE 00661 | FILE_SHARE_DELETE); 00662 #else 00663 // Open it. 00664 ACE_HANDLE handle = ACE_OS::open (name, mode, perm); 00665 #endif /* ACE_WIN32 */ 00666 00667 if (handle == ACE_INVALID_HANDLE) 00668 return ACE_INVALID_HANDLE; 00669 00670 // Unlink it so that the file will be removed automatically when the 00671 // process goes away. 00672 if (ACE_OS::unlink (name) == -1) 00673 { 00674 ACE_OS::close (handle); 00675 return ACE_INVALID_HANDLE; 00676 } 00677 else 00678 // Return the handle. 00679 return handle; 00680 }
int ACE::out_of_handles | ( | int | error | ) |
Check if error indicates the process being out of handles (file descriptors).
Definition at line 56 of file ACE.cpp.
00057 { 00058 // EMFILE is common to all platforms. 00059 if (error == EMFILE || 00060 #if defined (ACE_WIN32) 00061 // On Win32, we need to check for ENOBUFS also. 00062 error == ENOBUFS || 00063 #elif defined (HPUX) 00064 // On HPUX, we need to check for EADDRNOTAVAIL also. 00065 error == EADDRNOTAVAIL || 00066 #elif defined (ACE_LINUX) 00067 // On linux, we need to check for ENOENT also. 00068 error == ENOENT || 00069 // For RedHat5.2, need to check for EINVAL too. 00070 error == EINVAL || 00071 // Without threads check for EOPNOTSUPP 00072 error == EOPNOTSUPP || 00073 #elif defined (sun) 00074 // On sun, we need to check for ENOSR also. 00075 error == ENOSR || 00076 // Without threads check for ENOTSUP 00077 error == ENOTSUP || 00078 #elif defined (__FreeBSD__) 00079 // On FreeBSD we need to check for EOPNOTSUPP (LinuxThreads) or 00080 // ENOSYS (libc_r threads) also. 00081 error == EOPNOTSUPP || 00082 error == ENOSYS || 00083 #elif defined (__OpenBSD__) 00084 // OpenBSD appears to return EBADF. 00085 error == EBADF || 00086 #endif /* ACE_WIN32 */ 00087 error == ENFILE) 00088 return 1; 00089 else 00090 return 0; 00091 }
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 255 of file ACE.cpp.
00256 { 00257 #if !defined(ACE_WIN32) 00258 if (ACE_OS::kill (pid, 0) == 0) 00259 return 1; 00260 else if (errno == ESRCH) 00261 return 0; 00262 else 00263 return -1; 00264 #else 00265 // Create a handle for the given process id. 00266 ACE_HANDLE process_handle = 00267 ::OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid); 00268 if (process_handle == ACE_INVALID_HANDLE || process_handle == 0) 00269 return 0; 00270 else 00271 { 00272 DWORD status; 00273 int result = 1; 00274 if (::GetExitCodeProcess (process_handle, 00275 &status) == 0 00276 || status != STILL_ACTIVE) 00277 result = 0; 00278 00279 ::CloseHandle (process_handle); 00280 return result; 00281 } 00282 #endif /* !ACE_WIN32 */ 00283 }
ssize_t ACE::read_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
size_t * | bytes_transferred = 0 | |||
) | [inline] |
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 14 of file ACE.inl.
00018 { 00019 return ACE_OS::read_n (handle, 00020 buf, 00021 len, 00022 bytes_transferred); 00023 }
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 2114 of file ACE.cpp.
02118 { 02119 size_t temp; 02120 size_t &bytes_transferred = bt == 0 ? temp : *bt; 02121 bytes_transferred = 0; 02122 02123 for (int s = 0; 02124 s < iovcnt; 02125 ) 02126 { 02127 ssize_t n = ACE_OS::readv (handle, 02128 iov + s, 02129 iovcnt - s); 02130 02131 if (n == -1 || n == 0) 02132 return n; 02133 02134 for (bytes_transferred += n; 02135 s < iovcnt 02136 && n >= static_cast<ssize_t> (iov[s].iov_len); 02137 s++) 02138 n -= iov[s].iov_len; 02139 02140 if (n != 0) 02141 { 02142 char *base = reinterpret_cast<char *> (iov[s].iov_base); 02143 iov[s].iov_base = base + n; 02144 // This blind cast is safe because n < iov_len, after above loop. 02145 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n); 02146 } 02147 } 02148 02149 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 02150 }
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 2280 of file ACE.cpp.
02281 { 02282 // We need to record whether we are already *in* nonblocking mode, 02283 // so that we can correctly reset the state when we're done. 02284 val = ACE::get_flags (handle); 02285 02286 if (ACE_BIT_DISABLED (val, ACE_NONBLOCK)) 02287 // Set the handle into non-blocking mode if it's not already in 02288 // it. 02289 ACE::set_flags (handle, ACE_NONBLOCK); 02290 }
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 922 of file ACE.cpp.
00923 { 00924 va_list argp; 00925 int const total_tuples = static_cast<int> (n / 2); 00926 iovec *iovp = 0; 00927 #if defined (ACE_HAS_ALLOCA) 00928 iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); 00929 #else 00930 # ifdef ACE_HAS_ALLOC_HOOKS 00931 ACE_ALLOCATOR_RETURN (iovp, (iovec *) 00932 ACE_Allocator::instance ()->malloc (total_tuples * 00933 sizeof (iovec)), 00934 -1); 00935 # else 00936 ACE_NEW_RETURN (iovp, 00937 iovec[total_tuples], 00938 -1); 00939 # endif /* ACE_HAS_ALLOC_HOOKS */ 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 const result = ACE_OS::recvv (handle, iovp, total_tuples); 00951 #if !defined (ACE_HAS_ALLOCA) 00952 # ifdef ACE_HAS_ALLOC_HOOKS 00953 ACE_Allocator::instance ()->free (iovp); 00954 # else 00955 delete [] iovp; 00956 # endif /* ACE_HAS_ALLOC_HOOKS */ 00957 #endif /* !defined (ACE_HAS_ALLOCA) */ 00958 va_end (argp); 00959 return result; 00960 }
ssize_t ACE::recv | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 497 of file ACE.cpp.
00501 { 00502 if (timeout == 0) 00503 return ACE::recv_i (handle, buf, n); 00504 else 00505 { 00506 int val = 0; 00507 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1) 00508 return -1; 00509 else 00510 { 00511 ssize_t bytes_transferred = ACE::recv_i (handle, buf, n); 00512 ACE::restore_non_blocking_mode (handle, val); 00513 return bytes_transferred; 00514 } 00515 } 00516 }
ssize_t ACE::recv | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 445 of file ACE.cpp.
00450 { 00451 if (timeout == 0) 00452 return ACE_OS::recv (handle, (char *) buf, len, flags); 00453 else 00454 { 00455 int val = 0; 00456 if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1) 00457 return -1; 00458 else 00459 { 00460 ssize_t bytes_transferred = 00461 ACE_OS::recv (handle, (char *) buf, len, flags); 00462 ACE::restore_non_blocking_mode (handle, val); 00463 return bytes_transferred; 00464 } 00465 } 00466 }
Definition at line 228 of file ACE.inl.
00229 { 00230 #if defined (ACE_WIN32) || defined (ACE_OPENVMS) 00231 return ACE_OS::recv (handle, (char *) buf, len); 00232 #else 00233 return ACE_OS::read (handle, (char *) buf, len); 00234 #endif /* ACE_WIN32 */ 00235 }
ssize_t ACE::recv_n | ( | ACE_HANDLE | handle, | |
ACE_Message_Block * | message_block, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) |
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 1121 of file ACE.cpp.
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 { 01212 return result; 01213 } 01214 } 01215 01216 // Return total bytes transferred. 01217 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01218 }
ssize_t ACE::recv_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) | [inline] |
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 88 of file ACE.inl.
00093 { 00094 if (timeout == 0) 00095 return ACE::recv_n_i (handle, 00096 buf, 00097 len, 00098 bytes_transferred); 00099 else 00100 return ACE::recv_n_i (handle, 00101 buf, 00102 len, 00103 timeout, 00104 bytes_transferred); 00105 }
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 | |||
) | [inline] |
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 38 of file ACE.inl.
00044 { 00045 if (timeout == 0) 00046 return ACE::recv_n_i (handle, 00047 buf, 00048 len, 00049 flags, 00050 bytes_transferred); 00051 else 00052 return ACE::recv_n_i (handle, 00053 buf, 00054 len, 00055 flags, 00056 timeout, 00057 bytes_transferred); 00058 }
ssize_t ACE::recv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 852 of file ACE.cpp.
00857 { 00858 size_t temp; 00859 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00860 ssize_t n; 00861 ssize_t result = 0; 00862 int error = 0; 00863 00864 int val = 0; 00865 ACE::record_and_set_non_blocking_mode (handle, val); 00866 00867 for (bytes_transferred = 0; 00868 bytes_transferred < len; 00869 bytes_transferred += n) 00870 { 00871 // Try to transfer as much of the remaining data as possible. 00872 // Since the socket is in non-blocking mode, this call will not 00873 // block. 00874 n = ACE::recv_i (handle, 00875 static_cast <char *> (buf) + bytes_transferred, 00876 len - bytes_transferred); 00877 00878 // Check for errors. 00879 if (n == 0 || 00880 n == -1) 00881 { 00882 // Check for possible blocking. 00883 if (n == -1 && 00884 errno == EWOULDBLOCK) 00885 { 00886 // Wait upto <timeout> for the blocking to subside. 00887 int const rtn = ACE::handle_read_ready (handle, timeout); 00888 00889 // Did select() succeed? 00890 if (rtn != -1) 00891 { 00892 // Blocking subsided in <timeout> period. Continue 00893 // data transfer. 00894 n = 0; 00895 continue; 00896 } 00897 } 00898 00899 // Wait in select() timed out or other data transfer or 00900 // select() failures. 00901 error = 1; 00902 result = n; 00903 break; 00904 } 00905 } 00906 00907 ACE::restore_non_blocking_mode (handle, val); 00908 00909 if (error) 00910 return result; 00911 else 00912 return static_cast<ssize_t> (bytes_transferred); 00913 }
Definition at line 803 of file ACE.cpp.
00807 { 00808 size_t temp; 00809 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00810 ssize_t n; 00811 00812 for (bytes_transferred = 0; 00813 bytes_transferred < len; 00814 bytes_transferred += n) 00815 { 00816 // Try to transfer as much of the remaining data as possible. 00817 n = ACE::recv_i (handle, 00818 static_cast <char *> (buf) + bytes_transferred, 00819 len - bytes_transferred); 00820 // Check EOF. 00821 if (n == 0) 00822 { 00823 return 0; 00824 } 00825 // Check for other errors. 00826 if (n == -1) 00827 { 00828 // Check for possible blocking. 00829 if (errno == EWOULDBLOCK) 00830 { 00831 // Wait for the blocking to subside. 00832 int const result = ACE::handle_read_ready (handle, 0); 00833 00834 // Did select() succeed? 00835 if (result != -1) 00836 { 00837 // Blocking subsided. Continue data transfer. 00838 n = 0; 00839 continue; 00840 } 00841 } 00842 00843 // Other data transfer or select() failures. 00844 return -1; 00845 } 00846 } 00847 00848 return static_cast<ssize_t> (bytes_transferred); 00849 }
ssize_t ACE::recv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 617 of file ACE.cpp.
00623 { 00624 size_t temp; 00625 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00626 ssize_t n; 00627 ssize_t result = 0; 00628 int error = 0; 00629 00630 int val = 0; 00631 ACE::record_and_set_non_blocking_mode (handle, val); 00632 00633 for (bytes_transferred = 0; 00634 bytes_transferred < len; 00635 bytes_transferred += n) 00636 { 00637 // Try to transfer as much of the remaining data as possible. 00638 // Since the socket is in non-blocking mode, this call will not 00639 // block. 00640 n = ACE_OS::recv (handle, 00641 static_cast <char *> (buf) + bytes_transferred, 00642 len - bytes_transferred, 00643 flags); 00644 00645 // Check for errors. 00646 if (n == 0 || 00647 n == -1) 00648 { 00649 // Check for possible blocking. 00650 if (n == -1 && 00651 errno == EWOULDBLOCK) 00652 { 00653 // Wait upto <timeout> for the blocking to subside. 00654 int const rtn = ACE::handle_read_ready (handle, timeout); 00655 00656 // Did select() succeed? 00657 if (rtn != -1) 00658 { 00659 // Blocking subsided in <timeout> period. Continue 00660 // data transfer. 00661 n = 0; 00662 continue; 00663 } 00664 } 00665 00666 // Wait in select() timed out or other data transfer or 00667 // select() failures. 00668 error = 1; 00669 result = n; 00670 break; 00671 } 00672 } 00673 00674 ACE::restore_non_blocking_mode (handle, val); 00675 00676 if (error) 00677 return result; 00678 else 00679 return static_cast<ssize_t> (bytes_transferred); 00680 }
ssize_t ACE::recv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int | flags, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 567 of file ACE.cpp.
00572 { 00573 size_t temp; 00574 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00575 ssize_t n; 00576 00577 for (bytes_transferred = 0; 00578 bytes_transferred < len; 00579 bytes_transferred += n) 00580 { 00581 // Try to transfer as much of the remaining data as possible. 00582 n = ACE_OS::recv (handle, 00583 static_cast <char *> (buf) + bytes_transferred, 00584 len - bytes_transferred, 00585 flags); 00586 // Check EOF. 00587 if (n == 0) 00588 return 0; 00589 00590 // Check for other errors. 00591 if (n == -1) 00592 { 00593 // Check for possible blocking. 00594 if (errno == EWOULDBLOCK) 00595 { 00596 // Wait for the blocking to subside. 00597 int const result = ACE::handle_read_ready (handle, 0); 00598 00599 // Did select() succeed? 00600 if (result != -1) 00601 { 00602 // Blocking subsided. Continue data transfer. 00603 n = 0; 00604 continue; 00605 } 00606 } 00607 00608 // Other data transfer or select() failures. 00609 return -1; 00610 } 00611 } 00612 00613 return static_cast<ssize_t> (bytes_transferred); 00614 }
ssize_t ACE::recvfrom | ( | ACE_HANDLE | handle, | |
char * | buf, | |||
int | len, | |||
int | flags, | |||
struct sockaddr * | addr, | |||
int * | addrlen, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 541 of file ACE.cpp.
00548 { 00549 if (timeout == 0) 00550 return ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen); 00551 else 00552 { 00553 int val = 0; 00554 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1) 00555 return -1; 00556 else 00557 { 00558 ssize_t bytes_transferred = 00559 ACE_OS::recvfrom (handle, buf, len, flags, addr, addrlen); 00560 ACE::restore_non_blocking_mode (handle, val); 00561 return bytes_transferred; 00562 } 00563 } 00564 }
ssize_t ACE::recvmsg | ( | ACE_HANDLE | handle, | |
struct msghdr * | msg, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 519 of file ACE.cpp.
00523 { 00524 if (timeout == 0) 00525 return ACE_OS::recvmsg (handle, msg, flags); 00526 else 00527 { 00528 int val = 0; 00529 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1) 00530 return -1; 00531 else 00532 { 00533 ssize_t bytes_transferred = ACE_OS::recvmsg (handle, msg, flags); 00534 ACE::restore_non_blocking_mode (handle, val); 00535 return bytes_transferred; 00536 } 00537 } 00538 }
ssize_t ACE::recvv | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 965 of file ACE.cpp.
00969 { 00970 if (timeout == 0) 00971 return ACE_OS::recvv (handle, iov, iovcnt); 00972 else 00973 { 00974 int val = 0; 00975 if (ACE::enter_recv_timedwait (handle, timeout, val) == -1) 00976 return -1; 00977 else 00978 { 00979 ssize_t bytes_transferred = ACE_OS::recvv (handle, iov, iovcnt); 00980 ACE::restore_non_blocking_mode (handle, val); 00981 return bytes_transferred; 00982 } 00983 } 00984 }
ssize_t ACE::recvv_n | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) | [inline] |
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 108 of file ACE.inl.
00113 { 00114 if (timeout == 0) 00115 return ACE::recvv_n_i (handle, 00116 iov, 00117 iovcnt, 00118 bytes_transferred); 00119 else 00120 return ACE::recvv_n_i (handle, 00121 iov, 00122 iovcnt, 00123 timeout, 00124 bytes_transferred); 00125 }
ssize_t ACE::recvv_n_i | ( | ACE_HANDLE | handle, | |
iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1045 of file ACE.cpp.
01050 { 01051 size_t temp; 01052 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01053 bytes_transferred = 0; 01054 ssize_t result = 0; 01055 int error = 0; 01056 01057 int val = 0; 01058 ACE::record_and_set_non_blocking_mode (handle, val); 01059 01060 for (int s = 0; s < iovcnt; ) 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, iov + s, iovcnt - s); 01066 01067 // Check for errors. 01068 if (n == 0 || n == -1) 01069 { 01070 // Check for possible blocking. 01071 if (n == -1 && errno == EWOULDBLOCK) 01072 { 01073 // Wait upto <timeout> for the blocking to subside. 01074 int const rtn = ACE::handle_read_ready (handle, timeout); 01075 01076 // Did select() succeed? 01077 if (rtn != -1) 01078 { 01079 // Blocking subsided in <timeout> period. Continue 01080 // data transfer. 01081 n = 0; 01082 continue; 01083 } 01084 } 01085 01086 // Wait in select() timed out or other data transfer or 01087 // select() failures. 01088 error = 1; 01089 result = n; 01090 break; 01091 } 01092 01093 for (bytes_transferred += n; 01094 s < iovcnt 01095 && n >= static_cast<ssize_t> (iov[s].iov_len); 01096 s++) 01097 n -= iov[s].iov_len; 01098 01099 if (n != 0) 01100 { 01101 char *base = reinterpret_cast<char *> (iov[s].iov_base); 01102 iov[s].iov_base = base + n; 01103 // This blind cast is safe because n < iov_len, after above loop. 01104 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n); 01105 } 01106 } 01107 01108 ACE::restore_non_blocking_mode (handle, val); 01109 01110 if (error) 01111 { 01112 return result; 01113 } 01114 else 01115 { 01116 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01117 } 01118 }
Definition at line 987 of file ACE.cpp.
00991 { 00992 size_t temp; 00993 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00994 bytes_transferred = 0; 00995 00996 for (int s = 0; s < iovcnt; ) 00997 { 00998 // Try to transfer as much of the remaining data as possible. 00999 ssize_t n = ACE_OS::recvv (handle, iov + s, iovcnt - s); 01000 // Check EOF. 01001 if (n == 0) 01002 return 0; 01003 01004 // Check for other errors. 01005 if (n == -1) 01006 { 01007 // Check for possible blocking. 01008 if (errno == EWOULDBLOCK) 01009 { 01010 // Wait for the blocking to subside. 01011 int const result = ACE::handle_read_ready (handle, 0); 01012 01013 // Did select() succeed? 01014 if (result != -1) 01015 { 01016 // Blocking subsided. Continue data transfer. 01017 n = 0; 01018 continue; 01019 } 01020 } 01021 01022 // Other data transfer or select() failures. 01023 return -1; 01024 } 01025 01026 for (bytes_transferred += n; 01027 s < iovcnt 01028 && n >= static_cast<ssize_t> (iov[s].iov_len); 01029 s++) 01030 n -= iov[s].iov_len; 01031 01032 if (n != 0) 01033 { 01034 char *base = static_cast<char *> (iov[s].iov_base); 01035 iov[s].iov_base = base + n; 01036 // This blind cast is safe because n < iov_len, after above loop. 01037 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n); 01038 } 01039 } 01040 01041 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01042 }
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 2293 of file ACE.cpp.
02294 { 02295 if (ACE_BIT_DISABLED (val, ACE_NONBLOCK)) 02296 { 02297 // Save/restore errno. 02298 ACE_Errno_Guard error (errno); 02299 // Only disable ACE_NONBLOCK if we weren't in non-blocking mode 02300 // originally. 02301 ACE::clr_flags (handle, ACE_NONBLOCK); 02302 } 02303 }
Rounds the request to a multiple of the allocation granularity.
Definition at line 2471 of file ACE.cpp.
02472 { 02473 ACE_TRACE ("ACE::round_to_allocation_granularity"); 02474 02475 if (ACE::allocation_granularity_ == 0) 02476 ACE::allocation_granularity_ = ACE_OS::allocation_granularity (); 02477 02478 return (len + (ACE::allocation_granularity_ - 1)) & ~(ACE::allocation_granularity_ - 1); 02479 }
Rounds the request to a multiple of the page size.
This function rounds the request to a multiple of the page size.
Definition at line 2460 of file ACE.cpp.
02461 { 02462 ACE_TRACE ("ACE::round_to_pagesize"); 02463 02464 if (ACE::pagesize_ == 0) 02465 ACE::pagesize_ = ACE_OS::getpagesize (); 02466 02467 return (len + (ACE::pagesize_ - 1)) & ~(ACE::pagesize_ - 1); 02468 }
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 207 of file ACE.cpp.
00210 { 00211 int result = ACE_OS::select (width, 00212 readfds.fdset (), 00213 0, 00214 0, 00215 timeout); 00216 00217 #if !defined (ACE_WIN32) 00218 if (result > 0) 00219 readfds.sync ((ACE_HANDLE) width); 00220 #endif /* ACE_WIN32 */ 00221 return result; 00222 }
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 180 of file ACE.cpp.
00185 { 00186 int result = ACE_OS::select (width, 00187 readfds ? readfds->fdset () : 0, 00188 writefds ? writefds->fdset () : 0, 00189 exceptfds ? exceptfds->fdset () : 0, 00190 timeout); 00191 if (result > 0) 00192 { 00193 # if !defined (ACE_WIN32) 00194 // This isn't needed for Windows... it's a no-op anyway. 00195 if (readfds) 00196 readfds->sync ((ACE_HANDLE) width); 00197 if (writefds) 00198 writefds->sync ((ACE_HANDLE) width); 00199 if (exceptfds) 00200 exceptfds->sync ((ACE_HANDLE) width); 00201 #endif /* ACE_WIN32 */ 00202 } 00203 return result; 00204 }
Varargs variant.
Definition at line 1710 of file ACE.cpp.
01711 { 01712 va_list argp; 01713 int total_tuples = static_cast<int> (n / 2); 01714 iovec *iovp; 01715 #if defined (ACE_HAS_ALLOCA) 01716 iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); 01717 #else 01718 # ifdef ACE_HAS_ALLOC_HOOKS 01719 ACE_ALLOCATOR_RETURN (iovp, (iovec *) 01720 ACE_Allocator::instance ()->malloc (total_tuples * 01721 sizeof (iovec)), 01722 -1); 01723 # else 01724 ACE_NEW_RETURN (iovp, 01725 iovec[total_tuples], 01726 -1); 01727 # endif /* ACE_HAS_ALLOC_HOOKS */ 01728 #endif /* !defined (ACE_HAS_ALLOCA) */ 01729 01730 va_start (argp, n); 01731 01732 for (int i = 0; i < total_tuples; i++) 01733 { 01734 iovp[i].iov_base = va_arg (argp, char *); 01735 iovp[i].iov_len = va_arg (argp, int); 01736 } 01737 01738 ssize_t result = ACE_OS::sendv (handle, iovp, total_tuples); 01739 #if !defined (ACE_HAS_ALLOCA) 01740 # ifdef ACE_HAS_ALLOC_HOOKS 01741 ACE_Allocator::instance ()->free (iovp); 01742 # else 01743 delete [] iovp; 01744 # endif /* ACE_HAS_ALLOC_HOOKS */ 01745 #endif /* !defined (ACE_HAS_ALLOCA) */ 01746 va_end (argp); 01747 return result; 01748 }
ssize_t ACE::send | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 1273 of file ACE.cpp.
01277 { 01278 if (timeout == 0) 01279 return ACE::send_i (handle, buf, n); 01280 else 01281 { 01282 int val = 0; 01283 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01284 return -1; 01285 else 01286 { 01287 ssize_t const bytes_transferred = ACE::send_i (handle, buf, n); 01288 ACE::restore_non_blocking_mode (handle, val); 01289 return bytes_transferred; 01290 } 01291 } 01292 }
ssize_t ACE::send | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 1221 of file ACE.cpp.
01226 { 01227 if (timeout == 0) 01228 return ACE_OS::send (handle, (const char *) buf, n, flags); 01229 else 01230 { 01231 int val = 0; 01232 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01233 return -1; 01234 else 01235 { 01236 ssize_t const bytes_transferred = 01237 ACE_OS::send (handle, (const char *) buf, n, flags); 01238 ACE::restore_non_blocking_mode (handle, val); 01239 return bytes_transferred; 01240 } 01241 } 01242 }
Definition at line 218 of file ACE.inl.
00219 { 00220 #if defined (ACE_WIN32) || defined (HPUX) 00221 return ACE_OS::send (handle, (const char *) buf, len); 00222 #else 00223 return ACE_OS::write (handle, (const char *) buf, len); 00224 #endif /* ACE_WIN32 */ 00225 }
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 2014 of file ACE.cpp.
02018 { 02019 size_t temp; 02020 size_t &bytes_transferred = bt == 0 ? temp : *bt; 02021 bytes_transferred = 0; 02022 02023 iovec iov[ACE_IOV_MAX]; 02024 int iovcnt = 0; 02025 02026 while (message_block != 0) 02027 { 02028 // Our current message block chain. 02029 const ACE_Message_Block *current_message_block = message_block; 02030 02031 while (current_message_block != 0) 02032 { 02033 char *this_block_ptr = current_message_block->rd_ptr (); 02034 size_t current_message_block_length = 02035 current_message_block->length (); 02036 02037 // Check if this block has any data to be sent. 02038 while (current_message_block_length > 0) 02039 { 02040 u_long const this_chunk_length = 02041 ACE_Utils::truncate_cast<u_long> ( 02042 current_message_block_length); 02043 02044 // Collect the data in the iovec. 02045 iov[iovcnt].iov_base = this_block_ptr; 02046 iov[iovcnt].iov_len = this_chunk_length; 02047 current_message_block_length -= this_chunk_length; 02048 this_block_ptr += this_chunk_length; 02049 02050 // Increment iovec counter. 02051 ++iovcnt; 02052 02053 // The buffer is full make a OS call. @@ TODO find a way to 02054 // find ACE_IOV_MAX for platforms that do not define it rather 02055 // than simply setting ACE_IOV_MAX to some arbitrary value such 02056 // as 16. 02057 if (iovcnt == ACE_IOV_MAX) 02058 { 02059 size_t current_transfer = 0; 02060 02061 ssize_t const result = ACE::sendv_n (handle, 02062 iov, 02063 iovcnt, 02064 timeout, 02065 ¤t_transfer); 02066 02067 // Add to total bytes transferred. 02068 bytes_transferred += current_transfer; 02069 02070 // Errors. 02071 if (result == -1 || result == 0) 02072 return result; 02073 02074 // Reset iovec counter. 02075 iovcnt = 0; 02076 } 02077 } 02078 02079 // Select the next message block in the chain. 02080 current_message_block = current_message_block->cont (); 02081 } 02082 02083 // Selection of the next message block chain. 02084 message_block = message_block->next (); 02085 } 02086 02087 // Check for remaining buffers to be sent. This will happen when 02088 // ACE_IOV_MAX is not a multiple of the number of message blocks. 02089 if (iovcnt != 0) 02090 { 02091 size_t current_transfer = 0; 02092 02093 ssize_t const result = ACE::sendv_n (handle, 02094 iov, 02095 iovcnt, 02096 timeout, 02097 ¤t_transfer); 02098 02099 // Add to total bytes transferred. 02100 bytes_transferred += current_transfer; 02101 02102 // Errors. 02103 if (result == -1 || result == 0) 02104 { 02105 return result; 02106 } 02107 } 02108 02109 // Return total bytes transferred. 02110 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 02111 }
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 | |||
) | [inline] |
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 178 of file ACE.inl.
00183 { 00184 if (timeout == 0) 00185 return ACE::send_n_i (handle, 00186 buf, 00187 len, 00188 bytes_transferred); 00189 else 00190 return ACE::send_n_i (handle, 00191 buf, 00192 len, 00193 timeout, 00194 bytes_transferred); 00195 }
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 | |||
) | [inline] |
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 128 of file ACE.inl.
00134 { 00135 if (timeout == 0) 00136 return ACE::send_n_i (handle, 00137 buf, 00138 len, 00139 flags, 00140 bytes_transferred); 00141 else 00142 return ACE::send_n_i (handle, 00143 buf, 00144 len, 00145 flags, 00146 timeout, 00147 bytes_transferred); 00148 }
ssize_t ACE::send_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1637 of file ACE.cpp.
01642 { 01643 size_t temp; 01644 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01645 ssize_t n; 01646 ssize_t result = 0; 01647 int error = 0; 01648 01649 int val = 0; 01650 ACE::record_and_set_non_blocking_mode (handle, val); 01651 01652 for (bytes_transferred = 0; 01653 bytes_transferred < len; 01654 bytes_transferred += n) 01655 { 01656 // Try to transfer as much of the remaining data as possible. 01657 // Since the socket is in non-blocking mode, this call will not 01658 // block. 01659 n = ACE::send_i (handle, 01660 (char *) buf + bytes_transferred, 01661 len - bytes_transferred); 01662 01663 // Check for errors. 01664 if (n == 0 || 01665 n == -1) 01666 { 01667 // Check for possible blocking. 01668 if (n == -1 && 01669 (errno == EWOULDBLOCK || errno == ENOBUFS)) 01670 { 01671 // Wait upto <timeout> for the blocking to subside. 01672 int const rtn = ACE::handle_write_ready (handle, timeout); 01673 01674 // Did select() succeed? 01675 if (rtn != -1) 01676 { 01677 // Blocking subsided in <timeout> period. Continue 01678 // data transfer. 01679 n = 0; 01680 continue; 01681 } 01682 } 01683 01684 // Wait in select() timed out or other data transfer or 01685 // select() failures. 01686 error = 1; 01687 result = n; 01688 break; 01689 } 01690 } 01691 01692 ACE::restore_non_blocking_mode (handle, val); 01693 01694 if (error) 01695 { 01696 return result; 01697 } 01698 else 01699 { 01700 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01701 } 01702 }
ssize_t ACE::send_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1587 of file ACE.cpp.
01591 { 01592 size_t temp; 01593 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01594 ssize_t n; 01595 01596 for (bytes_transferred = 0; 01597 bytes_transferred < len; 01598 bytes_transferred += n) 01599 { 01600 // Try to transfer as much of the remaining data as possible. 01601 n = ACE::send_i (handle, 01602 (char *) buf + bytes_transferred, 01603 len - bytes_transferred); 01604 // Check EOF. 01605 if (n == 0) 01606 { 01607 return 0; 01608 } 01609 01610 // Check for other errors. 01611 if (n == -1) 01612 { 01613 // Check for possible blocking. 01614 if (errno == EWOULDBLOCK || errno == ENOBUFS) 01615 { 01616 // Wait for the blocking to subside. 01617 int const result = ACE::handle_write_ready (handle, 0); 01618 01619 // Did select() succeed? 01620 if (result != -1) 01621 { 01622 // Blocking subsided. Continue data transfer. 01623 n = 0; 01624 continue; 01625 } 01626 } 01627 01628 // Other data transfer or select() failures. 01629 return -1; 01630 } 01631 } 01632 01633 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01634 }
ssize_t ACE::send_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1398 of file ACE.cpp.
01404 { 01405 size_t temp; 01406 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01407 ssize_t n; 01408 ssize_t result = 0; 01409 int error = 0; 01410 01411 int val = 0; 01412 ACE::record_and_set_non_blocking_mode (handle, val); 01413 01414 for (bytes_transferred = 0; 01415 bytes_transferred < len; 01416 bytes_transferred += n) 01417 { 01418 // Try to transfer as much of the remaining data as possible. 01419 // Since the socket is in non-blocking mode, this call will not 01420 // block. 01421 n = ACE_OS::send (handle, 01422 (char *) buf + bytes_transferred, 01423 len - bytes_transferred, 01424 flags); 01425 01426 // Check for errors. 01427 if (n == 0 || 01428 n == -1) 01429 { 01430 // Check for possible blocking. 01431 if (n == -1 && (errno == EWOULDBLOCK || errno == ENOBUFS)) 01432 { 01433 // Wait upto <timeout> for the blocking to subside. 01434 int const rtn = ACE::handle_write_ready (handle, timeout); 01435 01436 // Did select() succeed? 01437 if (rtn != -1) 01438 { 01439 // Blocking subsided in <timeout> period. Continue 01440 // data transfer. 01441 n = 0; 01442 continue; 01443 } 01444 } 01445 01446 // Wait in select() timed out or other data transfer or 01447 // select() failures. 01448 error = 1; 01449 result = n; 01450 break; 01451 } 01452 } 01453 01454 ACE::restore_non_blocking_mode (handle, val); 01455 01456 if (error) 01457 { 01458 return result; 01459 } 01460 else 01461 { 01462 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01463 } 01464 }
ssize_t ACE::send_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1344 of file ACE.cpp.
01349 { 01350 size_t temp; 01351 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01352 ssize_t n; 01353 01354 for (bytes_transferred = 0; 01355 bytes_transferred < len; 01356 bytes_transferred += n) 01357 { 01358 // Try to transfer as much of the remaining data as possible. 01359 n = ACE_OS::send (handle, 01360 (char *) buf + bytes_transferred, 01361 len - bytes_transferred, 01362 flags); 01363 // Check EOF. 01364 if (n == 0) 01365 return 0; 01366 01367 // Check for other errors. 01368 if (n == -1) 01369 { 01370 // Check for possible blocking. 01371 #if defined (ACE_WIN32) 01372 if (errno == EWOULDBLOCK) // If enobufs no need to loop 01373 #else 01374 if (errno == EWOULDBLOCK || errno == ENOBUFS) 01375 #endif /* ACE_WIN32 */ 01376 { 01377 // Wait for the blocking to subside. 01378 int const result = ACE::handle_write_ready (handle, 0); 01379 01380 // Did select() succeed? 01381 if (result != -1) 01382 { 01383 // Blocking subsided. Continue data transfer. 01384 n = 0; 01385 continue; 01386 } 01387 } 01388 01389 // Other data transfer or select() failures. 01390 return -1; 01391 } 01392 } 01393 01394 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01395 }
ssize_t ACE::sendmsg | ( | ACE_HANDLE | handle, | |
const struct msghdr * | msg, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 1295 of file ACE.cpp.
01299 { 01300 if (timeout == 0) 01301 return ACE_OS::sendmsg (handle, msg, flags); 01302 else 01303 { 01304 int val = 0; 01305 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01306 return -1; 01307 else 01308 { 01309 ssize_t const bytes_transferred = 01310 ACE_OS::sendmsg (handle, msg, flags); 01311 ACE::restore_non_blocking_mode (handle, val); 01312 return bytes_transferred; 01313 } 01314 } 01315 }
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 | |||
) |
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 1318 of file ACE.cpp.
01325 { 01326 if (timeout == 0) 01327 return ACE_OS::sendto (handle, buf, len, flags, addr, addrlen); 01328 else 01329 { 01330 int val = 0; 01331 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01332 return -1; 01333 else 01334 { 01335 ssize_t const bytes_transferred = 01336 ACE_OS::sendto (handle, buf, len, flags, addr, addrlen); 01337 ACE::restore_non_blocking_mode (handle, val); 01338 return bytes_transferred; 01339 } 01340 } 01341 }
ssize_t ACE::sendv | ( | ACE_HANDLE | handle, | |
const iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 1752 of file ACE.cpp.
01756 { 01757 if (timeout == 0) 01758 return ACE_OS::sendv (handle, iov, iovcnt); 01759 else 01760 { 01761 int val = 0; 01762 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01763 return -1; 01764 else 01765 { 01766 ssize_t bytes_transferred = ACE_OS::sendv (handle, iov, iovcnt); 01767 ACE::restore_non_blocking_mode (handle, val); 01768 return bytes_transferred; 01769 } 01770 } 01771 }
ssize_t ACE::sendv_n | ( | ACE_HANDLE | handle, | |
const iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) | [inline] |
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 198 of file ACE.inl.
00203 { 00204 if (timeout == 0) 00205 return ACE::sendv_n_i (handle, 00206 iov, 00207 iovcnt, 00208 bytes_transferred); 00209 else 00210 return ACE::sendv_n_i (handle, 00211 iov, 00212 iovcnt, 00213 timeout, 00214 bytes_transferred); 00215 }
ssize_t ACE::sendv_n_i | ( | ACE_HANDLE | handle, | |
const iovec * | iov, | |||
int | iovcnt, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1837 of file ACE.cpp.
01842 { 01843 size_t temp; 01844 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01845 bytes_transferred = 0; 01846 ssize_t result = 0; 01847 int error = 0; 01848 01849 int val = 0; 01850 ACE::record_and_set_non_blocking_mode (handle, val); 01851 01852 iovec *iov = const_cast<iovec *> (i); 01853 01854 for (int s = 0; 01855 s < iovcnt; 01856 ) 01857 { 01858 // Try to transfer as much of the remaining data as possible. 01859 // Since the socket is in non-blocking mode, this call will not 01860 // block. 01861 ssize_t n = ACE_OS::sendv (handle, iov + s, iovcnt - s); 01862 01863 // Check for errors. 01864 if (n == 0 || 01865 n == -1) 01866 { 01867 // Check for possible blocking. 01868 if (n == -1 && 01869 (errno == EWOULDBLOCK || errno == ENOBUFS)) 01870 { 01871 // Wait upto <timeout> for the blocking to subside. 01872 int const rtn = ACE::handle_write_ready (handle, timeout); 01873 01874 // Did select() succeed? 01875 if (rtn != -1) 01876 { 01877 // Blocking subsided in <timeout> period. Continue 01878 // data transfer. 01879 n = 0; 01880 continue; 01881 } 01882 } 01883 01884 // Wait in select() timed out or other data transfer or 01885 // select() failures. 01886 error = 1; 01887 result = n; 01888 break; 01889 } 01890 01891 for (bytes_transferred += n; 01892 s < iovcnt 01893 && n >= static_cast<ssize_t> (iov[s].iov_len); 01894 s++) 01895 n -= iov[s].iov_len; 01896 01897 if (n != 0) 01898 { 01899 char *base = reinterpret_cast<char *> (iov[s].iov_base); 01900 iov[s].iov_base = base + n; 01901 // This blind cast is safe because n < iov_len, after above loop. 01902 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n); 01903 } 01904 } 01905 01906 ACE::restore_non_blocking_mode (handle, val); 01907 01908 if (error) 01909 { 01910 return result; 01911 } 01912 else 01913 { 01914 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01915 } 01916 }
ssize_t ACE::sendv_n_i | ( | ACE_HANDLE | handle, | |
const iovec * | iov, | |||
int | iovcnt, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1774 of file ACE.cpp.
01778 { 01779 size_t temp; 01780 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01781 bytes_transferred = 0; 01782 01783 iovec *iov = const_cast<iovec *> (i); 01784 01785 for (int s = 0; 01786 s < iovcnt; 01787 ) 01788 { 01789 // Try to transfer as much of the remaining data as possible. 01790 ssize_t n = ACE_OS::sendv (handle, iov + s, iovcnt - s); 01791 01792 // Check EOF. 01793 if (n == 0) 01794 return 0; 01795 01796 // Check for other errors. 01797 if (n == -1) 01798 { 01799 // Check for possible blocking. 01800 if (errno == EWOULDBLOCK || errno == ENOBUFS) 01801 { 01802 // Wait for the blocking to subside. 01803 int const result = ACE::handle_write_ready (handle, 0); 01804 01805 // Did select() succeed? 01806 if (result != -1) 01807 { 01808 // Blocking subsided. Continue data transfer. 01809 n = 0; 01810 continue; 01811 } 01812 } 01813 01814 // Other data transfer or select() failures. 01815 return -1; 01816 } 01817 01818 for (bytes_transferred += n; 01819 s < iovcnt 01820 && n >= static_cast<ssize_t> (iov[s].iov_len); 01821 s++) 01822 n -= iov[s].iov_len; 01823 01824 if (n != 0) 01825 { 01826 char *base = reinterpret_cast<char *> (iov[s].iov_base); 01827 iov[s].iov_base = base + n; 01828 // This blind cast is safe because n < iov_len, after above loop. 01829 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n); 01830 } 01831 } 01832 01833 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 01834 }
int ACE::set_flags | ( | ACE_HANDLE | handle, | |
int | flags | |||
) |
Set flags associated with handle.
Definition at line 25 of file Flag_Manip.cpp.
00026 { 00027 ACE_TRACE ("ACE::set_flags"); 00028 #if defined (ACE_LACKS_FCNTL) 00029 switch (flags) 00030 { 00031 case ACE_NONBLOCK: 00032 // nonblocking argument (1) 00033 // blocking: (0) 00034 { 00035 int nonblock = 1; 00036 # if defined (ACE_LACKS_IOCTL) 00037 int dev_info; 00038 return ACE_OS::posix_devctl (handle, FIONBIO, &nonblock, 00039 sizeof nonblock, &dev_info); 00040 # else 00041 return ACE_OS::ioctl (handle, FIONBIO, &nonblock); 00042 # endif 00043 } 00044 default: 00045 ACE_NOTSUP_RETURN (-1); 00046 } 00047 #else 00048 int val = ACE_OS::fcntl (handle, F_GETFL, 0); 00049 00050 if (val == -1) 00051 return -1; 00052 00053 // Turn on flags. 00054 ACE_SET_BITS (val, flags); 00055 00056 if (ACE_OS::fcntl (handle, F_SETFL, val) == -1) 00057 return -1; 00058 else 00059 return 0; 00060 #endif /* ACE_LACKS_FCNTL */ 00061 }
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 2857 of file ACE.cpp.
02859 { 02860 ACE_TRACE ("ACE::set_handle_limit"); 02861 int cur_limit = ACE::max_handles (); 02862 int max_limit = cur_limit; 02863 02864 if (cur_limit == -1) 02865 return -1; 02866 02867 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE) 02868 struct rlimit rl; 02869 02870 ACE_OS::memset ((void *) &rl, 0, sizeof rl); 02871 int r = ACE_OS::getrlimit (RLIMIT_NOFILE, &rl); 02872 if (r == 0) 02873 max_limit = rl.rlim_max; 02874 #endif /* ACE_LACKS_RLIMIT */ 02875 02876 if (new_limit == -1) 02877 new_limit = max_limit; 02878 02879 if (new_limit < 0) 02880 { 02881 errno = EINVAL; 02882 return -1; 02883 } 02884 else if (new_limit > cur_limit) 02885 { 02886 // Increase the limit. 02887 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE) 02888 rl.rlim_cur = new_limit; 02889 return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl); 02890 #elif !defined (RLIMIT_NOFILE) 02891 return 0; 02892 #else 02893 // Must return EINVAL errno. 02894 ACE_NOTSUP_RETURN (-1); 02895 #endif /* ACE_LACKS_RLIMIT */ 02896 } 02897 else if (increase_limit_only == 0) 02898 { 02899 // Decrease the limit. 02900 #if !defined (ACE_LACKS_RLIMIT) && defined (RLIMIT_NOFILE) 02901 rl.rlim_cur = new_limit; 02902 return ACE_OS::setrlimit (RLIMIT_NOFILE, &rl); 02903 #else 02904 // We give a chance to platforms without RLIMIT to work. 02905 // Instead of ACE_NOTSUP_RETURN (0), just return 0 because 02906 // new_limit is <= cur_limit, so it's a no-op. 02907 return 0; 02908 #endif /* ACE_LACKS_RLIMIT */ 02909 } 02910 02911 return 0; 02912 }
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 2989 of file ACE.cpp.
02990 { 02991 #if defined (ACE_WIN32) 02992 static ACE_TCHAR unknown_msg[64]; 02993 02994 switch (error) 02995 { 02996 case WSAVERNOTSUPPORTED: 02997 return ACE_TEXT ("version of WinSock not supported"); 02998 /* NOTREACHED */ 02999 case WSASYSNOTREADY: 03000 return ACE_TEXT ("WinSock not present or not responding"); 03001 /* NOTREACHED */ 03002 case WSAEINVAL: 03003 return ACE_TEXT ("app version not supported by DLL"); 03004 /* NOTREACHED */ 03005 case WSAHOST_NOT_FOUND: 03006 return ACE_TEXT ("Authoritive: Host not found"); 03007 /* NOTREACHED */ 03008 case WSATRY_AGAIN: 03009 return ACE_TEXT ("Non-authoritive: host not found or server failure"); 03010 /* NOTREACHED */ 03011 case WSANO_RECOVERY: 03012 return ACE_TEXT ("Non-recoverable: refused or not implemented"); 03013 /* NOTREACHED */ 03014 case WSANO_DATA: 03015 return ACE_TEXT ("Valid name, no data record for type"); 03016 /* NOTREACHED */ 03017 /* 03018 case WSANO_ADDRESS: 03019 return "Valid name, no MX record"; 03020 */ 03021 case WSANOTINITIALISED: 03022 return ACE_TEXT ("WSA Startup not initialized"); 03023 /* NOTREACHED */ 03024 case WSAENETDOWN: 03025 return ACE_TEXT ("Network subsystem failed"); 03026 /* NOTREACHED */ 03027 case WSAEINPROGRESS: 03028 return ACE_TEXT ("Blocking operation in progress"); 03029 /* NOTREACHED */ 03030 case WSAEINTR: 03031 return ACE_TEXT ("Blocking call cancelled"); 03032 /* NOTREACHED */ 03033 case WSAEAFNOSUPPORT: 03034 return ACE_TEXT ("address family not supported"); 03035 /* NOTREACHED */ 03036 case WSAEMFILE: 03037 return ACE_TEXT ("no file handles available"); 03038 /* NOTREACHED */ 03039 case WSAENOBUFS: 03040 return ACE_TEXT ("no buffer space available"); 03041 /* NOTREACHED */ 03042 case WSAEPROTONOSUPPORT: 03043 return ACE_TEXT ("specified protocol not supported"); 03044 /* NOTREACHED */ 03045 case WSAEPROTOTYPE: 03046 return ACE_TEXT ("protocol wrong type for this socket"); 03047 /* NOTREACHED */ 03048 case WSAESOCKTNOSUPPORT: 03049 return ACE_TEXT ("socket type not supported for address family"); 03050 /* NOTREACHED */ 03051 case WSAENOTSOCK: 03052 return ACE_TEXT ("handle is not a socket"); 03053 /* NOTREACHED */ 03054 case WSAEWOULDBLOCK: 03055 return ACE_TEXT ("resource temporarily unavailable"); 03056 /* NOTREACHED */ 03057 case WSAEADDRINUSE: 03058 return ACE_TEXT ("address already in use"); 03059 /* NOTREACHED */ 03060 case WSAECONNABORTED: 03061 return ACE_TEXT ("connection aborted"); 03062 /* NOTREACHED */ 03063 case WSAECONNRESET: 03064 return ACE_TEXT ("connection reset"); 03065 /* NOTREACHED */ 03066 case WSAENOTCONN: 03067 return ACE_TEXT ("not connected"); 03068 /* NOTREACHED */ 03069 case WSAETIMEDOUT: 03070 return ACE_TEXT ("connection timed out"); 03071 /* NOTREACHED */ 03072 case WSAECONNREFUSED: 03073 return ACE_TEXT ("connection refused"); 03074 /* NOTREACHED */ 03075 case WSAEHOSTDOWN: 03076 return ACE_TEXT ("host down"); 03077 /* NOTREACHED */ 03078 case WSAEHOSTUNREACH: 03079 return ACE_TEXT ("host unreachable"); 03080 /* NOTREACHED */ 03081 case WSAEADDRNOTAVAIL: 03082 return ACE_TEXT ("address not available"); 03083 /* NOTREACHED */ 03084 case WSAEISCONN: 03085 return ACE_TEXT ("socket is already connected"); 03086 /* NOTREACHED */ 03087 case WSAENETRESET: 03088 return ACE_TEXT ("network dropped connection on reset"); 03089 /* NOTREACHED */ 03090 case WSAEMSGSIZE: 03091 return ACE_TEXT ("message too long"); 03092 /* NOTREACHED */ 03093 case WSAENETUNREACH: 03094 return ACE_TEXT ("network is unreachable"); 03095 /* NOTREACHED */ 03096 case WSAEFAULT: 03097 return ACE_TEXT ("bad address"); 03098 /* NOTREACHED */ 03099 case WSAEDISCON: 03100 return ACE_TEXT ("graceful shutdown in progress"); 03101 /* NOTREACHED */ 03102 case WSAEACCES: 03103 return ACE_TEXT ("permission denied"); 03104 /* NOTREACHED */ 03105 case WSAESHUTDOWN: 03106 return ACE_TEXT ("cannot send after socket shutdown"); 03107 /* NOTREACHED */ 03108 case WSAEPROCLIM: 03109 return ACE_TEXT ("too many processes"); 03110 /* NOTREACHED */ 03111 case WSAEALREADY: 03112 return ACE_TEXT ("operation already in progress"); 03113 /* NOTREACHED */ 03114 case WSAEPFNOSUPPORT: 03115 return ACE_TEXT ("protocol family not supported"); 03116 /* NOTREACHED */ 03117 case WSAENOPROTOOPT: 03118 return ACE_TEXT ("bad protocol option"); 03119 /* NOTREACHED */ 03120 case WSATYPE_NOT_FOUND: 03121 return ACE_TEXT ("class type not found"); 03122 /* NOTREACHED */ 03123 case WSAEOPNOTSUPP: 03124 return ACE_TEXT ("operation not supported"); 03125 /* NOTREACHED */ 03126 case WSAEDESTADDRREQ: 03127 return ACE_TEXT ("destination address required"); 03128 /* NOTREACHED */ 03129 default: 03130 ACE_OS::snprintf (unknown_msg, 03131 sizeof unknown_msg / sizeof unknown_msg[0], 03132 ACE_TEXT ("unknown error: %d"), error); 03133 return unknown_msg; 03134 /* NOTREACHED */ 03135 } 03136 #else 03137 ACE_UNUSED_ARG (error); 03138 ACE_NOTSUP_RETURN (0); 03139 #endif /* ACE_WIN32 */ 03140 }
void ACE::strdelete | ( | wchar_t * | s | ) | [inline] |
void ACE::strdelete | ( | char * | s | ) | [inline] |
Delete the memory allocated by strnew
.
Definition at line 256 of file ACE.inl.
00257 { 00258 #if defined (ACE_HAS_ALLOC_HOOKS) 00259 ACE_Allocator::instance()->free(s); 00260 #else 00261 delete [] s; 00262 #endif /* ACE_HAS_ALLOC_HOOKS */ 00263 }
Definition at line 3315 of file ACE.cpp.
03316 { 03317 while (*s++ != ACE_TEXT_WIDE ('\0')) 03318 continue; 03319 03320 return s; 03321 }
const char * ACE::strend | ( | const char * | s | ) |
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.
00378 { 00379 ACE_TRACE ("ACE::strenvdup"); 00380 00381 return ACE_OS::strenvdup (str); 00382 }
Definition at line 3230 of file ACE.cpp.
03231 { 03232 const wchar_t *t = str; 03233 size_t len; 03234 03235 // Figure out how long this string is (remember, it might not be 03236 // NUL-terminated). 03237 03238 for (len = 0; 03239 len < n && *t++ != '\0'; 03240 len++) 03241 continue; 03242 03243 wchar_t *s; 03244 ACE_ALLOCATOR_RETURN (s, 03245 static_cast<wchar_t *> ( 03246 ACE_OS::malloc ((len + 1) * sizeof (wchar_t))), 03247 0); 03248 return ACE_OS::strsncpy (s, str, len + 1); 03249 }
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 3202 of file ACE.cpp.
03203 { 03204 const char *t = str; 03205 size_t len; 03206 03207 // Figure out how long this string is (remember, it might not be 03208 // NUL-terminated). 03209 03210 for (len = 0; 03211 len < n && *t++ != '\0'; 03212 len++) 03213 continue; 03214 03215 char *s; 03216 #if defined (ACE_HAS_ALLOC_HOOKS) 03217 ACE_ALLOCATOR_RETURN (s, 03218 (char *) ACE_Allocator::instance()->malloc (len + 1), 03219 0); 03220 #else 03221 ACE_ALLOCATOR_RETURN (s, 03222 (char *) ACE_OS::malloc (len + 1), 03223 0); 03224 #endif /* ACE_HAS_ALLOC_HOOKS */ 03225 return ACE_OS::strsncpy (s, str, len + 1); 03226 }
Definition at line 3345 of file ACE.cpp.
03346 { 03347 if (s == 0) 03348 return 0; 03349 wchar_t *t = 0; 03350 ACE_NEW_RETURN (t, 03351 wchar_t[ACE_OS::strlen (s) + 1], 03352 0); 03353 return ACE_OS::strcpy (t, s); 03354 }
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 3325 of file ACE.cpp.
03326 { 03327 if (s == 0) 03328 return 0; 03329 char *t = 0; 03330 #if defined (ACE_HAS_ALLOC_HOOKS) 03331 ACE_ALLOCATOR_RETURN (t, 03332 static_cast<char*> (ACE_Allocator::instance ()->malloc (sizeof (char) * (ACE_OS::strlen (s) + 1))), 03333 0); 03334 #else 03335 ACE_NEW_RETURN (t, 03336 char [ACE_OS::strlen (s) + 1], 03337 0); 03338 #endif /* ACE_HAS_ALLOC_HOOKS */ 03339 03340 return ACE_OS::strcpy (t, s); 03341 }
Definition at line 3283 of file ACE.cpp.
03284 { 03285 const wchar_t *t = str; 03286 size_t len; 03287 03288 // Figure out how long this string is (remember, it might not be 03289 // NUL-terminated). 03290 03291 for (len = 0; 03292 len < n && *t++ != ACE_TEXT_WIDE ('\0'); 03293 len++) 03294 continue; 03295 03296 wchar_t *s; 03297 ACE_NEW_RETURN (s, 03298 wchar_t[len + 1], 03299 0); 03300 return ACE_OS::strsncpy (s, str, len + 1); 03301 }
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 3253 of file ACE.cpp.
03254 { 03255 const char *t = str; 03256 size_t len; 03257 03258 // Figure out how long this string is (remember, it might not be 03259 // NUL-terminated). 03260 03261 for (len = 0; 03262 len < n && *t++ != L'\0'; 03263 len++) 03264 continue; 03265 03266 char *s; 03267 03268 #if defined (ACE_HAS_ALLOC_HOOKS) 03269 ACE_ALLOCATOR_RETURN (s, 03270 static_cast<char*> (ACE_Allocator::instance ()->malloc (sizeof (char) * (len + 1))), 03271 0); 03272 #else 03273 ACE_NEW_RETURN (s, 03274 char[len + 1], 03275 0); 03276 #endif /* ACE_HAS_ALLOC_HOOKS */ 03277 03278 return ACE_OS::strsncpy (s, str, len + 1); 03279 }
As strrepl, but for wide characters.
Definition at line 771 of file Lib_Find.cpp.
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 683 of file Lib_Find.cpp.
As strsplit_r, but for wide characters.
Definition at line 738 of file Lib_Find.cpp.
00741 { 00742 wchar_t *result = 0; 00743 00744 if (str != 0) 00745 next_start = str; 00746 00747 if (next_start != 0) 00748 { 00749 wchar_t *tok_loc = ACE_OS::strstr (next_start, token); 00750 00751 if (tok_loc != 0) 00752 { 00753 // Return the beginning of the string. 00754 result = next_start; 00755 00756 // Insure it's terminated. 00757 *tok_loc = '\0'; 00758 next_start = tok_loc + ACE_OS::strlen (token); 00759 } 00760 else 00761 { 00762 result = next_start; 00763 next_start = (wchar_t *) 0; 00764 } 00765 } 00766 00767 return result; 00768 }
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 704 of file Lib_Find.cpp.
00707 { 00708 char *result = 0; 00709 00710 if (str != 0) 00711 next_start = str; 00712 00713 if (next_start != 0) 00714 { 00715 char *tok_loc = ACE_OS::strstr (next_start, token); 00716 00717 if (tok_loc != 0) 00718 { 00719 // Return the beginning of the string. 00720 result = next_start; 00721 00722 // Insure it's terminated. 00723 *tok_loc = '\0'; 00724 next_start = tok_loc + ACE_OS::strlen (token); 00725 } 00726 else 00727 { 00728 result = next_start; 00729 next_start = (char *) 0; 00730 } 00731 } 00732 00733 return result; 00734 }
ssize_t ACE::t_rcv | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int * | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 471 of file ACE.cpp.
00476 { 00477 if (timeout == 0) 00478 return ACE_OS::t_rcv (handle, (char *) buf, len, flags); 00479 else 00480 { 00481 int val = 0; 00482 if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1) 00483 return -1; 00484 else 00485 { 00486 ssize_t bytes_transferred = 00487 ACE_OS::t_rcv (handle, (char *) buf, len, flags); 00488 ACE::restore_non_blocking_mode (handle, val); 00489 return bytes_transferred; 00490 } 00491 } 00492 }
ssize_t ACE::t_rcv_n | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int * | flags, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) | [inline] |
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 63 of file ACE.inl.
00069 { 00070 if (timeout == 0) 00071 return ACE::t_rcv_n_i (handle, 00072 buf, 00073 len, 00074 flags, 00075 bytes_transferred); 00076 else 00077 return ACE::t_rcv_n_i (handle, 00078 buf, 00079 len, 00080 flags, 00081 timeout, 00082 bytes_transferred); 00083 }
ssize_t ACE::t_rcv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int * | flags, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 735 of file ACE.cpp.
00741 { 00742 size_t temp; 00743 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00744 ssize_t n; 00745 ssize_t result = 0; 00746 int error = 0; 00747 00748 int val = 0; 00749 ACE::record_and_set_non_blocking_mode (handle, val); 00750 00751 for (bytes_transferred = 0; 00752 bytes_transferred < len; 00753 bytes_transferred += n) 00754 { 00755 // Try to transfer as much of the remaining data as possible. 00756 // Since the socket is in non-blocking mode, this call will not 00757 // block. 00758 n = ACE_OS::t_rcv (handle, 00759 (char *) buf + bytes_transferred, 00760 len - bytes_transferred, 00761 flags); 00762 00763 // Check for errors. 00764 if (n == 0 || 00765 n == -1) 00766 { 00767 // Check for possible blocking. 00768 if (n == -1 && 00769 errno == EWOULDBLOCK) 00770 { 00771 // Wait upto <timeout> for the blocking to subside. 00772 int const rtn = ACE::handle_read_ready (handle, timeout); 00773 00774 // Did select() succeed? 00775 if (rtn != -1) 00776 { 00777 // Blocking subsided in <timeout> period. Continue 00778 // data transfer. 00779 n = 0; 00780 continue; 00781 } 00782 } 00783 00784 // Wait in select() timed out or other data transfer or 00785 // select() failures. 00786 error = 1; 00787 result = n; 00788 break; 00789 } 00790 } 00791 00792 ACE::restore_non_blocking_mode (handle, val); 00793 00794 if (error) 00795 return result; 00796 else 00797 return bytes_transferred; 00798 }
ssize_t ACE::t_rcv_n_i | ( | ACE_HANDLE | handle, | |
void * | buf, | |||
size_t | len, | |||
int * | flags, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 685 of file ACE.cpp.
00690 { 00691 size_t temp; 00692 size_t &bytes_transferred = bt == 0 ? temp : *bt; 00693 ssize_t n; 00694 00695 for (bytes_transferred = 0; 00696 bytes_transferred < len; 00697 bytes_transferred += n) 00698 { 00699 // Try to transfer as much of the remaining data as possible. 00700 n = ACE_OS::t_rcv (handle, 00701 (char *) buf + bytes_transferred, 00702 len - bytes_transferred, 00703 flags); 00704 // Check EOF. 00705 if (n == 0) 00706 return 0; 00707 00708 // Check for other errors. 00709 if (n == -1) 00710 { 00711 // Check for possible blocking. 00712 if (errno == EWOULDBLOCK) 00713 { 00714 // Wait for the blocking to subside. 00715 int const result = ACE::handle_read_ready (handle, 0); 00716 00717 // Did select() succeed? 00718 if (result != -1) 00719 { 00720 // Blocking subsided. Continue data transfer. 00721 n = 0; 00722 continue; 00723 } 00724 } 00725 00726 // Other data transfer or select() failures. 00727 return -1; 00728 } 00729 } 00730 00731 return bytes_transferred; 00732 }
ssize_t ACE::t_snd | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 | |||
) |
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 1247 of file ACE.cpp.
01252 { 01253 if (timeout == 0) 01254 return ACE_OS::t_snd (handle, (const char *) buf, n, flags); 01255 else 01256 { 01257 int val = 0; 01258 if (ACE::enter_send_timedwait (handle, timeout, val) == -1) 01259 return -1; 01260 else 01261 { 01262 ssize_t const bytes_transferred = 01263 ACE_OS::t_snd (handle, (const char *) buf, n, flags); 01264 ACE::restore_non_blocking_mode (handle, val); 01265 return bytes_transferred; 01266 } 01267 } 01268 }
ssize_t ACE::t_snd_n | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout = 0 , |
|||
size_t * | bytes_transferred = 0 | |||
) | [inline] |
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 153 of file ACE.inl.
00159 { 00160 if (timeout == 0) 00161 return ACE::t_snd_n_i (handle, 00162 buf, 00163 len, 00164 flags, 00165 bytes_transferred); 00166 else 00167 return ACE::t_snd_n_i (handle, 00168 buf, 00169 len, 00170 flags, 00171 timeout, 00172 bytes_transferred); 00173 }
ssize_t ACE::t_snd_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
const ACE_Time_Value * | timeout, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1519 of file ACE.cpp.
01525 { 01526 size_t temp; 01527 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01528 ssize_t n; 01529 ssize_t result = 0; 01530 int error = 0; 01531 01532 int val = 0; 01533 ACE::record_and_set_non_blocking_mode (handle, val); 01534 01535 for (bytes_transferred = 0; 01536 bytes_transferred < len; 01537 bytes_transferred += n) 01538 { 01539 // Try to transfer as much of the remaining data as possible. 01540 // Since the socket is in non-blocking mode, this call will not 01541 // block. 01542 n = ACE_OS::t_snd (handle, 01543 (char *) buf + bytes_transferred, 01544 len - bytes_transferred, 01545 flags); 01546 01547 // Check for errors. 01548 if (n == 0 || 01549 n == -1) 01550 { 01551 // Check for possible blocking. 01552 if (n == -1 && 01553 (errno == EWOULDBLOCK || errno == ENOBUFS)) 01554 { 01555 // Wait upto <timeout> for the blocking to subside. 01556 int const rtn = ACE::handle_write_ready (handle, timeout); 01557 01558 // Did select() succeed? 01559 if (rtn != -1) 01560 { 01561 // Blocking subsided in <timeout> period. Continue 01562 // data transfer. 01563 n = 0; 01564 continue; 01565 } 01566 } 01567 01568 // Wait in select() timed out or other data transfer or 01569 // select() failures. 01570 error = 1; 01571 result = n; 01572 break; 01573 } 01574 } 01575 01576 ACE::restore_non_blocking_mode (handle, val); 01577 01578 if (error) 01579 return result; 01580 else 01581 return bytes_transferred; 01582 }
ssize_t ACE::t_snd_n_i | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
int | flags, | |||
size_t * | bytes_transferred | |||
) |
Definition at line 1469 of file ACE.cpp.
01474 { 01475 size_t temp; 01476 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01477 ssize_t n; 01478 01479 for (bytes_transferred = 0; 01480 bytes_transferred < len; 01481 bytes_transferred += n) 01482 { 01483 // Try to transfer as much of the remaining data as possible. 01484 n = ACE_OS::t_snd (handle, 01485 (char *) buf + bytes_transferred, 01486 len - bytes_transferred, 01487 flags); 01488 // Check EOF. 01489 if (n == 0) 01490 return 0; 01491 01492 // Check for other errors. 01493 if (n == -1) 01494 { 01495 // Check for possible blocking. 01496 if (errno == EWOULDBLOCK || errno == ENOBUFS) 01497 { 01498 // Wait for the blocking to subside. 01499 int const result = ACE::handle_write_ready (handle, 0); 01500 01501 // Did select() succeed? 01502 if (result != -1) 01503 { 01504 // Blocking subsided. Continue data transfer. 01505 n = 0; 01506 continue; 01507 } 01508 } 01509 01510 // Other data transfer or select() failures. 01511 return -1; 01512 } 01513 } 01514 01515 return bytes_transferred; 01516 }
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 225 of file ACE.cpp.
00226 { 00227 #if defined (ACE_HAS_PHARLAP) 00228 ACE_UNUSED_ARG (pid); 00229 ACE_NOTSUP_RETURN (-1); 00230 #elif defined (ACE_WIN32) 00231 // Create a handle for the given process id. 00232 ACE_HANDLE process_handle = 00233 ::OpenProcess (PROCESS_TERMINATE, 00234 FALSE, // New handle is not inheritable. 00235 pid); 00236 00237 if (process_handle == ACE_INVALID_HANDLE 00238 || process_handle == 0) 00239 return -1; 00240 else 00241 { 00242 // Kill the process associated with process_handle. 00243 BOOL terminate_result = 00244 ::TerminateProcess (process_handle, 0); 00245 // Free up the kernel resources. 00246 ACE_OS::close (process_handle); 00247 return terminate_result ? 0 : -1; 00248 } 00249 #else 00250 return ACE_OS::kill (pid, 9); 00251 #endif /* ACE_HAS_PHARLAP */ 00252 }
ACE_TCHAR * ACE::timestamp | ( | ACE_TCHAR | date_and_time[], | |
size_t | date_and_timelen, | |||
bool | return_pointer_to_first_digit = false | |||
) |
Translate the current time to ISO-8601 timestamp format.
date_and_time | Array to hold the timestamp. | |
time_len | Size of date_and_time in ACE_TCHARs. Must be greater than or equal to 27. | |
return_pointer_to_first_digit | If true, returned pointer value is to the first time digit, else to the space prior to the first time digit. See Return Values. |
0 | if unsuccessful, with errno set. If time_len is less than 27 errno will be EINVAL. | |
If | successful, pointer to beginning of the "time" portion of date_and_time. If return_pointer_to_first_digit is false the pointer is actually to the space before the time, else the pointer is to the first time digit. |
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 using ISO-8601 format.
Definition at line 2406 of file ACE.cpp.
02409 { 02410 return ACE::timestamp (ACE_Time_Value::zero, 02411 date_and_time, 02412 date_and_timelen, 02413 return_pointer_to_first_digit); 02414 }
ACE_TCHAR * ACE::timestamp | ( | const ACE_Time_Value & | time_value, | |
ACE_TCHAR | date_and_time[], | |||
size_t | date_and_timelen, | |||
bool | return_pointer_to_first_digit = false | |||
) |
Translate the given timestamp to ISO-8601 format.
time_value | ACE_Time_Value to format. This is assumed to be an absolute time value. | |
date_and_time | Array to hold the timestamp. | |
time_len | Size of date_and_time in ACE_TCHARs. Must be greater than or equal to 27. | |
return_pointer_to_first_digit | If true, returned pointer value is to the first time digit, else to the space prior to the first time digit. See Return Values. |
0 | if unsuccessful, with errno set. If time_len is less than 27 errno will be EINVAL. | |
If | successful, pointer to beginning of the "time" portion of date_and_time. If return_pointer_to_first_digit is false the pointer is actually to the space before the time, else the pointer is to the first time digit. |
Returns the given 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 using ISO-8601 format. 012345678901234567890123456 2010-12-02 12:56:00.123456<nul>
Definition at line 2423 of file ACE.cpp.
02427 { 02428 //ACE_TRACE ("ACE::timestamp"); 02429 02430 // This magic number is from the formatting statement 02431 // farther down this routine. 02432 if (date_and_timelen < 27) 02433 { 02434 errno = EINVAL; 02435 return 0; 02436 } 02437 02438 ACE_Time_Value cur_time = 02439 (time_value == ACE_Time_Value::zero) ? 02440 ACE_Time_Value (ACE_OS::gettimeofday ()) : time_value; 02441 time_t secs = cur_time.sec (); 02442 struct tm tms; 02443 ACE_OS::localtime_r (&secs, &tms); 02444 ACE_OS::snprintf (date_and_time, 02445 date_and_timelen, 02446 ACE_TEXT ("%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d.%06ld"), 02447 tms.tm_year + 1900, 02448 tms.tm_mon + 1, 02449 tms.tm_mday, 02450 tms.tm_hour, 02451 tms.tm_min, 02452 tms.tm_sec, 02453 static_cast<long> (cur_time.usec())); 02454 date_and_time[date_and_timelen - 1] = '\0'; 02455 return &date_and_time[10 + (return_pointer_to_first_digit != 0)]; 02456 }
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 290 of file ACE.inl.
00293 { 00294 ACE_OS::unique_name (object, name, length); 00295 }
bool ACE::wild_match | ( | const char * | s, | |
const char * | pattern, | |||
bool | case_sensitive = true , |
|||
bool | character_classes = false | |||
) |
Simple wildcard matching function supporting '*' and '?' return true if string s matches pattern. If character_classes is true, '[' is treated as a wildcard character as described in the fnmatch() POSIX API. The following POSIX "bracket expression" features are not implemented: collating symbols, equivalence class expressions, and character class expressions. The POSIX locale is assumed.
Definition at line 3414 of file ACE.cpp.
03416 { 03417 if (str == pat) 03418 return true; 03419 if (pat == 0 || str == 0) 03420 return false; 03421 03422 bool star = false, escape = false; 03423 const char *s = str; 03424 const char *p = pat; 03425 while (*s != '\0') 03426 { 03427 if (!escape && *p == '\\') 03428 { 03429 ++p; 03430 escape = true; 03431 } 03432 else if (!escape && *p == '*') 03433 { 03434 star = true; 03435 pat = p; 03436 while (*++pat == '*') {} 03437 03438 if (*pat == '\0') 03439 return true; 03440 p = pat; 03441 } 03442 else if (!escape && *p == '?') 03443 { 03444 ++s; 03445 ++p; 03446 } 03447 else if (!escape && character_classes && *p == '[') 03448 { 03449 if (equal_class (*s, p, case_sensitive)) 03450 { 03451 ++p; 03452 } 03453 else 03454 { 03455 if (!star) 03456 return false; 03457 p = pat; 03458 } 03459 ++s; 03460 } 03461 else if (!equal_char (*s, *p, case_sensitive)) 03462 { 03463 if (!star) 03464 return false; 03465 ++s; 03466 p = pat; 03467 escape = false; 03468 } 03469 else 03470 { 03471 ++s; 03472 ++p; 03473 escape = false; 03474 } 03475 } 03476 if (*p == '*') 03477 while (*++p == '*') {} 03478 03479 return *p == '\0'; 03480 }
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 1919 of file ACE.cpp.
01922 { 01923 size_t temp; 01924 size_t &bytes_transferred = bt == 0 ? temp : *bt; 01925 bytes_transferred = 0; 01926 01927 iovec iov[ACE_IOV_MAX]; 01928 int iovcnt = 0; 01929 01930 while (message_block != 0) 01931 { 01932 // Our current message block chain. 01933 const ACE_Message_Block *current_message_block = message_block; 01934 01935 while (current_message_block != 0) 01936 { 01937 size_t current_message_block_length = 01938 current_message_block->length (); 01939 char *this_block_ptr = current_message_block->rd_ptr (); 01940 01941 // Check if this block has any data to be sent. 01942 while (current_message_block_length > 0) 01943 { 01944 u_long const this_chunk_length = 01945 ACE_Utils::truncate_cast<u_long> ( 01946 current_message_block_length); 01947 01948 // Collect the data in the iovec. 01949 iov[iovcnt].iov_base = this_block_ptr; 01950 iov[iovcnt].iov_len = this_chunk_length; 01951 current_message_block_length -= this_chunk_length; 01952 this_block_ptr += this_chunk_length; 01953 01954 // Increment iovec counter. 01955 ++iovcnt; 01956 01957 // The buffer is full make a OS call. @@ TODO find a way to 01958 // find ACE_IOV_MAX for platforms that do not define it rather 01959 // than simply setting ACE_IOV_MAX to some arbitrary value such 01960 // as 16. 01961 if (iovcnt == ACE_IOV_MAX) 01962 { 01963 size_t current_transfer = 0; 01964 01965 ssize_t const result = ACE::writev_n (handle, 01966 iov, 01967 iovcnt, 01968 ¤t_transfer); 01969 01970 // Add to total bytes transferred. 01971 bytes_transferred += current_transfer; 01972 01973 // Errors. 01974 if (result == -1 || result == 0) 01975 return result; 01976 01977 // Reset iovec counter. 01978 iovcnt = 0; 01979 } 01980 } 01981 01982 // Select the next message block in the chain. 01983 current_message_block = current_message_block->cont (); 01984 } 01985 01986 // Selection of the next message block chain. 01987 message_block = message_block->next (); 01988 } 01989 01990 // Check for remaining buffers to be sent. This will happen when 01991 // ACE_IOV_MAX is not a multiple of the number of message blocks. 01992 if (iovcnt != 0) 01993 { 01994 size_t current_transfer = 0; 01995 01996 ssize_t const result = ACE::writev_n (handle, 01997 iov, 01998 iovcnt, 01999 ¤t_transfer); 02000 02001 // Add to total bytes transferred. 02002 bytes_transferred += current_transfer; 02003 02004 // Errors. 02005 if (result == -1 || result == 0) 02006 return result; 02007 } 02008 02009 // Return total bytes transferred. 02010 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 02011 }
ssize_t ACE::write_n | ( | ACE_HANDLE | handle, | |
const void * | buf, | |||
size_t | len, | |||
size_t * | bytes_transferred = 0 | |||
) | [inline] |
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 26 of file ACE.inl.
00030 { 00031 return ACE_OS::write_n (handle, 00032 buf, 00033 len, 00034 bytes_transferred); 00035 }
ssize_t ACE::writev_n | ( | ACE_HANDLE | handle, | |
const iovec * | iov, | |||
int | iovcnt, | |||
size_t * | bytes_transferred = 0 | |||
) |
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 2153 of file ACE.cpp.
02157 { 02158 size_t temp; 02159 size_t &bytes_transferred = bt == 0 ? temp : *bt; 02160 bytes_transferred = 0; 02161 02162 iovec *iov = const_cast<iovec *> (i); 02163 02164 for (int s = 0; 02165 s < iovcnt; 02166 ) 02167 { 02168 ssize_t n = ACE_OS::writev (handle, 02169 iov + s, 02170 iovcnt - s); 02171 02172 if (n == -1 || n == 0) 02173 { 02174 return n; 02175 } 02176 02177 for (bytes_transferred += n; 02178 s < iovcnt 02179 && n >= static_cast<ssize_t> (iov[s].iov_len); 02180 s++) 02181 n -= iov[s].iov_len; 02182 02183 if (n != 0) 02184 { 02185 char *base = reinterpret_cast<char *> (iov[s].iov_base); 02186 iov[s].iov_base = base + n; 02187 // This blind cast is safe because n < iov_len, after above loop. 02188 iov[s].iov_len = iov[s].iov_len - static_cast<u_long> (n); 02189 } 02190 } 02191 02192 return ACE_Utils::truncate_cast<ssize_t> (bytes_transferred); 02193 }
char ACE::debug_ |
unsigned int ACE::init_fini_count_ = 0 |
size_t ACE::pagesize_ = 0 |