Esempio n. 1
0
        private void FlushCommandBuffer()
        {
            if (_commandBuffer.Size > 0)
            {
                CheckDisposed();
                var state = new ClientAsyncWriteState
                                {
                                    WorkSocket = Socket.Socket,
                                    Buffer = _commandBuffer.Data,
                                    CallbackArg = this
                                };
   
                state.WorkSocket.BeginSend(state.Buffer, 0, _commandBuffer.Size,
                    SocketFlags.None,
                    new AsyncCallback(EndSendCommandBuffer), state);

                _commandBuffer.Reset(); // important that this DOES NOT deallocate buffer
                _sendMre.WaitOne();
                _sendMre.Reset();
            }
        }
Esempio n. 2
0
        public static void WriteAsync(this PooledSocket socket, RedisCommand command, Action<RedisCommand> callback)
        {
            var buffer = new CommandBuffer();
            buffer.Append(command);

            var state = new ClientAsyncWriteState
            {
                Buffer = buffer.Data,
                CallbackArg = command,
                WorkSocket = socket.Socket
            };

            if (callback != null)
            {
                state.CommandSent += (args, cmd) => callback(cmd);
            }
            socket.Socket.BeginSend(buffer.Data, 0, buffer.Size, SocketFlags.None,
                new AsyncCallback(EndWriteCmdAsynch), state);
        }