Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit b449d77

Browse files
author
Kai Ruhnau
committed
Removed the write callback function
1 parent e95b578 commit b449d77

File tree

6 files changed

+25
-61
lines changed

6 files changed

+25
-61
lines changed

src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public FrameContext(ConnectionContext context) : base(context)
3939
public interface IFrameControl
4040
{
4141
Task ProduceContinueAsync();
42-
Task WriteAsync(ArraySegment<byte> data, Action<Exception, object> callback, object state);
42+
Task WriteAsync(ArraySegment<byte> data);
4343
}
4444

4545
public class Frame : FrameContext, IFrameControl
@@ -235,10 +235,10 @@ private async Task ExecuteAsync()
235235
}
236236

237237

238-
public async Task WriteAsync(ArraySegment<byte> data, Action<Exception, object> callback, object state)
238+
public async Task WriteAsync(ArraySegment<byte> data)
239239
{
240240
await ProduceStartAsync();
241-
await SocketOutput.WriteAsync(data, callback, state);
241+
await SocketOutput.WriteAsync(data);
242242
}
243243

244244
public Task Upgrade(IDictionary<string, object> options, Func<object, Task> callback)
@@ -263,24 +263,17 @@ public Task ProduceContinueAsync()
263263
(expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase))
264264
{
265265
return SocketOutput.WriteAsync(
266-
new ArraySegment<byte>(_continueBytes, 0, _continueBytes.Length),
267-
(error, _) =>
268-
{
269-
if (error != null)
270-
{
271-
Trace.WriteLine("ProduceContinue " + error.ToString());
272-
}
273-
},
274-
null);
266+
new ArraySegment<byte>(_continueBytes, 0, _continueBytes.Length));
275267
}
276268

277269
return Task.FromResult(0);
278270
}
279271

280-
public Task ProduceStartAsync()
272+
public async Task ProduceStartAsync()
281273
{
282274
if (_resultStarted)
283-
return Task.CompletedTask;
275+
return;
276+
284277
_resultStarted = true;
285278

286279
FireOnSendingHeaders();
@@ -290,17 +283,14 @@ public Task ProduceStartAsync()
290283
var status = ReasonPhrases.ToStatus(StatusCode, ReasonPhrase);
291284

292285
var responseHeader = CreateResponseHeader(status, ResponseHeaders);
293-
return SocketOutput.WriteAsync(
294-
responseHeader.Item1,
295-
(error, x) =>
296-
{
297-
if (error != null)
298-
{
299-
Trace.WriteLine("ProduceStart " + error.ToString());
300-
}
301-
((IDisposable)x).Dispose();
302-
},
303-
responseHeader.Item2);
286+
try
287+
{
288+
await SocketOutput.WriteAsync(responseHeader.Item1);
289+
}
290+
finally
291+
{
292+
responseHeader.Item2.Dispose();
293+
}
304294
}
305295

306296
public Task ProduceEndAsync(Exception ex)

src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseStream.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ public override void Flush()
2424

2525
public override Task FlushAsync(CancellationToken cancellationToken)
2626
{
27-
return _context.FrameControl.WriteAsync(
28-
new ArraySegment<byte>(new byte[0]),
29-
(error, arg) =>
30-
{
31-
if (error != null)
32-
throw error;
33-
},
34-
null);
27+
return _context.FrameControl.WriteAsync(new ArraySegment<byte>(new byte[0]));
3528
}
3629

3730
public override long Seek(long offset, SeekOrigin origin)
@@ -56,14 +49,7 @@ public override void Write(byte[] buffer, int offset, int count)
5649

5750
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
5851
{
59-
return _context.FrameControl.WriteAsync(
60-
new ArraySegment<byte>(buffer, offset, count),
61-
(error, arg) =>
62-
{
63-
if (error != null)
64-
throw error;
65-
},
66-
null);
52+
return _context.FrameControl.WriteAsync(new ArraySegment<byte>(buffer, offset, count));
6753
}
6854

6955
public override bool CanRead

src/Microsoft.AspNet.Server.Kestrel/Http/SocketOutput.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
1313
/// </summary>
1414
public interface ISocketOutput
1515
{
16-
Task WriteAsync(ArraySegment<byte> buffer, Action<Exception, object> callback, object state);
16+
Task WriteAsync(ArraySegment<byte> buffer);
1717
}
1818

1919
public class SocketOutput : ISocketOutput
@@ -27,7 +27,7 @@ public SocketOutput(KestrelThread thread, UvTcpStreamHandle socket)
2727
_socket = socket;
2828
}
2929

30-
public Task WriteAsync(ArraySegment<byte> buffer, Action<Exception, object> callback, object state)
30+
public Task WriteAsync(ArraySegment<byte> buffer)
3131
{
3232
//TODO: need buffering that works
3333
var copy = new byte[buffer.Count];
@@ -38,9 +38,7 @@ public Task WriteAsync(ArraySegment<byte> buffer, Action<Exception, object> call
3838
var req = new UvWriteReq(
3939
_thread.Loop,
4040
_socket,
41-
arraySegment,
42-
callback,
43-
state);
41+
arraySegment);
4442
return _thread.PostAsync(req.Write);
4543
}
4644

src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteRequest.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public class UvWriteReq : UvMemoryResource
1515
private readonly uv_write_cb _uv_write_cb;
1616

1717
private readonly UvTcpStreamHandle _stream;
18-
private readonly Action<Exception, object> _callback;
19-
private readonly object _state;
2018

2119
private readonly UvBuffer[] _uvBuffers;
2220
private readonly GCHandle[] _bufferHandles;
@@ -25,15 +23,11 @@ public class UvWriteReq : UvMemoryResource
2523
public UvWriteReq(
2624
UvLoopHandle loop,
2725
UvTcpStreamHandle stream,
28-
ArraySegment<byte> buffer,
29-
Action<Exception, object> callback,
30-
object state)
26+
ArraySegment<byte> buffer)
3127
: base(loop.ThreadId, getSize())
3228
{
3329
_uv_write_cb = UvWriteCb;
3430
_stream = stream;
35-
_callback = callback;
36-
_state = state;
3731

3832
_bufferHandles = new GCHandle[1];
3933
_uvBuffers = new UvBuffer[1];
@@ -72,13 +66,11 @@ public void Write()
7266

7367
private void UvWriteCb(IntPtr ptr, int status)
7468
{
75-
var error = Libuv.ExceptionForError(status);
76-
7769
KestrelTrace.Log.ConnectionWriteCallback(0, status);
78-
//NOTE: pool this?
7970

8071
Dispose();
81-
_callback(error, _state);
72+
73+
Libuv.ThrowOnError(status);
8274
}
8375

8476
protected override bool ReleaseHandle()

test/Microsoft.AspNet.Server.KestrelTests/NetworkingTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ public async Task SocketCanReadAndWrite()
215215
loop,
216216
tcp2,
217217
new ArraySegment<byte>(
218-
new byte[] { 65, 66, 67, 68, 69 }),
219-
(_1, _2) => { },
220-
null
218+
new byte[] { 65, 66, 67, 68, 69 })
221219
);
222220
}
223221
}

test/Microsoft.AspNet.Server.KestrelTests/TestInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void Resume()
4646
{
4747
}
4848

49-
public Task WriteAsync(ArraySegment<byte> data, Action<Exception, object> callback, object state)
49+
public Task WriteAsync(ArraySegment<byte> data)
5050
{
5151
return Task.CompletedTask;
5252
}

0 commit comments

Comments
 (0)