Ejemplo n.º 1
0
        public void clear()
        {
            // 把不用的MemoryStream放回缓冲池,以减少垃圾回收的消耗
            for (int i = 0; i < streamList.Count; ++i)
            {
                if (stream != streamList[i])
                {
                    streamList[i].reclaimObject();
                }
            }

            streamList.Clear();

            if (stream != null)
            {
                stream.clear();
            }
            else
            {
                stream = MemoryStream.createObject();
            }

            numMessage         = 0;
            messageLength      = 0;
            msgtype            = null;
            _curMsgStreamIndex = 0;
        }
Ejemplo n.º 2
0
 public void clear()
 {
     stream             = MemoryStream.createObject();
     streamList         = new List <MemoryStream>();
     numMessage         = 0;
     messageLength      = 0;
     msgtype            = null;
     _curMsgStreamIndex = 0;
 }
Ejemplo n.º 3
0
        public void checkStream(int v)
        {
            if (v > stream.space())
            {
                streamList.Add(stream);
                stream = MemoryStream.createObject();
                ++_curMsgStreamIndex;
            }

            messageLength += v;
        }
Ejemplo n.º 4
0
 /// <summary>
 ///检查stream剩余空间是否足够写入新数据,
 ///不足够就把当前stream加到队列尾,然后创建一个新的stream写入数据,
 ///足够就增加消息长度messageLength
 /// </summary>
 /// <param name="v"></param>
 public void checkStream(int v)
 {
     //不足够就把当前stream加到队列尾,然后创建一个新的stream写入数据
     if (v > stream.space())
     {
         streamList.Add(stream);
         stream = MemoryStream.createObject();
         ++_curMsgStreamIndex;
     }
     //足够就增加消息长度
     messageLength += v;
 }
Ejemplo n.º 5
0
        public void fini(bool issend)
        {
            if (numMessage > 0)
            {
                writeMsgLength();

                streamList.Add(stream);
                stream = MemoryStream.createObject();
            }

            if (issend)
            {
                numMessage = 0;
                msgtype    = null;
            }

            _curMsgStreamIndex = 0;
        }
Ejemplo n.º 6
0
        public void onImportClientSDK(int remainingFiles, string fileName, int fileSize, byte[] fileDatas)
        {
            if (sdkFileStream == null)
            {
                sdkFileStream = MemoryStream.createObject();
            }

            sdkFileStream.append(fileDatas, (uint)sdkFileStream.rpos, (uint)fileDatas.Length);

            warnUpdateSDK = "Download:" + fileName + " -> " + sdkFileStream.length() + "/" + fileSize + "bytes! " + (int)(((float)downloadFiles / (float)(downloadFiles + remainingFiles)) * 100) + "%";
            Debug.Log(warnUpdateSDK);

            if (sdkFileStream.length() == fileSize)
            {
                Debug.Log("onImportClientSDK: " + fileName + "->" + fileSize + "bytes success!");

                string path = Path.GetDirectoryName(sdkTempPath + "//" + fileName);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                StreamWriter sw;
                FileInfo     t    = new FileInfo(sdkTempPath + "//" + fileName);
                string       data = System.Text.Encoding.UTF8.GetString(sdkFileStream.data(), 0, fileSize);
                sw = t.CreateText();
                sw.WriteLine(data);
                sw.Close();
                sw.Dispose();

                sdkFileStream.reclaimObject();
                sdkFileStream  = null;
                downloadFiles += 1;

                if (remainingFiles == 0)
                {
                    warnUpdateSDK = "";
                    downloadFiles = 0;
                    replaceNewSDK();
                }
            }
        }