/// <summary>
/// Reads the response of the server.
/// </summary>
/// <returns>The data sent by the memcached server.</returns>
/// <exception cref="T:System.InvalidOperationException">The server did not sent a response or an empty line was returned.</exception>
/// <exception cref="T:Enyim.Caching.Memcached.MemcachedException">The server did not specified any reason just returned the string ERROR. - or - The server returned a SERVER_ERROR, in this case the Message of the exception is the message returned by the server.</exception>
/// <exception cref="T:Enyim.Caching.Memcached.MemcachedClientException">The server did not recognize the request sent by the memcachedClient. The Message of the exception is the message returned by the server.</exception>
public static string ReadResponse(PooledSocket socket)
{
string response = TextSocketHelper.ReadLine(socket);
if (log.IsDebugEnabled)
{
log.Debug("Received response: " + response);
}
if (String.IsNullOrEmpty(response))
{
throw new MemcachedClientException("Empty response received.");
}
if (String.Compare(response, GenericErrorResponse, StringComparison.Ordinal) == 0)
{
throw new NotSupportedException("Operation is not supported by the server or the request was malformed. If the latter please report the bug to the developers.");
}
if (response.Length >= ErrorResponseLength)
{
if (String.Compare(response, 0, ClientErrorResponse, 0, ErrorResponseLength, StringComparison.Ordinal) == 0)
{
throw new MemcachedClientException(response.Remove(0, ErrorResponseLength));
}
else if (String.Compare(response, 0, ServerErrorResponse, 0, ErrorResponseLength, StringComparison.Ordinal) == 0)
{
throw new MemcachedException(response.Remove(0, ErrorResponseLength));
}
}
return(response);
}