protected internal override async Task <IOperationResult> ReadResponseAsync(PooledSocket socket, CancellationToken cancellationToken = default(CancellationToken)) { return(new TextOperationResult { Success = String.Compare(await TextSocketHelper.ReadResponseAsync(socket, cancellationToken).ConfigureAwait(false), "DELETED", StringComparison.Ordinal) == 0 }); }
public static async Task FinishCurrentAsync(PooledSocket socket, CancellationToken cancellationToken = default) { string response = await TextSocketHelper.ReadResponseAsync(socket, cancellationToken).ConfigureAwait(false); if (String.Compare(response, "END", StringComparison.Ordinal) != 0) { throw new MemcachedClientException("No END was received."); } }
public static async Task <GetResponse> ReadItemAsync(PooledSocket socket, CancellationToken cancellationToken = default) { var description = await TextSocketHelper.ReadResponseAsync(socket, cancellationToken).ConfigureAwait(false); if (String.Compare(description, "END", StringComparison.Ordinal) == 0) { return(null); } else if (description.Length < 6 || String.Compare(description, 0, "VALUE ", 0, 6, StringComparison.Ordinal) != 0) { throw new MemcachedClientException("No VALUE response received.\r\n" + description); } // response is: // VALUE <key> <flags> <bytes> [<cas unique>] // 0 1 2 3 4 // // cas only exists in 1.2.4+ // ulong cas = 0; var parts = description.Split(' '); if (parts.Length == 5) { if (!UInt64.TryParse(parts[4], out cas)) { throw new MemcachedClientException("Invalid CAS VALUE received."); } } else if (parts.Length < 4) { throw new MemcachedClientException("Invalid VALUE response received: " + description); } var flags = UInt16.Parse(parts[2], CultureInfo.InvariantCulture); var length = Int32.Parse(parts[3], CultureInfo.InvariantCulture); var allData = new byte[length]; var eod = new byte[2]; await socket.ReceiveAsync(allData, 0, length, cancellationToken).ConfigureAwait(false); await socket.ReceiveAsync(eod, 0, 2, cancellationToken).ConfigureAwait(false); // data is terminated by \r\n var result = new GetResponse(parts[1], flags, cas, allData); GetHelper.Logger = GetHelper.Logger ?? Caching.Logger.CreateLogger(typeof(GetHelper)); if (GetHelper.Logger.IsEnabled(LogLevel.Debug)) { GetHelper.Logger.LogDebug("Received value. Data type: {0}, size: {1}.", result.Item.Flags, result.Item.Data.Count); } return(result); }
protected internal override async Task <IOperationResult> ReadResponseAsync(PooledSocket socket, CancellationToken cancellationToken = default(CancellationToken)) { string response = await TextSocketHelper.ReadResponseAsync(socket, cancellationToken).ConfigureAwait(false); var result = new TextOperationResult(); //maybe we should throw an exception when the item is not found? if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0) { return(result.Fail("Failed to read response. Item not found")); } result.Success = UInt64.TryParse(response, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out this.result); return(result); }
protected internal override async Task <IOperationResult> ReadResponseAsync(PooledSocket socket, CancellationToken cancellationToken = default(CancellationToken)) { var serverData = new Dictionary <string, string>(); while (true) { string line = await TextSocketHelper.ReadResponseAsync(socket, cancellationToken).ConfigureAwait(false); // stat values are terminated by END if (String.Compare(line, "END", StringComparison.Ordinal) == 0) { break; } // expected response is STAT item_name item_value if (line.Length < 6 || String.Compare(line, 0, "STAT ", 0, 5, StringComparison.Ordinal) != 0) { if (this._logger.IsEnabled(LogLevel.Debug)) { this._logger.LogWarning("Unknow response: " + line); } continue; } // get the key&value string[] parts = line.Remove(0, 5).Split(' '); if (parts.Length != 2) { if (this._logger.IsEnabled(LogLevel.Debug)) { this._logger.LogWarning("Unknow response: " + line); } continue; } // store the stat item serverData[parts[0]] = parts[1]; } this._result = serverData; return(new TextOperationResult().Pass()); }
protected internal override async Task <IOperationResult> ReadResponseAsync(PooledSocket socket, CancellationToken cancellationToken = default) { await TextSocketHelper.ReadResponseAsync(socket, cancellationToken).ConfigureAwait(false); return(new TextOperationResult().Pass()); }