From 12d441b493f57486da7f0bfbf46f8e1af8f6f498 Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Sun, 4 Jan 2015 20:30:26 +0100 Subject: [PATCH] Use blocking for input reader --- src/com/limelight/input/EvdevReader.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/com/limelight/input/EvdevReader.java b/src/com/limelight/input/EvdevReader.java index d03ae897..e9b3de7d 100644 --- a/src/com/limelight/input/EvdevReader.java +++ b/src/com/limelight/input/EvdevReader.java @@ -5,15 +5,15 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.nio.channels.FileChannel; public abstract class EvdevReader implements Runnable { private final static int EVIOCGNAME = 0x06; - private FileChannel deviceInput; + private InputStream in; private ByteBuffer inputBuffer; public EvdevReader(String device) throws FileNotFoundException, IOException { @@ -30,8 +30,7 @@ public EvdevReader(String device) throws FileNotFoundException, IOException { LimeLog.info("Using " + new String(data)); - FileInputStream in = new FileInputStream(file); - deviceInput = in.getChannel(); + in = new FileInputStream(file); inputBuffer = ByteBuffer.allocate(EvdevConstants.MAX_STRUCT_SIZE_BYTES); inputBuffer.order(ByteOrder.nativeOrder()); } @@ -49,10 +48,7 @@ public void start() { public void run() { try { while (true) { - while(inputBuffer.remaining()==EvdevConstants.MAX_STRUCT_SIZE_BYTES) - deviceInput.read(inputBuffer); - - inputBuffer.flip(); + inputBuffer.limit(in.read(inputBuffer.array())); parseEvent(inputBuffer); inputBuffer.clear(); }