Ejemplo n.º 1
0
 public RedisContinuousReaderCtx(RedisContinuousReader reader, RedisConnection connection,
                                 RedisSocket socket, Action <IRedisRawResponse> onReceive)
     : base(connection.Settings)
 {
     Reader      = reader;
     Connection  = connection;
     Socket      = socket;
     m_OnReceive = onReceive;
 }
Ejemplo n.º 2
0
        public bool BeginReceive(Action <object> onComplete)
        {
            ValidateNotDisposed();

            var onReceiveResponse = m_OnReceiveResponse;

            if ((onReceiveResponse != null) &&
                Interlocked.CompareExchange(ref m_ReceiveState, RedisConstants.One, RedisConstants.Zero) == RedisConstants.Zero)
            {
                try
                {
                    var reader = new RedisContinuousReader(this);

                    var prevReader = Interlocked.Exchange(ref m_Reader, reader);
                    if (prevReader != null)
                    {
                        prevReader.Dispose();
                    }

                    reader.BeginReceive((sr) =>
                    {
                        Interlocked.Exchange(ref m_ReceiveState, RedisConstants.Zero);
                        if (onComplete != null)
                        {
                            onComplete(this);
                        }
                    },
                                        (response) =>
                    {
                        onReceiveResponse(response);
                    });

                    return(true);
                }
                catch (Exception)
                {
                    Interlocked.Exchange(ref m_ReceiveState, RedisConstants.Zero);
                    throw;
                }
            }
            return(false);
        }