Esempio n. 1
0
        public void PostSendRequest(byte[] buffer, int startIndex, int len, bool copyBuffer)
        {
            SocketSendRequest req = new SocketSendRequest();

            if (copyBuffer)
            {
                byte[] tmpBuffer = new byte[len];
                Array.Copy(buffer, startIndex, tmpBuffer, 0, len);
                req.SocketEventArg.SetBuffer(tmpBuffer, 0, len);
            }
            else
            {
                req.SocketEventArg.SetBuffer(buffer, startIndex, len);
            }
            PostSendRequest(req);
        }
Esempio n. 2
0
        public void PostSendRequest(SocketSendRequest req)
        {
            bool start = false;

            req.Context = this;
            lock (sendCache)
            {
                sendCache.Add(req);
                if (!sending)
                {
                    sending = true;
                    start   = true;
                }
            }

            if (start)
            {
                SendNextRequest();
            }
        }
Esempio n. 3
0
        /// <summary>
        ///  从发送缓存队列中取出数据,然后进行发送
        /// </summary>
        public void SendNextRequest()
        {
            SocketSendRequest req = null;

            lock (sendCache)
            {
                if (sendCache.Count == 0)
                {
                    sending = false;
                    return;
                }
                req = sendCache[0];
                sendCache.RemoveAt(0);
            }

            // 处理一个异步发送请求
            if (!RawSocket.SendAsync(req.SocketEventArg))
            {
                req.DoResponse();
            }
        }