/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*
*
* Tests that the channel returned by System.inheritedChannel()
* is in blocking mode, bound, and in the case of a SocketChannel
* connected to a peer.
*
* The test works by launching a test service (called StateTestService) so
* that it inherits each type of channel. The test service checks the
* socket state and replies back to this class via an out-of-band
* channel.
*/
public class StateTest {
/*
* Reads the test result from the "out-of-band" connection to the test service.
*
* The out-of-band connection is just a TCP connection from the service to
* this class. waitForTestResult just waits (with timeout) for the service
* to connect. Once connected it waits (with timeout) for the test result.
* The test result is examined.
*/
private static void waitForTestResult(ServerSocketChannel ssc, boolean expectFail) throws IOException {
/*
* Wait for service to connect
*/
ssc.configureBlocking(false);
for (;;) {
// connection established
break;
}
if (to <= 0) {
throw new IOException("Timed out waiting for service to report test result");
}
}
ssc.configureBlocking(false);
/*
* Wait for service to report test result
*/
sc.configureBlocking(false);
to = 5000;
for (;;) {
if (sk.isReadable()) {
if (n > 0) {
break;
}
if (n < 0) {
throw new IOException("Premature EOF - no test result from service");
}
}
if (to <= 0) {
throw new IOException("Timed out waiting for service to report test result");
}
}
/*
* Examine the test result
*/
if (expectFail && b == 'P') {
failures++;
}
if (!expectFail && b != 'P') {
failures++;
}
}
boolean expectFail = false;
/*
* [-expectFail] [options...]
*/
// shift out first arg to create options
expectFail = true;
}
}
/*
* Create the listener which will be used to read the test result
* from the service.
*/
/*
* The port is passed to the service as an argument.
*/
/*
* Launch service with a SocketChannel (tcp nowait)
*/
/*
* Launch service with a ServerSocketChannel (tcp wait)
* launchWithServerSocketChannel establishes a connection to the service
* and the returned SocketChannel is connected to the service.
*/
/*
* Launch service with a DatagramChannel (udp wait)
*/
if (failures > 0) {
throw new RuntimeException("Test failed - see log for details");
} else {
}
}
}