Skip to content

Commit

Permalink
Use blocking for input reader
Browse files Browse the repository at this point in the history
  • Loading branch information
irtimmer committed Jan 4, 2015
1 parent b88c5f0 commit 12d441b
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/com/limelight/input/EvdevReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
Expand All @@ -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();
}
Expand Down

0 comments on commit 12d441b

Please sign in to comment.