@@ -637,7 +637,6 @@ struct SC::AsyncEventLoop::Internal::KernelEventsPosix
637
637
{
638
638
if (handle == current->handle and (current->flags & Internal::Flag_WatcherSet))
639
639
{
640
- current->flags |= Internal::Flag_WatcherSet;
641
640
return Result (KernelQueuePosix::startSingleWatcherImmediate (*current->eventLoop , current->handle ,
642
641
OUTPUT_EVENTS_MASK));
643
642
}
@@ -735,15 +734,16 @@ struct SC::AsyncEventLoop::Internal::KernelEventsPosix
735
734
SC_ASSERT_RELEASE ((async.flags & Internal::Flag_ManualCompletion) == 0 );
736
735
if (not posixTryWrite (async, totalBytesToSend, offset))
737
736
{
738
- // Not all bytes have been written
737
+ // Not all bytes have been written, so if descriptor supports watching
738
+ // start monitoring it, otherwise just return error
739
739
if (watchable)
740
740
{
741
- // setup a writable state watcher for this handle
742
741
async.flags |= Internal::Flag_WatcherSet;
743
742
return Result (setEventWatcher (async, async.handle , OUTPUT_EVENTS_MASK));
744
743
}
745
744
return Result::Error (" Error in posixTryWrite" );
746
745
}
746
+ // Write has finished synchronously so force a manual invocation of its completion
747
747
async.flags |= Internal::Flag_ManualCompletion;
748
748
return Result (true );
749
749
}
@@ -776,6 +776,7 @@ struct SC::AsyncEventLoop::Internal::KernelEventsPosix
776
776
static Result posixWriteManualActivateWithSameHandle (T& async, T* current)
777
777
{
778
778
// Activate all asyncs on the same socket descriptor too
779
+ // TODO: This linear search is not great
779
780
while (current)
780
781
{
781
782
if (current->handle == async.handle )
@@ -784,6 +785,7 @@ struct SC::AsyncEventLoop::Internal::KernelEventsPosix
784
785
async.flags |= Internal::Flag_ManualCompletion;
785
786
async.eventLoop ->internal .manualCompletions .queueBack (*current);
786
787
}
788
+ current = static_cast <T*>(current->next );
787
789
}
788
790
return Result (true );
789
791
}
@@ -808,9 +810,9 @@ struct SC::AsyncEventLoop::Internal::KernelEventsPosix
808
810
809
811
static Result completeAsync (AsyncSocketSend::Result& result)
810
812
{
813
+ AsyncSocketSend& async = result.getAsync ();
811
814
SC_TRY (posixWriteCompleteAsync<AsyncSocketSend>(result, -1 ));
812
- return posixWriteManualActivateWithSameHandle (result.getAsync (),
813
- result.getAsync ().eventLoop ->internal .activeSocketSends .front );
815
+ return posixWriteManualActivateWithSameHandle (async, async.eventLoop ->internal .activeSocketSends .front );
814
816
}
815
817
816
818
// -------------------------------------------------------------------------------------------------------
@@ -947,14 +949,17 @@ struct SC::AsyncEventLoop::Internal::KernelEventsPosix
947
949
948
950
static Result completeAsync (AsyncFileWrite::Result& result)
949
951
{
950
- AsyncFileWrite& async = result.getAsync ();
951
- return posixWriteCompleteAsync<AsyncFileWrite>(result, async.useOffset ? static_cast <off_t >(async.offset ) : -1 );
952
+ AsyncFileWrite& async = result.getAsync ();
953
+ const off_t offset = async.useOffset ? static_cast <off_t >(async.offset ) : -1 ;
954
+ SC_TRY (posixWriteCompleteAsync<AsyncFileWrite>(result, offset));
955
+ return posixWriteManualActivateWithSameHandle (async, async.eventLoop ->internal .activeFileWrites .front );
952
956
}
953
957
954
958
static Result executeOperation (AsyncFileWrite& async, AsyncFileWrite::CompletionData& completionData)
955
959
{
956
960
const size_t totalBytesToSend = Internal::getSummedSizeOfBuffers (async);
957
- SC_TRY ((posixTryWrite (async, totalBytesToSend, async.useOffset ? static_cast <off_t >(async.offset ) : -1 )));
961
+ const off_t offset = async.useOffset ? static_cast <off_t >(async.offset ) : -1 ;
962
+ SC_TRY (posixTryWrite (async, totalBytesToSend, offset));
958
963
completionData.numBytes = async.totalBytesWritten ;
959
964
SC_TRY_MSG (completionData.numBytes == totalBytesToSend, " Partial write (disk full or RLIMIT_FSIZE reached)" );
960
965
return Result (true );
0 commit comments