I write a small Jetpack extension that starts a server using Cc["@mozilla.org/network/server-socket;1"]
. I read from a connected client asynchronously using: conn.istream.asyncWait(conn, 0, 0, null);
The documentation says that the callback is invoked when data arrives AND when the stream is closed: https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIAsyncInputStream#asyncWait%28%29
However, it isn't invoked when the stream is closed. :(
I also tried to use clientSocket.setEventSink(obj, null);
but the event sink also gets only called when data arrives but not when the stream is closed.
This is pretty bad, because this will be used in an automated environment and without a callback on close I cannot free allocated resources! Is there anything else I might try?
Here is the source of my Jetpack script: https://web.student.tuwien.ac.at/~e0427417/hg/exin/public.cgi/file/tip/lib/main.js It's not documented very well yet. It starts a web server (very basic HTTP implementation) on port 1133.
Edit: Because I couldn't find another way I've implemented a garbage collector that checks if the client sockets are alive every fixed interval. This works but isn't as nice as it could be. https://developer.mozilla.org/en/nsITimer