< prev index next >

src/java.base/unix/native/libnio/ch/FileChannelImpl.c

Print this page
rev 59105 : imported patch corelibs


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <sys/mman.h>
  27 #include <sys/stat.h>
  28 #include <fcntl.h>
  29 #include <sys/types.h>
  30 #include <unistd.h>
  31 
  32 #if defined(__linux__) || defined(__solaris__)
  33 #include <sys/sendfile.h>
  34 #elif defined(_AIX)
  35 #include <string.h>
  36 #include <sys/socket.h>
  37 #elif defined(_ALLBSD_SOURCE)
  38 #include <sys/socket.h>
  39 #include <sys/uio.h>
  40 #define lseek64 lseek
  41 #define mmap64 mmap
  42 #endif
  43 
  44 #include "jni.h"
  45 #include "jni_util.h"
  46 #include "jlong.h"
  47 #include "nio.h"
  48 #include "nio_util.h"
  49 #include "sun_nio_ch_FileChannelImpl.h"
  50 #include "java_lang_Integer.h"
  51 #include <assert.h>
  52 


 165                                             jobject dstFDO)
 166 {
 167     jint srcFD = fdval(env, srcFDO);
 168     jint dstFD = fdval(env, dstFDO);
 169 
 170 #if defined(__linux__)
 171     off64_t offset = (off64_t)position;
 172     jlong n = sendfile64(dstFD, srcFD, &offset, (size_t)count);
 173     if (n < 0) {
 174         if (errno == EAGAIN)
 175             return IOS_UNAVAILABLE;
 176         if ((errno == EINVAL) && ((ssize_t)count >= 0))
 177             return IOS_UNSUPPORTED_CASE;
 178         if (errno == EINTR) {
 179             return IOS_INTERRUPTED;
 180         }
 181         JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
 182         return IOS_THROWN;
 183     }
 184     return n;
 185 #elif defined (__solaris__)
 186     sendfilevec64_t sfv;
 187     size_t numBytes = 0;
 188     jlong result;
 189 
 190     sfv.sfv_fd = srcFD;
 191     sfv.sfv_flag = 0;
 192     sfv.sfv_off = (off64_t)position;
 193     sfv.sfv_len = count;
 194 
 195     result = sendfilev64(dstFD, &sfv, 1, &numBytes);
 196 
 197     /* Solaris sendfilev() will return -1 even if some bytes have been
 198      * transferred, so we check numBytes first.
 199      */
 200     if (numBytes > 0)
 201         return numBytes;
 202     if (result < 0) {
 203         if (errno == EAGAIN)
 204             return IOS_UNAVAILABLE;
 205         if (errno == EOPNOTSUPP)
 206             return IOS_UNSUPPORTED_CASE;
 207         if ((errno == EINVAL) && ((ssize_t)count >= 0))
 208             return IOS_UNSUPPORTED_CASE;
 209         if (errno == EINTR)
 210             return IOS_INTERRUPTED;
 211         JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
 212         return IOS_THROWN;
 213     }
 214     return result;
 215 #elif defined(__APPLE__)
 216     off_t numBytes;
 217     int result;
 218 
 219     numBytes = count;
 220 
 221     result = sendfile(srcFD, dstFD, position, &numBytes, NULL, 0);
 222 
 223     if (numBytes > 0)
 224         return numBytes;
 225 
 226     if (result == -1) {
 227         if (errno == EAGAIN)
 228             return IOS_UNAVAILABLE;
 229         if (errno == EOPNOTSUPP || errno == ENOTSOCK || errno == ENOTCONN)
 230             return IOS_UNSUPPORTED_CASE;
 231         if ((errno == EINVAL) && ((ssize_t)count >= 0))
 232             return IOS_UNSUPPORTED_CASE;
 233         if (errno == EINTR)
 234             return IOS_INTERRUPTED;




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <sys/mman.h>
  27 #include <sys/stat.h>
  28 #include <fcntl.h>
  29 #include <sys/types.h>
  30 #include <unistd.h>
  31 
  32 #if defined(__linux__)
  33 #include <sys/sendfile.h>
  34 #elif defined(_AIX)
  35 #include <string.h>
  36 #include <sys/socket.h>
  37 #elif defined(_ALLBSD_SOURCE)
  38 #include <sys/socket.h>
  39 #include <sys/uio.h>
  40 #define lseek64 lseek
  41 #define mmap64 mmap
  42 #endif
  43 
  44 #include "jni.h"
  45 #include "jni_util.h"
  46 #include "jlong.h"
  47 #include "nio.h"
  48 #include "nio_util.h"
  49 #include "sun_nio_ch_FileChannelImpl.h"
  50 #include "java_lang_Integer.h"
  51 #include <assert.h>
  52 


 165                                             jobject dstFDO)
 166 {
 167     jint srcFD = fdval(env, srcFDO);
 168     jint dstFD = fdval(env, dstFDO);
 169 
 170 #if defined(__linux__)
 171     off64_t offset = (off64_t)position;
 172     jlong n = sendfile64(dstFD, srcFD, &offset, (size_t)count);
 173     if (n < 0) {
 174         if (errno == EAGAIN)
 175             return IOS_UNAVAILABLE;
 176         if ((errno == EINVAL) && ((ssize_t)count >= 0))
 177             return IOS_UNSUPPORTED_CASE;
 178         if (errno == EINTR) {
 179             return IOS_INTERRUPTED;
 180         }
 181         JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
 182         return IOS_THROWN;
 183     }
 184     return n;






























 185 #elif defined(__APPLE__)
 186     off_t numBytes;
 187     int result;
 188 
 189     numBytes = count;
 190 
 191     result = sendfile(srcFD, dstFD, position, &numBytes, NULL, 0);
 192 
 193     if (numBytes > 0)
 194         return numBytes;
 195 
 196     if (result == -1) {
 197         if (errno == EAGAIN)
 198             return IOS_UNAVAILABLE;
 199         if (errno == EOPNOTSUPP || errno == ENOTSOCK || errno == ENOTCONN)
 200             return IOS_UNSUPPORTED_CASE;
 201         if ((errno == EINVAL) && ((ssize_t)count >= 0))
 202             return IOS_UNSUPPORTED_CASE;
 203         if (errno == EINTR)
 204             return IOS_INTERRUPTED;


< prev index next >