Hello Simone,
1) I'll try the master branch and let you know.
2) My current test case is not easily convertible to something without using other code in my project; I can try to create a small test case that can produce this problem, but I'm not sure.
About the synchronized: the problem is that doWrite would be possibly be called in two threads, something like this:
// asynchronously called by Jetty
onWritePossible()
{
doWrite();
}
// asynchronously called by possibly other threads
onDataGenerated(byte [] data)
{
synchronized(this)
{
_buffer.put(data);
doWrite();
}
}
I need to doWrite in two places, because there are two situations:
1) when onWritePossible() is called by Jetty, but the application may not have any data to write (i.e. _os.isReady() returns true, but _buffer.hasRemaining() returns false); so when onDataGenerated() is called, it has to attempt to write because otherwise onWritePossible() won't be called again; so this write could happen in application threads
2) when onDataGenerated() is called, but _os.isReady() returns false, the data would be buffered; later Jetty would invoke onWritePossible(); it has to attempt to write there because there can be data in buffer, and it cannot wait to invoke doWrite() inside onDataGenerated(), because onDataGenerated() may not be invoked again (e.g. it was the last invocation); the the write could happen in Jetty threads
Because there can be two threads attempting to invoke doWrite(), I think some locking is needed. Do you have any suggestions on a better approach to solve the problem?
Btw, is it assumed that write() must happen inside onWritePossible()? Could this be the problem? At least in most example code I saw write() happens inside onWritePossible().
Thanks,
Michael