diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-04-19 05:36:30 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-04-19 05:36:30 +0000 |
commit | 4b7dc1d9f044b32ae12c0ab57c467574de53b5ba (patch) | |
tree | 6e2b2452a31672fc3b0187fad324f76daa9c071c /ace | |
parent | b071b5699f35956ff5291ec8d9a5bf0f2978fdaa (diff) | |
download | ATCD-4b7dc1d9f044b32ae12c0ab57c467574de53b5ba.tar.gz |
ChangeLogTag: Wed Apr 19 00:00:29 2000 Irfan Pyarali <irfan@cs.wustl.edu>
Diffstat (limited to 'ace')
-rw-r--r-- | ace/ACE.cpp | 925 | ||||
-rw-r--r-- | ace/ACE.h | 157 | ||||
-rw-r--r-- | ace/ACE.i | 122 | ||||
-rw-r--r-- | ace/OS.cpp | 34 | ||||
-rw-r--r-- | ace/OS.h | 24 | ||||
-rw-r--r-- | ace/OS.i | 56 | ||||
-rw-r--r-- | ace/SOCK_Stream.h | 18 | ||||
-rw-r--r-- | ace/SOCK_Stream.i | 18 | ||||
-rw-r--r-- | ace/TLI_Stream.h | 40 | ||||
-rw-r--r-- | ace/TLI_Stream.i | 114 |
10 files changed, 1082 insertions, 426 deletions
diff --git a/ace/ACE.cpp b/ace/ACE.cpp index bbd77c5c121..ecacb7bb570 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -15,8 +15,8 @@ ACE_RCSID(ace, ACE, "$Id$") -// Static data members. -u_int ACE::init_fini_count_ = 0; + // Static data members. + u_int ACE::init_fini_count_ = 0; // Keeps track of whether we're in some global debug mode. char ACE::debug_ = 0; @@ -56,8 +56,8 @@ ACE::out_of_handles (int error) #elif defined (__FreeBSD__) // On FreeBSD we need to check for EOPNOTSUPP (LinuxThreads) or // ENOSYS (libc_r threads) also. - error == EOPNOTSUPP || - error == ENOSYS || + error == EOPNOTSUPP || + error == ENOSYS || #endif /* ACE_WIN32 */ error == ENFILE) return 1; @@ -186,11 +186,11 @@ ACE::terminate_process (pid_t pid) # if defined(CHORUS_4) if (::acap (pid, &cap_) == 0) # else - if (::acap (AM_MYSITE, pid, &cap_) == 0) + if (::acap (AM_MYSITE, pid, &cap_) == 0) # endif - return ::akill (&cap_); - else - return -1; + return ::akill (&cap_); + else + return -1; #else return ACE_OS::kill (pid, 9); #endif /* ACE_WIN32 */ @@ -670,15 +670,15 @@ ACE::ldfind (const ASYS_TCHAR filename[], #if !defined (ACE_HAS_MOSTLY_UNICODE_APIS) if (::ExpandEnvironmentStringsA (filename, expanded_filename, - (sizeof expanded_filename - / sizeof (ASYS_TCHAR)))) + (sizeof expanded_filename + / sizeof (ASYS_TCHAR)))) #else - if (::ExpandEnvironmentStringsW (filename, - expanded_filename, - (sizeof expanded_filename - / sizeof (ASYS_TCHAR)))) + if (::ExpandEnvironmentStringsW (filename, + expanded_filename, + (sizeof expanded_filename + / sizeof (ASYS_TCHAR)))) #endif /* ACE_HAS_MOSTLY_UNICODE_APIS */ - filename = expanded_filename; + filename = expanded_filename; #endif /* ACE_WIN32 && !ACE_HAS_WINCE && !ACE_HAS_PHARLAP */ ASYS_TCHAR tempcopy[MAXPATHLEN + 1]; @@ -769,213 +769,213 @@ ACE::ldfind (const ASYS_TCHAR filename[], searchfilename [len_searchfilename] = 0; #endif /* ACE_WIN32 && _DEBUG && !ACE_DISABLE_DEBUG_DLL_CHECK */ - // Use absolute pathname if there is one. - if (ACE_OS::strlen (searchpathname) > 0) - { - if (ACE_OS::strlen (searchfilename) - + ACE_OS::strlen (searchpathname) >= maxpathnamelen) + // Use absolute pathname if there is one. + if (ACE_OS::strlen (searchpathname) > 0) { - errno = ENOMEM; - return -1; - } - else - { -#if (ACE_DIRECTORY_SEPARATOR_CHAR != '/') - // Revert to native path name separators. - ACE::strrepl (searchpathname, - '/', - ACE_DIRECTORY_SEPARATOR_CHAR); -#endif /* ACE_DIRECTORY_SEPARATOR_CHAR */ - // First, try matching the filename *without* adding a - // prefix. -#if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) - ACE_OS::sprintf (pathname, - ASYS_TEXT ("%s%s%s"), - searchpathname, - searchfilename, - got_suffix ? ACE_static_cast (char *, - ASYS_TEXT ("")) - : ACE_static_cast (char *, - dll_suffix)); -#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - ACE_OS::sprintf (pathname, - ASYS_TEXT ("%s%s%s"), - searchpathname, - searchfilename, - got_suffix ? ASYS_TEXT ("") : dll_suffix); -#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - if (ACE_OS::access (pathname, F_OK) == 0) - return 0; - - // Second, try matching the filename *with* adding a prefix. -#if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) - ACE_OS::sprintf (pathname, - ASYS_TEXT ("%s%s%s%s"), - searchpathname, - ACE_DLL_PREFIX, - searchfilename, - got_suffix ? ACE_static_cast (char *, - ASYS_TEXT ("")) - : ACE_static_cast (char *, - dll_suffix)); -#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - ACE_OS::sprintf (pathname, - ASYS_TEXT ("%s%s%s%s"), - searchpathname, - ACE_DLL_PREFIX, - searchfilename, - got_suffix ? ASYS_TEXT ("") : dll_suffix); -#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - if (ACE_OS::access (pathname, F_OK) == 0) - return 0; - } - } - - // Use relative filenames via LD_LIBRARY_PATH or PATH (depending on - // OS platform). - else - { - char *ld_path = -#if defined ACE_DEFAULT_LD_SEARCH_PATH - ACE_DEFAULT_LD_SEARCH_PATH; -#else - ACE_OS::getenv (ACE_LD_SEARCH_PATH); -#endif /* ACE_DEFAULT_LD_SEARCH_PATH */ - -#if defined (ACE_WIN32) - char *ld_path_temp = 0; - if (ld_path != 0) - { - ld_path_temp = (char *) ACE_OS::malloc (ACE_OS::strlen (ld_path) + 2); - if (ld_path_temp != 0) + if (ACE_OS::strlen (searchfilename) + + ACE_OS::strlen (searchpathname) >= maxpathnamelen) { - ACE_OS::strcpy (ld_path_temp, ACE_LD_SEARCH_PATH_SEPARATOR_STR); - ACE_OS::strcat (ld_path_temp, ld_path); - ld_path = ld_path_temp; + errno = ENOMEM; + return -1; } else { - ACE_OS::free ((void *) ld_path_temp); - ld_path = ld_path_temp = 0; - } - } -#endif /* ACE_WIN32 */ - - if (ld_path != 0 - && (ld_path = ACE_OS::strdup (ld_path)) != 0) - { - // strtok has the strange behavior of not separating the - // string ":/foo:/bar" into THREE tokens. One would expect - // that the first iteration the token would be an empty - // string, the second iteration would be "/foo", and the - // third iteration would be "/bar". However, this is not - // the case; one only gets two iterations: "/foo" followed - // by "/bar". - - // This is especially a problem in parsing Unix paths - // because it is permissible to specify 'the current - // directory' as an empty entry. So, we introduce the - // following special code to cope with this: - - // Look at each dynamic lib directory in the search path. - - char *nextholder = 0; - const char *path_entry = - ACE::strsplit_r (ld_path, - ACE_LD_SEARCH_PATH_SEPARATOR_STR, - nextholder); - int result = 0; - - for (;;) - { - // Check if at end of search path. - if (path_entry == 0) - { - errno = ENOENT; - result = -1; - break; - } - else if (ACE_OS::strlen (path_entry) - + 1 - + ACE_OS::strlen (searchfilename) - >= maxpathnamelen) - { - errno = ENOMEM; - result = -1; - break; - } - // This works around the issue where a path might have - // an empty component indicating 'current directory'. - // We need to do it here rather than anywhere else so - // that the loop condition will still work. - else if (path_entry[0] == '\0') - path_entry = "."; - +#if (ACE_DIRECTORY_SEPARATOR_CHAR != '/') + // Revert to native path name separators. + ACE::strrepl (searchpathname, + '/', + ACE_DIRECTORY_SEPARATOR_CHAR); +#endif /* ACE_DIRECTORY_SEPARATOR_CHAR */ // First, try matching the filename *without* adding a // prefix. #if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) ACE_OS::sprintf (pathname, - ASYS_TEXT ("%s%c%s%s"), - path_entry, - ACE_DIRECTORY_SEPARATOR_CHAR, + ASYS_TEXT ("%s%s%s"), + searchpathname, searchfilename, got_suffix ? ACE_static_cast (char *, ASYS_TEXT ("")) - : ACE_static_cast (char *, - dll_suffix)); + : ACE_static_cast (char *, + dll_suffix)); #else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ ACE_OS::sprintf (pathname, - ASYS_TEXT ("%s%c%s%s"), - path_entry, - ACE_DIRECTORY_SEPARATOR_CHAR, + ASYS_TEXT ("%s%s%s"), + searchpathname, searchfilename, got_suffix ? ASYS_TEXT ("") : dll_suffix); #endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ if (ACE_OS::access (pathname, F_OK) == 0) - break; + return 0; - // Second, try matching the filename *with* adding a - // prefix. + // Second, try matching the filename *with* adding a prefix. #if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) ACE_OS::sprintf (pathname, - ASYS_TEXT ("%s%c%s%s%s"), - path_entry, - ACE_DIRECTORY_SEPARATOR_CHAR, + ASYS_TEXT ("%s%s%s%s"), + searchpathname, ACE_DLL_PREFIX, searchfilename, got_suffix ? ACE_static_cast (char *, - ASYS_TEXT ("")) - : ACE_static_cast (char *, - dll_suffix)); + ASYS_TEXT ("")) + : ACE_static_cast (char *, + dll_suffix)); #else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ ACE_OS::sprintf (pathname, - ASYS_TEXT ("%s%c%s%s%s"), - path_entry, - ACE_DIRECTORY_SEPARATOR_CHAR, + ASYS_TEXT ("%s%s%s%s"), + searchpathname, ACE_DLL_PREFIX, searchfilename, got_suffix ? ASYS_TEXT ("") : dll_suffix); #endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ if (ACE_OS::access (pathname, F_OK) == 0) - break; + return 0; + } + } + + // Use relative filenames via LD_LIBRARY_PATH or PATH (depending on + // OS platform). + else + { + char *ld_path = +#if defined ACE_DEFAULT_LD_SEARCH_PATH + ACE_DEFAULT_LD_SEARCH_PATH; +#else + ACE_OS::getenv (ACE_LD_SEARCH_PATH); +#endif /* ACE_DEFAULT_LD_SEARCH_PATH */ - // Fetch the next item in the path - path_entry = ACE::strsplit_r (0, - ACE_LD_SEARCH_PATH_SEPARATOR_STR, - nextholder); +#if defined (ACE_WIN32) + char *ld_path_temp = 0; + if (ld_path != 0) + { + ld_path_temp = (char *) ACE_OS::malloc (ACE_OS::strlen (ld_path) + 2); + if (ld_path_temp != 0) + { + ACE_OS::strcpy (ld_path_temp, ACE_LD_SEARCH_PATH_SEPARATOR_STR); + ACE_OS::strcat (ld_path_temp, ld_path); + ld_path = ld_path_temp; + } + else + { + ACE_OS::free ((void *) ld_path_temp); + ld_path = ld_path_temp = 0; + } } +#endif /* ACE_WIN32 */ + + if (ld_path != 0 + && (ld_path = ACE_OS::strdup (ld_path)) != 0) + { + // strtok has the strange behavior of not separating the + // string ":/foo:/bar" into THREE tokens. One would expect + // that the first iteration the token would be an empty + // string, the second iteration would be "/foo", and the + // third iteration would be "/bar". However, this is not + // the case; one only gets two iterations: "/foo" followed + // by "/bar". + + // This is especially a problem in parsing Unix paths + // because it is permissible to specify 'the current + // directory' as an empty entry. So, we introduce the + // following special code to cope with this: + + // Look at each dynamic lib directory in the search path. + + char *nextholder = 0; + const char *path_entry = + ACE::strsplit_r (ld_path, + ACE_LD_SEARCH_PATH_SEPARATOR_STR, + nextholder); + int result = 0; + + for (;;) + { + // Check if at end of search path. + if (path_entry == 0) + { + errno = ENOENT; + result = -1; + break; + } + else if (ACE_OS::strlen (path_entry) + + 1 + + ACE_OS::strlen (searchfilename) + >= maxpathnamelen) + { + errno = ENOMEM; + result = -1; + break; + } + // This works around the issue where a path might have + // an empty component indicating 'current directory'. + // We need to do it here rather than anywhere else so + // that the loop condition will still work. + else if (path_entry[0] == '\0') + path_entry = "."; + + // First, try matching the filename *without* adding a + // prefix. +#if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) + ACE_OS::sprintf (pathname, + ASYS_TEXT ("%s%c%s%s"), + path_entry, + ACE_DIRECTORY_SEPARATOR_CHAR, + searchfilename, + got_suffix ? ACE_static_cast (char *, + ASYS_TEXT ("")) + : ACE_static_cast (char *, + dll_suffix)); +#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ + ACE_OS::sprintf (pathname, + ASYS_TEXT ("%s%c%s%s"), + path_entry, + ACE_DIRECTORY_SEPARATOR_CHAR, + searchfilename, + got_suffix ? ASYS_TEXT ("") : dll_suffix); +#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ + if (ACE_OS::access (pathname, F_OK) == 0) + break; + + // Second, try matching the filename *with* adding a + // prefix. +#if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) + ACE_OS::sprintf (pathname, + ASYS_TEXT ("%s%c%s%s%s"), + path_entry, + ACE_DIRECTORY_SEPARATOR_CHAR, + ACE_DLL_PREFIX, + searchfilename, + got_suffix ? ACE_static_cast (char *, + ASYS_TEXT ("")) + : ACE_static_cast (char *, + dll_suffix)); +#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ + ACE_OS::sprintf (pathname, + ASYS_TEXT ("%s%c%s%s%s"), + path_entry, + ACE_DIRECTORY_SEPARATOR_CHAR, + ACE_DLL_PREFIX, + searchfilename, + got_suffix ? ASYS_TEXT ("") : dll_suffix); +#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ + if (ACE_OS::access (pathname, F_OK) == 0) + break; + + // Fetch the next item in the path + path_entry = ACE::strsplit_r (0, + ACE_LD_SEARCH_PATH_SEPARATOR_STR, + nextholder); + } #if defined (ACE_WIN32) - if (ld_path_temp != 0) - ACE_OS::free (ld_path_temp); + if (ld_path_temp != 0) + ACE_OS::free (ld_path_temp); #endif /* ACE_WIN32 */ - ACE_OS::free ((void *) ld_path); + ACE_OS::free ((void *) ld_path); #if defined (ACE_WIN32) && defined (_DEBUG) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) - if (result == 0 || tag == 0) + if (result == 0 || tag == 0) #endif /* ACE_WIN32 && _DEBUG && !ACE_DISABLE_DEBUG_DLL_CHECK */ - return result; + return result; + } } - } #if defined (ACE_WIN32) && defined (_DEBUG) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) } #endif /* ACE_WIN32 && _DEBUG && !ACE_DISABLE_DEBUG_DLL_CHECK */ @@ -1195,6 +1195,33 @@ ACE::recv (ACE_HANDLE handle, } } +#if defined (ACE_HAS_TLI) + +ssize_t +ACE::t_rcv (ACE_HANDLE handle, + void *buf, + size_t len, + int *flags, + const ACE_Time_Value *timeout) +{ + if (timeout == 0) + return ACE_OS::t_rcv (handle, (char *) buf, len, flags); + else + { + int val = 0; + if (ACE::enter_recv_timedwait (handle, timeout, val) ==-1) + return -1; + else + { + ssize_t bytes_transferred = ACE_OS::t_rcv (handle, (char *) buf, len, flags); + ACE::restore_non_blocking_mode (handle, val); + return bytes_transferred; + } + } +} + +#endif /* ACE_HAS_TLI */ + ssize_t ACE::recv (ACE_HANDLE handle, void *buf, @@ -1289,7 +1316,8 @@ ssize_t ACE::recv_n_i (ACE_HANDLE handle, void *buf, size_t len, - int flags) + int flags, + int error_on_eof) { size_t bytes_transferred; ssize_t n; @@ -1317,7 +1345,12 @@ ACE::recv_n_i (ACE_HANDLE handle, return -1; } else if (n == 0) - break; + { + if (error_on_eof) + return -1; + else + break; + } } return bytes_transferred; @@ -1328,7 +1361,8 @@ ACE::recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { int val = 0; ACE::record_and_set_non_blocking_mode (handle, val); @@ -1362,11 +1396,124 @@ ACE::recv_n_i (ACE_HANDLE handle, // Errors (note that errno cannot be EWOULDBLOCK since select() // just told us that data is available to read). - if (n == -1 || n == 0) + if (n == -1) + { + error = 1; + break; + } + else if (n == 0) + { + if (error_on_eof) + error = 1; + break; + } + } + + ACE::restore_non_blocking_mode (handle, val); + + if (error) + return -1; + else + return bytes_transferred; +} + +#if defined (ACE_HAS_TLI) + +ssize_t +ACE::t_rcv_n_i (ACE_HANDLE handle, + void *buf, + size_t len, + int *flags, + int error_on_eof) +{ + size_t bytes_transferred; + ssize_t n; + + for (bytes_transferred = 0; + bytes_transferred < len; + bytes_transferred += n) + { + n = ACE_OS::t_rcv (handle, + (char *) buf + bytes_transferred, + len - bytes_transferred, + flags); + if (n == -1) + { + // If blocked, try again. + if (errno == EWOULDBLOCK) + { + n = 0; + continue; + } + + // No timeouts in this version. + + // Other errors. + return -1; + } + else if (n == 0) + { + if (error_on_eof) + return -1; + else + break; + } + } + + return bytes_transferred; +} + +ssize_t +ACE::t_rcv_n_i (ACE_HANDLE handle, + void *buf, + size_t len, + int flags, + const ACE_Time_Value *timeout, + int error_on_eof) +{ + int val = 0; + ACE::record_and_set_non_blocking_mode (handle, val); + + size_t bytes_transferred; + ssize_t n; + ssize_t error = 0; + + for (bytes_transferred = 0; + bytes_transferred < len; + bytes_transferred += n) + { + int result = ACE::handle_read_ready (handle, + timeout); + + if (result == -1) { + // Timed out; return bytes transferred. + if (errno == ETIME) + break; + + // Other errors. error = 1; break; } + + n = ACE_OS::t_rcv (handle, + (char *) buf + bytes_transferred, + len - bytes_transferred, + flags); + + // Errors (note that errno cannot be EWOULDBLOCK since select() + // just told us that data is available to read). + if (n == -1) + { + error = 1; + break; + } + else if (n == 0) + { + if (error_on_eof) + error = 1; + break; + } } ACE::restore_non_blocking_mode (handle, val); @@ -1377,10 +1524,13 @@ ACE::recv_n_i (ACE_HANDLE handle, return bytes_transferred; } +#endif /* ACE_HAS_TLI */ + ssize_t ACE::recv_n_i (ACE_HANDLE handle, void *buf, - size_t len) + size_t len, + int error_on_eof) { size_t bytes_transferred; ssize_t n; @@ -1407,7 +1557,12 @@ ACE::recv_n_i (ACE_HANDLE handle, return -1; } else if (n == 0) - break; + { + if (error_on_eof) + return -1; + else + break; + } } return bytes_transferred; @@ -1417,7 +1572,8 @@ ssize_t ACE::recv_n_i (ACE_HANDLE handle, void *buf, size_t len, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { int val = 0; ACE::record_and_set_non_blocking_mode (handle, val); @@ -1450,11 +1606,17 @@ ACE::recv_n_i (ACE_HANDLE handle, // Errors (note that errno cannot be EWOULDBLOCK since select() // just told us that data is available to read). - if (n == -1 || n == 0) + if (n == -1) { error = 1; break; } + else if (n == 0) + { + if (error_on_eof) + error = 1; + break; + } } ACE::restore_non_blocking_mode (handle, val); @@ -1533,7 +1695,8 @@ ACE::recvv (ACE_HANDLE handle, ssize_t ACE::recvv_n_i (ACE_HANDLE handle, iovec *iov, - int iovcnt) + int iovcnt, + int error_on_eof) { ssize_t bytes_transferred = 0; @@ -1559,7 +1722,12 @@ ACE::recvv_n_i (ACE_HANDLE handle, return -1; } else if (n == 0) - break; + { + if (error_on_eof) + return -1; + else + break; + } for (bytes_transferred += n; s < iovcnt @@ -1584,7 +1752,8 @@ ssize_t ACE::recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { int val = 0; ACE::record_and_set_non_blocking_mode (handle, val); @@ -1616,11 +1785,17 @@ ACE::recvv_n_i (ACE_HANDLE handle, // Errors (note that errno cannot be EWOULDBLOCK since select() // just told us that data is available to read). - if (n == -1 || n == 0) + if (n == -1) { error = 1; break; } + else if (n == 0) + { + if (error_on_eof) + error = 1; + break; + } for (bytes_transferred += n; s < iovcnt @@ -1649,7 +1824,8 @@ ACE::recvv_n_i (ACE_HANDLE handle, ssize_t ACE::recv_n (ACE_HANDLE handle, ACE_Message_Block *message_block, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { iovec iov[IOV_MAX]; int iovcnt = 0; @@ -1688,7 +1864,9 @@ ACE::recv_n (ACE_HANDLE handle, { n = ACE::recvv_n (handle, iov, - iovcnt); + iovcnt, + timeout, + error_on_eof); // Errors. Make sure that we don't treat a timeout // as an error. @@ -1729,7 +1907,8 @@ ACE::recv_n (ACE_HANDLE handle, n = ACE::recvv_n (handle, iov, iovcnt, - timeout); + timeout, + error_on_eof); // Errors. Make sure that we don't treat a timeout // as an error. @@ -1776,6 +1955,33 @@ ACE::send (ACE_HANDLE handle, } } +#if defined (ACE_HAS_TLI) + +ssize_t +ACE::t_snd (ACE_HANDLE handle, + const void *buf, + size_t n, + int flags, + const ACE_Time_Value *timeout) +{ + if (timeout == 0) + return ACE_OS::t_snd (handle, (const char *) buf, n, flags); + else + { + int val = 0; + if (ACE::enter_send_timedwait (handle, timeout, val) == -1) + return -1; + else + { + ssize_t bytes_transferred = ACE_OS::t_snd (handle, (const char *) buf, n, flags); + ACE::restore_non_blocking_mode (handle, val); + return bytes_transferred; + } + } +} + +#endif /* ACE_HAS_TLI */ + ssize_t ACE::send (ACE_HANDLE handle, const void *buf, @@ -1870,7 +2076,8 @@ ssize_t ACE::send_n_i (ACE_HANDLE handle, const void *buf, size_t len, - int flags) + int flags, + int error_on_eof) { size_t bytes_transferred; ssize_t n; @@ -1898,7 +2105,12 @@ ACE::send_n_i (ACE_HANDLE handle, return -1; } else if (n == 0) - break; + { + if (error_on_eof) + return -1; + else + break; + } } return bytes_transferred; @@ -1909,7 +2121,8 @@ ACE::send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { int val = 0; ACE::record_and_set_non_blocking_mode (handle, val); @@ -1943,11 +2156,124 @@ ACE::send_n_i (ACE_HANDLE handle, // Errors (note that errno cannot be EWOULDBLOCK since select() // just told us that data can be written). - if (n == -1 || n == 0) + if (n == -1) + { + error = 1; + break; + } + else if (n == 0) + { + if (error_on_eof) + error = 1; + break; + } + } + + ACE::restore_non_blocking_mode (handle, val); + + if (error) + return -1; + else + return bytes_transferred; +} + +#if defined (ACE_HAS_TLI) + +ssize_t +ACE::t_snd_n_i (ACE_HANDLE handle, + const void *buf, + size_t len, + int flags, + int error_on_eof) +{ + size_t bytes_transferred; + ssize_t n; + + for (bytes_transferred = 0; + bytes_transferred < len; + bytes_transferred += n) + { + n = ACE_OS::t_snd (handle, + (char *) buf + bytes_transferred, + len - bytes_transferred, + flags); + if (n == -1) + { + // If blocked, try again. + if (errno == EWOULDBLOCK) + { + n = 0; + continue; + } + + // No timeouts in this version. + + // Other errors. + return -1; + } + else if (n == 0) + { + if (error_on_eof) + return -1; + else + break; + } + } + + return bytes_transferred; +} + +ssize_t +ACE::t_snd_n_i (ACE_HANDLE handle, + const void *buf, + size_t len, + int flags, + const ACE_Time_Value *timeout, + int error_on_eof) +{ + int val = 0; + ACE::record_and_set_non_blocking_mode (handle, val); + + size_t bytes_transferred; + ssize_t n; + ssize_t error = 0; + + for (bytes_transferred = 0; + bytes_transferred < len; + bytes_transferred += n) + { + int result = ACE::handle_write_ready (handle, + timeout); + + if (result == -1) + { + // Timed out; return bytes transferred. + if (errno == ETIME) + break; + + // Other errors. + error = 1; + break; + } + + n = ACE_OS::t_snd (handle, + (char *) buf + bytes_transferred, + len - bytes_transferred, + flags); + + // Errors (note that errno cannot be EWOULDBLOCK since select() + // just told us that data can be written). + if (n == -1) { error = 1; break; } + else if (n == 0) + { + if (error_on_eof) + error = 1; + break; + } } ACE::restore_non_blocking_mode (handle, val); @@ -1958,10 +2284,13 @@ ACE::send_n_i (ACE_HANDLE handle, return bytes_transferred; } +#endif /* ACE_HAS_TLI */ + ssize_t ACE::send_n_i (ACE_HANDLE handle, const void *buf, - size_t len) + size_t len, + int error_on_eof) { size_t bytes_transferred; ssize_t n; @@ -1988,7 +2317,12 @@ ACE::send_n_i (ACE_HANDLE handle, return -1; } else if (n == 0) - break; + { + if (error_on_eof) + return -1; + else + break; + } } return bytes_transferred; @@ -1998,7 +2332,8 @@ ssize_t ACE::send_n_i (ACE_HANDLE handle, const void *buf, size_t len, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { int val = 0; ACE::record_and_set_non_blocking_mode (handle, val); @@ -2031,11 +2366,17 @@ ACE::send_n_i (ACE_HANDLE handle, // Errors (note that errno cannot be EWOULDBLOCK since select() // just told us that data can be written). - if (n == -1 || n == 0) + if (n == -1) { error = 1; break; } + else if (n == 0) + { + if (error_on_eof) + error = 1; + break; + } } ACE::restore_non_blocking_mode (handle, val); @@ -2113,7 +2454,8 @@ ACE::sendv (ACE_HANDLE handle, ssize_t ACE::sendv_n_i (ACE_HANDLE handle, const iovec *i, - int iovcnt) + int iovcnt, + int error_on_eof) { iovec *iov = ACE_const_cast (iovec *, i); @@ -2141,7 +2483,12 @@ ACE::sendv_n_i (ACE_HANDLE handle, return -1; } else if (n == 0) - break; + { + if (error_on_eof) + return -1; + else + break; + } for (bytes_transferred += n; s < iovcnt @@ -2166,7 +2513,8 @@ ssize_t ACE::sendv_n_i (ACE_HANDLE handle, const iovec *i, int iovcnt, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { iovec *iov = ACE_const_cast (iovec *, i); @@ -2200,11 +2548,17 @@ ACE::sendv_n_i (ACE_HANDLE handle, // Errors (note that errno cannot be EWOULDBLOCK since select() // just told us that data can be written). - if (n == -1 || n == 0) + if (n == -1) { error = 1; break; } + else if (n == 0) + { + if (error_on_eof) + error = 1; + break; + } for (bytes_transferred += n; s < iovcnt @@ -2233,7 +2587,8 @@ ACE::sendv_n_i (ACE_HANDLE handle, ssize_t ACE::send_n (ACE_HANDLE handle, const ACE_Message_Block *message_block, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { iovec iov[IOV_MAX]; int iovcnt = 0; @@ -2273,7 +2628,8 @@ ACE::send_n (ACE_HANDLE handle, n = ACE::sendv_n (handle, iov, iovcnt, - timeout); + timeout, + error_on_eof); // Errors. Make sure that we don't treat a timeout // as an error. @@ -2314,7 +2670,8 @@ ACE::send_n (ACE_HANDLE handle, n = ACE::sendv_n (handle, iov, iovcnt, - timeout); + timeout, + error_on_eof); // Errors. Make sure that we don't treat a timeout // as an error. @@ -2334,7 +2691,8 @@ ACE::send_n (ACE_HANDLE handle, ssize_t ACE::readv_n (ACE_HANDLE handle, iovec *iov, - int iovcnt) + int iovcnt, + int error_on_eof) { ssize_t bytes_transferred = 0; @@ -2345,8 +2703,18 @@ ACE::readv_n (ACE_HANDLE handle, ssize_t n = ACE_OS::readv (handle, iov + s, iovcnt - s); - if (n == -1 || n == 0) - return n; + if (n == -1) + { + // Errors. + return -1; + } + else if (n == 0) + { + if (error_on_eof) + return -1; + else + break; + } for (bytes_transferred += n; s < iovcnt @@ -2370,7 +2738,8 @@ ACE::readv_n (ACE_HANDLE handle, ssize_t ACE::writev_n (ACE_HANDLE handle, const iovec *i, - int iovcnt) + int iovcnt, + int error_on_eof) { iovec *iov = ACE_const_cast (iovec *, i); @@ -2383,8 +2752,18 @@ ACE::writev_n (ACE_HANDLE handle, ssize_t n = ACE_OS::writev (handle, iov + s, iovcnt - s); - if (n == -1 || n == 0) - return n; + if (n == -1) + { + // Errors. + return -1; + } + else if (n == 0) + { + if (error_on_eof) + return -1; + else + break; + } for (bytes_transferred += n; s < iovcnt @@ -2754,7 +3133,7 @@ ACE::handle_timed_complete (ACE_HANDLE h, # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) need_to_check = (fds.revents & POLLIN) && !(fds.revents & POLLOUT); # else - need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h); + need_to_check = rd_handles.is_set (h) && !wr_handles.is_set (h); # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ else @@ -2764,9 +3143,9 @@ ACE::handle_timed_complete (ACE_HANDLE h, need_to_check = 1; #else # if defined (ACE_HAS_POLL) && defined (ACE_HAS_LIMITED_SELECT) - need_to_check = (fds.revents & POLLIN); + need_to_check = (fds.revents & POLLIN); # else - need_to_check = rd_handles.is_set (h); + need_to_check = rd_handles.is_set (h); # endif /* ACE_HAS_POLL && ACE_HAS_LIMITED_SELECT */ #endif /* AIX */ #endif /* ACE_WIN32 */ @@ -3047,7 +3426,7 @@ ACE::fork (const char *program_name, union wait status; if (pid < 0 || ACE_OS::waitpid (pid, &(status.w_status), 0) < 0) #else - ACE_exitcode status; + ACE_exitcode status; if (pid < 0 || ACE_OS::waitpid (pid, &status, 0) < 0) #endif /* ACE_HAS_UNION_WAIT */ return -1; @@ -3080,7 +3459,7 @@ ACE::max_handles (void) if (rl.rlim_cur != RLIM_INFINITY) return rl.rlim_cur; #else - return rl.rlim_cur; + return rl.rlim_cur; # endif /* RLIM_INFINITY */ # if defined (_SC_OPEN_MAX) return ACE_OS::sysconf (_SC_OPEN_MAX); @@ -3245,13 +3624,13 @@ u_long ACE::gcd (u_long x, u_long y) { if (y == 0) - { - return x; - } + { + return x; + } else - { - return ACE::gcd (y, x % y); - } + { + return ACE::gcd (y, x % y); + } } @@ -3262,40 +3641,40 @@ ACE::minimum_frame_size (u_long period1, u_long period2) // if one of the periods is zero, treat it as though it as // uninitialized and return the other period as the frame size if (0 == period1) - { - return period2; - } + { + return period2; + } if (0 == period2) - { - return period1; - } + { + return period1; + } // if neither is zero, find the greatest common divisor of the two periods u_long greatest_common_divisor = ACE::gcd (period1, period2); // explicitly consider cases to reduce risk of possible overflow errors if (greatest_common_divisor == 1) - { - // periods are relative primes: just multiply them together - return period1 * period2; - } + { + // periods are relative primes: just multiply them together + return period1 * period2; + } else if (greatest_common_divisor == period1) - { - // the first period divides the second: return the second - return period2; - } + { + // the first period divides the second: return the second + return period2; + } else if (greatest_common_divisor == period2) - { - // the second period divides the first: return the first - return period1; - } + { + // the second period divides the first: return the first + return period1; + } else - { - // the current frame size and the entry's effective period - // have a non-trivial greatest common divisor: return the - // product of factors divided by those in their gcd. - return (period1 * period2) / greatest_common_divisor; - } + { + // the current frame size and the entry's effective period + // have a non-trivial greatest common divisor: return the + // product of factors divided by those in their gcd. + return (period1 * period2) / greatest_common_divisor; + } } @@ -3346,7 +3725,7 @@ ACE::sock_error (int error) /* case WSANO_ADDRESS: return "Valid name, no MX record"; - */ + */ case WSANOTINITIALISED: return ASYS_TEXT ("WSA Startup not initialized"); /* NOTREACHED */ @@ -3478,12 +3857,12 @@ ACE::get_bcast_addr (ACE_UINT32 &bcast_addr, (char *) hp->h_addr, hp->h_length); #else /* _UNICOS */ - { - ACE_UINT64 haddr; // a place to put the address - char * haddrp = (char *) &haddr; // convert to char pointer - ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length); - ip_addr.sin_addr.s_addr = haddr; - } + { + ACE_UINT64 haddr; // a place to put the address + char * haddrp = (char *) &haddr; // convert to char pointer + ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length); + ip_addr.sin_addr.s_addr = haddr; + } #endif /* ! _UNICOS */ } else @@ -3614,12 +3993,12 @@ ACE::count_interfaces (ACE_HANDLE handle, how_many = (size_t) tmp_how_many; return 0; #elif defined (__unix) || defined (__Lynx__) || defined (_AIX) - // Note: DEC CXX doesn't define "unix". BSD compatible OS: HP UX, - // AIX, SunOS 4.x perform some ioctls to retrieve ifconf list of - // ifreq structs no SIOCGIFNUM on SunOS 4.x, so use guess and scan - // algorithm + // Note: DEC CXX doesn't define "unix". BSD compatible OS: HP UX, + // AIX, SunOS 4.x perform some ioctls to retrieve ifconf list of + // ifreq structs no SIOCGIFNUM on SunOS 4.x, so use guess and scan + // algorithm - // Probably hard to put this many ifs in a unix box.. + // Probably hard to put this many ifs in a unix box.. const int MAX_IF = 50; // HACK - set to an unreasonable number @@ -3677,9 +4056,9 @@ ACE::count_interfaces (ACE_HANDLE handle, how_many = if_count; return 0; #else - ACE_UNUSED_ARG (handle); - ACE_UNUSED_ARG (how_many); - ACE_NOTSUP_RETURN (-1);; // no implmentation + ACE_UNUSED_ARG (handle); + ACE_UNUSED_ARG (how_many); + ACE_NOTSUP_RETURN (-1);; // no implmentation #endif /* sparc && SIOCGIFNUM */ } @@ -3688,7 +4067,7 @@ ACE::count_interfaces (ACE_HANDLE handle, ACE_HANDLE ACE::get_handle (void) { -// Solaris 2.x + // Solaris 2.x ACE_HANDLE handle = ACE_INVALID_HANDLE; #if defined (sparc) && ! defined (CHORUS) handle = ACE_OS::open ("/dev/udp", O_RDONLY); @@ -3763,10 +4142,10 @@ ACE::get_ip_interfaces (size_t &count, // following condition to the #if above. It tests ok at Riverace w/ 4.2, // but this isn't a virgin install of 4.2 so there's a minimal risk that // it may need work later. - defined (_MSC_VER) && (_MSC_VER >= 1100) + defined (_MSC_VER) && (_MSC_VER >= 1100) #endif /* 0 */ - int i, n_interfaces, status; + int i, n_interfaces, status; INTERFACE_INFO info[64]; LPINTERFACE_INFO lpii; SOCKET sock; @@ -3786,7 +4165,7 @@ ACE::get_ip_interfaces (size_t &count, 0); closesocket (sock); if (status == SOCKET_ERROR) - return -1; + return -1; n_interfaces = bytes / sizeof(INTERFACE_INFO); if (n_interfaces == 0) diff --git a/ace/ACE.h b/ace/ACE.h index 15703f492f0..9ded60b00c9 100644 --- a/ace/ACE.h +++ b/ace/ACE.h @@ -112,6 +112,11 @@ public: // is not counted down. If the transfer times out, the number of // bytes transferred so far are returned. // + // If EOF is reached while transmitting data, a value of 1 for + // <error_on_eof> causes -1 to be returned to the caller. However, + // if <error_on_eof> is 0, whatever has been transmitted so far will + // be returned to the caller. + // // Methods with <iovec> parameter are I/O vector variants of the I/O // operations. @@ -121,6 +126,16 @@ public: int flags, const ACE_Time_Value *timeout = 0); +#if defined (ACE_HAS_TLI) + + static ssize_t t_rcv (ACE_HANDLE handle, + void *buf, + size_t len, + int *flags, + const ACE_Time_Value *timeout = 0); + +#endif /* ACE_HAS_TLI */ + static ssize_t recv (ACE_HANDLE handle, void *buf, size_t len, @@ -143,12 +158,25 @@ public: void *buf, size_t len, int flags, - const ACE_Time_Value *timeout = 0); + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); + +#if defined (ACE_HAS_TLI) + + static ssize_t t_rcv_n (ACE_HANDLE handle, + void *buf, + size_t len, + int *flags, + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); + +#endif /* ACE_HAS_TLI */ static ssize_t recv_n (ACE_HANDLE handle, void *buf, size_t len, - const ACE_Time_Value *timeout = 0); + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); static ssize_t recv (ACE_HANDLE handle, size_t n, ...); // Varargs variant. @@ -161,21 +189,33 @@ public: static ssize_t recvv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, - const ACE_Time_Value *timeout = 0); + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); static ssize_t recv_n (ACE_HANDLE handle, ACE_Message_Block *message_block, - const ACE_Time_Value *timeout = 0); + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); static ssize_t send (ACE_HANDLE handle, const void *buf, size_t len, + int flags, const ACE_Time_Value *timeout = 0); +#if defined (ACE_HAS_TLI) + + static ssize_t t_snd (ACE_HANDLE handle, + const void *buf, + size_t len, + int flags, + const ACE_Time_Value *timeout = 0); + +#endif /* ACE_HAS_TLI */ + static ssize_t send (ACE_HANDLE handle, const void *buf, size_t len, - int flags, const ACE_Time_Value *timeout = 0); static ssize_t sendmsg (ACE_HANDLE handle, @@ -195,12 +235,25 @@ public: const void *buf, size_t len, int flags, - const ACE_Time_Value *timeout = 0); + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); + +#if defined (ACE_HAS_TLI) + + static ssize_t t_snd_n (ACE_HANDLE handle, + const void *buf, + size_t len, + int flags, + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); + +#endif /* ACE_HAS_TLI */ static ssize_t send_n (ACE_HANDLE handle, const void *buf, size_t len, - const ACE_Time_Value *timeout = 0); + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); static ssize_t send (ACE_HANDLE handle, size_t n, ...); // Varargs variant. @@ -213,29 +266,35 @@ public: static ssize_t sendv_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, - const ACE_Time_Value *timeout = 0); + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); static ssize_t send_n (ACE_HANDLE handle, const ACE_Message_Block *message_block, - const ACE_Time_Value *timeout = 0); + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1); // = File system I/O functions (these don't support timeouts). static ssize_t read_n (ACE_HANDLE handle, void *buf, - size_t len); + size_t len, + int error_on_eof = 1); static ssize_t write_n (ACE_HANDLE handle, const void *buf, - size_t len); + size_t len, + int error_on_eof = 1); static ssize_t readv_n (ACE_HANDLE handle, iovec *iov, - int iovcnt); + int iovcnt, + int error_on_eof = 1); static ssize_t writev_n (ACE_HANDLE handle, const iovec *iov, - int iovcnt); + int iovcnt, + int error_on_eof = 1); // = Socket connection establishment calls. @@ -563,7 +622,7 @@ public: // Timed wait for handle to get read ready. static int handle_write_ready (ACE_HANDLE handle, - const ACE_Time_Value *timeout); + const ACE_Time_Value *timeout); // Timed wait for handle to get write ready. static int handle_exception_ready (ACE_HANDLE handle, @@ -612,31 +671,54 @@ private: static ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, - int flags); + int flags, + int error_on_eof); static ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, int flags, - const ACE_Time_Value *timeout); + const ACE_Time_Value *timeout, + int error_on_eof); + +#if defined (ACE_HAS_TLI) + + static ssize_t t_rcv_n_i (ACE_HANDLE handle, + void *buf, + size_t len, + int *flags, + int error_on_eof); + + static ssize_t t_rcv_n_i (ACE_HANDLE handle, + void *buf, + size_t len, + int *flags, + const ACE_Time_Value *timeout, + int error_on_eof); + +#endif /* ACE_HAS_TLI */ static ssize_t recv_n_i (ACE_HANDLE handle, void *buf, - size_t len); + size_t len, + int error_on_eof); static ssize_t recv_n_i (ACE_HANDLE handle, void *buf, size_t len, - const ACE_Time_Value *timeout); + const ACE_Time_Value *timeout, + int error_on_eof); static ssize_t recvv_n_i (ACE_HANDLE handle, iovec *iov, - int iovcnt); + int iovcnt, + int error_on_eof); static ssize_t recvv_n_i (ACE_HANDLE handle, iovec *iov, int iovcnt, - const ACE_Time_Value *timeout); + const ACE_Time_Value *timeout, + int error_on_eof); // // = Send_n helpers @@ -649,31 +731,54 @@ private: static ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, - int flags); + int flags, + int error_on_eof); static ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, int flags, - const ACE_Time_Value *timeout); + const ACE_Time_Value *timeout, + int error_on_eof); + +#if defined (ACE_HAS_TLI) + + static ssize_t t_snd_n_i (ACE_HANDLE handle, + const void *buf, + size_t len, + int flags, + int error_on_eof); + + static ssize_t t_snd_n_i (ACE_HANDLE handle, + const void *buf, + size_t len, + int flags, + const ACE_Time_Value *timeout, + int error_on_eof); + +#endif /* ACE_HAS_TLI */ static ssize_t send_n_i (ACE_HANDLE handle, const void *buf, - size_t len); + size_t len, + int error_on_eof); static ssize_t send_n_i (ACE_HANDLE handle, const void *buf, size_t len, - const ACE_Time_Value *timeout); + const ACE_Time_Value *timeout, + int error_on_eof); static ssize_t sendv_n_i (ACE_HANDLE handle, const iovec *iov, - int iovcnt); + int iovcnt, + int error_on_eof); static ssize_t sendv_n_i (ACE_HANDLE handle, const iovec *iov, int iovcnt, - const ACE_Time_Value *timeout); + const ACE_Time_Value *timeout, + int error_on_eof); static u_int init_fini_count_; // Counter to match <init>/<fini> calls. <init> must increment it; diff --git a/ace/ACE.i b/ace/ACE.i index b2db5c6cdbb..a4d7bce3b9c 100644 --- a/ace/ACE.i +++ b/ace/ACE.i @@ -6,17 +6,19 @@ ASYS_INLINE ssize_t ACE::read_n (ACE_HANDLE handle, void *buf, - size_t len) + size_t len, + int error_on_eof) { - return ACE_OS::read_n (handle, buf, len); + return ACE_OS::read_n (handle, buf, len, error_on_eof); } ASYS_INLINE ssize_t ACE::write_n (ACE_HANDLE handle, const void *buf, - size_t len) + size_t len, + int error_on_eof) { - return ACE_OS::write_n (handle, buf, len); + return ACE_OS::write_n (handle, buf, len, error_on_eof); } ASYS_INLINE ssize_t @@ -24,53 +26,89 @@ ACE::recv_n (ACE_HANDLE handle, void *buf, size_t len, int flags, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { if (timeout == 0) return ACE::recv_n_i (handle, buf, len, - flags); + flags, + error_on_eof); else return ACE::recv_n_i (handle, buf, len, flags, - timeout); + timeout, + error_on_eof); +} + +#if defined (ACE_HAS_TLI) + +ASYS_INLINE ssize_t +ACE::t_rcv_n (ACE_HANDLE handle, + void *buf, + size_t len, + int *flags, + const ACE_Time_Value *timeout, + int error_on_eof) +{ + if (timeout == 0) + return ACE::t_rcv_n_i (handle, + buf, + len, + flags, + error_on_eof); + else + return ACE::t_rcv_n_i (handle, + buf, + len, + flags, + timeout, + error_on_eof); } +#endif /* ACE_HAS_TLI */ + ASYS_INLINE ssize_t ACE::recv_n (ACE_HANDLE handle, void *buf, size_t len, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { if (timeout == 0) return ACE::recv_n_i (handle, buf, - len); + len, + error_on_eof); else return ACE::recv_n_i (handle, buf, len, - timeout); + timeout, + error_on_eof); } ASYS_INLINE ssize_t ACE::recvv_n (ACE_HANDLE handle, iovec *iov, int iovcnt, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { if (timeout == 0) return ACE::recvv_n_i (handle, iov, - iovcnt); + iovcnt, + error_on_eof); else return ACE::recvv_n_i (handle, iov, iovcnt, - timeout); + timeout, + error_on_eof); } ASYS_INLINE ssize_t @@ -78,53 +116,89 @@ ACE::send_n (ACE_HANDLE handle, const void *buf, size_t len, int flags, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { if (timeout == 0) return ACE::send_n_i (handle, buf, len, - flags); + flags, + error_on_eof); else return ACE::send_n_i (handle, buf, len, flags, - timeout); + timeout, + error_on_eof); +} + +#if defined (ACE_HAS_TLI) + +ASYS_INLINE ssize_t +ACE::t_snd_n (ACE_HANDLE handle, + const void *buf, + size_t len, + int flags, + const ACE_Time_Value *timeout, + int error_on_eof) +{ + if (timeout == 0) + return ACE::t_snd_n_i (handle, + buf, + len, + flags, + error_on_eof); + else + return ACE::t_snd_n_i (handle, + buf, + len, + flags, + timeout, + error_on_eof); } +#endif /* ACE_HAS_TLI */ + ASYS_INLINE ssize_t ACE::send_n (ACE_HANDLE handle, const void *buf, size_t len, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { if (timeout == 0) return ACE::send_n_i (handle, buf, - len); + len, + error_on_eof); else return ACE::send_n_i (handle, buf, len, - timeout); + timeout, + error_on_eof); } ASYS_INLINE ssize_t ACE::sendv_n (ACE_HANDLE handle, const iovec *iov, int iovcnt, - const ACE_Time_Value *timeout) + const ACE_Time_Value *timeout, + int error_on_eof) { if (timeout == 0) return ACE::sendv_n_i (handle, iov, - iovcnt); + iovcnt, + error_on_eof); else return ACE::sendv_n_i (handle, iov, iovcnt, - timeout); + timeout, + error_on_eof); } ASYS_INLINE ssize_t @@ -141,9 +215,9 @@ ASYS_INLINE ssize_t ACE::recv_i (ACE_HANDLE handle, void *buf, size_t len) { #if defined (ACE_WIN32) || defined (ACE_PSOS) - return ACE_OS::recv (handle, (char *) buf, len); + return ACE_OS::recv (handle, (char *) buf, len); #else - return ACE_OS::read (handle, (char *) buf, len); + return ACE_OS::read (handle, (char *) buf, len); #endif /* ACE_WIN32 */ } diff --git a/ace/OS.cpp b/ace/OS.cpp index 069f944f457..2d615d47c0f 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -4319,7 +4319,8 @@ ACE_OS::fork_exec (ASYS_TCHAR *argv[]) ssize_t ACE_OS::read_n (ACE_HANDLE handle, void *buf, - size_t len) + size_t len, + int error_on_eof) { size_t bytes_transferred; ssize_t n; @@ -4331,8 +4332,18 @@ ACE_OS::read_n (ACE_HANDLE handle, n = ACE_OS::read (handle, (char *) buf + bytes_transferred, len - bytes_transferred); - if (n == -1 || n == 0) - return n; + if (n == -1) + { + // Errors. + return -1; + } + else if (n == 0) + { + if (error_on_eof) + return -1; + else + break; + } } return bytes_transferred; @@ -4344,7 +4355,8 @@ ACE_OS::read_n (ACE_HANDLE handle, ssize_t ACE_OS::write_n (ACE_HANDLE handle, const void *buf, - size_t len) + size_t len, + int error_on_eof) { size_t bytes_transferred; ssize_t n; @@ -4356,8 +4368,18 @@ ACE_OS::write_n (ACE_HANDLE handle, n = ACE_OS::write (handle, (char *) buf + bytes_transferred, len - bytes_transferred); - if (n == -1 || n == 0) - return n; + if (n == -1) + { + // Errors. + return -1; + } + else if (n == 0) + { + if (error_on_eof) + return -1; + else + break; + } } return bytes_transferred; @@ -3827,7 +3827,7 @@ extern "C" int t_rcvrel(int fildes); int t_rcvudata(int fildes, struct t_unitdata *unitdata, int *flags); int t_rcvuderr(int fildes, struct t_uderr *uderr); - int t_snd(int fildes, char *buf, u_int nbytes, int flags); + int t_snd(int fildes, const char *buf, u_int nbytes, int flags); int t_snddis(int fildes, struct t_call *call); int t_sndrel(int fildes); int t_sndudata(int fildes, struct t_unitdata *unitdata); @@ -5867,12 +5867,15 @@ public: ACE_OVERLAPPED *); static ssize_t read_n (ACE_HANDLE handle, void *buf, - size_t len); + size_t len, + int error_on_eof = 1); // Receive <len> bytes into <buf> from <handle> (uses the // <ACE_OS::read> call, which uses the <read> system call on UNIX - // and the <ReadFile> call on Win32). If <handle> is set to - // non-blocking mode this call will poll until all <len> bytes are - // received. + // and the <ReadFile> call on Win32). If EOF is reached while + // transmitting data, a value of 1 for <error_on_eof> causes -1 to + // be returned to the caller. However, if <error_on_eof> is 0, + // whatever has been transmitted so far will be returned to the + // caller. static int readlink (const char *path, char *buf, size_t bufsiz); @@ -5895,11 +5898,14 @@ public: ACE_OVERLAPPED *); static ssize_t write_n (ACE_HANDLE handle, const void *buf, - size_t len); + size_t len, + int error_on_eof = 1); // Send <len> bytes from <buf> to <handle> (uses the <ACE_OS::write> // calls, which is uses the <write> system call on UNIX and the - // <WriteFile> call on Win32). If <handle> is set to non-blocking - // mode this call will poll until all <len> bytes are sent. + // <WriteFile> call on Win32). If EOF is reached while transmitting + // data, a value of 1 for <error_on_eof> causes -1 to be returned to + // the caller. However, if <error_on_eof> is 0, whatever has been + // transmitted so far will be returned to the caller. static ssize_t pwrite (ACE_HANDLE handle, const void *buf, size_t nbyte, @@ -6524,7 +6530,7 @@ public: static int t_rcvuderr (ACE_HANDLE fildes, struct t_uderr *uderr); static int t_snd (ACE_HANDLE fildes, - char *buf, + const char *buf, u_int nbytes, int flags); static int t_snddis (ACE_HANDLE fildes, @@ -1906,7 +1906,7 @@ ACE_OS::mutex_init (ACE_mutex_t *m, # if !defined (ACE_LACKS_MUTEXATTR_PSHARED) ::pthread_mutexattr_setpshared (attributes, type) == 0 && # endif /* ACE_LACKS_MUTEXATTR_PSHARED */ -# if defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP) +# if defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP) ::pthread_mutexattr_setkind_np (attributes, type) == 0 && # endif /* ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP */ ::pthread_mutex_init (m, attributes) == 0) @@ -8343,11 +8343,11 @@ ACE_OS::t_rcvuderr (ACE_HANDLE handle, struct t_uderr *uderr) } ACE_INLINE int -ACE_OS::t_snd (ACE_HANDLE handle, char *buf, unsigned nbytes, int flags) +ACE_OS::t_snd (ACE_HANDLE handle, const char *buf, unsigned nbytes, int flags) { ACE_TRACE ("ACE_OS::t_snd"); #if defined (ACE_HAS_TLI) - ACE_OSCALL_RETURN (::t_snd (handle, buf, nbytes, flags), int, -1); + ACE_OSCALL_RETURN (::t_snd (handle, (char *) buf, nbytes, flags), int, -1); #else ACE_UNUSED_ARG (handle); ACE_UNUSED_ARG (buf); @@ -12413,11 +12413,11 @@ ACE_OS::opendir (const char *filename) ACE_NEW_RETURN (dir, DIR, 0); ACE_NEW_RETURN (dir->directory_name_, char[ACE_OS::strlen (filename)], - 0); + 0); ACE_OS::strcpy (dir->directory_name_, filename); dir->current_handle_ = INVALID_HANDLE_VALUE; dir->started_reading_ = 0; - return dir; + return dir; #else // VxWorks' ::opendir () is declared with a non-const argument. return ::opendir (ACE_const_cast (char *, filename)); @@ -12489,43 +12489,43 @@ ACE_OS::readdir (DIR *d) # if defined (ACE_WIN32) if (!d->started_reading_) { - d->current_handle_ = ::FindFirstFile (d->directory_name_, + d->current_handle_ = ::FindFirstFile (d->directory_name_, &(d->fdata_)); if (d->current_handle_ != INVALID_HANDLE_VALUE - && d->fdata_.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) - { + && d->fdata_.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) + { ::FindClose (d->current_handle_); d->current_handle_ = INVALID_HANDLE_VALUE; - } - else // Skip "." and ".." - { - int retval = 1; - while (*(d->fdata_.cFileName) == '.' - && retval - && d->current_handle_ != INVALID_HANDLE_VALUE) - { - retval = ::FindNextFile (d->current_handle_, &(d->fdata_)); - } - if (retval == 0) - d->current_handle_ = INVALID_HANDLE_VALUE; - } - - d->started_reading_ = 1; - } + } + else // Skip "." and ".." + { + int retval = 1; + while (*(d->fdata_.cFileName) == '.' + && retval + && d->current_handle_ != INVALID_HANDLE_VALUE) + { + retval = ::FindNextFile (d->current_handle_, &(d->fdata_)); + } + if (retval == 0) + d->current_handle_ = INVALID_HANDLE_VALUE; + } + + d->started_reading_ = 1; + } else { int retval = ::FindNextFile (d->current_handle_, &(d->fdata_)); - if (retval == 0) - d->current_handle_ = INVALID_HANDLE_VALUE; + if (retval == 0) + d->current_handle_ = INVALID_HANDLE_VALUE; } if (d->current_handle_ != INVALID_HANDLE_VALUE) - { + { d->dirent_.d_name = d->fdata_.cFileName; return &(d->dirent_); - } + } else return 0; # else /* defined (ACE_WIN32) */ diff --git a/ace/SOCK_Stream.h b/ace/SOCK_Stream.h index a020ab6e3fc..2d67713a878 100644 --- a/ace/SOCK_Stream.h +++ b/ace/SOCK_Stream.h @@ -69,33 +69,39 @@ public: ssize_t recv_n (void *buf, size_t len, int flags, - const ACE_Time_Value *timeout = 0) const; + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Try to recv exactly <len> bytes into <buf> from <handle>. ssize_t recv_n (void *buf, size_t len, - const ACE_Time_Value *timeout = 0) const; + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Try to recv exactly <len> bytes into <buf> from <handle>. ssize_t recvv_n (iovec iov[], size_t iovcnt, - const ACE_Time_Value *timeout = 0) const; + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Receive an <iovec> of size <iovcnt> to the connected socket. ssize_t send_n (const void *buf, size_t len, int flags, - const ACE_Time_Value *timeout = 0) const; + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Try to send exactly <len> bytes into <buf> from <handle>. ssize_t send_n (const void *buf, size_t len, - const ACE_Time_Value *timeout = 0) const; + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Try to send exactly <len> bytes into <buf> from <handle>. ssize_t sendv_n (const iovec iov[], size_t iovcnt, - const ACE_Time_Value *timeout = 0) const; + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Send an <iovec> of size <iovcnt> to the connected socket. // = Send/receive ``urgent'' data (see TCP specs...). diff --git a/ace/SOCK_Stream.i b/ace/SOCK_Stream.i index 3b28043fb74..675981f20f6 100644 --- a/ace/SOCK_Stream.i +++ b/ace/SOCK_Stream.i @@ -48,7 +48,8 @@ ASYS_INLINE ssize_t ACE_SOCK_Stream::recv_n (void *buf, size_t len, int flags, - const ACE_Time_Value *timeout) const + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_SOCK_Stream::recv_n"); return ACE::recv_n (this->get_handle (), @@ -61,7 +62,8 @@ ACE_SOCK_Stream::recv_n (void *buf, ASYS_INLINE ssize_t ACE_SOCK_Stream::recv_n (void *buf, size_t len, - const ACE_Time_Value *timeout) const + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_SOCK_Stream::recv_n"); return ACE::recv_n (this->get_handle (), @@ -73,7 +75,8 @@ ACE_SOCK_Stream::recv_n (void *buf, ASYS_INLINE ssize_t ACE_SOCK_Stream::recvv_n (iovec iov[], size_t n, - const ACE_Time_Value *timeout) const + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_SOCK_Stream::recvv_n"); return ACE::recvv_n (this->get_handle (), @@ -86,7 +89,8 @@ ASYS_INLINE ssize_t ACE_SOCK_Stream::send_n (const void *buf, size_t len, int flags, - const ACE_Time_Value *timeout) const + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_SOCK_Stream::send_n"); return ACE::send_n (this->get_handle (), @@ -99,7 +103,8 @@ ACE_SOCK_Stream::send_n (const void *buf, ASYS_INLINE ssize_t ACE_SOCK_Stream::send_n (const void *buf, size_t len, - const ACE_Time_Value *timeout) const + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_SOCK_Stream::send_n"); return ACE::send_n (this->get_handle (), @@ -111,7 +116,8 @@ ACE_SOCK_Stream::send_n (const void *buf, ASYS_INLINE ssize_t ACE_SOCK_Stream::sendv_n (const iovec iov[], size_t n, - const ACE_Time_Value *timeout) const + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_SOCK_Stream::sendv_n"); return ACE::sendv_n (this->get_handle (), diff --git a/ace/TLI_Stream.h b/ace/TLI_Stream.h index 7c0bb7c2022..e59327a5b60 100644 --- a/ace/TLI_Stream.h +++ b/ace/TLI_Stream.h @@ -55,27 +55,51 @@ public: // Return address of remotely connected peer. // = timod bindings - ssize_t send (const void *buf, size_t n, int flags) const; + ssize_t send (const void *buf, + size_t n, + int flags, + const ACE_Time_Value *timeout = 0) const; // Send an n byte buffer to the connected socket (uses t_snd(3)). - ssize_t recv (void *buf, size_t n, int *flags) const; + ssize_t recv (void *buf, + size_t n, + int *flags, + const ACE_Time_Value *timeout = 0) const; // Recv an n byte buffer from the connected socket (uses t_rcv(3)). - ssize_t send_n (const void *buf, size_t n, int flags) const; + ssize_t send_n (const void *buf, + size_t n, + int flags, + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Send exactly n bytes to the connected socket (uses t_snd(3)). - ssize_t recv_n (void *buf, size_t n, int *flags) const; + ssize_t recv_n (void *buf, + size_t n, + int *flags, + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Recv exactly n bytes from the connected socket (uses t_rcv(3)). // = tirdwr bindings - ssize_t send (const void *buf, size_t n) const; + ssize_t send (const void *buf, + size_t n, + const ACE_Time_Value *timeout = 0) const; // Send an n byte buffer to the connected socket (uses write(2)). - ssize_t recv (void *buf, size_t n) const; + ssize_t recv (void *buf, + size_t n, + const ACE_Time_Value *timeout = 0) const; // Recv an n byte buffer from the connected socket (uses read(2)). - ssize_t send_n (const void *buf, size_t n) const; + ssize_t send_n (const void *buf, + size_t n, + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Send n bytes, keep trying until n are sent (uses write(2)). - ssize_t recv_n (void *buf, size_t n) const; + ssize_t recv_n (void *buf, + size_t n, + const ACE_Time_Value *timeout = 0, + int error_on_eof = 1) const; // Recv n bytes, keep trying until n are received (uses read (2)). // = Meta-type info diff --git a/ace/TLI_Stream.i b/ace/TLI_Stream.i index 5139e8fb819..1dd512e5b81 100644 --- a/ace/TLI_Stream.i +++ b/ace/TLI_Stream.i @@ -6,87 +6,122 @@ #include "ace/TLI_Stream.h" inline ssize_t -ACE_TLI_Stream::send (const void *buf, size_t n) const +ACE_TLI_Stream::send (const void *buf, + size_t n, + const ACE_Time_Value *timeout) const { ACE_TRACE ("ACE_TLI_Stream::send"); - return ACE_OS::write (this->get_handle (), (const char *) buf, n); + return ACE::send (this->get_handle (), + buf, + n, + timeout); } inline ssize_t -ACE_TLI_Stream::send (const void *buf, size_t n, int flags) const +ACE_TLI_Stream::send (const void *buf, + size_t n, + int flags, + const ACE_Time_Value *timeout) const { ACE_TRACE ("ACE_TLI_Stream::send"); - return ACE_OS::t_snd (this->get_handle (), (char *) buf, n, flags); + return ACE::t_snd (this->get_handle (), + buf, + n, + flags, + timeout); } inline ssize_t -ACE_TLI_Stream::recv (void *buf, size_t n) const +ACE_TLI_Stream::recv (void *buf, + size_t n, + const ACE_Time_Value *timeout) const { ACE_TRACE ("ACE_TLI_Stream::recv"); - return ACE_OS::read (this->get_handle (), (char *) buf, n); + return ACE::recv (this->get_handle (), + buf, + n, + timeout); } inline ssize_t -ACE_TLI_Stream::recv (void *buf, size_t n, int *flags) const +ACE_TLI_Stream::recv (void *buf, + size_t n, + int *flags, + const ACE_Time_Value *timeout) const { ACE_TRACE ("ACE_TLI_Stream::recv"); int f = 0; if (flags == 0) flags = &f; - return ACE_OS::t_rcv (this->get_handle (), (char *) buf, n, flags); + + return ACE::t_rcv (this->get_handle (), + buf, + n, + flags, + timeout); } inline ssize_t -ACE_TLI_Stream::send_n (const void *buf, size_t n) const +ACE_TLI_Stream::send_n (const void *buf, + size_t n, + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_TLI_Stream::send_n"); - return ACE::send_n (this->get_handle (), buf, n); + return ACE::send_n (this->get_handle (), + buf, + n, + timeout, + error_on_eof); } inline ssize_t -ACE_TLI_Stream::send_n (const void *buf, size_t n, int flags) const +ACE_TLI_Stream::send_n (const void *buf, + size_t n, + int flags, + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_TLI_Stream::send_n"); - size_t b_sent; - ssize_t b_written = 0; - - for (b_sent = 0; b_sent < n; b_sent += b_written) - if ((b_written = ACE_OS::t_snd (this->get_handle (), - (char *) buf + b_sent, - n - b_sent, flags)) == -1) - return -1; - - return b_sent; + + return ACE::t_snd_n (this->get_handle (), + buf, + n, + flags, + timeout, + error_on_eof); } inline ssize_t -ACE_TLI_Stream::recv_n (void *buf, size_t n) const +ACE_TLI_Stream::recv_n (void *buf, + size_t n, + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_TLI_Stream::recv_n"); - return ACE::recv_n (this->get_handle (), buf, n); + return ACE::recv_n (this->get_handle (), + buf, + n, + timeout, + error_on_eof); } inline ssize_t -ACE_TLI_Stream::recv_n (void *buf, size_t n, int *flags) const +ACE_TLI_Stream::recv_n (void *buf, + size_t n, + int *flags, + const ACE_Time_Value *timeout, + int error_on_eof) const { ACE_TRACE ("ACE_TLI_Stream::recv_n"); - size_t b_read = 0; - ssize_t b_recv = 0; - int f = 0; - - if (flags == 0) - flags = &f; - for (b_read = 0; b_read < n; b_read += b_recv) - if ((b_recv = ACE_OS::t_rcv (this->get_handle (), - (char *) buf + b_read, - n - b_read, flags)) == -1) - return -1; - else if (b_recv == 0) - break; - - return b_read; + return ACE::t_rcv_n (this->get_handle (), + buf, + n, + flags, + timeout, + error_on_eof); } inline void @@ -102,4 +137,3 @@ ACE_TLI_Stream::get_rwflag (void) ACE_TRACE ("ACE_TLI_Stream::get_rwflag"); return this->rwflag_; } - |