This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Bug in libgcj UDP network classes
On Thu, 2003-11-20 at 21:36, Michael Koch wrote:
> I'm looking into it as I'm currently at that code anyway.
> Thx for testing and reporting.
>
>
> Michael
>
... got curious myself ... and i think i have found it:
The buffer size which is told to recvfrom() in
"gnu::java::net::PlainDatagramSocketImpl::receive" is the size of the
previously received Packet. Which is kept in the "length" variable of
DatagramPacket. Therefore the number of bytes read via recvfrom() gets
reduced with every packet that is smaller than the previous one.
This is not really a bug, i think java-api-doc is not clear about that.
I don't know why the sun-java implementation of DatagramPacket behaves
differently. Maybe it keeps two "length" variables. One for setLength()
and one for getLength(). The first for setting the max buffer-size to
use - and the other for reporting the actual length of the recieved
packet.
this is the dirty bugfix - it made my Program work - but it's wrong!
/*
retlen =
::recvfrom (native_fd, (char *) dbytes, p->getLength(), 0,
(sockaddr*) &u,
&addrlen);
*/
// hack by nf
// we need the length of the data-buffer and not the previous packet
retlen =
::recvfrom (native_fd, (char *) dbytes, p->getData()->length, 0,
(sockaddr*) &u,
&addrlen);
//~ end hack by nf
The bug (or let's say "behavior") seems to be everywhere in
gnu-classpath - i just tried kaffe 1.1.2 and it revealed the same
problem.
Looking at gnu::java::net::PlainDatagramSocketImpl i think i've seen
another bug - i think the "offset" field of DatagramPacket is totally
ignored.
norbert