/**
* @see java.net.SocketOptions#setOption(int, java.lang.Object)
*/
public final synchronized void setOption(int option_id, Object val) throws SocketException {
if (closed) {
throw new SocketException("DatagramSocket closed");
}
try {
switch (option_id) {
case IP_TOS:
tos = (Integer) val;
break;
case SO_BINDADDR:
throw new SocketException("Get only option: SO_BINDADDR");
case SO_BROADCAST:
broadcast = (Boolean) val;
break;
case SO_RCVBUF: /* ignore */
break;
case SO_SNDBUF: /* ignore */
break;
case SO_TRANSMIT_IF:
if (val == null) {
device = null;
} else {
final NetworkInterface netIf = (NetworkInterface) val;
try {
device = DeviceUtils.getDevice(netIf.getName());
} catch (DeviceNotFoundException ex) {
throw new SocketException("Unknown networkinterface " + netIf.getName());
}
}
break;
case SO_TIMEOUT:
timeout = (Integer) val;
break;
case SO_REUSEADDR:
// Ignored for now
break;
default:
doSetOption(option_id, val);
}
} catch (ClassCastException ex) {
throw (SocketException) new SocketException("Invalid option type").initCause(ex);
}
}