Path: blob/master/test/jdk/java/net/Socket/ProxyCons.java
41149 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 409782626* @library /test/lib27* @summary SOCKS support inadequate28* @run main/timeout=40/othervm -DsocksProxyHost=nonexistant ProxyCons29* @run main/timeout=40/othervm -DsocksProxyHost=nonexistant -Djava.net.preferIPv4Stack=true ProxyCons30*/3132import java.net.*;33import jdk.test.lib.net.IPSupport;3435public class ProxyCons {36class Server extends Thread {37ServerSocket server;38Server (ServerSocket server) {39super ();40this.server = server;41}42public void run () {43try {44Socket s = server.accept ();45s.close();46while (!finished ()) {47Thread.sleep (500);48}49} catch (Exception e) {50}51}52boolean isFinished = false;5354synchronized boolean finished () {55return (isFinished);56}57synchronized void done () {58isFinished = true;59}60}6162public ProxyCons() {63}6465void test() throws Exception {66InetAddress localHost = InetAddress.getLocalHost();67ServerSocket ss = new ServerSocket();68ss.bind(new InetSocketAddress(localHost, 0));69try {70Server s = new Server(ss);71s.start();72Socket sock = new Socket(Proxy.NO_PROXY);73sock.connect(new InetSocketAddress(localHost, ss.getLocalPort()));74s.done();75sock.close();76} catch (java.io.IOException e) {77throw new RuntimeException(e);78} finally {79ss.close();80}81}8283public static void main(String[] args) throws Exception {84IPSupport.throwSkippedExceptionIfNonOperational();8586ProxyCons c = new ProxyCons();87c.test();88}89}909192