Skip to content

Commit a65f19f

Browse files
committed
Async: Move AsyncFileClose return code to completion data
1 parent 0e71359 commit a65f19f

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

Libraries/Async/Async.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,17 +788,17 @@ struct AsyncFileClose : public AsyncRequest
788788
AsyncFileClose() : AsyncRequest(Type::FileClose) {}
789789

790790
/// @brief Completion data for AsyncFileClose
791-
using CompletionData = AsyncCompletionData;
791+
struct CompletionData : public AsyncCompletionData
792+
{
793+
int code = 0; ///< Return code of close file operation
794+
};
792795

793796
/// @brief Callback result for AsyncFileClose
794797
using Result = AsyncResultOf<AsyncFileClose, CompletionData>;
795798

796799
/// @brief Sets async request members and calls AsyncEventLoop::start
797800
SC::Result start(AsyncEventLoop& eventLoop, FileDescriptor::Handle fileDescriptor);
798801

799-
// TODO: Move code to CompletionData
800-
int code = 0; ///< Return code of close socket operation
801-
802802
Function<void(Result&)> callback; ///< Callback called after fully closing the file descriptor
803803

804804
private:

Libraries/Async/Internal/AsyncLinux.inl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,9 @@ struct SC::AsyncEventLoop::Internal::KernelEventsIoURing
605605

606606
Result completeAsync(AsyncFileClose::Result& result)
607607
{
608-
result.returnCode = Result(true);
608+
io_uring_cqe& completion = events[result.eventIndex];
609+
result.returnCode = Result(true);
610+
result.completionData.code = completion.res;
609611
return Result(true);
610612
}
611613

Libraries/Async/Internal/AsyncPosix.inl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ struct SC::AsyncEventLoop::Internal::KernelQueuePosix
299299
#if SC_ASYNC_USE_EPOLL
300300
constexpr auto VALUE = EPOLL_CTL_ADD;
301301
#else
302-
constexpr auto VALUE = EV_ADD | EV_ENABLE;
302+
constexpr auto VALUE = EV_ADD;
303303
#endif
304304
return setSingleWatcherImmediate<VALUE>(eventLoop, handle, filter);
305305
}
@@ -389,7 +389,7 @@ struct SC::AsyncEventLoop::Internal::KernelEventsPosix
389389
Result setEventWatcher(AsyncEventLoop& eventLoop, AsyncRequest& async, int fileDescriptor, short filter,
390390
unsigned int options = 0)
391391
{
392-
EV_SET(events + newEvents, fileDescriptor, filter, EV_ADD | EV_ENABLE, options, 0, &async);
392+
EV_SET(events + newEvents, fileDescriptor, filter, EV_ADD, options, 0, &async);
393393
newEvents += 1;
394394
if (newEvents >= totalNumEvents)
395395
{
@@ -1001,13 +1001,21 @@ struct SC::AsyncEventLoop::Internal::KernelEventsPosix
10011001
//-------------------------------------------------------------------------------------------------------
10021002
Result setupAsync(AsyncEventLoop&, AsyncFileClose& async)
10031003
{
1004-
// TODO: Allow running close on thread pool
10051004
async.flags |= Internal::Flag_ManualCompletion;
1006-
async.code = ::close(async.handle);
1007-
SC_TRY_MSG(async.code == 0, "Close returned error");
10081005
return Result(true);
10091006
}
10101007

1008+
static Result executeOperation(AsyncFileClose& async, AsyncFileClose::CompletionData& completionData)
1009+
{
1010+
completionData.code = ::close(async.handle);
1011+
return Result(true);
1012+
}
1013+
1014+
Result completeAsync(AsyncFileClose::Result& result)
1015+
{
1016+
return executeOperation(result.getAsync(), result.completionData);
1017+
}
1018+
10111019
//-------------------------------------------------------------------------------------------------------
10121020
// Process EXIT
10131021
//-------------------------------------------------------------------------------------------------------

Libraries/Async/Internal/AsyncWindows.inl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,21 @@ struct SC::AsyncEventLoop::Internal::KernelEvents
692692
//-------------------------------------------------------------------------------------------------------
693693
Result setupAsync(AsyncEventLoop&, AsyncFileClose& async)
694694
{
695-
// TODO: Allow running close on thread pool
696695
async.flags |= Internal::Flag_ManualCompletion;
697-
async.code = ::CloseHandle(async.handle) == FALSE ? -1 : 0;
698-
SC_TRY_MSG(async.code == 0, "Close returned error");
699696
return Result(true);
700697
}
701698

699+
static Result executeOperation(AsyncFileClose& async, AsyncFileClose::CompletionData& completionData)
700+
{
701+
completionData.code = ::CloseHandle(async.handle);
702+
return Result(true);
703+
}
704+
705+
Result completeAsync(AsyncFileClose::Result& result)
706+
{
707+
return executeOperation(result.getAsync(), result.completionData);
708+
}
709+
702710
//-------------------------------------------------------------------------------------------------------
703711
// Process EXIT
704712
//-------------------------------------------------------------------------------------------------------

Tests/SCTest/SC Spaces.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Stefano Cristiano
2+
// SPDX-License-Identifier: MIT
3+
14
// The only reason why this file exists is to test that build system can handle spaces in files
25
#ifndef SC_SPACES_SPECIFIC_DEFINE
36
// This is a define specific to this file that has been created in SC-Build.cpp as a tests

0 commit comments

Comments
 (0)