Surprisingly, it works on the channels
This commit is contained in:
@@ -13,10 +13,8 @@ namespace mROA.Implementation.Backend
|
||||
return _ownerships.GetValueOrDefault(Environment.CurrentManagedThreadId, 0);
|
||||
}
|
||||
|
||||
public int GetHostOwnershipId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public int GetHostOwnershipId() => 0;
|
||||
|
||||
|
||||
public void RegisterOwnership(int ownershipId)
|
||||
{
|
||||
|
||||
@@ -78,7 +78,10 @@ namespace mROA.Implementation.Backend
|
||||
|
||||
var streamExtractor = new StreamExtractor(client.GetStream(), _serialization);
|
||||
interaction.IsConnected = () => streamExtractor.IsConnected;
|
||||
streamExtractor.MessageReceived = message => interaction.ReceiveChanel.Writer.WriteAsync(message);
|
||||
streamExtractor.MessageReceived = message =>
|
||||
{
|
||||
interaction.ReceiveChanel.Writer.WriteAsync(message);
|
||||
};
|
||||
streamExtractor.SingleReceive();
|
||||
var connectionRequest = interaction.GetNextMessageReceiving(false)
|
||||
.GetAwaiter().GetResult()!;
|
||||
@@ -98,7 +101,10 @@ namespace mROA.Implementation.Backend
|
||||
var recoveryRequest = _serialization!.Deserialize<ClientRecovery>(connectionRequest.Data)!;
|
||||
var recoveryInteraction = _hub.GetInteraction(recoveryRequest.Id);
|
||||
|
||||
streamExtractor.MessageReceived = message => recoveryInteraction.ReceiveChanel.Writer.WriteAsync(message);
|
||||
streamExtractor.MessageReceived = message =>
|
||||
{
|
||||
recoveryInteraction.ReceiveChanel.Writer.WriteAsync(message);
|
||||
};
|
||||
|
||||
recoveryInteraction.Restart(false);
|
||||
Console.WriteLine("Connection recovery for client {0} finished", recoveryRequest.Id);
|
||||
|
||||
@@ -28,14 +28,14 @@ namespace mROA.Implementation
|
||||
{
|
||||
SingleReader = false,
|
||||
SingleWriter = false,
|
||||
AllowSynchronousContinuations = true
|
||||
// AllowSynchronousContinuations = true
|
||||
});
|
||||
_receiveReader = ReceiveChanel.Reader;
|
||||
_outputTrustedChannel = Channel.CreateBounded<NetworkMessageHeader>(new BoundedChannelOptions(1)
|
||||
{
|
||||
SingleReader = true,
|
||||
SingleWriter = true,
|
||||
AllowSynchronousContinuations = true,
|
||||
// AllowSynchronousContinuations = true,
|
||||
|
||||
});
|
||||
_trustedWriter = _outputTrustedChannel.Writer;
|
||||
@@ -43,7 +43,7 @@ namespace mROA.Implementation
|
||||
{
|
||||
SingleReader = true,
|
||||
SingleWriter = true,
|
||||
AllowSynchronousContinuations = true
|
||||
// AllowSynchronousContinuations = true
|
||||
});
|
||||
_untrustedWriter = _outputUntrustedChannel.Writer;
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ namespace mROA.Implementation.Frontend
|
||||
_tcpClient.Connect(_serverEndPoint);
|
||||
|
||||
PrepareExtractor();
|
||||
_interactionModule.IsConnected = () => _currentExtractor.IsConnected;
|
||||
_interactionModule.IsConnected = () => _currentExtractor.IsConnected;
|
||||
_interactionModule.OnDisconnected += id => { Reconnect(); };
|
||||
|
||||
_interactionModule.PostMessageAsync(new NetworkMessageHeader(_serialization, new ClientConnect())).Wait();
|
||||
|
||||
|
||||
_currentExtractor.SingleReceive();
|
||||
var idMessage = _interactionModule.GetNextMessageReceiving(false).GetAwaiter().GetResult();
|
||||
|
||||
@@ -78,7 +78,10 @@ namespace mROA.Implementation.Frontend
|
||||
|
||||
_ = _currentExtractor.SendFromChannel(_interactionModule.TrustedPostChanel,
|
||||
_rawExtractorCancellation.Token);
|
||||
_currentExtractor.MessageReceived = message => _interactionModule.ReceiveChanel.Writer.WriteAsync(message);
|
||||
_currentExtractor.MessageReceived = message =>
|
||||
{
|
||||
_interactionModule.ReceiveChanel.Writer.WriteAsync(message);
|
||||
};
|
||||
}
|
||||
|
||||
private async Task Reconnect()
|
||||
@@ -90,7 +93,7 @@ namespace mROA.Implementation.Frontend
|
||||
_rawExtractorCancellation = new CancellationTokenSource();
|
||||
|
||||
PrepareExtractor();
|
||||
|
||||
|
||||
_ = _currentExtractor.LoopedReceive(_rawExtractorCancellation.Token);
|
||||
|
||||
await _interactionModule.Restart(true);
|
||||
|
||||
@@ -48,11 +48,14 @@ namespace mROA.Implementation.Frontend
|
||||
{
|
||||
ThrowIfNotInjected();
|
||||
|
||||
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(_representationModule.Id);
|
||||
|
||||
|
||||
var multiClientOwnershipRepository =
|
||||
TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
|
||||
multiClientOwnershipRepository?.RegisterOwnership(_representationModule!.Id);
|
||||
if (multiClientOwnershipRepository is not null)
|
||||
{
|
||||
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(_representationModule.Id);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace mROA.Implementation
|
||||
throw new NullReferenceException("representation producer is not initialized");
|
||||
|
||||
var representationModule =
|
||||
_representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||
_representationProducer.Produce(ownerId);
|
||||
|
||||
_producedRemoteEndpoints.Add((Activator.CreateInstance(RemoteTypes[type], -1,
|
||||
representationModule) as RemoteObjectBase)!);
|
||||
|
||||
@@ -35,7 +35,10 @@ namespace mROA.Implementation
|
||||
CancellationToken token = default, params Func<NetworkMessageHeader, Type?>[] converter)
|
||||
{
|
||||
var writer = _interaction.ReceiveChanel.Writer;
|
||||
await foreach (var message in _interaction.ReceiveChanel.Reader.ReadAllAsync(token))
|
||||
var reader = _interaction.ReceiveChanel.Reader;
|
||||
|
||||
|
||||
await foreach (var message in reader.ReadAllAsync(token))
|
||||
{
|
||||
if (!rule(message))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user