Made sure OioDatagramChannel.joinGroup() is allowed only when the channel is bound.

This commit is contained in:
Trustin Lee 2009-04-22 21:32:12 +00:00
parent 59956be369
commit 967bd4d06d

View File

@ -113,6 +113,7 @@ final class OioDatagramChannel extends AbstractChannel
}
public void joinGroup(InetAddress multicastAddress) {
ensureBound();
try {
socket.joinGroup(multicastAddress);
} catch (IOException e) {
@ -122,6 +123,7 @@ final class OioDatagramChannel extends AbstractChannel
public void joinGroup(
InetSocketAddress multicastAddress, NetworkInterface networkInterface) {
ensureBound();
try {
socket.joinGroup(multicastAddress, networkInterface);
} catch (IOException e) {
@ -129,6 +131,14 @@ final class OioDatagramChannel extends AbstractChannel
}
}
private void ensureBound() {
if (!isBound()) {
throw new IllegalStateException(
DatagramChannel.class.getName() +
" must be bound to join a group.");
}
}
public void leaveGroup(InetAddress multicastAddress) {
try {
socket.leaveGroup(multicastAddress);