Skip to content

Commit 47273cc

Browse files
2 parents 4dc1554 + 50f4494 commit 47273cc

8 files changed

Lines changed: 588 additions & 22 deletions

File tree

.vscode/settings.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"haxe.configurations": [
3+
{
4+
"label": "Aedifex Root",
5+
"args": [
6+
"c:/Users/Chris/Documents/GitHub/crossbyte/.aedifex/aedifex.display.hxml"
7+
],
8+
"files": [
9+
"Aedifex.hx",
10+
"ProjectDefines.hx"
11+
]
12+
}
13+
],
14+
"haxe.displayConfigurations": [
15+
{
16+
"label": "Aedifex Root",
17+
"args": [
18+
"c:/Users/Chris/Documents/GitHub/crossbyte/.aedifex/aedifex.display.hxml"
19+
],
20+
"files": [
21+
"Aedifex.hx",
22+
"ProjectDefines.hx"
23+
]
24+
}
25+
]
26+
}

src/crossbyte/ipc/LocalConnection.hx

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class LocalConnection implements INetConnection {
115115
@:noCompletion private var __dispatchListener:TickEvent->Void;
116116
@:noCompletion private var __dispatchAttached:Bool = false;
117117
@:noCompletion private var __pendingPayloads:Array<ByteArray> = [];
118+
@:noCompletion private var __dispatchFailed:Bool = false;
118119

119120
public function new() {
120121
__captureRuntime();
@@ -139,6 +140,7 @@ class LocalConnection implements INetConnection {
139140
__requireConnectionName(connectionName);
140141
close();
141142
__captureRuntime();
143+
__dispatchFailed = false;
142144
__mode = SERVER;
143145
__connectionName = connectionName;
144146
__running = true;
@@ -178,6 +180,7 @@ class LocalConnection implements INetConnection {
178180
__requireConnectionName(connectionName);
179181
close();
180182
__captureRuntime();
183+
__dispatchFailed = false;
181184
__mode = CLIENT;
182185
__connectionName = connectionName;
183186

@@ -239,6 +242,7 @@ class LocalConnection implements INetConnection {
239242
var wasConnected = __connected;
240243
__running = false;
241244
__connected = false;
245+
__dispatchFailed = false;
242246
__mode = NONE;
243247
__connectionName = null;
244248
__receiveBuffer.clear();
@@ -255,7 +259,9 @@ class LocalConnection implements INetConnection {
255259
}
256260

257261
if (wasConnected) {
258-
__onClose(Reason.Closed);
262+
try {
263+
__onClose(Reason.Closed);
264+
} catch (_:Dynamic) {}
259265
}
260266
}
261267

@@ -428,21 +434,53 @@ class LocalConnection implements INetConnection {
428434
}
429435

430436
@:noCompletion private function __applyDispatch(message:LocalConnectionDispatch):Void {
431-
switch (message) {
432-
case Ready:
433-
__onReady();
434-
case Close(reason):
435-
__onClose(reason);
436-
case Error(reason):
437-
__onError(reason);
438-
case Data(payload):
439-
if (!__readEnabled) {
440-
__pushPendingPayload(payload);
441-
return;
442-
}
443-
payload.position = 0;
444-
__onData(payload);
437+
try {
438+
switch (message) {
439+
case Ready:
440+
__onReady();
441+
case Close(reason):
442+
__onClose(reason);
443+
case Error(reason):
444+
__onError(reason);
445+
case Data(payload):
446+
if (!__readEnabled) {
447+
__pushPendingPayload(payload);
448+
return;
449+
}
450+
payload.position = 0;
451+
__onData(payload);
452+
}
453+
} catch (error:Dynamic) {
454+
__handleCallbackFailure(error);
455+
}
456+
}
457+
458+
@:noCompletion private function __handleCallbackFailure(error:Dynamic):Void {
459+
if (__dispatchFailed) {
460+
return;
445461
}
462+
463+
__dispatchFailed = true;
464+
__running = false;
465+
__connected = false;
466+
__mode = NONE;
467+
__receiveBuffer.clear();
468+
__clearPendingPayloads();
469+
__detachDispatchListener();
470+
471+
if (__activePipe != null) {
472+
__close(__activePipe);
473+
__activePipe = null;
474+
}
475+
if (__listeningPipe != null) {
476+
__close(__listeningPipe);
477+
__listeningPipe = null;
478+
}
479+
480+
var reason = Reason.Error("Local transport callback failed: " + Std.string(error));
481+
try {
482+
__onError(reason);
483+
} catch (_:Dynamic) {}
446484
}
447485

448486
@:noCompletion private function __flushPendingPayloads():Void {

src/crossbyte/rpc/RPCHandler.hx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ abstract class RPCHandler {
3333
final payloadLen:Int = input.readInt();
3434

3535
if (payloadLen < RPCWire.MIN_PAYLOAD_LEN || (MAX_FRAME_LEN != 0 && payloadLen > MAX_FRAME_LEN)) {
36-
input.position = input.length;
37-
return;
36+
throw "Invalid RPC frame length";
3837
}
3938

4039
if (input.bytesAvailable < payloadLen) {
@@ -44,6 +43,9 @@ abstract class RPCHandler {
4443

4544
final frameEnd:Int = input.position + payloadLen;
4645
final flags:Int = input.readByte();
46+
if ((flags & RPCWire.FLAG_RUNTIME) != 0) {
47+
throw "Runtime RPC frame delivered to compile-time handler lane";
48+
}
4749
final op:Int = input.readInt();
4850
if (flags == 0) {
4951
this.dispatch(op, input, 0);

src/crossbyte/rpc/RPCResponse.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import crossbyte.events.EventType;
66
import crossbyte.events.IEventDispatcher;
77

88
@:allow(crossbyte.rpc.RPCCommands)
9+
@:allow(crossbyte.rpc.RPCSession)
910
/**
1011
* Represents the eventual result of a request/response RPC invocation.
1112
*

0 commit comments

Comments
 (0)