Skip to content

Commit ba9c973

Browse files
committed
Implement Operation.ReadResponseAsync()
1 parent 23174c8 commit ba9c973

16 files changed

+739
-575
lines changed

Enyim.Caching/Enyim.Caching.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.1.2" />
2626
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />
2727
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.1" />
28+
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" />
2829
</ItemGroup>
2930
</Project>

Enyim.Caching/Memcached/PooledSocket.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Microsoft.Extensions.Logging;
21
using System;
32
using System.Collections.Generic;
43
using System.Diagnostics;
@@ -11,6 +10,7 @@
1110
using System.Text;
1211
using System.Threading;
1312
using System.Threading.Tasks;
13+
using Microsoft.Extensions.Logging;
1414

1515
namespace Enyim.Caching.Memcached
1616
{
@@ -208,6 +208,21 @@ public int ReadByte()
208208
}
209209
}
210210

211+
public int ReadByteAsync()
212+
{
213+
this.CheckDisposed();
214+
215+
try
216+
{
217+
return this.inputStream.ReadByte();
218+
}
219+
catch (IOException)
220+
{
221+
this.isAlive = false;
222+
throw;
223+
}
224+
}
225+
211226
public async Task<byte[]> ReadBytesAsync(int count)
212227
{
213228
var buffer = new ArraySegment<byte>(new byte[count], 0, count);

Enyim.Caching/Memcached/Protocol/Binary/BinaryOperation.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Threading.Tasks;
34

45
namespace Enyim.Caching.Memcached.Protocol.Binary
56
{
@@ -12,15 +13,10 @@ protected internal override IList<ArraySegment<byte>> GetBuffer()
1213
return this.Build().CreateBuffer();
1314
}
1415

15-
protected internal override System.Threading.Tasks.Task<Results.IOperationResult> ReadResponseAsync(PooledSocket socket)
16-
{
17-
throw new NotImplementedException();
18-
}
19-
2016
protected internal override bool ReadResponseAsync(PooledSocket socket, System.Action<bool> next)
2117
{
2218
throw new System.NotSupportedException();
23-
}
19+
}
2420
}
2521
}
2622

Enyim.Caching/Memcached/Protocol/Binary/BinarySingleItemOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected internal override IOperationResult ReadResponse(PooledSocket socket)
4444
return result;
4545
}
4646

47-
protected internal override async Task<IOperationResult> ReadResponseAsync(PooledSocket socket)
47+
protected internal override async ValueTask<IOperationResult> ReadResponseAsync(PooledSocket socket)
4848
{
4949
var response = new BinaryResponse();
5050
var retval = await response.ReadAsync(socket);

Enyim.Caching/Memcached/Protocol/Binary/FlushOperation.cs

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Threading.Tasks;
34
using Enyim.Caching.Memcached.Results;
45
using Enyim.Caching.Memcached.Results.Extensions;
56

67
namespace Enyim.Caching.Memcached.Protocol.Binary
78
{
8-
public class FlushOperation : BinaryOperation, IFlushOperation
9-
{
10-
public FlushOperation() { }
11-
12-
protected override BinaryRequest Build()
13-
{
14-
var request = new BinaryRequest(OpCode.Flush);
15-
16-
return request;
17-
}
18-
19-
protected internal override IOperationResult ReadResponse(PooledSocket socket)
20-
{
21-
var response = new BinaryResponse();
22-
var retval = response.Read(socket);
23-
24-
this.StatusCode = StatusCode;
25-
var result = new BinaryOperationResult()
26-
{
27-
Success = retval,
28-
StatusCode = this.StatusCode
29-
};
30-
31-
result.PassOrFail(retval, "Failed to read response");
32-
return result;
33-
}
34-
}
9+
public class FlushOperation : BinaryOperation, IFlushOperation
10+
{
11+
public FlushOperation() { }
12+
13+
protected override BinaryRequest Build()
14+
{
15+
var request = new BinaryRequest(OpCode.Flush);
16+
17+
return request;
18+
}
19+
20+
protected internal override IOperationResult ReadResponse(PooledSocket socket)
21+
{
22+
var response = new BinaryResponse();
23+
var retval = response.Read(socket);
24+
25+
this.StatusCode = StatusCode;
26+
var result = new BinaryOperationResult()
27+
{
28+
Success = retval,
29+
StatusCode = this.StatusCode
30+
};
31+
32+
result.PassOrFail(retval, "Failed to read response");
33+
return result;
34+
}
35+
36+
protected internal override async ValueTask<IOperationResult> ReadResponseAsync(PooledSocket socket)
37+
{
38+
var response = new BinaryResponse();
39+
var retval = await response.ReadAsync(socket);
40+
41+
this.StatusCode = StatusCode;
42+
var result = new BinaryOperationResult()
43+
{
44+
Success = retval,
45+
StatusCode = this.StatusCode
46+
};
47+
48+
result.PassOrFail(retval, "Failed to read response");
49+
return result;
50+
}
51+
}
3552
}
3653

3754
#region [ License information ]

0 commit comments

Comments
 (0)