src/java.base/share/classes/sun/nio/ch/ServerSocketAdaptor.java
author alanb
Sat, 30 Nov 2019 16:21:19 +0000
changeset 59329 289000934908
parent 58614 29624901d8bc
child 58801 119ac9128c1b
permissions -rw-r--r--
8234805: (dc) Remove JNI upcall from DatagramChannel.receive implementation Reviewed-by: dfuchs, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
     2
 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.nio.ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
48761
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    28
import java.io.IOException;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    29
import java.net.InetAddress;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    30
import java.net.InetSocketAddress;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    31
import java.net.ServerSocket;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    32
import java.net.Socket;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    33
import java.net.SocketAddress;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    34
import java.net.SocketException;
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    35
import java.net.SocketOption;
48761
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    36
import java.net.StandardSocketOptions;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    37
import java.nio.channels.IllegalBlockingModeException;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    38
import java.nio.channels.ServerSocketChannel;
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    39
import java.nio.channels.SocketChannel;
58614
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    40
import java.security.AccessController;
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    41
import java.security.PrivilegedActionException;
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    42
import java.security.PrivilegedExceptionAction;
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    43
import java.util.Set;
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    44
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    45
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
// Make a server-socket channel look like a server socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
// The methods in this class are defined in exactly the same order as in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
// java.net.ServerSocket so as to simplify tracking future changes to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
// class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
48761
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
    55
class ServerSocketAdaptor                        // package-private
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    extends ServerSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // The channel being adapted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private final ServerSocketChannelImpl ssc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // Timeout "option" value for accepts
34774
03b4e6dc367b 8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents: 25859
diff changeset
    62
    private volatile int timeout;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    64
    static ServerSocket create(ServerSocketChannelImpl ssc) {
58614
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    65
        PrivilegedExceptionAction<ServerSocket> pa = () -> new ServerSocketAdaptor(ssc);
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    66
        try {
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    67
            return AccessController.doPrivileged(pa);
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    68
        } catch (PrivilegedActionException pae) {
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    69
            throw new InternalError("Should not reach here", pae);
29624901d8bc 8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
aefimov
parents: 54620
diff changeset
    70
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    73
    private ServerSocketAdaptor(ServerSocketChannelImpl ssc) {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    74
        super(DummySocketImpl.create());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.ssc = ssc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    78
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public void bind(SocketAddress local) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        bind(local, 50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    83
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public void bind(SocketAddress local, int backlog) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (local == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            local = new InetSocketAddress(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            ssc.bind(local, backlog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } catch (Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            Net.translateException(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
    94
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public InetAddress getInetAddress() {
49001
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
    96
        InetSocketAddress local = ssc.localAddress();
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
    97
        if (local == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            return null;
49001
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
    99
        } else {
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
   100
            return Net.getRevealedLocalAddress(local).getAddress();
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
   101
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   104
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public int getLocalPort() {
49001
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
   106
        InetSocketAddress local = ssc.localAddress();
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
   107
        if (local == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return -1;
49001
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
   109
        } else {
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
   110
            return local.getPort();
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48761
diff changeset
   111
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   114
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public Socket accept() throws IOException {
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   116
        SocketChannel sc = null;
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   117
        try {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   118
            int timeout = this.timeout;
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   119
            if (timeout > 0) {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   120
                long nanos = MILLISECONDS.toNanos(timeout);
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   121
                sc = ssc.blockingAccept(nanos);
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   122
            } else {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   123
                // accept connection if possible when non-blocking (to preserve
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   124
                // long standing behavior)
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   125
                sc = ssc.accept();
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   126
                if (sc == null) {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   127
                    throw new IllegalBlockingModeException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   130
        } catch (Exception e) {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   131
            Net.translateException(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   133
        return sc.socket();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   136
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void close() throws IOException {
5784
e565c553e9fc 6938230: (so) SocketAdaptor.close() does not translate IOException resulting in Error
alanb
parents: 5506
diff changeset
   138
        ssc.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   141
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public ServerSocketChannel getChannel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return ssc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   146
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public boolean isBound() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return ssc.isBound();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   151
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public boolean isClosed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return !ssc.isOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   156
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void setSoTimeout(int timeout) throws SocketException {
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   158
        if (!ssc.isOpen())
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   159
            throw new SocketException("Socket is closed");
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   160
        if (timeout < 0)
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   161
            throw new IllegalArgumentException("timeout < 0");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        this.timeout = timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   165
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public int getSoTimeout() throws SocketException {
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   167
        if (!ssc.isOpen())
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   168
            throw new SocketException("Socket is closed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   172
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public void setReuseAddress(boolean on) throws SocketException {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   174
        try {
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
   175
            ssc.setOption(StandardSocketOptions.SO_REUSEADDR, on);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   176
        } catch (IOException x) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   177
            Net.translateToSocketException(x);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   178
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   181
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public boolean getReuseAddress() throws SocketException {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   183
        try {
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
   184
            return ssc.getOption(StandardSocketOptions.SO_REUSEADDR).booleanValue();
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   185
        } catch (IOException x) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   186
            Net.translateToSocketException(x);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   187
            return false;       // Never happens
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   188
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   191
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (!isBound())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return "ServerSocket[unbound]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return "ServerSocket[addr=" + getInetAddress() +
48761
74c1fa26435a 8196956: (ch) More channels cleanup
alanb
parents: 47216
diff changeset
   196
               ",localport=" + getLocalPort()  + "]";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   199
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public void setReceiveBufferSize(int size) throws SocketException {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   201
        // size 0 valid for ServerSocketChannel, invalid for ServerSocket
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   202
        if (size <= 0)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   203
            throw new IllegalArgumentException("size cannot be 0 or negative");
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   204
        try {
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
   205
            ssc.setOption(StandardSocketOptions.SO_RCVBUF, size);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   206
        } catch (IOException x) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   207
            Net.translateToSocketException(x);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   208
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   211
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public int getReceiveBufferSize() throws SocketException {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   213
        try {
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
   214
            return ssc.getOption(StandardSocketOptions.SO_RCVBUF).intValue();
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   215
        } catch (IOException x) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   216
            Net.translateToSocketException(x);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   217
            return -1;          // Never happens
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   218
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
54620
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   220
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   221
    @Override
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   222
    public <T> ServerSocket setOption(SocketOption<T> name, T value) throws IOException {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   223
        ssc.setOption(name, value);
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   224
        return this;
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   225
    }
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   226
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   227
    @Override
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   228
    public <T> T getOption(SocketOption<T> name) throws IOException {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   229
        return ssc.getOption(name);
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   230
    }
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   231
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   232
    @Override
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   233
    public Set<SocketOption<?>> supportedOptions() {
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   234
        return ssc.supportedOptions();
13b67c1420b8 8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents: 49001
diff changeset
   235
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
}