///// <summary> ///// 保持回调序号 ///// </summary> //protected int keepCallbackIdentity; ///// <summary> ///// 保持回调 ///// </summary> //internal bool SetKeepCallback() //{ // int index = (int)(CommandIndex & Server.CommandIndexAnd); // try // { // KeepCallback = new KeepCallback(this, ++keepCallbackIdentity); // return true; // } // catch (Exception error) // { // Socket.Log.add(LogLevel.Error, error); // } // Socket.FreeIndex(index); // return false; //} /// <summary> /// 创建命令输入数据 /// </summary> /// <param name="buildInfo">TCP 客户端创建命令参数</param> /// <returns>下一个命令</returns> internal unsafe override CommandBase Build(ref SenderBuildInfo buildInfo) { UnmanagedStream stream = Socket.OutputSerializer.Stream; if ((buildInfo.SendBufferSize - stream.Data.CurrentIndex) >= sizeof(int) + sizeof(uint)) { CommandBase nextBuild = LinkNext; int commandIndex = Socket.CommandPool.Push(this); if (commandIndex != 0) { if (KeepCallback.SetCommandIndex(commandIndex)) { stream.Data.Write(CommandInfo.Command, (uint)commandIndex | (uint)(CommandInfo.CommandFlags | CommandFlags.NullData)); ++buildInfo.Count; LinkNext = null; return(nextBuild); } Socket.CommandPool.Cancel(commandIndex); } else { KeepCallback.BuildCancel(); } LinkNext = null; return(nextBuild); } buildInfo.isFullSend = 1; return(this); }
/// <summary> /// 创建命令输入数据 /// </summary> /// <param name="buildInfo">TCP 客户端创建命令参数</param> /// <returns>是否成功</returns> internal unsafe override CommandBase Build(ref SenderBuildInfo buildInfo) { UnmanagedStream stream = Socket.OutputSerializer.Stream; if (buildInfo.Count == 0 || (buildInfo.SendBufferSize - stream.ByteSize) >= CommandInfo.MaxDataSize) { int streamLength = stream.ByteSize; stream.PrepLength(sizeof(uint) + sizeof(int) * 3); CommandBase nextBuild = LinkNext; stream.ByteSize += sizeof(uint) + sizeof(int) * 2; if ((CommandInfo.CommandFlags & CommandFlags.JsonSerialize) == 0) { Socket.Serialize(CommandInfo, ref InputParameter); } else { Socket.JsonSerialize(ref InputParameter); } int dataLength = stream.ByteSize - streamLength - (sizeof(int) * 2 + sizeof(uint)); InputParameter = default(inputParameterType); if (dataLength <= Socket.MaxInputSize) { int commandIndex = Socket.CommandPool.Push(this); if (commandIndex != 0) { if (KeepCallback.SetCommandIndex(commandIndex)) { byte *write = stream.Data.Byte + streamLength; buildInfo.IsVerifyMethod |= CommandInfo.IsVerifyMethod; ++buildInfo.Count; *(int *)write = CommandInfo.Command; *(uint *)(write + sizeof(int)) = (uint)commandIndex | (uint)CommandInfo.CommandFlags; *(int *)(write + (sizeof(uint) + sizeof(int))) = dataLength; CommandInfo.CheckMaxDataSize(Math.Max(dataLength + (sizeof(int) * 2 + sizeof(uint)), stream.LastPrepSize - streamLength)); LinkNext = null; return(nextBuild); } Socket.CommandPool.Cancel(commandIndex); } else { KeepCallback.BuildCancel(); } } else { KeepCallback.BuildCancel(); } stream.ByteSize = streamLength; LinkNext = null; return(nextBuild); } buildInfo.isFullSend = 1; return(this); }