本文整理汇总了C#中PooledSocket.Read方法的典型用法代码示例。如果您正苦于以下问题:C# PooledSocket.Read方法的具体用法?C# PooledSocket.Read怎么用?C# PooledSocket.Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PooledSocket
的用法示例。
在下文中一共展示了PooledSocket.Read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public unsafe bool Read(PooledSocket socket)
{
this.StatusCode = -1;
if (!socket.IsAlive)
return false;
var header = new byte[HeaderLength];
socket.Read(header, 0, header.Length);
int dataLength, extraLength;
DeserializeHeader(header, out dataLength, out extraLength);
if (dataLength > 0)
{
var data = new byte[dataLength];
socket.Read(data, 0, dataLength);
this.Extra = new ArraySegment<byte>(data, 0, extraLength);
this.Data = new ArraySegment<byte>(data, extraLength, data.Length - extraLength);
}
return this.StatusCode == 0;
}
示例2: Read
public unsafe bool Read(PooledSocket socket)
{
if (!socket.IsAlive)
{
this.StatusCode = -1;
return false;
}
byte[] header = new byte[24];
socket.Read(header, 0, 24);
#if DEBUG_PROTOCOL
if (log.IsDebugEnabled)
{
log.Debug("Received binary response");
StringBuilder sb = new StringBuilder(128).AppendLine();
for (int i = 0; i < header.Length; i++)
{
byte value = header[i];
sb.Append(value < 16 ? "0x0" : "0x").Append(value.ToString("X"));
if (i % 4 == 3) sb.AppendLine(); else sb.Append(" ");
}
log.Debug(sb.ToString());
}
#endif
fixed (byte* buffer = header)
{
if (buffer[0] != MAGIC_VALUE)
throw new InvalidOperationException("Expected magic value " + MAGIC_VALUE + ", received: " + buffer[0]);
int remaining = BinaryConverter.DecodeInt32(buffer, HEADER_BODY);
int extraLength = buffer[HEADER_EXTRA];
byte[] data = new byte[remaining];
socket.Read(data, 0, remaining);
this.Extra = new ArraySegment<byte>(data, 0, extraLength);
this.Data = new ArraySegment<byte>(data, extraLength, data.Length - extraLength);
this.DataType = buffer[HEADER_DATATYPE];
this.Opcode = buffer[HEADER_OPCODE];
this.StatusCode = BinaryConverter.DecodeInt16(buffer, HEADER_STATUS);
this.KeyLength = BinaryConverter.DecodeInt16(buffer, HEADER_KEY);
this.CorrelationId = BinaryConverter.DecodeInt32(buffer, HEADER_OPAQUE);
this.CAS = BinaryConverter.DecodeUInt64(buffer, HEADER_CAS);
}
return this.StatusCode == 0;
}
示例3: ReadItem
public static GetResponse ReadItem(PooledSocket socket)
{
string description = TextSocketHelper.ReadResponse(socket);
if (String.Compare(description, "END", StringComparison.Ordinal) == 0)
return null;
if (description.Length < 6 || String.Compare(description, 0, "VALUE ", 0, 6, StringComparison.Ordinal) != 0)
throw new MemcachedClientException("No VALUE response received.\r\n" + description);
ulong cas = 0;
string[] parts = description.Split(' ');
// response is:
// VALUE <key> <flags> <bytes> [<cas unique>]
// 0 1 2 3 4
//
// cas only exists in 1.2.4+
//
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);
}
ushort flags = UInt16.Parse(parts[2], CultureInfo.InvariantCulture);
int length = Int32.Parse(parts[3], CultureInfo.InvariantCulture);
byte[] allData = new byte[length];
byte[] eod = new byte[2];
socket.Read(allData, 0, length);
socket.Read(eod, 0, 2); // data is terminated by \r\n
GetResponse retval = new GetResponse(parts[1], flags, cas, allData);
if (log.IsDebugEnabled)
log.DebugFormat("Received value. Data type: {0}, size: {1}.", retval.Item.Flags, retval.Item.Data.Count);
return retval;
}