示例#1
0
        private void Send(byte[] msg)
        {
            try
            {
                SendQueue.Gram buff = null;

                lock (_send)
                {
                    lock (_sendQueue)
                    {
                        buff = _sendQueue.Enqueue(msg, 0, msg.Length);
                    }

                    if (buff != null && !_isSending)
                    {
                        _isSending = true;
                        _sendEventArgs.SetBuffer(buff.Buffer, 0, buff.Length);

                        if (!_clientSocket.SendAsync(_sendEventArgs))
                        {
                            _sendEventArgs_Completed(null, _sendEventArgs);
                        }
                    }
                }
            }
            catch (CapacityExceededException)
            {
                NetworkManager.Disconnect(false);
            }
        }
示例#2
0
        private void Flush()
        {
            if (_clientSocket == null)
            {
                return;
            }

            lock (_send)
            {
                if (_isSending)
                {
                    return;
                }

                SendQueue.Gram buffer = null;
                lock (_sendQueue)
                {
                    if (!_sendQueue.IsFlushReady)
                    {
                        return;
                    }
                    buffer = _sendQueue.CheckFlushReady();
                }

                if (buffer != null)
                {
                    _isSending = true;
                    _sendEventArgs.SetBuffer(buffer.Buffer, 0, buffer.Length);

                    if (!_clientSocket.SendAsync(_sendEventArgs))
                    {
                        _sendEventArgs_Completed(null, _sendEventArgs);
                    }
                }
            }
        }