test/micro/org/openjdk/bench/java/net/SocketChannelCompare.java
author michaelm
Tue, 05 Nov 2019 16:00:51 +0000
branchunixdomainchannels
changeset 58935 f31f0c8bff89
parent 58933 57a2e3ed90ec
child 59003 aaba7cc40951
permissions -rw-r--r--
make benchmark use loopback address
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58933
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     1
/*
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     4
 *
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     8
 *
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    13
 * accompanied this code).
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    14
 *
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    18
 *
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    21
 * questions.
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    22
 */
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    23
package org.openjdk.bench.java.net;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    24
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    25
import java.io.IOException;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    26
import java.net.InetAddress;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    27
import java.net.InetSocketAddress;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    28
import java.net.StandardProtocolFamily;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    29
import java.nio.channels.UnixDomainSocketAddress;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    30
import java.nio.ByteBuffer;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    31
import java.nio.channels.ClosedChannelException;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    32
import java.nio.channels.ServerSocketChannel;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    33
import java.nio.channels.SocketChannel;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    34
import java.nio.file.*;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    35
import java.util.concurrent.TimeUnit;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    36
import java.util.concurrent.atomic.AtomicInteger;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    37
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    38
import org.openjdk.jmh.annotations.*;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    39
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    40
/**
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    41
 * Tests sending a 128 byte message on a second, to a thread which
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    42
 * echo's it back and received by the original thread.
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    43
 * Benchmark is performed for "inet" channels over TCP/IP
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    44
 * and "unix" domain channels.
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    45
 */
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    46
@BenchmarkMode(Mode.Throughput)
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    47
@OutputTimeUnit(TimeUnit.MILLISECONDS)
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    48
@State(Scope.Thread)
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    49
public class SocketChannelCompare {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    50
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    51
    static final int BUFSIZE = 128; // message size sent and received
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    52
    private ServerSocketChannel ssc;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    53
    private SocketChannel s1, s2;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    54
    private EchoThread rt;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    55
    private ByteBuffer bb = ByteBuffer.allocate(BUFSIZE);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    56
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    57
    private static volatile String tempDir;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    58
    private static final AtomicInteger count = new AtomicInteger(0);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    59
    private volatile Path socket;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    60
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    61
    @Param({"inet", "unix"})
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    62
    private volatile String family;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    63
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    64
    static {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    65
        try {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    66
            Path p = Files.createTempDirectory("readWriteTest");
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    67
            tempDir = p.toString();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    68
        } catch (IOException e) {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    69
            tempDir = null;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    70
        }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    71
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    72
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    73
    private ServerSocketChannel getServerSocketChannel() throws IOException {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    74
        if (family.equals("inet"))
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    75
            return getInetServerSocketChannel();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    76
        else if (family.equals("unix"))
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    77
            return getUnixServerSocketChannel();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    78
        throw new InternalError();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    79
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    80
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    81
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    82
    private ServerSocketChannel getInetServerSocketChannel() throws IOException {
58935
f31f0c8bff89 make benchmark use loopback address
michaelm
parents: 58933
diff changeset
    83
        InetAddress iaddr = InetAddress.getLoopbackAddress();
58933
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    84
        return ServerSocketChannel.open().bind(null);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    85
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    86
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    87
    private ServerSocketChannel getUnixServerSocketChannel() throws IOException {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    88
        int next = count.incrementAndGet();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    89
        socket = Paths.get(tempDir, Integer.toString(next));
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    90
        UnixDomainSocketAddress addr = new UnixDomainSocketAddress(socket);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    91
        return ServerSocketChannel.open(StandardProtocolFamily.UNIX).bind(addr);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    92
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    93
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    94
    @Setup(Level.Trial)
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    95
    public void beforeRun() throws IOException {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    96
        ssc = getServerSocketChannel();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    97
        s1 = SocketChannel.open(ssc.getLocalAddress());
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    98
        s2 = ssc.accept();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
    99
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   100
        rt = new EchoThread(s2);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   101
        rt.start();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   102
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   103
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   104
    @TearDown(Level.Trial)
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   105
    public void afterRun() throws IOException, InterruptedException {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   106
        s1.close();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   107
        s2.close();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   108
        ssc.close();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   109
        if (family.equals("unix")) {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   110
            Files.delete(socket);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   111
            Files.delete(Path.of(tempDir));
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   112
        }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   113
        rt.join();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   114
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   115
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   116
    @Benchmark
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   117
    public void test() throws IOException {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   118
        bb.position(0).limit(BUFSIZE);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   119
        s1.write(bb);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   120
        bb.clear();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   121
        readFully(s1, bb);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   122
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   123
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   124
    // read until buf is full, or EOF. Always returns number of bytes read
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   125
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   126
    static int readFully(SocketChannel chan, ByteBuffer buf) throws IOException {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   127
        int n = buf.remaining();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   128
        int count = 0;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   129
        while (n > 0) {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   130
            int c = chan.read(buf);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   131
            if (c == -1)
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   132
                return count;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   133
            n -= c;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   134
            count += c;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   135
        }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   136
        return count;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   137
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   138
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   139
    static class EchoThread extends Thread {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   140
        private SocketChannel sc;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   141
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   142
        public EchoThread(SocketChannel s2) {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   143
            this.sc = s2;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   144
        }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   145
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   146
        public void run() {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   147
            try {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   148
                ByteBuffer bb = ByteBuffer.allocate(BUFSIZE);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   149
                while (true) {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   150
                    bb.clear();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   151
                    int c = readFully(sc, bb);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   152
                    if (c == 0) {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   153
                        sc.close();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   154
                        return;
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   155
                    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   156
                    bb.flip();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   157
                    sc.write(bb);
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   158
                }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   159
            } catch (ClosedChannelException ex) {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   160
                // shutdown time
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   161
            } catch (IOException ioex) {
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   162
		ioex.printStackTrace();
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   163
            }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   164
        }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   165
    }
57a2e3ed90ec added some micro benchmarks (SocketChannelCompare does direct comparison)
michaelm
parents:
diff changeset
   166
}