mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-26 20:06:28 -08:00
server: Implement non-blocking IO for VR bridges (#629)
This commit is contained in:
1 parent
9d90186472
commit
e9553b4ded
4 files changed
+276
-140
No files matched your search
@@ -66,6 +66,7 @@ public class VRServer extends Thread {
|
||||
private final NanoTimer fpsTimer = new NanoTimer();
|
||||
private final ProvisioningHandler provisioningHandler;
|
||||
private final ResetHandler resetHandler;
|
||||
private final Object wakeupLock = new Object();
|
||||
|
||||
/**
|
||||
* This function is used by VRWorkout, do not remove!
|
||||
@@ -297,9 +298,18 @@ public class VRServer extends Thread {
|
||||
vrcOSCHandler.update();
|
||||
vmcHandler.update();
|
||||
// final long time = System.currentTimeMillis() - start;
|
||||
try {
|
||||
Thread.sleep(1); // 1000Hz
|
||||
} catch (InterruptedException ignored) {}
|
||||
synchronized (wakeupLock) {
|
||||
try {
|
||||
wakeupLock.wait(1); // 1000Hz
|
||||
} catch (InterruptedException ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
public void wakeup() {
|
||||
synchronized (wakeupLock) {
|
||||
wakeupLock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,20 @@ public abstract class ProtobufBridge<T extends VRTracker> implements Bridge {
|
||||
this.hmd = hmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wakes the bridge thread, implementation is platform-specific.
|
||||
*/
|
||||
@ThreadSafe
|
||||
protected abstract void signalSend();
|
||||
|
||||
/**
|
||||
* Wakes the VRServer thread.
|
||||
*/
|
||||
@ThreadSafe
|
||||
protected void signalRecv() {
|
||||
Main.getVrServer().wakeup();
|
||||
}
|
||||
|
||||
@BridgeThread
|
||||
protected abstract boolean sendMessageReal(ProtobufMessage message);
|
||||
|
||||
@@ -56,6 +70,7 @@ public abstract class ProtobufBridge<T extends VRTracker> implements Bridge {
|
||||
@ThreadSafe
|
||||
protected void sendMessage(ProtobufMessage message) {
|
||||
outputQueue.add(message);
|
||||
signalSend();
|
||||
}
|
||||
|
||||
@BridgeThread
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.slimevr.bridge.BridgeThread;
|
||||
import dev.slimevr.bridge.ProtobufMessages;
|
||||
import dev.slimevr.platform.SteamVRBridge;
|
||||
import dev.slimevr.tracking.trackers.*;
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
@@ -17,6 +18,8 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -28,6 +31,7 @@ public class UnixSocketBridge extends SteamVRBridge implements AutoCloseable {
|
||||
|
||||
private ServerSocketChannel server;
|
||||
private SocketChannel channel;
|
||||
private Selector selector;
|
||||
private boolean socketError = false;
|
||||
|
||||
public UnixSocketBridge(
|
||||
@@ -56,7 +60,10 @@ public class UnixSocketBridge extends SteamVRBridge implements AutoCloseable {
|
||||
this.server = createSocket();
|
||||
while (true) {
|
||||
if (this.channel == null) {
|
||||
this.selector = Selector.open();
|
||||
this.channel = server.accept();
|
||||
this.channel.configureBlocking(false);
|
||||
this.channel.register(this.selector, SelectionKey.OP_READ);
|
||||
if (this.channel == null)
|
||||
continue;
|
||||
Main.getVrServer().queueTask(this::reconnected);
|
||||
@@ -73,15 +80,23 @@ public class UnixSocketBridge extends SteamVRBridge implements AutoCloseable {
|
||||
this.resetChannel();
|
||||
continue;
|
||||
}
|
||||
boolean update = this.updateSocket();
|
||||
if (!update) {
|
||||
try {
|
||||
boolean updated = this.updateSocket();
|
||||
updateMessageQueue();
|
||||
if (updated) {
|
||||
signalRecv();
|
||||
} else {
|
||||
this.waitForData(10);
|
||||
}
|
||||
} catch (IOException ioError) {
|
||||
this.resetChannel();
|
||||
ioError.printStackTrace();
|
||||
try {
|
||||
Thread.sleep(5); // Up to 200Hz
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
updateMessageQueue();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -90,6 +105,21 @@ public class UnixSocketBridge extends SteamVRBridge implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ThreadSafe
|
||||
protected void signalSend() {
|
||||
Selector selector = this.selector;
|
||||
if (selector == null) {
|
||||
return;
|
||||
}
|
||||
selector.wakeup();
|
||||
}
|
||||
|
||||
@BridgeThread
|
||||
private void waitForData(long timeoutMs) throws IOException {
|
||||
this.selector.select(timeoutMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@BridgeThread
|
||||
protected boolean sendMessageReal(ProtobufMessages.ProtobufMessage message) {
|
||||
@@ -116,6 +146,20 @@ public class UnixSocketBridge extends SteamVRBridge implements AutoCloseable {
|
||||
|
||||
private boolean updateSocket() throws IOException {
|
||||
int read = channel.read(dst);
|
||||
if (read == -1) {
|
||||
LogManager
|
||||
.info(
|
||||
"["
|
||||
+ bridgeName
|
||||
+ "] Reached end-of-stream on connection of "
|
||||
+ this.channel.getRemoteAddress().toString()
|
||||
);
|
||||
socketError = true;
|
||||
return false;
|
||||
} else if (read == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean readAnything = false;
|
||||
// if buffer has 4 bytes at least, we got the message size!
|
||||
// processs all messages
|
||||
@@ -130,6 +174,7 @@ public class UnixSocketBridge extends SteamVRBridge implements AutoCloseable {
|
||||
+ messageLength
|
||||
);
|
||||
socketError = true;
|
||||
break;
|
||||
} else if (dst.position() >= messageLength) {
|
||||
// Parse the message (this reads the array directly from the
|
||||
// dst, so we need to move position ourselves)
|
||||
@@ -145,18 +190,10 @@ public class UnixSocketBridge extends SteamVRBridge implements AutoCloseable {
|
||||
// move position after compacting
|
||||
dst.position(originalpos - messageLength);
|
||||
readAnything = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (read == -1) {
|
||||
LogManager
|
||||
.info(
|
||||
"["
|
||||
+ bridgeName
|
||||
+ "] Reached end-of-stream on connection of "
|
||||
+ this.channel.getRemoteAddress().toString()
|
||||
);
|
||||
socketError = true;
|
||||
}
|
||||
return readAnything;
|
||||
}
|
||||
|
||||
@@ -178,6 +215,8 @@ public class UnixSocketBridge extends SteamVRBridge implements AutoCloseable {
|
||||
+ "] Disconnected from "
|
||||
+ this.channel.getRemoteAddress().toString()
|
||||
);
|
||||
this.selector.close();
|
||||
this.selector = null;
|
||||
this.channel.close();
|
||||
this.channel = null;
|
||||
this.socketError = false;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package dev.slimevr.platform.windows;
|
||||
|
||||
import com.google.protobuf.CodedOutputStream;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.*;
|
||||
import com.sun.jna.platform.win32.Kernel32;
|
||||
import com.sun.jna.platform.win32.WinBase;
|
||||
import com.sun.jna.platform.win32.WinError;
|
||||
import com.sun.jna.platform.win32.WinNT;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
import dev.slimevr.Main;
|
||||
import dev.slimevr.VRServer;
|
||||
import dev.slimevr.bridge.BridgeThread;
|
||||
@@ -13,19 +14,46 @@ import dev.slimevr.bridge.PipeState;
|
||||
import dev.slimevr.bridge.ProtobufMessages.ProtobufMessage;
|
||||
import dev.slimevr.platform.SteamVRBridge;
|
||||
import dev.slimevr.tracking.trackers.*;
|
||||
import io.eiren.util.ann.ThreadSafe;
|
||||
import io.eiren.util.logging.LogManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
interface Kernel32IO extends Kernel32 {
|
||||
Kernel32IO INSTANCE = Native.load("kernel32", Kernel32IO.class, W32APIOptions.DEFAULT_OPTIONS);
|
||||
|
||||
boolean GetOverlappedResult(
|
||||
/* [in] */ HANDLE hFile,
|
||||
/* [in] */ WinBase.OVERLAPPED lpOverlapped,
|
||||
/* [out] */ IntByReference lpNumberOfBytesTransferred,
|
||||
/* [in] */ boolean bWait
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public class WindowsNamedPipeBridge extends SteamVRBridge {
|
||||
private static final Kernel32 k32 = Kernel32.INSTANCE;
|
||||
private static final Kernel32IO k32io = Kernel32IO.INSTANCE;
|
||||
|
||||
protected final String pipeName;
|
||||
private final byte[] buffArray = new byte[2048];
|
||||
protected WindowsPipe pipe;
|
||||
protected WinNT.HANDLE dataEvent = Kernel32.INSTANCE.CreateEvent(null, false, false, null);
|
||||
protected WinBase.OVERLAPPED overlapped = new WinBase.OVERLAPPED();
|
||||
protected WinNT.HANDLE openEvent = k32.CreateEvent(null, false, false, null);
|
||||
protected WinNT.HANDLE readEvent = k32.CreateEvent(null, false, false, null);
|
||||
protected WinNT.HANDLE writeEvent = k32.CreateEvent(null, false, false, null);
|
||||
protected WinNT.HANDLE rxEvent = k32.CreateEvent(null, false, false, null);
|
||||
protected WinNT.HANDLE txEvent = k32.CreateEvent(null, false, false, null);
|
||||
protected WinNT.HANDLE[] events = new WinNT.HANDLE[] { rxEvent, txEvent };
|
||||
private final WinBase.OVERLAPPED overlappedOpen = new WinBase.OVERLAPPED();
|
||||
private final WinBase.OVERLAPPED overlappedWrite = new WinBase.OVERLAPPED();
|
||||
private final WinBase.OVERLAPPED overlappedRead = new WinBase.OVERLAPPED();
|
||||
private final WinBase.OVERLAPPED overlappedWait = new WinBase.OVERLAPPED();
|
||||
private final IntByReference bytesWritten = new IntByReference(0);
|
||||
private final IntByReference bytesAvailable = new IntByReference(0);
|
||||
private final IntByReference bytesRead = new IntByReference(0);
|
||||
private boolean pendingWait = false;
|
||||
|
||||
public WindowsNamedPipeBridge(
|
||||
VRServer server,
|
||||
@@ -37,7 +65,7 @@ public class WindowsNamedPipeBridge extends SteamVRBridge {
|
||||
) {
|
||||
super(server, hmd, "Named pipe thread", bridgeName, bridgeSettingsKey, shareableTrackers);
|
||||
this.pipeName = pipeName;
|
||||
overlapped.hEvent = dataEvent;
|
||||
overlappedWait.hEvent = rxEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,12 +85,14 @@ public class WindowsNamedPipeBridge extends SteamVRBridge {
|
||||
if (pipe.state == PipeState.ERROR) {
|
||||
resetPipe();
|
||||
}
|
||||
if (!pipesUpdated) {
|
||||
if (pipesUpdated) {
|
||||
signalRecv();
|
||||
} else {
|
||||
if (pipe.state == PipeState.OPEN) {
|
||||
waitForData();
|
||||
waitForData(10);
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -76,102 +106,141 @@ public class WindowsNamedPipeBridge extends SteamVRBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
@BridgeThread
|
||||
protected boolean sendMessageReal(ProtobufMessage message) {
|
||||
if (pipe.state == PipeState.OPEN) {
|
||||
try {
|
||||
int size = message.getSerializedSize();
|
||||
CodedOutputStream os = CodedOutputStream.newInstance(buffArray, 4, size);
|
||||
message.writeTo(os);
|
||||
size += 4;
|
||||
buffArray[0] = (byte) (size & 0xFF);
|
||||
buffArray[1] = (byte) ((size >> 8) & 0xFF);
|
||||
buffArray[2] = (byte) ((size >> 16) & 0xFF);
|
||||
buffArray[3] = (byte) ((size >> 24) & 0xFF);
|
||||
if (Kernel32.INSTANCE.WriteFile(pipe.pipeHandle, buffArray, size, null, null)) {
|
||||
return true;
|
||||
}
|
||||
pipe.state = PipeState.ERROR;
|
||||
LogManager
|
||||
.severe("[" + bridgeName + "] Pipe error: " + Kernel32.INSTANCE.GetLastError());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ThreadSafe
|
||||
protected void signalSend() {
|
||||
k32.SetEvent(txEvent);
|
||||
}
|
||||
|
||||
private void waitForData() {
|
||||
@BridgeThread
|
||||
private void waitForData(int timeoutMs) {
|
||||
if (pipe.state != PipeState.OPEN)
|
||||
return;
|
||||
// async request for data, overlapped contains the event handle
|
||||
Kernel32.INSTANCE.ReadFile(pipe.pipeHandle, null, 0, null, overlapped);
|
||||
Kernel32.INSTANCE.WaitForSingleObject(dataEvent, 20);
|
||||
if (!pendingWait) {
|
||||
k32.ReadFile(pipe.pipeHandle, null, 0, null, overlappedWait);
|
||||
pendingWait = true;
|
||||
}
|
||||
int evIdx = k32.WaitForMultipleObjects(events.length, events, false, timeoutMs);
|
||||
if (evIdx == 0) {
|
||||
// events[0] == overlappedWait.hEvent == rxEvent
|
||||
pendingWait = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@BridgeThread
|
||||
protected boolean sendMessageReal(ProtobufMessage message) {
|
||||
if (pipe.state != PipeState.OPEN) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
int size = message.getSerializedSize();
|
||||
CodedOutputStream os = CodedOutputStream.newInstance(buffArray, 4, size);
|
||||
message.writeTo(os);
|
||||
size += 4;
|
||||
buffArray[0] = (byte) (size & 0xFF);
|
||||
buffArray[1] = (byte) ((size >> 8) & 0xFF);
|
||||
buffArray[2] = (byte) ((size >> 16) & 0xFF);
|
||||
buffArray[3] = (byte) ((size >> 24) & 0xFF);
|
||||
|
||||
overlappedWrite.clear();
|
||||
overlappedWrite.hEvent = writeEvent;
|
||||
boolean immediate = k32
|
||||
.WriteFile(pipe.pipeHandle, buffArray, size, null, overlappedWrite);
|
||||
int err = k32.GetLastError();
|
||||
if (!immediate && err != WinError.ERROR_IO_PENDING) {
|
||||
setPipeError("WriteFile failed: " + err);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!k32io.GetOverlappedResult(pipe.pipeHandle, overlappedWrite, bytesWritten, true)) {
|
||||
setPipeError(
|
||||
"sendMessageReal/GetOverlappedResult failed: " + k32.GetLastError()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bytesWritten.getValue() != size) {
|
||||
setPipeError("Bytes written " + bytesWritten.getValue() + ", expected " + size);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean updatePipe() throws IOException {
|
||||
if (pipe.state == PipeState.OPEN) {
|
||||
boolean readAnything = false;
|
||||
IntByReference bytesAvailable = new IntByReference(0);
|
||||
while (
|
||||
Kernel32.INSTANCE
|
||||
.PeekNamedPipe(pipe.pipeHandle, buffArray, 4, null, bytesAvailable, null)
|
||||
) {
|
||||
if (bytesAvailable.getValue() >= 4) { // Got size
|
||||
int messageLength = (buffArray[3] << 24)
|
||||
| (buffArray[2] << 16)
|
||||
| (buffArray[1] << 8)
|
||||
| buffArray[0];
|
||||
if (messageLength > 1024) { // Overflow
|
||||
LogManager
|
||||
.severe(
|
||||
"["
|
||||
+ bridgeName
|
||||
+ "] Pipe overflow. Message length: "
|
||||
+ messageLength
|
||||
);
|
||||
pipe.state = PipeState.ERROR;
|
||||
return readAnything;
|
||||
}
|
||||
if (bytesAvailable.getValue() >= messageLength) {
|
||||
if (
|
||||
Kernel32.INSTANCE
|
||||
.ReadFile(
|
||||
pipe.pipeHandle,
|
||||
buffArray,
|
||||
messageLength,
|
||||
bytesAvailable,
|
||||
null
|
||||
)
|
||||
) {
|
||||
ProtobufMessage message = ProtobufMessage
|
||||
.parser()
|
||||
.parseFrom(buffArray, 4, messageLength - 4);
|
||||
messageReceived(message);
|
||||
readAnything = true;
|
||||
} else {
|
||||
pipe.state = PipeState.ERROR;
|
||||
LogManager
|
||||
.severe(
|
||||
"["
|
||||
+ bridgeName
|
||||
+ "] Pipe error: "
|
||||
+ Kernel32.INSTANCE.GetLastError()
|
||||
);
|
||||
return readAnything;
|
||||
}
|
||||
} else {
|
||||
return readAnything; // Wait for more data
|
||||
}
|
||||
} else {
|
||||
return readAnything; // Wait for more data
|
||||
}
|
||||
}
|
||||
pipe.state = PipeState.ERROR;
|
||||
LogManager
|
||||
.severe("[" + bridgeName + "] Pipe error: " + Kernel32.INSTANCE.GetLastError());
|
||||
if (pipe.state != PipeState.OPEN) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
boolean readAnything = false;
|
||||
while (k32.PeekNamedPipe(pipe.pipeHandle, buffArray, 4, null, bytesAvailable, null)) {
|
||||
if (bytesAvailable.getValue() < 4) {
|
||||
return readAnything; // Wait for more data
|
||||
}
|
||||
int messageLength = (buffArray[3] << 24)
|
||||
| (buffArray[2] << 16)
|
||||
| (buffArray[1] << 8)
|
||||
| buffArray[0];
|
||||
if (messageLength > 1024) { // Overflow
|
||||
setPipeError("Pipe overflow. Message length: " + messageLength);
|
||||
return readAnything;
|
||||
}
|
||||
if (bytesAvailable.getValue() < messageLength) {
|
||||
return readAnything; // Wait for more data
|
||||
}
|
||||
|
||||
overlappedRead.clear();
|
||||
overlappedRead.hEvent = readEvent;
|
||||
boolean immediate = k32
|
||||
.ReadFile(pipe.pipeHandle, buffArray, messageLength, null, overlappedRead);
|
||||
int err = k32.GetLastError();
|
||||
if (!immediate && err != WinError.ERROR_IO_PENDING) {
|
||||
setPipeError("ReadFile failed: " + err);
|
||||
return readAnything;
|
||||
}
|
||||
|
||||
if (!k32io.GetOverlappedResult(pipe.pipeHandle, overlappedRead, bytesRead, true)) {
|
||||
setPipeError(
|
||||
"updatePipe/GetOverlappedResult failed: " + k32.GetLastError()
|
||||
);
|
||||
return readAnything;
|
||||
}
|
||||
|
||||
if (bytesRead.getValue() != messageLength) {
|
||||
setPipeError(
|
||||
"Bytes read " + bytesRead.getValue() + ", expected " + messageLength
|
||||
);
|
||||
return readAnything;
|
||||
}
|
||||
|
||||
try {
|
||||
ProtobufMessage message = ProtobufMessage
|
||||
.parser()
|
||||
.parseFrom(buffArray, 4, messageLength - 4);
|
||||
messageReceived(message);
|
||||
readAnything = true;
|
||||
} catch (InvalidProtocolBufferException parseEx) {
|
||||
parseEx.printStackTrace();
|
||||
setPipeError("Failed to parse message: " + parseEx.getMessage());
|
||||
return readAnything;
|
||||
}
|
||||
}
|
||||
|
||||
int err = k32.GetLastError();
|
||||
if (err == WinError.ERROR_BROKEN_PIPE) {
|
||||
setPipeError("Pipe closed");
|
||||
} else {
|
||||
setPipeError("Pipe error: " + err);
|
||||
}
|
||||
return readAnything;
|
||||
}
|
||||
|
||||
private void setPipeError(String message) {
|
||||
pipe.state = PipeState.ERROR;
|
||||
LogManager.severe("[" + bridgeName + "] " + message);
|
||||
}
|
||||
|
||||
private void resetPipe() {
|
||||
@@ -183,24 +252,23 @@ public class WindowsNamedPipeBridge extends SteamVRBridge {
|
||||
private void createPipe() throws IOException {
|
||||
try {
|
||||
pipe = new WindowsPipe(
|
||||
Kernel32.INSTANCE
|
||||
k32
|
||||
.CreateNamedPipe(
|
||||
pipeName,
|
||||
WinBase.PIPE_ACCESS_DUPLEX, // dwOpenMode
|
||||
WinBase.PIPE_ACCESS_DUPLEX | WinNT.FILE_FLAG_OVERLAPPED, // dwOpenMode
|
||||
WinBase.PIPE_TYPE_BYTE | WinBase.PIPE_READMODE_BYTE | WinBase.PIPE_WAIT, // dwPipeMode
|
||||
1, // nMaxInstances,
|
||||
1024 * 16, // nOutBufferSize,
|
||||
1024 * 16, // nInBufferSize,
|
||||
0, // nDefaultTimeOut,
|
||||
null
|
||||
null // lpSecurityAttributes
|
||||
),
|
||||
pipeName
|
||||
); // lpSecurityAttributes
|
||||
);
|
||||
LogManager.info("[" + bridgeName + "] Pipe " + pipe.name + " created");
|
||||
if (WinBase.INVALID_HANDLE_VALUE.equals(pipe.pipeHandle))
|
||||
throw new IOException(
|
||||
"Can't open " + pipeName + " pipe: " + Kernel32.INSTANCE.GetLastError()
|
||||
);
|
||||
if (WinBase.INVALID_HANDLE_VALUE.equals(pipe.pipeHandle)) {
|
||||
throw new IOException("Can't open " + pipeName + " pipe: " + k32.GetLastError());
|
||||
}
|
||||
LogManager.info("[" + bridgeName + "] Pipes are created");
|
||||
} catch (IOException e) {
|
||||
WindowsPipe.safeDisconnect(pipe);
|
||||
@@ -209,25 +277,29 @@ public class WindowsNamedPipeBridge extends SteamVRBridge {
|
||||
}
|
||||
|
||||
private boolean tryOpeningPipe(WindowsPipe pipe) {
|
||||
if (
|
||||
Kernel32.INSTANCE.ConnectNamedPipe(pipe.pipeHandle, null)
|
||||
|| Kernel32.INSTANCE.GetLastError() == WinError.ERROR_PIPE_CONNECTED
|
||||
) {
|
||||
pipe.state = PipeState.OPEN;
|
||||
LogManager.info("[" + bridgeName + "] Pipe " + pipe.name + " is open");
|
||||
Main.getVrServer().queueTask(this::reconnected);
|
||||
return true;
|
||||
overlappedOpen.clear();
|
||||
overlappedOpen.hEvent = openEvent;
|
||||
|
||||
boolean ok = k32.ConnectNamedPipe(pipe.pipeHandle, overlappedOpen);
|
||||
int err = k32.GetLastError();
|
||||
if (!ok && err != WinError.ERROR_PIPE_CONNECTED) {
|
||||
if (err != WinError.ERROR_IO_PENDING) {
|
||||
setPipeError("ConnectNamedPipe failed: " + err);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!k32io.GetOverlappedResult(pipe.pipeHandle, overlappedOpen, bytesRead, true)) {
|
||||
setPipeError(
|
||||
"tryOpeningPipe/GetOverlappedResult failed: " + k32.GetLastError()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
LogManager
|
||||
.info(
|
||||
"["
|
||||
+ bridgeName
|
||||
+ "] Error connecting to pipe "
|
||||
+ pipe.name
|
||||
+ ": "
|
||||
+ Kernel32.INSTANCE.GetLastError()
|
||||
);
|
||||
return false;
|
||||
|
||||
pipe.state = PipeState.OPEN;
|
||||
LogManager.info("[" + bridgeName + "] Pipe " + pipe.name + " is open");
|
||||
Main.getVrServer().queueTask(this::reconnected);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user