equal
deleted
inserted
replaced
534 assert IOStatus.check(n); |
534 assert IOStatus.check(n); |
535 } |
535 } |
536 } |
536 } |
537 } |
537 } |
538 |
538 |
539 private long read0(ByteBuffer[] bufs) throws IOException { |
539 public long read(ByteBuffer[] dsts, int offset, int length) |
540 if (bufs == null) |
540 throws IOException |
541 throw new NullPointerException(); |
541 { |
|
542 if ((offset < 0) || (length < 0) || (offset > dsts.length - length)) |
|
543 throw new IndexOutOfBoundsException(); |
542 synchronized (readLock) { |
544 synchronized (readLock) { |
543 synchronized (stateLock) { |
545 synchronized (stateLock) { |
544 ensureOpen(); |
546 ensureOpen(); |
545 if (!isConnected()) |
547 if (!isConnected()) |
546 throw new NotYetConnectedException(); |
548 throw new NotYetConnectedException(); |
550 begin(); |
552 begin(); |
551 if (!isOpen()) |
553 if (!isOpen()) |
552 return 0; |
554 return 0; |
553 readerThread = NativeThread.current(); |
555 readerThread = NativeThread.current(); |
554 do { |
556 do { |
555 n = IOUtil.read(fd, bufs, nd); |
557 n = IOUtil.read(fd, dsts, offset, length, nd); |
556 } while ((n == IOStatus.INTERRUPTED) && isOpen()); |
558 } while ((n == IOStatus.INTERRUPTED) && isOpen()); |
557 return IOStatus.normalize(n); |
559 return IOStatus.normalize(n); |
558 } finally { |
560 } finally { |
559 readerThread = 0; |
561 readerThread = 0; |
560 end((n > 0) || (n == IOStatus.UNAVAILABLE)); |
562 end((n > 0) || (n == IOStatus.UNAVAILABLE)); |
561 assert IOStatus.check(n); |
563 assert IOStatus.check(n); |
562 } |
564 } |
563 } |
565 } |
564 } |
|
565 |
|
566 public long read(ByteBuffer[] dsts, int offset, int length) |
|
567 throws IOException |
|
568 { |
|
569 if ((offset < 0) || (length < 0) || (offset > dsts.length - length)) |
|
570 throw new IndexOutOfBoundsException(); |
|
571 // ## Fix IOUtil.write so that we can avoid this array copy |
|
572 return read0(Util.subsequence(dsts, offset, length)); |
|
573 } |
566 } |
574 |
567 |
575 public int write(ByteBuffer buf) throws IOException { |
568 public int write(ByteBuffer buf) throws IOException { |
576 if (buf == null) |
569 if (buf == null) |
577 throw new NullPointerException(); |
570 throw new NullPointerException(); |
597 assert IOStatus.check(n); |
590 assert IOStatus.check(n); |
598 } |
591 } |
599 } |
592 } |
600 } |
593 } |
601 |
594 |
602 private long write0(ByteBuffer[] bufs) throws IOException { |
595 public long write(ByteBuffer[] srcs, int offset, int length) |
603 if (bufs == null) |
596 throws IOException |
604 throw new NullPointerException(); |
597 { |
|
598 if ((offset < 0) || (length < 0) || (offset > srcs.length - length)) |
|
599 throw new IndexOutOfBoundsException(); |
605 synchronized (writeLock) { |
600 synchronized (writeLock) { |
606 synchronized (stateLock) { |
601 synchronized (stateLock) { |
607 ensureOpen(); |
602 ensureOpen(); |
608 if (!isConnected()) |
603 if (!isConnected()) |
609 throw new NotYetConnectedException(); |
604 throw new NotYetConnectedException(); |
613 begin(); |
608 begin(); |
614 if (!isOpen()) |
609 if (!isOpen()) |
615 return 0; |
610 return 0; |
616 writerThread = NativeThread.current(); |
611 writerThread = NativeThread.current(); |
617 do { |
612 do { |
618 n = IOUtil.write(fd, bufs, nd); |
613 n = IOUtil.write(fd, srcs, offset, length, nd); |
619 } while ((n == IOStatus.INTERRUPTED) && isOpen()); |
614 } while ((n == IOStatus.INTERRUPTED) && isOpen()); |
620 return IOStatus.normalize(n); |
615 return IOStatus.normalize(n); |
621 } finally { |
616 } finally { |
622 writerThread = 0; |
617 writerThread = 0; |
623 end((n > 0) || (n == IOStatus.UNAVAILABLE)); |
618 end((n > 0) || (n == IOStatus.UNAVAILABLE)); |
624 assert IOStatus.check(n); |
619 assert IOStatus.check(n); |
625 } |
620 } |
626 } |
621 } |
627 } |
|
628 |
|
629 public long write(ByteBuffer[] srcs, int offset, int length) |
|
630 throws IOException |
|
631 { |
|
632 if ((offset < 0) || (length < 0) || (offset > srcs.length - length)) |
|
633 throw new IndexOutOfBoundsException(); |
|
634 // ## Fix IOUtil.write so that we can avoid this array copy |
|
635 return write0(Util.subsequence(srcs, offset, length)); |
|
636 } |
622 } |
637 |
623 |
638 protected void implConfigureBlocking(boolean block) throws IOException { |
624 protected void implConfigureBlocking(boolean block) throws IOException { |
639 IOUtil.configureBlocking(fd, block); |
625 IOUtil.configureBlocking(fd, block); |
640 } |
626 } |