Exemplo n.º 1
0
            // 在指定 id 的连接上发送请求
            public IWriteableBuffer BeginRequest(string componentName, Action <IReadableBuffer> cb, Action <bool> expiredProcess)
            {
                WriteBuffer buff = null;

                if (WriteBufferPool.Count > 0)
                {
                    buff = WriteBufferPool.Dequeue() as WriteBuffer;
                    buff.Clear();
                }
                else
                {
                    buff = new WriteBuffer(true);
                }

                buff.IsUsing = true;

                buff.Reserve(sizeof(int));
                long no = p();

                buff.Write(no);
                buff.Write(componentName);

                // 记录回调处理句柄
                CallbackNode cbn = new CallbackNode();

                cbn.time       = Utils.NowSecond;
                cbn.cb         = cb;
                callbacks[-no] = cbn;

                if (expiredProcess != null)
                {
                    usrDefinedExpireProcess[-no] = expiredProcess;
                }

                return(buff);
            }
Exemplo n.º 2
0
            // 在指定 id 的连接上开始发送消息
            public IWriteableBuffer BeginSend(string componentName)
            {
                WriteBuffer buff = null;

                if (WriteBufferPool.Count > 0)
                {
                    buff = WriteBufferPool.Dequeue() as WriteBuffer;
                    buff.Clear();
                }
                else
                {
                    buff = new WriteBuffer(true);
                }

                buff.IsUsing = true;

                buff.Reserve(sizeof(int));
                long no = p();

                buff.Write(no);
                buff.Write(componentName);

                return(buff);
            }