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

Commit f2e60cc

Browse files
committed
Allow for inline write completion
1 parent 33e9563 commit f2e60cc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private void OnWriteCompleted(WriteContext writeContext)
351351

352352
if (scheduleWrite)
353353
{
354-
WriteAllPending();
354+
ScheduleWrite();
355355
}
356356

357357
_tasksCompleted.Clear();
@@ -399,7 +399,7 @@ private void PoolWriteContext(WriteContext writeContext)
399399
}
400400
}
401401

402-
public void Dispose()
402+
private void Dispose()
403403
{
404404
lock (_contextLock)
405405
{
@@ -471,6 +471,11 @@ public void DoWriteIfNeeded()
471471
return;
472472
}
473473

474+
// Sample values locally in case write completes inline
475+
// to allow block to be Reset and still complete this function
476+
var lockedEndBlock = _lockedEnd.Block;
477+
var lockedEndIndex = _lockedEnd.Index;
478+
474479
_writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) =>
475480
{
476481
var _this = (WriteContext)state;
@@ -480,12 +485,8 @@ public void DoWriteIfNeeded()
480485
_this.DoShutdownIfNeeded();
481486
}, this);
482487

483-
Self._head = _lockedEnd.Block;
484-
if (Self._head != null)
485-
{
486-
// Avoid shutdown race
487-
Self._head.Start = _lockedEnd.Index;
488-
}
488+
Self._head = lockedEndBlock;
489+
Self._head.Start = lockedEndIndex;
489490
}
490491

491492
/// <summary>

0 commit comments

Comments
 (0)