Correct fail write with NotYetConnectedException when OioDatagramChannel is not connected yet.
Motivation: NioDatagramChannel fails a write with NotYetConnectedException when the DatagramChannel was not yet connected and a ByteBuf is written. The same should be done for OioDatagramChannel as well. Modifications: Make OioDatagramChannel consistent with NioDatagramChannel Result: Correct and consistent implementations of DatagramChannel
This commit is contained in:
parent
66b9be3a46
commit
8a5e42ad2e
@ -44,6 +44,7 @@ import java.net.NetworkInterface;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.channels.NotYetConnectedException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -253,8 +254,15 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
|
||||
}
|
||||
|
||||
final int length = data.readableBytes();
|
||||
try {
|
||||
if (remoteAddress != null) {
|
||||
tmpPacket.setSocketAddress(remoteAddress);
|
||||
} else {
|
||||
if (!isConnected()) {
|
||||
// If not connected we should throw a NotYetConnectedException() to be consistent with
|
||||
// NioDatagramChannel
|
||||
throw new NotYetConnectedException();
|
||||
}
|
||||
}
|
||||
if (data.hasArray()) {
|
||||
tmpPacket.setData(data.array(), data.arrayOffset() + data.readerIndex(), length);
|
||||
@ -263,7 +271,6 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
|
||||
data.getBytes(data.readerIndex(), tmp);
|
||||
tmpPacket.setData(tmp);
|
||||
}
|
||||
try {
|
||||
socket.send(tmpPacket);
|
||||
in.remove();
|
||||
} catch (IOException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user