mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-16 03:31:43 +02:00
.config
.run
.workdir
Agent
Common
Controller
Docker
Utils
Phantom.Utils
Phantom.Utils.Actor
Phantom.Utils.Events
Phantom.Utils.Logging
Phantom.Utils.Rpc
Message
Runtime
Sockets
Phantom.Utils.Rpc.csproj
RpcConfiguration.cs
RpcExtensions.cs
Phantom.Utils.Tests
Web
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
33 lines
824 B
C#
33 lines
824 B
C#
using NetMQ;
|
|
using NetMQ.Sockets;
|
|
|
|
namespace Phantom.Utils.Rpc;
|
|
|
|
static class RpcExtensions {
|
|
public static ReadOnlyMemory<byte> Receive(this ClientSocket socket, CancellationToken cancellationToken) {
|
|
var msg = new Msg();
|
|
msg.InitEmpty();
|
|
|
|
try {
|
|
socket.Receive(ref msg, cancellationToken);
|
|
return msg.SliceAsMemory();
|
|
} finally {
|
|
// Only releases references, so the returned ReadOnlyMemory is safe.
|
|
msg.Close();
|
|
}
|
|
}
|
|
|
|
public static (uint, ReadOnlyMemory<byte>) Receive(this ServerSocket socket, CancellationToken cancellationToken) {
|
|
var msg = new Msg();
|
|
msg.InitEmpty();
|
|
|
|
try {
|
|
socket.Receive(ref msg, cancellationToken);
|
|
return (msg.RoutingId, msg.SliceAsMemory());
|
|
} finally {
|
|
// Only releases references, so the returned ReadOnlyMemory is safe.
|
|
msg.Close();
|
|
}
|
|
}
|
|
}
|