Does Kaffe handle threaded network I/O?
Bernie Solomon
bernard at UG.EDS.COM
Thu Apr 24 01:54:52 PDT 1997
Stewart Allen wrote:
>
> I sent this to the list last week, but I haven't heard back.
> I'm writing an application that has a background thread handling
> communications via UDP. Kaffe seems to block all threads whenever
> I do a receive() on a UDP socket. Sun's VM doesn't do this.
>
> I haven't tested for other forms of I/O (like file), but I'm curious if
> this is a known problem (Tim?).
This peeked my interest so I had a quick look. Basically the recvfrom
inside DatagramSocket wasn't threaded like other I/O calls. I just
copied what read did and your example works. This has had no other
testing other than your example.
sdlhpp5% diff ~/orig-kaffe-0.8.4/kaffe/kaffevm/threadCalls.h
master/kaffe/kaffevm
24a25
> extern ssize_t threadedRecvfrom(int, void *, size_t, int, struct sockaddr *, size_t *);
sdlhpp5% diff -c ~/orig-kaffe-0.8.4/kaffe/kaffevm/threadCalls.h
master/kaffe/kaffevm
*** /users/bernard/orig-kaffe-0.8.4/kaffe/kaffevm/threadCalls.h Fri Apr
18 15:58:35 1997
--- master/kaffe/kaffevm/threadCalls.h Thu Apr 24 09:35:03 1997
***************
*** 22,26 ****
--- 22,27 ----
extern int threadedAccept(int, struct sockaddr*, size_t*);
extern ssize_t threadedRead(int, char*, size_t);
extern ssize_t threadedWrite(int, const char*, size_t);
+ extern ssize_t threadedRecvfrom(int, void *, size_t, int, struct
sockaddr *, size_t *);
#endif
sdlhpp5% diff -c ~/orig-kaffe-0.8.4/kaffe/kaffevm/threadCalls.c
master/kaffe/kaffevm
*** /users/bernard/orig-kaffe-0.8.4/kaffe/kaffevm/threadCalls.c Fri Apr
18 15:58:35 1997
--- master/kaffe/kaffevm/threadCalls.c Thu Apr 24 09:37:52 1997
***************
*** 158,163 ****
--- 158,187 ----
}
/*
+ * Recvfrom but only if we can.
+ */
+ ssize_t
+ threadedRecvfrom(int fd, void *buf, size_t len, int flags, struct
sockaddr *from, size_t *fromlen)
+ {
+ ssize_t r;
+
+ #if defined(BLOCKING_CALLS)
+ if (blockOnFile(fd, TH_READ) < 0) {
+ return (-1);
+ }
+ #endif
+ for (;;) {
+ r = recvfrom(fd, buf, len, flags, from, fromlen);
+ if (r >= 0 || !(errno == EAGAIN || errno == EWOULDBLOCK
|| errno == EINTR)) {
+ return (r);
+ }
+ if (blockOnFile(fd, TH_READ) < 0) {
+ return (-1);
+ }
+ }
+ }
+
+ /*
* Read but only if we can.
*/
ssize_t
sdlhpp5% diff -c
~/orig-kaffe-0.8.4/packages/tjwassoc.co.uk/APInet/lib/java.net/DatagramSocket.c
master/packages/tjwassoc.co.uk/APInet/lib/java.net/
***
/users/bernard/orig-kaffe-0.8.4/packages/tjwassoc.co.uk/APInet/lib/java.net/DatagramSocket.c
Fri Apr 18 15:58:48 1997
---
master/packages/tjwassoc.co.uk/APInet/lib/java.net//DatagramSocket.c
Thu Apr 24 09:35:37 1997
***************
*** 108,114 ****
size_t alen = sizeof(addr);
struct Hjava_net_InetAddress **fromaddr;
! r = recvfrom(unhand(unhand(this)->fd)->fd,
unhand(unhand(pkt)->buf)->body, unhand(pkt)->length, 0, (struct
sockaddr*)&addr, &alen);
if (r < 0) {
SignalError(NULL, "java.net.SocketException",
SYS_ERROR);
}
--- 108,114 ----
size_t alen = sizeof(addr);
struct Hjava_net_InetAddress **fromaddr;
! r = threadedRecvfrom(unhand(unhand(this)->fd)->fd,
unhand(unhand(pkt)->buf)->body, unhand(pkt)->length, 0, (struct
sockaddr*)&addr, &alen);
if (r < 0) {
SignalError(NULL, "java.net.SocketException",
SYS_ERROR);
}
--
Bernie Solomon (bernard at edsug.com or Bernard.Solomon at acm.org)
Unigraphics Architecture, EDS-Unigraphics, Cambridge, UK
More information about the kaffe
mailing list