Skip to content

Commit 9ab03b2

Browse files
committed
Create ConnectionConfig for Windows that uses getenv_s
1 parent c664d61 commit 9ab03b2

File tree

6 files changed

+69
-18
lines changed

6 files changed

+69
-18
lines changed

eventstream_rpc/include/aws/eventstreamrpc/EventStreamClient.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ namespace Aws
231231
/* User data passed to callbacks for a new stream. */
232232
class ContinuationCallbackData
233233
{
234-
public:
234+
public:
235235
ContinuationCallbackData(
236236
ClientContinuation *clientContinuation,
237237
Crt::Allocator *allocator = Crt::g_allocator) noexcept
@@ -240,7 +240,7 @@ namespace Aws
240240
continuationDestroyed = false;
241241
}
242242
ContinuationCallbackData(const ContinuationCallbackData &lhs) noexcept = delete;
243-
std::atomic_bool continuationDestroyed;
243+
bool continuationDestroyed;
244244
std::mutex callbackMutex;
245245
ClientContinuation *clientContinuation;
246246
Crt::Allocator *allocator;
@@ -413,8 +413,7 @@ namespace Aws
413413
ResultType GetResultType() const noexcept { return m_responseType; }
414414

415415
private:
416-
union AWS_EVENTSTREAMRPC_API OperationResult
417-
{
416+
union AWS_EVENTSTREAMRPC_API OperationResult {
418417
OperationResult(Crt::ScopedResource<AbstractShapeBase> &&response) noexcept
419418
: m_response(std::move(response))
420419
{
@@ -443,12 +442,12 @@ namespace Aws
443442
{
444443
/* An interface shared by all operations for retrieving the response object given the model name. */
445444
public:
446-
virtual ExpectedResponseFactory GetInitialResponseFromModelName(
447-
const Crt::String &modelName) const noexcept = 0;
448-
virtual ExpectedResponseFactory GetStreamingResponseFromModelName(
449-
const Crt::String &modelName) const noexcept = 0;
450-
virtual ErrorResponseFactory GetOperationErrorFromModelName(
451-
const Crt::String &modelName) const noexcept = 0;
445+
virtual ExpectedResponseFactory GetInitialResponseFromModelName(const Crt::String &modelName) const
446+
noexcept = 0;
447+
virtual ExpectedResponseFactory GetStreamingResponseFromModelName(const Crt::String &modelName) const
448+
noexcept = 0;
449+
virtual ErrorResponseFactory GetOperationErrorFromModelName(const Crt::String &modelName) const
450+
noexcept = 0;
452451
};
453452

454453
class AWS_EVENTSTREAMRPC_API ServiceModel
@@ -511,8 +510,7 @@ namespace Aws
511510
const OperationModelContext &m_operationModelContext;
512511

513512
private:
514-
EventStreamRpcStatusCode HandleData(
515-
const Crt::Optional<Crt::ByteBuf> &payload);
513+
EventStreamRpcStatusCode HandleData(const Crt::Optional<Crt::ByteBuf> &payload);
516514
EventStreamRpcStatusCode HandleError(
517515
const Crt::String &modelName,
518516
const Crt::Optional<Crt::ByteBuf> &payload,

eventstream_rpc/source/EventStreamClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ namespace Aws
818818
if (m_callbackData)
819819
{
820820
m_callbackData->callbackMutex.lock();
821-
m_callbackData->continuationDestroyed.store(true);
821+
m_callbackData->continuationDestroyed = true;
822822
m_callbackData->callbackMutex.unlock();
823823
}
824824
}
@@ -852,7 +852,7 @@ namespace Aws
852852
}
853853

854854
const std::lock_guard<std::mutex> lock(callbackData->callbackMutex);
855-
if (callbackData->continuationDestroyed.load())
855+
if (callbackData->continuationDestroyed)
856856
return;
857857
thisContinuation->m_continuationHandler.OnContinuationMessage(
858858
continuationMessageHeaders, payload, messageArgs->message_type, messageArgs->message_flags);
@@ -868,7 +868,7 @@ namespace Aws
868868
auto *callbackData = static_cast<ContinuationCallbackData *>(userData);
869869

870870
const std::lock_guard<std::mutex> lock(callbackData->callbackMutex);
871-
if (callbackData->continuationDestroyed.load())
871+
if (callbackData->continuationDestroyed)
872872
return;
873873

874874
auto *thisContinuation = callbackData->clientContinuation;

eventstream_rpc/tests/EventStreamClientTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,7 @@ static int s_TestStressClient(struct aws_allocator *allocator, void *ctx)
499499
Awstest::EchoTestRpcClient client(*testContext->clientBootstrap, allocator);
500500
auto connectedStatus = client.Connect(lifecycleHandler);
501501
ASSERT_TRUE(connectedStatus.get().baseStatus == EVENT_STREAM_RPC_SUCCESS);
502-
auto invokeOperation = [&](void) -> int
503-
{
502+
auto invokeOperation = [&](void) -> int {
504503
auto echoMessage = client.NewEchoMessage();
505504
messageData.SetStringMessage(expectedMessage);
506505
echoMessageRequest.SetMessage(messageData);
@@ -515,7 +514,7 @@ static int s_TestStressClient(struct aws_allocator *allocator, void *ctx)
515514
return AWS_OP_SUCCESS;
516515
};
517516

518-
for (int i = 0; i < 100000; i++)
517+
for (int i = 0; i < 100; i++)
519518
threadPool.AddTask(invokeOperation);
520519

521520
threadPool.BlockUntilTasksFinish();

greengrass_ipc/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ file(GLOB AWS_GREENGRASSIPC_CPP_SRC
3131
${AWS_GREENGRASSIPC_SRC}
3232
)
3333

34+
if (WIN32 OR MSVC)
35+
set(AWS_GREENGRASSIPC_CPP_SRC
36+
${AWS_GREENGRASSIPC_CPP_SRC}
37+
"source/platform/WindowsConnectionConfig.cpp")
38+
else()
39+
set(AWS_GREENGRASSIPC_CPP_SRC
40+
${AWS_GREENGRASSIPC_CPP_SRC}
41+
"source/platform/PosixConnectionConfig.cpp")
42+
endif()
43+
3444
if (WIN32)
3545
if (MSVC)
3646
source_group("Header Files\\aws\\greengrass\\" FILES ${AWS_GREENGRASSIPC_HEADERS})
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <aws/greengrass/GreengrassCoreIpcClient.h>
2+
3+
#include <stdlib.h>
4+
5+
#include <sstream>
6+
7+
namespace Aws
8+
{
9+
namespace Greengrass
10+
{
11+
DefaultConnectionConfig::DefaultConnectionConfig() noexcept
12+
{
13+
size_t ipcSocketSize = 0;
14+
char *ipcSocketCStr = nullptr;
15+
getenv_s( &ipcSocketSize, NULL, 0, "AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT");
16+
Crt::Vector<char> ipcSocket(ipcSocketSize);
17+
getenv_s( &ipcSocketSize, &ipcSocket[0], ipcSocketSize, "AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT" );
18+
if (ipcSocketSize > 0)
19+
{
20+
m_hostName = Crt::String(&ipcSocket[0]);
21+
}
22+
23+
size_t authTokenSize = 0;
24+
const char *authTokenCStr = std::getenv("SVCUID");
25+
getenv_s( &authTokenCStr, NULL, 0, "SVCUID");
26+
Crt::Vector<char> authToken(authTokenSize);
27+
getenv_s( &authTokenSize, &authToken[0], authTokenSize, "SVCUID" );
28+
if (authTokenSize > 0)
29+
{
30+
/* Encode authToken as JSON. */
31+
Crt::StringStream authTokenPayloadSS;
32+
authTokenPayloadSS << "{\"authToken\":\"" << Crt::String(&authToken[0]) << "\"}";
33+
m_connectAmendment = MessageAmendment(Crt::ByteBufFromCString(authTokenPayloadSS.str().c_str()));
34+
}
35+
const char *ipcSocketCStr = std::getenv("AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT");
36+
37+
m_port = static_cast<uint16_t>(0);
38+
Crt::Io::SocketOptions socketOptions;
39+
socketOptions.SetSocketDomain(Crt::Io::SocketDomain::Local);
40+
socketOptions.SetSocketType(Crt::Io::SocketType::Stream);
41+
m_socketOptions = std::move(socketOptions);
42+
}
43+
} // namespace Greengrass
44+
} // namespace Aws

0 commit comments

Comments
 (0)