Skip to content

Commit

Permalink
Worked around JNR bug 50
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Wilkins <gregw@webtide.com>
  • Loading branch information
gregw committed Dec 7, 2017
1 parent 33ebd90 commit 1921220
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;

import org.eclipse.jetty.io.ChannelEndPoint;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.ManagedSelector;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Scheduler;
Expand All @@ -33,6 +36,8 @@
public class UnixSocketEndPoint extends ChannelEndPoint
{
private static final Logger LOG = Log.getLogger(UnixSocketEndPoint.class);
private static final Logger CEPLOG = Log.getLogger(ChannelEndPoint.class);


private final UnixSocketChannel _channel;

Expand Down Expand Up @@ -70,4 +75,50 @@ protected void doShutdownOutput()
LOG.debug(e);
}
}


@Override
public boolean flush(ByteBuffer... buffers) throws IOException
{
// TODO this is a work around for https://github.com/jnr/jnr-unixsocket/issues/50
long flushed=0;
try
{
for (ByteBuffer b : buffers)
{
if (b.hasRemaining())
{
int r=b.remaining();
int p=b.position();
int l=_channel.write(b);
if (l>=0)
{
b.position(p+l);
flushed+=l;
}

if (CEPLOG.isDebugEnabled())
CEPLOG.debug("flushed {}/{} r={} {}", l,r,b.remaining(), this);

if (b.hasRemaining())
break;
}
}

}
catch (IOException e)
{
throw new EofException(e);
}

if (flushed>0)
notIdle();

for (ByteBuffer b : buffers)
if (!BufferUtil.isEmpty(b))
return false;

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
#org.eclipse.jetty.http2.LEVEL=DEBUG
#org.eclipse.jetty.http2.hpack.LEVEL=INFO
#org.eclipse.jetty.http2.client.LEVEL=DEBUG

org.eclipse.jetty.io.LEVEL=DEBUG
#org.eclipse.jetty.io.LEVEL=DEBUG

0 comments on commit 1921220

Please sign in to comment.