[kaffe] [PATCH] fixing UDP receive timeout (makes mauve not hang on CVS head)

Noa Resare noa at resare.com
Wed Sep 8 14:26:09 PDT 2004


For some reason beyond my understanding I decided that I should devote
some of my very few hacking cycles to kaffe. However, being sort of a
newbie in the JVM hacking business I didn't feel comfortable doing
anything before I could regression test any contributions. So I had a
look at mauve and got it to work with kaffe-1.1.4. kaffe from cvs HEAD
on the other hand hang on a java.net.DatagramSocket test.

So, I thought, what better way to start my kaffe career than to have a
look at the failed test. Said and done, some investigation lead me to
jthreadedRecvfrom() in kaffevm/systems/unix-pthreads/syscalls.c

The code has a few problems preventing the timeout functionality from
working:

1) The code checks for EAGAIN from recvfrom() but the socket doesn't
have O_NONBLOCK set.

2) The BREAK_IF_LATE macro sets errno to EINTR. EINTR makes
gnu_java_net_PlainDatagramSocketImpl_receive0() in
libraries/clib/net/PlainDatagramSocketImpl.c just call jthreadedRecvfrom
again.

3) The code is a tight loop that will suck up available CPU if
O_NONBLOCK is set and the read operation blocks.

The attached patch attempts to fix these problems while minimizing the
risk of unwanted side effects. To summarize:

- O_NONBLOCK is set on the socket
- BREAK_IF_LATE sets errno to ETIMEDOUT instead, which is handled in
receive0().
- poll() is used to prevent CPU hogging if the read would have blocked
- any socket options are restored to their previous state

Issues:

- is poll() available on all relevant systems?
- should the socket be permanently non blocking?

The patch is only tested on i386 Fedora Core 2.90 (which means
gcc-3.4.1-2)

please apply :)
cheers/noa

-- 
And the lions ate the christians and the christians burned the witches,
and even I am out of explanations -- Ola Salo
gpg fingerprint: F3C4 AC90 B885 FE15 344B  4D05 220B 7662 A190 6F09
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kaffe-udp-receive-timeout.patch
Type: text/x-patch
Size: 1924 bytes
Desc: not available
Url : http://kaffe.org/pipermail/kaffe/attachments/20040908/41c300a7/attachment-0002.bin 


More information about the kaffe mailing list