test/jdk/java/net/Socket/TestClose.java
changeset 57686 70f5cbb711a9
parent 54811 9db7c0f561a6
equal deleted inserted replaced
57685:e4cc5231ce2d 57686:70f5cbb711a9
     1 /*
     1 /*
     2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    42         ServerSocket ss;
    42         ServerSocket ss;
    43         Socket s;
    43         Socket s;
    44         InetAddress ad1, ad2;
    44         InetAddress ad1, ad2;
    45         int port1, port2, serverport;
    45         int port1, port2, serverport;
    46 
    46 
    47         ss = new ServerSocket(0);
    47         InetAddress loopback = InetAddress.getLoopbackAddress();
       
    48         ss = new ServerSocket();
       
    49         ss.bind(new InetSocketAddress(loopback, 0));
    48         serverport = ss.getLocalPort();
    50         serverport = ss.getLocalPort();
    49         s = new Socket("localhost", serverport);
    51         s = new Socket(loopback, serverport);
    50         s.close();
    52         s.close();
    51         ss.close();
    53         ss.close();
    52         ad1 = ss.getInetAddress();
    54         ad1 = ss.getInetAddress();
    53         if (ad1 == null)
    55         if (ad1 == null)
    54             throw new RuntimeException("ServerSocket.getInetAddress() returned null");
    56             throw new RuntimeException("ServerSocket.getInetAddress() returned null");