Example #1
0
        // 收到升级请求
        public static void RecvUpdate(SocketAsyncEventArgs e, Packet fp, ref bool IsSend)
        {
            AsyncUserToken       token = (AsyncUserToken)e.UserToken;
            UpdatePacketProParam param = new UpdatePacketProParam();

            token.Param      = param;
            param.ActionCode = fp.ActionCode;
            string fv      = fp.DataToString();
            int    nUpdate = 0;

            // 比较版本
            if (Function.CompareVersion(UpdateFileBufMgr.Instance.FileVersion, fv) > 0)
            {
                // 可以升级
                nUpdate = 1;
            }
            else
            {
                // 不需要升级
            }
            ((PacketUpdate)fp).CreateCVAckPacket(nUpdate, UpdateFileBufMgr.Instance.Length);
            fp.PacketToBuf(e.Buffer, e.Offset);
            param.SendType = 0;
            e.SetBuffer(e.Offset, fp.GetPacketLen());
        }
Example #2
0
        // 异步已发送升级应答包
        public static bool SendUpdate(SocketAsyncEventArgs e)
        {
            UpdatePacketProParam param = (UpdatePacketProParam)((AsyncUserToken)e.UserToken).Param;

            if (param.SendType == 1)
            {
                param.DownOffsert += e.BytesTransferred;
            }
            if (UpdateFileBufMgr.Instance.Length <= param.DownOffsert)
            {
                // 发送完成
                param.DownOffsert = 0;
            }
            else
            {
                param.SendType = 1;
                int nLen = UpdateFileBufMgr.Instance.GetBuf(e.Buffer, e.Offset, param.DownOffsert);
                e.SetBuffer(e.Offset, nLen);
                return(true);
            }
            return(false);
        }