[xSocket-develop] Question: SSL with non-threaded onData() hangs sometimes
Status: Inactive
Brought to you by:
grro
|
From: Christian K. <ck...@vx...> - 2008-05-26 10:37:49
|
Hi there,
at first thanks for the good work. I stumbled over xSocket and
instantly loved it. ;)
So, I was starting to write a repeater service using SSL.
That means a client and a server both connect the repeater and
identify themselves either as being client or server and to whom
they belong. The result is a pair of two connections - similar to
the proxy example. (it's all about remote desktop stuff)
Everything is working fine - until some sporadic hang occurs in the
onData handler. Because it is non-threaded the whole server hangs.
The code:
public boolean onData(INonBlockingConnection c)
throws IOException, BufferUnderflowException,
MaxReadSizeExceededException {
Node n = (Node)c.getAttachment();
if(n != null && n.sessionID != null) {
Node n2 = n.server ? viewers.get(n.sessionID) :
servers.get(n.sessionID);
if(n2 != null) {
System.out.print((n2.server ? "S" : "C") +
c.available() + ">");
// before hang #1
ByteBuffer[] data =
c.readByteBufferByLength(c.available());
System.out.print("<" + (n2.server ? "S" :
"C"));
// before hang #2
n2.c.write(data);
System.out.println("#");
}
}
return true;
}
I identified two positions where the code may hang. The write hangs far more
often than the
read. But as I said - sometimes it's running for hours, even days. In
another case it died
within 3 minutes. :(
Could anyone please give me a hint what to watch out for? What to tune?
I supposed some synchronisation cludge with the SSL stack and modified
xSocket, so that I
can deliver my own customized SSLEngine. I forced the connection to use RC4
stream-cipher,
because I thought there may be some length difference issue due to
padding/unpadding when
using a block-cipher - but nothing changed. :-/
Or do I simply _have to_ use multi-threading as soon as I want to have SSL?
Did I understand the other threads correctly, that I would have to
synchronize on the
connection objects for each read and write operation when using
multi-threading?
Thanks in advance.
Best regards,
Christian
|