Exemple #1
0
        public unsafe void Send(RioBuffer buffer)
        {
            var requestContextKey = new RioRequestContextKey(buffer.Id, RioRequestType.Send);

            if (!WinSock.Extensions.Send(_handle, buffer.BufferDescriptor, 1, RIO_SEND_FLAGS.NONE, requestContextKey.ToRioRequestCorrelationId()))
            {
                WinSock.ThrowLastWsaError();
            }
        }
Exemple #2
0
        private void OnSendComplete(RioRequestContextKey requestContextKey, int bytesTransferred)
        {
            var buffer = _sendingBufferManager.ReadBuffer(requestContextKey.BufferId);

            if (buffer.DataLength != bytesTransferred)
            {
                // this is an abnormal incomplete send; we disconnect the session
                Close();
                return;
            }

            _sendingBufferManager.ReleaseBuffer(buffer);
        }
Exemple #3
0
        private void OnReceiveComplete(RioRequestContextKey requestContextKey, int bytesTransferred)
        {
            var buffer = _receivingBufferManager.ReadBuffer(requestContextKey.BufferId);

            if (buffer.Length < bytesTransferred)
            {
                throw new InvalidOperationException("Received more bytes than expected");
            }

            buffer.DataLength = bytesTransferred;

            OnReceiveComplete(buffer);

            EnqueueReceive();
        }
        private unsafe void ProcessCompletions(object state)
        {
            Thread.CurrentThread.Name = $"Completion processing Worker #{_workerId}";

            var completionQueue      = (RioCompletionQueue)state;
            var maxCompletionResults = _configuration.MaxCompletionResults;
            var results = stackalloc RIO_RESULT[maxCompletionResults];

            int resultCount;

            while ((resultCount = completionQueue.TryGetCompletionResults(_cancellationTokenSource.Token, results, maxCompletionResults)) > 0)
            {
                for (var i = 0; i < resultCount; i++)
                {
                    var result            = results[i];
                    var sessionId         = (int)result.ConnectionCorrelation;
                    var requestContextKey = new RioRequestContextKey(result.RequestCorrelation);
                    _completionHandler.OnRequestCompletion(sessionId, requestContextKey, (int)result.BytesTransferred);
                }
            }
        }
Exemple #5
0
        public void OnRequestCompletion(RioRequestContextKey requestContextKey, int bytesTransferred)
        {
            if (bytesTransferred == 0)
            {
                Close();
                return;
            }

            switch (requestContextKey.RequestType)
            {
            case RioRequestType.Send:
                OnSendComplete(requestContextKey, bytesTransferred);
                break;

            case RioRequestType.Receive:
                OnReceiveComplete(requestContextKey, bytesTransferred);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(RioRequestContextKey.RequestType));
            }
        }