src/java.base/share/classes/java/net/HttpConnectSocketImpl.java
author michaelm
Fri, 08 Feb 2019 19:29:14 +0000
branchniosocketimpl-branch
changeset 57167 82874527373e
parent 57112 d7b54daf5e1a
child 57171 d8ed7335dadd
permissions -rw-r--r--
Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     1
/*
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     4
 *
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    10
 *
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    15
 * accompanied this code).
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    16
 *
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    20
 *
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    23
 * questions.
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    24
 */
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    25
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    26
package java.net;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    27
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    28
import java.io.FileDescriptor;
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    29
import java.io.IOException;
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    30
import java.io.InputStream;
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    31
import java.io.OutputStream;
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    32
import java.lang.reflect.Field;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    33
import java.lang.reflect.Method;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    34
import java.util.HashMap;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    35
import java.util.Map;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    36
import java.util.Set;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    37
57110
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
    38
import sun.nio.ch.NioSocketImpl;
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
    39
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    40
/**
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    41
 * Basic SocketImpl that relies on the internal HTTP protocol handler
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    42
 * implementation to perform the HTTP tunneling and authentication. The
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    43
 * sockets impl is swapped out and replaced with the socket from the HTTP
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    44
 * handler after the tunnel is successfully setup.
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    45
 *
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    46
 * @since 1.8
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    47
 */
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    48
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    49
/*package*/ class HttpConnectSocketImpl extends SocketImpl implements SocketImpl.DelegatingImpl {
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    50
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    51
    private static final String httpURLClazzStr =
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    52
                                  "sun.net.www.protocol.http.HttpURLConnection";
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    53
    private static final String netClientClazzStr = "sun.net.NetworkClient";
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    54
    private static final String doTunnelingStr = "doTunneling";
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    55
    private static final Field httpField;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    56
    private static final Field serverSocketField;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    57
    private static final Method doTunneling;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    58
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    59
    private final String server;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    60
    private InetSocketAddress external_address;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    61
    private HashMap<Integer, Object> optionsMap = new HashMap<>();
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    62
    private final SocketImpl delegate;
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    63
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    64
    static  {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    65
        try {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    66
            Class<?> httpClazz = Class.forName(httpURLClazzStr, true, null);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    67
            httpField = httpClazz.getDeclaredField("http");
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    68
            doTunneling = httpClazz.getDeclaredMethod(doTunnelingStr);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    69
            Class<?> netClientClazz = Class.forName(netClientClazzStr, true, null);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    70
            serverSocketField = netClientClazz.getDeclaredField("serverSocket");
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    71
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    72
            java.security.AccessController.doPrivileged(
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
    73
                new java.security.PrivilegedAction<>() {
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    74
                    public Void run() {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    75
                        httpField.setAccessible(true);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    76
                        serverSocketField.setAccessible(true);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    77
                        return null;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    78
                }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    79
            });
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    80
        } catch (ReflectiveOperationException x) {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    81
            throw new InternalError("Should not reach here", x);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    82
        }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    83
    }
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    84
    HttpConnectSocketImpl(SocketImpl delegate) {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    85
        this.delegate = delegate;
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    86
        this.server = null;
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    87
        throw new InternalError();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    88
    }
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    89
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    90
    HttpConnectSocketImpl(Proxy proxy, SocketImpl delegate) {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
    91
        this.delegate = delegate;
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    92
        SocketAddress a = proxy.address();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    93
        if ( !(a instanceof InetSocketAddress) )
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    94
            throw new IllegalArgumentException("Unsupported address type");
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    95
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    96
        InetSocketAddress ad = (InetSocketAddress) a;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    97
        server = ad.getHostString();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    98
        port = ad.getPort();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
    99
    }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   100
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   101
    @Override
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   102
    protected void create(boolean stream) throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   103
        delegate.create(stream);
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   104
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   105
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   106
    @Override
57110
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   107
    protected void connect(String host, int port) throws IOException {
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   108
        connect(new InetSocketAddress(host, port), 0);
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   109
    }
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   110
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   111
    @Override
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   112
    protected void connect(InetAddress address, int port) throws IOException {
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   113
        connect(new InetSocketAddress(address, port), 0);
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   114
    }
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   115
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   116
    @Override
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   117
    void setSocket(Socket socket) {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   118
        delegate.socket = socket;
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   119
        super.setSocket(socket);
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   120
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   121
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   122
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   123
    void setServerSocket(ServerSocket socket) {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   124
        delegate.serverSocket = socket;
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   125
        super.setServerSocket(socket);
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   126
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   127
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   128
    @Override
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   129
    protected void connect(SocketAddress endpoint, int timeout)
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   130
        throws IOException
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   131
    {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   132
        if (endpoint == null || !(endpoint instanceof InetSocketAddress))
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   133
            throw new IllegalArgumentException("Unsupported address type");
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   134
        final InetSocketAddress epoint = (InetSocketAddress)endpoint;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   135
        final String destHost = epoint.isUnresolved() ? epoint.getHostName()
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   136
                                                      : epoint.getAddress().getHostAddress();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   137
        final int destPort = epoint.getPort();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   138
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   139
        SecurityManager security = System.getSecurityManager();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   140
        if (security != null)
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   141
            security.checkConnect(destHost, destPort);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   142
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   143
        // Connect to the HTTP proxy server
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   144
        String urlString = "http://" + destHost + ":" + destPort;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   145
        Socket httpSocket = privilegedDoTunnel(urlString, timeout);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   146
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   147
        // Success!
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   148
        external_address = epoint;
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   149
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   150
        // close the original socket impl and release its descriptor
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   151
        close();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   152
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   153
        // update the Sockets impl to the impl from the http Socket
57110
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   154
        SocketImpl si = httpSocket.impl;
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   155
        ((SocketImpl) this).getSocket().setImpl(si);
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   156
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   157
        // best effort is made to try and reset options previously set
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   158
        Set<Map.Entry<Integer,Object>> options = optionsMap.entrySet();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   159
        try {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   160
            for(Map.Entry<Integer,Object> entry : options) {
57110
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   161
                si.setOption(entry.getKey(), entry.getValue());
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   162
            }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   163
        } catch (IOException x) {  /* gulp! */  }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   164
    }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   165
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   166
    @Override
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   167
    protected void bind(InetAddress host, int port) throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   168
        delegate.bind(host, port);
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   169
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   170
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   171
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   172
    protected void listen(int backlog) throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   173
        throw new IllegalStateException();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   174
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   175
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   176
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   177
    protected void accept(SocketImpl s) throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   178
        throw new IllegalStateException();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   179
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   180
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   181
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   182
    protected InputStream getInputStream() throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   183
        return delegate.getInputStream();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   184
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   185
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   186
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   187
    protected OutputStream getOutputStream() throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   188
        return delegate.getOutputStream();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   189
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   190
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   191
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   192
    protected int available() throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   193
        return delegate.available();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   194
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   195
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   196
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   197
    protected void close() throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   198
        delegate.close();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   199
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   200
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   201
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   202
    protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   203
        delegate.setOption(name, value);
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   204
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   205
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   206
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   207
    protected <T> T getOption(SocketOption<T> name) throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   208
        return delegate.getOption(name);
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   209
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   210
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   211
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   212
    void reset() throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   213
        delegate.reset();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   214
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   215
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   216
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   217
    protected Set<SocketOption<?>> supportedOptions() {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   218
        return delegate.supportedOptions();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   219
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   220
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   221
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   222
    protected boolean supportsUrgentData () {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   223
        return delegate.supportsUrgentData();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   224
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   225
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   226
    @Override
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   227
    public void setOption(int opt, Object val) throws SocketException {
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   228
        delegate.setOption(opt, val);
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   229
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   230
        if (external_address != null)
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   231
            return;  // we're connected, just return
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   232
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   233
        // store options so that they can be re-applied to the impl after connect
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   234
        optionsMap.put(opt, val);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   235
    }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   236
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   237
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   238
    public Object getOption(int optID) throws SocketException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   239
        return delegate.getOption(optID);
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   240
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   241
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   242
    private Socket privilegedDoTunnel(final String urlString,
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   243
                                      final int timeout)
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   244
        throws IOException
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   245
    {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   246
        try {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   247
            return java.security.AccessController.doPrivileged(
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   248
                new java.security.PrivilegedExceptionAction<>() {
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   249
                    public Socket run() throws IOException {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   250
                        return doTunnel(urlString, timeout);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   251
                }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   252
            });
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   253
        } catch (java.security.PrivilegedActionException pae) {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   254
            throw (IOException) pae.getException();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   255
        }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   256
    }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   257
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   258
    private Socket doTunnel(String urlString, int connectTimeout)
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   259
        throws IOException
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   260
    {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   261
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(server, port));
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   262
        URL destURL = new URL(urlString);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   263
        HttpURLConnection conn = (HttpURLConnection) destURL.openConnection(proxy);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   264
        conn.setConnectTimeout(connectTimeout);
57112
alanb
parents: 57110 53473
diff changeset
   265
        int timeout = (int) getOption(SocketOptions.SO_TIMEOUT);
alanb
parents: 57110 53473
diff changeset
   266
        if (timeout > 0) {
57110
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   267
            conn.setReadTimeout(timeout);
b848ca1ef778 Prototype of NIO based SocketImpl
alanb
parents: 47216
diff changeset
   268
        }
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   269
        conn.connect();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   270
        doTunneling(conn);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   271
        try {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   272
            Object httpClient = httpField.get(conn);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   273
            return (Socket) serverSocketField.get(httpClient);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   274
        } catch (IllegalAccessException x) {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   275
            throw new InternalError("Should not reach here", x);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   276
        }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   277
    }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   278
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   279
    private void doTunneling(HttpURLConnection conn) {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   280
        try {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   281
            doTunneling.invoke(conn);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   282
        } catch (ReflectiveOperationException x) {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   283
            throw new InternalError("Should not reach here", x);
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   284
        }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   285
    }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   286
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   287
    @Override
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   288
    protected InetAddress getInetAddress() {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   289
        if (external_address != null)
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   290
            return external_address.getAddress();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   291
        else
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   292
            return delegate.getInetAddress();
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   293
    }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   294
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   295
    @Override
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   296
    protected int getPort() {
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   297
        if (external_address != null)
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   298
            return external_address.getPort();
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   299
        else
57167
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   300
            return delegate.getPort();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   301
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   302
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   303
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   304
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   305
    protected FileDescriptor getFileDescriptor() {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   306
        return delegate.getFileDescriptor();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   307
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   308
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   309
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   310
    protected void shutdownInput() throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   311
        delegate.shutdownInput();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   312
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   313
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   314
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   315
    protected void shutdownOutput() throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   316
        delegate.shutdownOutput();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   317
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   318
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   319
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   320
    protected int getLocalPort() {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   321
        return delegate.getLocalPort();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   322
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   323
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   324
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   325
    protected void sendUrgentData(int data) throws IOException {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   326
        delegate.sendUrgentData(data);
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   327
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   328
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   329
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   330
    public SocketImpl delegate() {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   331
        return delegate;
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   332
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   333
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   334
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   335
    public SocketImpl newInstance() {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   336
        if (delegate instanceof PlainSocketImpl)
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   337
            return new HttpConnectSocketImpl(new PlainSocketImpl());
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   338
        else if (delegate instanceof NioSocketImpl)
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   339
            return new HttpConnectSocketImpl(new NioSocketImpl(false));
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   340
        throw new InternalError();
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   341
    }
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   342
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   343
    @Override
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   344
    public void postCustomAccept() {
82874527373e Socket changes to support both NioSocketImpl and PlainSocketImpl switchable by net property
michaelm
parents: 57112
diff changeset
   345
        // TODO
16061
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   346
    }
c80133bafef0 6370908: Add support for HTTP_CONNECT proxy in Socket class
chegar
parents:
diff changeset
   347
}