Esempio n. 1
0
        public NetByteBuffer Copy()
        {
            NetByteBuffer buffer = CreateWithSize(this.DataCount);

            buffer.Write(this.sourceArray, 0, this.DataCount);

            return(buffer);
        }
Esempio n. 2
0
        void ReceiveCallBack(IAsyncResult result)
        {
            try
            {
                if (!result.IsCompleted)
                {
                    LogMgr.LogError("recive error");
                }
                if (msocket != null && isConnected)
                {
                    int datalen = msocket.EndReceive(result);
                    if (datalen > 0)
                    {
                        // LogMgr.LogFormat("接受到字节 :{0}", datalen);
                        byte[] bysarray = result.AsyncState as byte[];

                        if (buffer.byteAviliable + datalen > buffer.capacity && FrameWorkConfig.Open_DEBUG)
                        {
                            LogMgr.LogError("缓冲区即将扩容");
                        }

                        lock (objectLock)
                        {
                            buffer.Write(bysarray, 0, datalen);
                        }

                        //NetByteBuffer copy = buffer.Copy();

                        //开始pack
                        DispatcherPkg(buffer);
                    }
                    //继续接受
                    BeginReceive();
                }
                else
                {
                    LogMgr.LogError("not connect to socket");
                }
            }
            catch (SocketException ex)
            {
                LogMgr.LogError(ex);
                ExceptionThrowed(ex);
            }
            catch (Exception ex)
            {
                LogMgr.LogError(ex);
                ExceptionThrowed(ex);
            }
        }