private async ValueTask <IConnection?> InternalConnectAsync(ICap cap, string serviceType, CancellationToken cancellationToken) { using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); linkedTokenSource.CancelAfter(TimeSpan.FromSeconds(20)); var baseConnectionOptions = new BaseConnectionOptions() { MaxSendByteCount = 4 * 1024 * 1024, MaxReceiveByteCount = 4 * 1024 * 1024, BytesPool = _bytesPool, }; var baseConnection = new BaseConnection(cap, _baseConnectionDispatcher, baseConnectionOptions); var omniSecureConnectionOptions = new OmniSecureConnectionOptions() { Type = OmniSecureConnectionType.Connected, BufferPool = _bytesPool, }; var omniSecureConnection = new OmniSecureConnection(baseConnection, omniSecureConnectionOptions); await omniSecureConnection.HandshakeAsync(linkedTokenSource.Token); var helloMessage = new ConnectionHelloMessage(serviceType); await omniSecureConnection.EnqueueAsync((bufferWriter) => helloMessage.Export(bufferWriter, _bytesPool), linkedTokenSource.Token); return(omniSecureConnection); }
private async ValueTask <(IConnection?, string?)> InternalAcceptAsync(ICap cap, CancellationToken cancellationToken) { using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); linkedTokenSource.CancelAfter(TimeSpan.FromSeconds(20)); var baseConnectionOptions = new BaseConnectionOptions() { MaxSendByteCount = 4 * 1024 * 1024, MaxReceiveByteCount = 4 * 1024 * 1024, BytesPool = _bytesPool, }; var baseConnection = new BaseConnection(cap, _baseConnectionDispatcher, baseConnectionOptions); var omniSecureConnectionOptions = new OmniSecureConnectionOptions() { Type = OmniSecureConnectionType.Accepted, BufferPool = _bytesPool, }; var omniSecureConnection = new OmniSecureConnection(baseConnection, omniSecureConnectionOptions); await omniSecureConnection.HandshakeAsync(linkedTokenSource.Token); ConnectionHelloMessage?helloMessage = null; await omniSecureConnection.DequeueAsync((sequence) => helloMessage = ConnectionHelloMessage.Import(sequence, _bytesPool), linkedTokenSource.Token); return(omniSecureConnection, helloMessage?.ServiceType); }
public ConnectionSender(ICap cap, IBytesPool bytesPool, CancellationToken cancellationToken) { _cap = cap; _bytesPool = bytesPool; _cancellationToken = cancellationToken; _bytesPipe = new BytesPipe(_bytesPool); _semaphoreSlim = new SemaphoreSlim(1, 1); }
public ConnectionReceiver(ICap cap, int maxReceiveByteCount, IBytesPool bytesPool, CancellationToken cancellationToken) { _cap = cap; _maxReceiveByteCount = maxReceiveByteCount; _bytesPool = bytesPool; _cancellationToken = cancellationToken; _bytesPipe = new BytesPipe(_bytesPool); _semaphoreSlim = new SemaphoreSlim(0, 1); }
/// <summary> /// 创建最终药水对象 /// </summary> /// <param name="factory">抽象工厂具体对象</param> public void MakeProduct(AbstractFactory factory) { _bottle = factory.CreateBottle(); _cap = factory.CreateCap(); Console.WriteLine("准备英雄需要的瓶子和瓶盖。"); _bottle.ShowInfo(); _cap.ShowInfo(); Console.WriteLine("开始往瓶子了灌入隐形药水,然后封上瓶盖。"); }
private ICap _cap; // 瓶盖对象 /// <summary> /// 创建最终药水对象 /// </summary> /// <param name="bottleColor"></param> /// <param name="capShape"></param> public void MakeProduct(string bottleColor, string capShape) { _bottle = BottleFactory.CreateBottle(bottleColor); _cap = CapFactory.CreateCap(capShape); Console.WriteLine("准备英雄需要的瓶子和瓶盖。"); _bottle.ShowInfo(); _cap.ShowInfo(); Console.WriteLine("开始往瓶子了灌入隐形药水,然后封上瓶盖。"); }