/*
* 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.
*/
/* @test
* @bug 4617165
* @summary Ensure that socket hangups are handled correctly
* @library ..
* @build TestUtil
* @run main Hangup
*/
public class Hangup {
private static class Failure
extends RuntimeException
{
super(s);
}
}
throws IOException
{
if (n != 1)
throw new Failure("Select returned zero");
throw new Failure("Wrong size for selected-key set: "
throw new Failure("Key not in selected-key set");
}
static void dally() {
try {
} catch (InterruptedException x) { }
}
throws IOException
{
+ ", readAfterClose = " + readAfterClose);
try {
// Set up server socket
// Connect client
// Accept client connection
// Create selector and register server side
sv.configureBlocking(false);
int n;
if (writeFromClient) {
// Write from client, read from server
throw new Failure("Incorrect number of bytes written");
dally();
throw new Failure("Wrong number of bytes read");
}
// Close client side
dally();
// Select again
if (readAfterClose) {
// Read from client after client has disconnected
throw new Failure("Wrong number of bytes read");
}
// Select a couple more times just to make sure we're doing
// the right thing
} finally {
}
}
for (boolean writeFromClient = false;; writeFromClient = true) {
for (boolean readAfterClose = false;; readAfterClose = true) {
try {
} catch (Failure x) {
x.printStackTrace(log);
failures++;
}
if (readAfterClose)
break;
}
if (writeFromClient)
break;
}
if (failures > 0) {
throw new RuntimeException("Some tests failed");
}
}
}