示例#1
0
        /// <summary>
        /// 创建输出信息
        /// </summary>
        /// <param name="sender">TCP 服务套接字数据发送</param>
        /// <param name="buildInfo">输出创建参数</param>
        internal override OutputLink Build(ServerSocketSenderBase sender, ref SenderBuildInfo buildInfo)
        {
            UnmanagedStream stream = sender.OutputSerializer.Stream;

            if (buildInfo.Count == 0 || (buildInfo.SendBufferSize - stream.ByteSize) >= outputInfo.MaxDataSize)
            {
                int        streamLength = stream.ByteSize;
                OutputLink nextBuild    = LinkNext;
                stream.PrepLength(sizeof(uint) + sizeof(int) * 2);
                stream.ByteSize += sizeof(uint) + sizeof(int);
                if ((Server.GetCommandFlags(ref CommandIndex) & CommandFlags.JsonSerialize) == 0)
                {
                    sender.Serialize(outputInfo, ref outputParameter);
                }
                else
                {
                    sender.JsonSerialize(ref outputParameter);
                }
                int   dataLength = stream.ByteSize - streamLength - (sizeof(uint) + sizeof(int));
                byte *dataFixed  = stream.Data.Byte + streamLength;
                *(uint *)dataFixed = CommandIndex;
                *(int *)(dataFixed + sizeof(uint)) = dataLength;
                outputInfo.CheckMaxDataSize(Math.Max(dataLength + (sizeof(uint) + sizeof(int)), stream.LastPrepSize - streamLength));
                ++buildInfo.Count;
                LinkNext        = null;
                outputParameter = default(outputParameterType);
                AutoCSer.Threading.RingPool <Output <outputParameterType> > .Default.PushNotNull(this);

                return(nextBuild);
            }
            buildInfo.isFullSend = 1;
            return(this);
        }
示例#2
0
        /// <summary>
        /// 创建输出信息
        /// </summary>
        /// <param name="sender">TCP 服务套接字数据发送</param>
        /// <param name="buildInfo">输出创建参数</param>
        internal override OutputLink Build(ServerSocketSenderBase sender, ref SenderBuildInfo buildInfo)
        {
            UnmanagedStream stream = sender.OutputSerializer.Stream;
            int             dataSize = (Data.Length + (sizeof(int) + 3)) & (int.MaxValue), prepLength = dataSize + (sizeof(uint) + sizeof(int));

            if (buildInfo.Count == 0 || (buildInfo.SendBufferSize - stream.Data.CurrentIndex) >= prepLength ||
                (stream.Data.FreeSize >= prepLength && prepLength > buildInfo.SendBufferSize - TcpServer.ServerOutput.OutputLink.StreamStartIndex))
            {
                OutputLink nextBuild = LinkNext;
                byte *     write     = stream.GetPrepSizeCurrent(prepLength);
                *(uint *)write = ClientCommand.KeepCommand.CustomDataIndex;
                *(int *)(write + sizeof(uint)) = dataSize;
                *(int *)(write + (sizeof(uint) + sizeof(int))) = Data.Length;
                if (Data.Length != 0)
                {
                    fixed(byte *dataFixed = Data.GetFixedBuffer()) AutoCSer.Memory.Common.CopyNotNull(dataFixed + Data.Start, write + (sizeof(uint) + sizeof(int) * 2), Data.Length);
                }
                stream.Data.CurrentIndex += dataSize + (sizeof(uint) + sizeof(int));
                ++buildInfo.Count;
                LinkNext   = null;
                Data.Array = null;
                AutoCSer.Threading.RingPool <CustomDataOutput> .Default.PushNotNull(this);

                return(nextBuild);
            }
            buildInfo.isFullSend = 1;
            return(this);
        }
        /// <summary>
        /// 释放 TCP 服务端套接字输出信息
        /// </summary>
        /// <returns></returns>
        protected override OutputLink free()
        {
            OutputLink next = LinkNext;

            LinkNext = null;
            AutoCSer.Threading.RingPool <ReturnTypeOutput> .Default.PushNotNull(this);

            return(next);
        }
示例#4
0
        /// <summary>
        /// 释放 TCP 服务端套接字输出信息
        /// </summary>
        /// <returns></returns>
        protected override OutputLink free()
        {
            OutputLink next = LinkNext;

            Data.Array = null;
            LinkNext   = null;
            AutoCSer.Threading.RingPool <CustomDataOutput> .Default.PushNotNull(this);

            return(next);
        }
示例#5
0
        /// <summary>
        /// 释放 TCP 服务端套接字输出信息
        /// </summary>
        /// <returns></returns>
        protected override OutputLink free()
        {
            OutputLink next = LinkNext;

            outputParameter = default(outputParameterType);
            LinkNext        = null;
            AutoCSer.Threading.RingPool <Output <outputParameterType> > .Default.PushNotNull(this);

            return(next);
        }
 internal ServerOutput.OutputLink Pop()
 {
     ServerOutput.OutputLink value = head.TryFreeBuildQueue();
     if (value != null)
     {
         head = value;
         return(value);
     }
     return(null);
 }
        internal int Push(ServerOutput.OutputLink output)
        {
            AutoCSer.Threading.Interlocked.CompareExchangeYieldOnly(ref pushLock);
            int IsOutput = this.IsOutput;

            end.LinkNext  = output;
            this.IsOutput = 1;
            end           = output;
            pushLock      = 0;
            return(IsOutput);
        }
示例#8
0
        /// <summary>
        /// 创建输出信息
        /// </summary>
        /// <param name="sender">TCP 服务套接字数据发送</param>
        /// <param name="buildInfo">输出创建参数</param>
        internal unsafe override OutputLink Build(ServerSocketSenderBase sender, ref SenderBuildInfo buildInfo)
        {
            UnmanagedStream stream = sender.OutputSerializer.Stream;

            if ((buildInfo.SendBufferSize - stream.Data.CurrentIndex) >= sizeof(uint))
            {
                OutputLink nextBuild = LinkNext;
                stream.Data.Write(CommandIndex);
                LinkNext = null;
                ++buildInfo.Count;
                AutoCSer.Threading.RingPool <ReturnTypeOutput> .Default.PushNotNull(this);

                return(nextBuild);
            }
            buildInfo.isFullSend = 1;
            return(this);
        }
 /// <summary>
 /// 单线程读队列
 /// </summary>
 /// <param name="free">空闲节点</param>
 internal ServerOuputBuildQueue()
 {
     head          = end = Head = new OutputHead();
     Head.LinkNext = null;
 }
 internal void PushHead()
 {
     Head.LinkNext = head;
     head          = Head;
 }