コード例 #1
0
ファイル: TcpService.cs プロジェクト: moien007/TcpFramework
        static Pool <T> CreatePool <T>(TcpServicePoolType poolType, int count, Func <T> activator)
        {
            switch (poolType)
            {
            case TcpServicePoolType.Cache:
            case TcpServicePoolType.DemandCache:
                return(new CachedPool <T>(count, activator, TcpServicePoolType.DemandCache == poolType));

            case TcpServicePoolType.Cyclic:
            case TcpServicePoolType.DemandCyclic:
                return(new CyclicPool <T>(count, activator, TcpServicePoolType.DemandCyclic == poolType));

            default:
                throw new NotImplementedException(poolType.ToString());
            }
        }
コード例 #2
0
 /// <summary>
 /// Sets <see cref="TcpServiceConfiguration.SendBufferPoolType"/>
 /// </summary>
 public TcpServiceConfigurationBuilder WithSendBufferPoolType(TcpServicePoolType poolType)
 {
     ServiceConfiguration.SendBufferPoolType = poolType;
     return(this);
 }
コード例 #3
0
 /// <summary>
 /// Sets <see cref="TcpServiceConfiguration.ReceiveBufferPoolType"/> and <see cref="TcpServiceConfiguration.SendBufferPoolType"/>
 /// </summary>
 public TcpServiceConfigurationBuilder WithBufferPoolType(TcpServicePoolType poolType)
 {
     WithReceiveBufferPoolType(poolType);
     return(WithSendBufferPoolType(poolType));
 }
コード例 #4
0
ファイル: TcpService.cs プロジェクト: moien007/TcpFramework
        static Pool <SocketAsyncEventArgs> CreateSAEABufferPool(int count, int bufferSize, TcpServicePoolType poolType)
        {
            if (poolType == TcpServicePoolType.Cyclic)
            {
                var buffer = new byte[bufferSize * count];
                var offset = 0;

                return(new CyclicPool <SocketAsyncEventArgs>(count, () =>
                {
                    var eventArgs = new SocketAsyncEventArgs();
                    eventArgs.SetBuffer(buffer, offset, bufferSize);
                    offset += bufferSize;
                    return eventArgs;
                }, false));
            }

            if (poolType == TcpServicePoolType.Cache)
            {
                var buffer = new byte[bufferSize * count];
                var offset = 0;

                return(new CachedPool <SocketAsyncEventArgs>(count, () =>
                {
                    var eventArgs = new SocketAsyncEventArgs();
                    if (offset != count)
                    {
                        eventArgs.SetBuffer(buffer, offset, bufferSize);
                        offset += bufferSize;
                    }
                    else
                    {
                        eventArgs.SetBuffer(new byte[bufferSize], 0, bufferSize);
                    }
                    return eventArgs;
                }, false));
            }

            if (poolType == TcpServicePoolType.DemandCyclic)
            {
                return(new CyclicPool <SocketAsyncEventArgs>(count, () =>
                {
                    var eventArgs = new SocketAsyncEventArgs();
                    var buffer = new byte[bufferSize];
                    eventArgs.SetBuffer(buffer, 0, buffer.Length);
                    return eventArgs;
                }, true));
            }

            if (poolType == TcpServicePoolType.DemandCache)
            {
                return(new CyclicPool <SocketAsyncEventArgs>(count, () =>
                {
                    var eventArgs = new SocketAsyncEventArgs();
                    var buffer = new byte[bufferSize];
                    eventArgs.SetBuffer(buffer, 0, buffer.Length);
                    return eventArgs;
                }, true));
            }

            throw new NotImplementedException(poolType.ToString());
        }