protected virtual Task <AssociationHandle> CreateOutboundAssociation(Stream stream, Address localAddress, Address remoteAddress, Socket socket) { var association = new StreamAssociationHandle(Settings, stream, localAddress, remoteAddress, socket); RegisterAssociation(association); association.ReadHandlerSource.Task.ContinueWith(task => association.Initialize(task.Result), CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); return(Task.FromResult((AssociationHandle)association)); }
public AssociationHandle CreateInboundAssociation(NamedPipeServerStream stream, Address remoteAddress) { //TODO Add unique id in InboundAddress? var association = new StreamAssociationHandle(Settings, stream, InboundAddress, remoteAddress, null); RegisterAssociation(association); association.ReadHandlerSource.Task.ContinueWith(task => association.Initialize(task.Result), CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); return(association); }
public AssociationHandle CreateOutboundAssociation(Address remoteAddress) { NamedPipeClientStream stream = new NamedPipeClientStream(".", remoteAddress.Host, PipeDirection.InOut, PipeOptions.Asynchronous); // Should not block, the server listens for `MaxAllowedServerInstances` // Connect will throw if the server is not listening stream.Connect(); string uniqueId = Guid.NewGuid().ToString("N"); var localAddress = new Address(ProtocolName, System.Name, Settings.PipeName + "_" + uniqueId, 1); var association = new StreamAssociationHandle(Settings, stream, localAddress, remoteAddress.WithPort(1), null); RegisterAssociation(association); association.ReadHandlerSource.Task.ContinueWith(task => association.Initialize(task.Result), CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); return(association); }