jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java
changeset 6301 c90a67d75c9f
parent 6117 471ae95609d5
child 6525 56be41b86ef8
equal deleted inserted replaced
6300:700ec2a5d680 6301:c90a67d75c9f
   383 
   383 
   384             }
   384             }
   385         }
   385         }
   386     }
   386     }
   387 
   387 
   388     private long read0(ByteBuffer[] bufs) throws IOException {
   388     public long read(ByteBuffer[] dsts, int offset, int length)
   389         if (bufs == null)
   389         throws IOException
   390             throw new NullPointerException();
   390     {
       
   391         if ((offset < 0) || (length < 0) || (offset > dsts.length - length))
       
   392             throw new IndexOutOfBoundsException();
   391         synchronized (readLock) {
   393         synchronized (readLock) {
   392             if (!ensureReadOpen())
   394             if (!ensureReadOpen())
   393                 return -1;
   395                 return -1;
   394             long n = 0;
   396             long n = 0;
   395             try {
   397             try {
   399                         return 0;
   401                         return 0;
   400                     readerThread = NativeThread.current();
   402                     readerThread = NativeThread.current();
   401                 }
   403                 }
   402 
   404 
   403                 for (;;) {
   405                 for (;;) {
   404                     n = IOUtil.read(fd, bufs, nd);
   406                     n = IOUtil.read(fd, dsts, offset, length, nd);
   405                     if ((n == IOStatus.INTERRUPTED) && isOpen())
   407                     if ((n == IOStatus.INTERRUPTED) && isOpen())
   406                         continue;
   408                         continue;
   407                     return IOStatus.normalize(n);
   409                     return IOStatus.normalize(n);
   408                 }
   410                 }
   409             } finally {
   411             } finally {
   414                         return IOStatus.EOF;
   416                         return IOStatus.EOF;
   415                 }
   417                 }
   416                 assert IOStatus.check(n);
   418                 assert IOStatus.check(n);
   417             }
   419             }
   418         }
   420         }
   419     }
       
   420 
       
   421     public long read(ByteBuffer[] dsts, int offset, int length)
       
   422         throws IOException
       
   423     {
       
   424         if ((offset < 0) || (length < 0) || (offset > dsts.length - length))
       
   425             throw new IndexOutOfBoundsException();
       
   426         // ## Fix IOUtil.write so that we can avoid this array copy
       
   427         return read0(Util.subsequence(dsts, offset, length));
       
   428     }
   421     }
   429 
   422 
   430     public int write(ByteBuffer buf) throws IOException {
   423     public int write(ByteBuffer buf) throws IOException {
   431         if (buf == null)
   424         if (buf == null)
   432             throw new NullPointerException();
   425             throw new NullPointerException();
   456                 assert IOStatus.check(n);
   449                 assert IOStatus.check(n);
   457             }
   450             }
   458         }
   451         }
   459     }
   452     }
   460 
   453 
   461     public long write0(ByteBuffer[] bufs) throws IOException {
   454     public long write(ByteBuffer[] srcs, int offset, int length)
   462         if (bufs == null)
   455         throws IOException
   463             throw new NullPointerException();
   456     {
       
   457         if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
       
   458             throw new IndexOutOfBoundsException();
   464         synchronized (writeLock) {
   459         synchronized (writeLock) {
   465             ensureWriteOpen();
   460             ensureWriteOpen();
   466             long n = 0;
   461             long n = 0;
   467             try {
   462             try {
   468                 begin();
   463                 begin();
   470                     if (!isOpen())
   465                     if (!isOpen())
   471                         return 0;
   466                         return 0;
   472                     writerThread = NativeThread.current();
   467                     writerThread = NativeThread.current();
   473                 }
   468                 }
   474                 for (;;) {
   469                 for (;;) {
   475                     n = IOUtil.write(fd, bufs, nd);
   470                     n = IOUtil.write(fd, srcs, offset, length, nd);
   476                     if ((n == IOStatus.INTERRUPTED) && isOpen())
   471                     if ((n == IOStatus.INTERRUPTED) && isOpen())
   477                         continue;
   472                         continue;
   478                     return IOStatus.normalize(n);
   473                     return IOStatus.normalize(n);
   479                 }
   474                 }
   480             } finally {
   475             } finally {
   485                         throw new AsynchronousCloseException();
   480                         throw new AsynchronousCloseException();
   486                 }
   481                 }
   487                 assert IOStatus.check(n);
   482                 assert IOStatus.check(n);
   488             }
   483             }
   489         }
   484         }
   490     }
       
   491 
       
   492     public long write(ByteBuffer[] srcs, int offset, int length)
       
   493         throws IOException
       
   494     {
       
   495         if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
       
   496             throw new IndexOutOfBoundsException();
       
   497         // ## Fix IOUtil.write so that we can avoid this array copy
       
   498         return write0(Util.subsequence(srcs, offset, length));
       
   499     }
   485     }
   500 
   486 
   501     // package-private
   487     // package-private
   502     int sendOutOfBandData(byte b) throws IOException {
   488     int sendOutOfBandData(byte b) throws IOException {
   503         synchronized (writeLock) {
   489         synchronized (writeLock) {