Ejemplo n.º 1
0
        private void OnSendCompleted(object sender, SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success || e.BytesTransferred == 0)
            {
                // ignore errors, let the receiving end take care of that.
                return;
            }

            try
            {
                var isComplete = _encoder.OnSendCompleted(e.BytesTransferred);
                if (!isComplete)
                {
                    _encoder.Send(_writeArgsWrapper);
                    var isPending = _socket.SendAsync(_writeArgs);
                    if (!isPending)
                    {
                        OnSendCompleted(this, _writeArgs);
                    }
                    return;
                }

                _sendLock.Release();
                _sendCompleteAction(this, _messagePendingSendOperation);
            }
            catch (Exception ex)
            {
                _sendLock.Release();
                OnChannelFailure(ex);
            }
        }
Ejemplo n.º 2
0
        private void OnSendCompleted(IAsyncResult ar)
        {
            try { _stream.EndWrite(ar); }
            catch (Exception) {
                // ignore errors, let the receiving end take care of that.
                return;
            }

            var isComplete = _encoder.OnSendCompleted(_writeBuffer.Count);

            if (!isComplete)
            {
                _encoder.Send(_writeBuffer);
                _stream.BeginWrite(_writeBuffer.Buffer, _writeBuffer.Offset, _writeBuffer.Count, OnSendCompleted, null);
                return;
            }

            var msg = _currentOutboundMessage;

            lock (_outboundMessages) {
                if (!_outboundMessages.TryDequeue(out _currentOutboundMessage))
                {
                    _currentOutboundMessage = null;
                    _sendCompleteAction(this, msg);
                    return;
                }
            }

            _sendCompleteAction(this, msg);
            SendCurrent();
        }
Ejemplo n.º 3
0
        private void OnSendCompleted(object sender, SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success ||
                e.BytesTransferred == 0)
            {
                // ignore errors, let the receiving end take care of that.
                return;
            }

            var isComplete = _encoder.OnSendCompleted(e.BytesTransferred);

            if (!isComplete)
            {
                _encoder.Send(_writeArgsWrapper);
                var isPending = _socket.SendAsync(_writeArgs);
                if (!isPending)
                {
                    OnSendCompleted(this, _writeArgs);
                }
                return;
            }

            var msg = _currentOutboundMessage;

            lock (_outboundMessages) {
                if (!_outboundMessages.TryDequeue(out _currentOutboundMessage))
                {
                    _currentOutboundMessage = null;
                    _sendCompleteAction(this, msg);
                    return;
                }
            }

            _sendCompleteAction(this, msg);
            SendCurrent();
        }