1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-08-16 21:31:45 +02:00
Files
.config
.run
.workdir
Agent
Common
Docker
Server
Utils
Phantom.Utils.Collections
Phantom.Utils.Collections.Tests
Phantom.Utils.Cryptography
Phantom.Utils.Events
Phantom.Utils.IO
Phantom.Utils.Rpc
Message
Phantom.Utils.Rpc.csproj
RpcConfiguration.cs
RpcExtensions.cs
RpcRuntime.cs
Phantom.Utils.Runtime
Phantom.Utils.Runtime.Tests
.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
831 B
C#

using NetMQ;
using NetMQ.Sockets;
namespace Phantom.Utils.Rpc;
public 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();
}
}
}