mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-16 22:01:11 +00:00
Use blocking for input reader
This commit is contained in:
@@ -5,15 +5,15 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.channels.FileChannel;
|
|
||||||
|
|
||||||
public abstract class EvdevReader implements Runnable {
|
public abstract class EvdevReader implements Runnable {
|
||||||
|
|
||||||
private final static int EVIOCGNAME = 0x06;
|
private final static int EVIOCGNAME = 0x06;
|
||||||
|
|
||||||
private FileChannel deviceInput;
|
private InputStream in;
|
||||||
private ByteBuffer inputBuffer;
|
private ByteBuffer inputBuffer;
|
||||||
|
|
||||||
public EvdevReader(String device) throws FileNotFoundException, IOException {
|
public EvdevReader(String device) throws FileNotFoundException, IOException {
|
||||||
@@ -30,8 +30,7 @@ public abstract class EvdevReader implements Runnable {
|
|||||||
|
|
||||||
LimeLog.info("Using " + new String(data));
|
LimeLog.info("Using " + new String(data));
|
||||||
|
|
||||||
FileInputStream in = new FileInputStream(file);
|
in = new FileInputStream(file);
|
||||||
deviceInput = in.getChannel();
|
|
||||||
inputBuffer = ByteBuffer.allocate(EvdevConstants.MAX_STRUCT_SIZE_BYTES);
|
inputBuffer = ByteBuffer.allocate(EvdevConstants.MAX_STRUCT_SIZE_BYTES);
|
||||||
inputBuffer.order(ByteOrder.nativeOrder());
|
inputBuffer.order(ByteOrder.nativeOrder());
|
||||||
}
|
}
|
||||||
@@ -49,10 +48,7 @@ public abstract class EvdevReader implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
while(inputBuffer.remaining()==EvdevConstants.MAX_STRUCT_SIZE_BYTES)
|
inputBuffer.limit(in.read(inputBuffer.array()));
|
||||||
deviceInput.read(inputBuffer);
|
|
||||||
|
|
||||||
inputBuffer.flip();
|
|
||||||
parseEvent(inputBuffer);
|
parseEvent(inputBuffer);
|
||||||
inputBuffer.clear();
|
inputBuffer.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user