mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
[ORC] Add ErrorSuccess and void specializations to AsyncHandlerTraits.
This will allow async handlers to be added that return void or Error::success(). Such handlers are expected to be common, since one of the primary uses of addAsyncHandler is to run the body of the handler in a detached thread, in which case the main handler returns immediately and does not need to provide an Error value. llvm-svn: 312746
This commit is contained in:
parent
39b8dda8b4
commit
bd35aa1ac3
@ -534,6 +534,20 @@ public:
|
|||||||
using ResultType = Error;
|
using ResultType = Error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename... ArgTs>
|
||||||
|
class AsyncHandlerTraits<ErrorSuccess(std::function<Error(Error)>, ArgTs...)> {
|
||||||
|
public:
|
||||||
|
using Type = Error(ArgTs...);
|
||||||
|
using ResultType = Error;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... ArgTs>
|
||||||
|
class AsyncHandlerTraits<void(std::function<Error(Error)>, ArgTs...)> {
|
||||||
|
public:
|
||||||
|
using Type = Error(ArgTs...);
|
||||||
|
using ResultType = Error;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename ResponseHandlerT, typename... ArgTs>
|
template <typename ResponseHandlerT, typename... ArgTs>
|
||||||
class AsyncHandlerTraits<Error(ResponseHandlerT, ArgTs...)> :
|
class AsyncHandlerTraits<Error(ResponseHandlerT, ArgTs...)> :
|
||||||
public AsyncHandlerTraits<Error(typename std::decay<ResponseHandlerT>::type,
|
public AsyncHandlerTraits<Error(typename std::decay<ResponseHandlerT>::type,
|
||||||
|
@ -263,6 +263,51 @@ TEST(DummyRPC, TestCallAsyncIntInt) {
|
|||||||
ServerThread.join();
|
ServerThread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(DummyRPC, TestAsyncVoidBoolHandler) {
|
||||||
|
auto Channels = createPairedQueueChannels();
|
||||||
|
DummyRPCEndpoint Client(*Channels.first);
|
||||||
|
DummyRPCEndpoint Server(*Channels.second);
|
||||||
|
|
||||||
|
std::thread ServerThread([&]() {
|
||||||
|
Server.addAsyncHandler<DummyRPCAPI::VoidBool>(
|
||||||
|
[](std::function<Error(Error)> SendResult,
|
||||||
|
bool B) {
|
||||||
|
EXPECT_EQ(B, true) << "Server void(bool) receieved unexpected result";
|
||||||
|
cantFail(SendResult(Error::success()));
|
||||||
|
return Error::success();
|
||||||
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
// Poke the server to handle the negotiate call.
|
||||||
|
auto Err = Server.handleOne();
|
||||||
|
EXPECT_FALSE(!!Err) << "Server failed to handle call to negotiate";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Poke the server to handle the VoidBool call.
|
||||||
|
auto Err = Server.handleOne();
|
||||||
|
EXPECT_FALSE(!!Err) << "Server failed to handle call to void(bool)";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
auto Err = Client.callAsync<DummyRPCAPI::VoidBool>(
|
||||||
|
[](Error Result) {
|
||||||
|
EXPECT_FALSE(!!Result) << "Async void(bool) response handler failed";
|
||||||
|
return Error::success();
|
||||||
|
}, true);
|
||||||
|
EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(bool)";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Poke the client to process the result.
|
||||||
|
auto Err = Client.handleOne();
|
||||||
|
EXPECT_FALSE(!!Err) << "Client failed to handle response from void(bool)";
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerThread.join();
|
||||||
|
}
|
||||||
|
|
||||||
TEST(DummyRPC, TestAsyncIntIntHandler) {
|
TEST(DummyRPC, TestAsyncIntIntHandler) {
|
||||||
auto Channels = createPairedQueueChannels();
|
auto Channels = createPairedQueueChannels();
|
||||||
DummyRPCEndpoint Client(*Channels.first);
|
DummyRPCEndpoint Client(*Channels.first);
|
||||||
|
Loading…
Reference in New Issue
Block a user