示例#1
0
        public override void Import(byte[] data, int start, int count)
        {
            while (count > 0)
            {
                if (mContentLength == null)
                {
                    if (mHeader == null)
                    {
                        mHeader = new HttpHeader(mHeaderBuffer);
                    }
                    if (mHeader.Import(data, ref start, ref count))
                    {
                        if (mHeader.Length == 0)
                        {
                            mReceiveMessage.Channel = this.Channel;
                            mReceiveMessage.Message = mHeader;
                            mHeader = null;
                            mContentLength = null;
                            OnReceiveMessage(mReceiveMessage);

                        }
                        else
                        {
                            mContentLength = mHeader.Length;
                        }
                    }
                }
                else
                {
                    HttpBody body = InstanceBodyData();
                    int blockSize = (int)(mContentLength > BODY_BLOCK_SIZE ? BODY_BLOCK_SIZE : mContentLength);
                    blockSize = blockSize > count ? count : blockSize;
                    ByteArraySegment segment = body.Data;
                    Buffer.BlockCopy(data, start, segment.Array, 0, blockSize);
                    count -= blockSize;
                    mContentLength -= blockSize;
                    body.Eof = mContentLength == 0;
                    if (body.Eof)
                    {
                        mContentLength = null;
                        mHeader = null;
                    }
                    mReceiveMessage.Channel = this.Channel;
                    mReceiveMessage.Message = body;
                    OnReceiveMessage(mReceiveMessage);
                }
            }
        }
示例#2
0
        public override void Import(byte[] data, int start, int count)
        {
            HttpBody         body;
            int              blockSize;
            ByteArraySegment segment;

            while (count > 0)
            {
                if (mContentLength == null)
                {
                    if (mHeader == null)
                    {
                        mHeader = new HttpHeader(mHeaderBuffer);
                    }
                    if (mHeader.Import(data, ref start, ref count))
                    {
                        if (mHeader.Length == 0)
                        {
                            mReceiveMessage.Channel = this.Channel;
                            mReceiveMessage.Message = mHeader;
                            mHeader        = null;
                            mContentLength = null;
                            OnReceiveMessage(mReceiveMessage);
                            if (ReadSinglePackage)
                            {
                                BufferOffset = start;
                                BufferCount  = count;
                                break;
                            }
                        }
                        else
                        {
                            mContentLength          = mHeader.Length;
                            mReceiveMessage.Channel = this.Channel;
                            mReceiveMessage.Message = mHeader;

                            OnReceiveMessage(mReceiveMessage);
                            if (ReadSinglePackage)
                            {
                                BufferOffset = start;
                                BufferCount  = count;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    body      = InstanceBodyData();
                    blockSize = (int)(mContentLength > BODY_BLOCK_SIZE ? BODY_BLOCK_SIZE : mContentLength);
                    blockSize = blockSize > count ? count : blockSize;
                    segment   = body.Data;
                    Buffer.BlockCopy(data, start, segment.Array, 0, blockSize);
                    count          -= blockSize;
                    mContentLength -= blockSize;
                    segment.SetInfo(0, blockSize);
                    body.Eof = mContentLength == 0;
                    if (body.Eof)
                    {
                        mContentLength = null;
                        mHeader        = null;
                    }
                    mReceiveMessage.Channel = this.Channel;
                    mReceiveMessage.Message = body;
                    OnReceiveMessage(mReceiveMessage);
                    if (ReadSinglePackage)
                    {
                        BufferOffset = start;
                        BufferCount  = count;
                        break;
                    }
                }
            }
        }
示例#3
0
 private void OnGetInfo(Beetle.IChannel channel, string appname, IProperties properties)
 {
     HttpHeader result;
     TrackerInfo info;
     byte[] data;
     BytesReader reader;
     HttpBody body;
     IAppTrackerHandler appHandler = GetAppHandler(appname);
     if (appHandler == null)
     {
         result = new HttpHeader();
         result.Action = "500 " + string.Format("{0} Tracker Handler Notfound", appname);
         channel.Send(result);
     }
     else
     {
         info = appHandler.GetInfo(properties);
         data = Encoding.UTF8.GetBytes(info.Data);
         result = new HttpHeader();
         result.Action = "200";
         result.Length = data.Length;
         result[Protocol.HEADER_INFOTYPE] = info.TypeName;
         channel.Send(result);
         reader = new BytesReader(data, 0, data.Length);
         while (reader.Read())
         {
             body = HttpPacket.InstanceBodyData();
             reader.ReadTo(body);
             channel.Send(body);
         }
     }
 }
示例#4
0
 private void OnGet(Beetle.IChannel channel, string appname, IProperties properties)
 {
     IAppTrackerHandler appHandler = GetAppHandler(appname);
     if (appHandler == null)
     {
         HttpHeader result = new HttpHeader();
         result.Action = "500 " + string.Format("{0} Tracker Handler Notfound", appname);
         channel.Send(result);
     }
     else
     {
         AppHost apphost = appHandler.GetHost(properties);
         if (apphost == null)
         {
             HttpHeader result = new HttpHeader();
             result.Action = "500 App Host Notfound!";
             channel.Send(result);
         }
         else
         {
             HttpHeader result = new HttpHeader();
             result.Action = "200";
             result["Host"] = apphost.Host;
             result["Port"] = apphost.Port.ToString();
             channel.Send(result);
         }
     }
 }
示例#5
0
        private void OnRegister(Beetle.IChannel channel, string appName, IProperties properties)
        {
            IAppTrackerHandler appHandler;
            HttpHeader result;
            IProperties ips;
            appHandler = GetAppHandler(appName);
            if (appHandler == null)
            {
                result = new HttpHeader();
                result.Action = RESULT_STATE_500 + string.Format(ERROR_MSG_TRACKER_NOTFOUND, appName);
                channel.Send(result);
            }
            else
            {
                ips = appHandler.Register(properties);
                result = this.GetResponse(ips);
                result.Action = RESULT_STATE_200;
                channel.Send(result);
            }

        }