jdk/test/java/nio/channels/AsynchronousSocketChannel/StressLoopback.java
changeset 3327 82e069ae54ab
parent 2705 27b7f2d5e949
child 3632 399359a027de
equal deleted inserted replaced
3326:31a5302fe6d4 3327:82e069ae54ab
    97         }
    97         }
    98 
    98 
    99         void start() {
    99         void start() {
   100             sentBuffer.position(0);
   100             sentBuffer.position(0);
   101             sentBuffer.limit(sentBuffer.capacity());
   101             sentBuffer.limit(sentBuffer.capacity());
   102             channel.write(sentBuffer, null, new CompletionHandler<Integer,Void> () {
   102             channel.write(sentBuffer, (Void)null, new CompletionHandler<Integer,Void> () {
   103                 public void completed(Integer nwrote, Void att) {
   103                 public void completed(Integer nwrote, Void att) {
   104                     bytesSent += nwrote;
   104                     bytesSent += nwrote;
   105                     if (finished) {
   105                     if (finished) {
   106                         closeUnchecked(channel);
   106                         closeUnchecked(channel);
   107                     } else {
   107                     } else {
   108                         sentBuffer.position(0);
   108                         sentBuffer.position(0);
   109                         sentBuffer.limit(sentBuffer.capacity());
   109                         sentBuffer.limit(sentBuffer.capacity());
   110                         channel.write(sentBuffer, null, this);
   110                         channel.write(sentBuffer, (Void)null, this);
   111                     }
   111                     }
   112                 }
   112                 }
   113                 public void failed(Throwable exc, Void att) {
   113                 public void failed(Throwable exc, Void att) {
   114                     exc.printStackTrace();
   114                     exc.printStackTrace();
   115                     closeUnchecked(channel);
   115                     closeUnchecked(channel);
   140             this.readBuffer = (rand.nextBoolean()) ?
   140             this.readBuffer = (rand.nextBoolean()) ?
   141                 ByteBuffer.allocateDirect(size) : ByteBuffer.allocate(size);
   141                 ByteBuffer.allocateDirect(size) : ByteBuffer.allocate(size);
   142         }
   142         }
   143 
   143 
   144         void start() {
   144         void start() {
   145             channel.read(readBuffer, null, new CompletionHandler<Integer,Void> () {
   145             channel.read(readBuffer, (Void)null, new CompletionHandler<Integer,Void> () {
   146                 public void completed(Integer nread, Void att) {
   146                 public void completed(Integer nread, Void att) {
   147                     if (nread < 0) {
   147                     if (nread < 0) {
   148                         closeUnchecked(channel);
   148                         closeUnchecked(channel);
   149                     } else {
   149                     } else {
   150                         bytesRead += nread;
   150                         bytesRead += nread;
   151                         readBuffer.clear();
   151                         readBuffer.clear();
   152                         channel.read(readBuffer, null, this);
   152                         channel.read(readBuffer, (Void)null, this);
   153                     }
   153                     }
   154                 }
   154                 }
   155                 public void failed(Throwable exc, Void att) {
   155                 public void failed(Throwable exc, Void att) {
   156                     exc.printStackTrace();
   156                     exc.printStackTrace();
   157                     closeUnchecked(channel);
   157                     closeUnchecked(channel);