Beispiel #1
0
        void OnSocketSent(SocketAsyncEventArgs args)
        {
            AsyncTransferPool.Release(args);

            IRedisAsyncCommandToken token;

            lock (_readLock)
            {
                if (AsyncReadQueue.TryDequeue(out token))
                {
                    try
                    {
                        token.SetResult(_reader);
                    }
                    catch (IOException)
                    {
                        if (ReconnectAttempts == 0)
                        {
                            throw;
                        }
                        Reconnect();
                        AsyncWriteQueue.Enqueue(token);
                        ConnectAsync().ContinueWith(CallAsyncDeferred);
                    }
                    catch (Exception e)
                    {
                        token.TrySetException(e);
                    }
                }
            }
        }
Beispiel #2
0
        void CallAsyncDeferred(Task t)
        {
            lock (_writeLock)
            {
                IRedisAsyncCommandToken token;
                if (!AsyncWriteQueue.TryDequeue(out token))
                {
                    throw new Exception();
                }

                AsyncReadQueue.Enqueue(token);

                var args = AsyncTransferPool.Acquire();
                int bytes;
                try
                {
                    bytes = _writer.Write(token.Command, args.Buffer, args.Offset);
                }
                catch (ArgumentException e)
                {
                    throw new RedisClientException("Could not write command '" + token.Command.Command + "'. Argument size exceeds buffer allocation of " + args.Count + ".", e);
                }
                args.SetBuffer(args.Offset, bytes);

                if (!_socket.SendAsync(args))
                {
                    OnSocketSent(args);
                }
            }
        }