test/jdk/java/net/SocketImpl/java.base/java/net/PlatformSocketImpl.java
author alanb
Thu, 30 May 2019 07:19:19 +0100
changeset 55102 59567035d279
permissions -rw-r--r--
8221481: Reimplement the Legacy Socket API Reviewed-by: michaelm, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55102
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     1
/*
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     4
 *
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     8
 *
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    13
 * accompanied this code).
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    14
 *
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    18
 *
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    21
 * questions.
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    22
 */
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    23
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    24
package java.net;
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    25
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    26
import java.io.InputStream;
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    27
import java.io.OutputStream;
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    28
import java.io.IOException;
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    29
import java.util.Set;
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    30
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    31
/**
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    32
 * A SocketImpl that delegates all operations to a platform SocketImpl. It also
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    33
 * overrides all methods with public methods and implements AutoCloseable to make
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    34
 * it easy to write tests.
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    35
 */
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    36
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    37
public class PlatformSocketImpl extends SocketImpl implements AutoCloseable {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    38
    private final SocketImpl impl;
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    39
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    40
    public PlatformSocketImpl(boolean server) {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    41
        impl = new sun.nio.ch.NioSocketImpl(server);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    42
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    43
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    44
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    45
    public void close() throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    46
        impl.close();
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    47
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    48
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    49
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    50
    public void create(boolean stream) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    51
        impl.create(stream);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    52
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    53
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    54
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    55
    public void connect(SocketAddress remote, int millis) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    56
        impl.connect(remote, millis);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    57
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    58
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    59
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    60
    public void connect(String host, int port) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    61
        impl.connect(host, port);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    62
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    63
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    64
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    65
    public void connect(InetAddress address, int port) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    66
        impl.connect(address, port);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    67
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    68
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    69
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    70
    public void bind(InetAddress address, int port) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    71
        impl.bind(address, port);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    72
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    73
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    74
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    75
    public void listen(int backlog) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    76
        impl.listen(backlog);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    77
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    78
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    79
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    80
    public void accept(SocketImpl si) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    81
        impl.accept(((PlatformSocketImpl) si).impl);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    82
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    83
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    84
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    85
    public InputStream getInputStream() throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    86
        return impl.getInputStream();
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    87
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    88
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    89
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    90
    public OutputStream getOutputStream() throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    91
        return impl.getOutputStream();
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    92
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    93
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    94
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    95
    public int available() throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    96
        return impl.available();
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    97
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    98
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
    99
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   100
    public Set<SocketOption<?>> supportedOptions() {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   101
        return impl.supportedOptions();
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   102
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   103
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   104
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   105
    public <T> void setOption(SocketOption<T> opt, T value) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   106
        impl.setOption(opt, value);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   107
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   108
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   109
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   110
    public <T> T getOption(SocketOption<T> opt) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   111
        return impl.getOption(opt);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   112
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   113
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   114
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   115
    public void setOption(int opt, Object value) throws SocketException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   116
        impl.setOption(opt, value);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   117
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   118
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   119
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   120
    public Object getOption(int opt) throws SocketException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   121
       return impl.getOption(opt);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   122
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   123
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   124
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   125
    public void shutdownInput() throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   126
       impl.shutdownInput();
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   127
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   128
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   129
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   130
    public void shutdownOutput() throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   131
        impl.shutdownOutput();
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   132
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   133
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   134
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   135
    public boolean supportsUrgentData() {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   136
        return impl.supportsUrgentData();
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   137
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   138
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   139
    @Override
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   140
    public void sendUrgentData(int data) throws IOException {
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   141
        impl.sendUrgentData(data);
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   142
    }
59567035d279 8221481: Reimplement the Legacy Socket API
alanb
parents:
diff changeset
   143
}