Example #1
0
            internal void EraseBack(int count)
            {
                int total = m_kvCallback.Count;

                if (count > total)
                {
                    count = total;
                }
                int start = (total - count);

                for (; start < total; ++start)
                {
                    CResultCb p = m_kvCallback[start].Value;
                    if (p.Discarded != null)
                    {
                        p.Discarded(this, true);
                    }
                }
                m_kvCallback.RemoveRange(start, count);
            }
Example #2
0
            internal void OnSE(ushort reqId, string errMessage, string errWhere, int errCode)
            {
                MyKeyValue <ushort, CResultCb> p = GetAsyncResultHandler(reqId);

                OnExceptionFromServer(reqId, errMessage, errWhere, errCode);
                if (p != null)
                {
                    CResultCb rcb = p.Value;
                    if (rcb != null && rcb.ExceptionFromServer != null)
                    {
                        rcb.ExceptionFromServer.Invoke(this, reqId, errMessage, errWhere, errCode);
                    }
                }
                lock (m_cs)
                {
                    foreach (var el in m_lstEFS)
                    {
                        el.Invoke(this, reqId, errMessage, errWhere, errCode);
                    }
                }
            }
Example #3
0
            public virtual bool SendRequest(ushort reqId, byte[] data, uint len, DAsyncResultHandler ash, DDiscarded discarded, DOnExceptionFromServer exception)
            {
                bool sent;
                byte batching;
                MyKeyValue <ushort, CResultCb> kv;

                if (reqId <= (ushort)tagBaseRequestID.idReservedTwo)
                {
                    throw new ArgumentException("Request id must be larger than 0x2001");
                }
                if (null == m_ClientSocket)
                {
                    return(false);
                }
                IntPtr h = m_ClientSocket.Handle;

                if (data != null && len > (uint)data.Length)
                {
                    len = (uint)data.Length;
                }
                if (ash != null || discarded != null || exception != null)
                {
                    CResultCb rcb = new CResultCb(ash, discarded, exception);
                    kv       = new MyKeyValue <ushort, CResultCb>(reqId, rcb);
                    batching = ClientCoreLoader.IsBatching(h);
                    lock (m_csSend)
                    {
                        lock (m_cs)
                        {
                            if (batching != 0)
                            {
                                m_kvBatching.AddToBack(kv);
                            }
                            else
                            {
                                m_kvCallback.AddToBack(kv);
                            }
                        }
                        unsafe
                        {
                            fixed(byte *buffer = data)
                            {
                                sent = (ClientCoreLoader.SendRequest(h, reqId, buffer, len) != 0);
                            }
                        }
                    }
                }
                else
                {
                    kv       = null;
                    batching = 0;
                    unsafe
                    {
                        fixed(byte *buffer = data)
                        {
                            sent = (ClientCoreLoader.SendRequest(h, reqId, buffer, len) != 0);
                        }
                    }
                }
                if (sent)
                {
                    return(true);
                }
                if (kv != null)
                {
                    lock (m_cs)
                    {
                        if (batching > 0)
                        {
                            m_kvBatching.Clear();
                        }
                        else
                        {
                            m_kvCallback.Clear();
                        }
                    }
                }
                return(false);
            }