diff options
author | Michael Koch <konqueror@gmx.de> | 2003-12-04 10:59:56 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2003-12-04 10:59:56 +0000 |
commit | 477913522a0768c5653299757a06e8de0a8a7f7a (patch) | |
tree | da9d9cde6113f511230666f5365023e8ee3caa08 /libjava/java/net | |
parent | 7f1156ed35e4f5a14cea93e42137302eb1d1f07a (diff) | |
download | gcc-477913522a0768c5653299757a06e8de0a8a7f7a.zip gcc-477913522a0768c5653299757a06e8de0a8a7f7a.tar.gz gcc-477913522a0768c5653299757a06e8de0a8a7f7a.tar.bz2 |
2003-12-04 Michael Koch <konqueror@gmx.de>
* java/net/DatagramPacket.java
(length): Made packge-private to make it accessible via CNI.
(maxlen): New field.
(DatagramPacket): Cleaned up.
(setSocketAddress): Add message to exception.
(setData): Call other setData().
(setData): Call setLength().
(setLength): Initialize maxlen too.
* gnu/java/net/natPlainDatagramSocketImplPosix.cc (peekData):
Get maximal length from maxlen field, set length field directly.
(receive): Likewise.
* gnu/java/net/natPlainDatagramSocketImplWin32.cc (peekData):
Get maximal length from maxlen field, set length field directly.
(receive): Likewise.
From-SVN: r74278
Diffstat (limited to 'libjava/java/net')
-rw-r--r-- | libjava/java/net/DatagramPacket.java | 88 |
1 files changed, 30 insertions, 58 deletions
diff --git a/libjava/java/net/DatagramPacket.java b/libjava/java/net/DatagramPacket.java index f9a9cd5..f23364c 100644 --- a/libjava/java/net/DatagramPacket.java +++ b/libjava/java/net/DatagramPacket.java @@ -78,13 +78,18 @@ public final class DatagramPacket private int offset; /** - * The length of the data buffer to send + * The length of the data buffer to send. */ - private int length; + int length; /** + * The maximal length of the buffer. + */ + int maxlen; + + /** * The address to which the packet should be sent or from which it - * was received + * was received. */ private InetAddress address; @@ -106,21 +111,9 @@ public final class DatagramPacket */ public DatagramPacket(byte[] buf, int offset, int length) { - if (buf == null) - throw new NullPointerException("Null buffer"); - if (offset < 0) - throw new IllegalArgumentException("Invalid offset: " + offset); - if (length < 0) - throw new IllegalArgumentException("Invalid length: " + length); - if (offset + length > buf.length) - throw new IllegalArgumentException("Potential buffer overflow - offset: " - + offset + " length: " + length); - - buffer = buf; - this.offset = offset; - this.length = length; - this.address = null; - this.port = -1; + setData(buf, offset, length); + address = null; + port = -1; } /** @@ -150,25 +143,9 @@ public final class DatagramPacket public DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port) { - if (buf == null) - throw new NullPointerException("Null buffer"); - if (offset < 0) - throw new IllegalArgumentException("Invalid offset: " + offset); - if (length < 0) - throw new IllegalArgumentException("Invalid length: " + length); - if (offset + length > buf.length) - throw new IllegalArgumentException("Potential buffer overflow - offset: " - + offset + " length: " + length); - if (port < 0 || port > 65535) - throw new IllegalArgumentException("Invalid port: " + port); - if (address == null) - throw new NullPointerException("Null address"); - - buffer = buf; - this.offset = offset; - this.length = length; - this.address = address; - this.port = port; + setData(buf, offset, length); + setAddress(address); + setPort(port); } /** @@ -203,8 +180,13 @@ public final class DatagramPacket SocketAddress address) throws SocketException { - this(buf, offset, length, ((InetSocketAddress)address).getAddress(), - ((InetSocketAddress)address).getPort()); + if (! (address instanceof InetSocketAddress)) + throw new IllegalArgumentException("unsupported address type"); + + InetSocketAddress tmp = (InetSocketAddress) address; + setData(buf, offset, length); + setAddress(tmp.getAddress()); + setPort(tmp.getPort()); } /** @@ -223,8 +205,7 @@ public final class DatagramPacket public DatagramPacket(byte[] buf, int length, SocketAddress address) throws SocketException { - this(buf, 0, length, ((InetSocketAddress)address).getAddress(), - ((InetSocketAddress)address).getPort()); + this(buf, 0, length, address); } /** @@ -330,9 +311,10 @@ public final class DatagramPacket public void setSocketAddress(SocketAddress address) throws IllegalArgumentException { - if (address == null) throw new IllegalArgumentException(); + if (address == null) + throw new IllegalArgumentException("address may not be null"); - InetSocketAddress tmp = (InetSocketAddress)address; + InetSocketAddress tmp = (InetSocketAddress) address; this.address = tmp.getAddress(); this.port = tmp.getPort(); } @@ -359,14 +341,9 @@ public final class DatagramPacket * * @since 1.1 */ - public synchronized void setData(byte[] buf) + public void setData(byte[] buf) { - // This form of setData requires setLength to be called separately - // and subsequently. - if (buf == null) - throw new NullPointerException("Null buffer"); - - buffer = buf; + setData(buf, 0, buf.length); } /** @@ -388,15 +365,10 @@ public final class DatagramPacket throw new NullPointerException("Null buffer"); if (offset < 0) throw new IllegalArgumentException("Invalid offset: " + offset); - if (length < 0) - throw new IllegalArgumentException("Invalid length: " + length); - if (offset + length > buf.length) - throw new IllegalArgumentException("Potential buffer overflow - offset: " - + offset + " length: " + length); buffer = buf; this.offset = offset; - this.length = length; + setLength(length); } /** @@ -418,6 +390,6 @@ public final class DatagramPacket + offset + " length: " + length); this.length = length; + this.maxlen = length; } -} // class DatagramPacket - +} |