Esempio n. 1
0
 private void StartBLOB(uint lenExpected)
 {
     m_Blob.SetSize(0);
     if (lenExpected > m_Blob.MaxBufferSize)
     {
         m_Blob.Realloc(lenExpected);
     }
     m_Blob.Push(UQueue.IntenalBuffer, UQueue.HeadPosition, UQueue.GetSize());
     UQueue.SetSize(0);
 }
Esempio n. 2
0
            private void OnChatComing(ulong hSocket, tagChatRequestID chatRequestID, uint len)
            {
                uint        res;
                CSocketPeer sp = Seek(hSocket);

                if (sp == null)
                {
                    return;
                }
                sp.m_CurrReqID = (ushort)chatRequestID;
                CUQueue q = sp.m_qBuffer;

                q.SetSize(0);
                if (len > q.MaxBufferSize)
                {
                    q.Realloc(len);
                }
                unsafe
                {
                    fixed(byte *buffer = q.m_bytes)
                    {
                        res = ServerCoreLoader.RetrieveBuffer(hSocket, len, buffer, true);
                    }
                }
                System.Diagnostics.Debug.Assert(res == len);
                q.SetSize(res);
                sp.OnChatComing(chatRequestID);
            }
Esempio n. 3
0
 internal static uint Read(Stream s, CUQueue q)
 {
     uint res;
     if (q.MaxBufferSize < STREAM_CHUNK_SIZE + 16)
         q.Realloc(STREAM_CHUNK_SIZE + 16);
     res = (uint)s.Read(q.m_bytes, 0, (int)STREAM_CHUNK_SIZE);
     q.SetSize(res);
     return res;
 }
Esempio n. 4
0
        internal static uint Read(Stream s, CUQueue q)
        {
            uint res;

            if (q.MaxBufferSize < STREAM_CHUNK_SIZE + 16)
            {
                q.Realloc(STREAM_CHUNK_SIZE + 16);
            }
            res = (uint)s.Read(q.m_bytes, 0, (int)STREAM_CHUNK_SIZE);
            q.SetSize(res);
            return(res);
        }
            protected override void OnResultReturned(ushort reqId, CUQueue mc)
            {
                switch (reqId)
                {
                case DB_CONSTS.idRowsetHeader:
                {
                    m_Blob.SetSize(0);
                    if (m_Blob.MaxBufferSize > ONE_MEGA_BYTES)
                    {
                        m_Blob.Realloc(ONE_MEGA_BYTES);
                    }
                    CDBColumnInfoArray vColInfo;
                    mc.Load(out vColInfo).Load(out m_indexRowset);
                    KeyValuePair <DRowsetHeader, DRows> p = new KeyValuePair <DRowsetHeader, DRows>();
                    lock (m_csCache)
                    {
                        m_vData.Clear();
                        if (m_mapRowset.ContainsKey(m_indexRowset))
                        {
                            p = m_mapRowset[m_indexRowset];
                        }
                    }
                    if (p.Key != null)
                    {
                        p.Key.Invoke(vColInfo);
                    }
                }
                break;

                case DB_CONSTS.idBeginRows:
                    m_Blob.SetSize(0);
                    m_vData.Clear();
                    break;

                case DB_CONSTS.idTransferring:
                    while (mc.GetSize() > 0)
                    {
                        object vt;
                        mc.Load(out vt);
                        m_vData.Add(vt);
                    }
                    break;

                case DB_CONSTS.idEndRows:
                    if (mc.GetSize() > 0 || m_vData.Count > 0)
                    {
                        object vt;
                        while (mc.GetSize() > 0)
                        {
                            mc.Load(out vt);
                            m_vData.Add(vt);
                        }
                        DRows row = null;
                        lock (m_csCache)
                        {
                            if (m_mapRowset.ContainsKey(m_indexRowset))
                            {
                                row = m_mapRowset[m_indexRowset].Value;
                            }
                        }
                        if (row != null)
                        {
                            row.Invoke(m_vData);
                        }
                    }
                    m_vData.Clear();
                    break;

                case DB_CONSTS.idStartBLOB:
                {
                    m_Blob.SetSize(0);
                    uint len;
                    mc.Load(out len);
                    if (len != uint.MaxValue && len > m_Blob.MaxBufferSize)
                    {
                        m_Blob.Realloc(len);
                    }
                    m_Blob.Push(mc.IntenalBuffer, mc.HeadPosition, mc.GetSize());
                    mc.SetSize(0);
                }
                break;

                case DB_CONSTS.idChunk:
                    m_Blob.Push(mc.IntenalBuffer, mc.GetSize());
                    mc.SetSize(0);
                    break;

                case DB_CONSTS.idEndBLOB:
                    if (mc.GetSize() > 0 || m_Blob.GetSize() > 0)
                    {
                        m_Blob.Push(mc.IntenalBuffer, mc.GetSize());
                        mc.SetSize(0);
                        unsafe
                        {
                            fixed(byte *p = m_Blob.IntenalBuffer)
                            {
                                uint *len = (uint *)(p + m_Blob.HeadPosition + sizeof(ushort));

                                if (*len >= BLOB_LENGTH_NOT_AVAILABLE)
                                {
                                    //length should be reset if BLOB length not available from server side at beginning
                                    *len = (m_Blob.GetSize() - sizeof(ushort) - sizeof(uint));
                                }
                            }
                        }
                        object vt;
                        m_Blob.Load(out vt);
                        m_vData.Add(vt);
                    }
                    break;

                default:
                    base.OnResultReturned(reqId, mc);
                    break;
                }
            }
Esempio n. 6
0
            private void OnReqArrive(ulong hSocket, ushort usRequestID, uint len)
            {
                CSocketPeer sp = Seek(hSocket);

                if (sp == null)
                {
                    return;
                }
                sp.m_CurrReqID = usRequestID;
                CUQueue q = sp.m_qBuffer;

                q.SetSize(0);
                if (len > q.MaxBufferSize)
                {
                    q.Realloc(len);
                }
                if (len > 0)
                {
                    uint res;
                    unsafe
                    {
                        fixed(byte *buffer = q.m_bytes)
                        {
                            if (m_nMainThreads <= 1)
                            {
                                CUQueue.CopyMemory(buffer, (void *)ServerCoreLoader.GetRequestBuffer(hSocket), len);
                                res = len;
                            }
                            else
                            {
                                res = ServerCoreLoader.RetrieveBuffer(hSocket, len, buffer, false);
                            }
                        }
                    }
                    System.Diagnostics.Debug.Assert(res == len);
                    q.SetSize(res);
                }
                if (m_svsId != BaseServiceID.sidHTTP)
                {
                    q.OS     = sp.m_os;
                    q.Endian = sp.m_endian;
                    if ((tagBaseRequestID)usRequestID == tagBaseRequestID.idInterrupt)
                    {
                        CClientPeer cp = (CClientPeer)sp;
                        ulong       options;
                        q.Load(out options);
                        cp.OnIntNotified(options);
                        return;
                    }
                }
                else
                {
                    CHttpPeerBase hp = (CHttpPeerBase)sp;
                    hp.m_WebRequestName = null;
                    hp.m_vArg.Clear();
                    if (usRequestID == (ushort)tagHttpRequestID.idUserRequest)
                    {
                        uint    count;
                        sbyte[] reqName;
                        q.Load(out reqName);
                        hp.m_WebRequestName = CUQueue.ToString(reqName);
                        q.Load(out count);
                        for (uint n = 0; n < count; ++n)
                        {
                            object arg;
                            q.Load(out arg);
                            hp.m_vArg.Add(arg);
                        }
                    }
                }
                sp.OnRArrive(usRequestID, len);
            }