Skip to content

Commit caf5fcf

Browse files
committed
Fix bug
1 parent afe0f9e commit caf5fcf

File tree

9 files changed

+27
-45
lines changed

9 files changed

+27
-45
lines changed

eventstreamrpc/include/aws/eventstreamrpc/EventStreamClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ namespace Aws
299299
std::future<RpcError> Connect(
300300
const ConnectionConfig &connectionOptions,
301301
ConnectionLifecycleHandler *connectionLifecycleHandler,
302-
ConnectMessageAmender connectMessageAmender,
303302
Crt::Io::ClientBootstrap &clientBootstrap) noexcept;
304303

305304
std::future<RpcError> SendPing(
@@ -344,6 +343,7 @@ namespace Aws
344343
std::promise<RpcError> m_closedPromise;
345344
OnMessageFlushCallback m_onConnectRequestCallback;
346345
Crt::Io::SocketOptions m_socketOptions;
346+
ConnectionConfig m_connectionConfig;
347347
static void s_customDeleter(ClientConnection *connection) noexcept;
348348
std::future<RpcError> SendProtocolMessage(
349349
const Crt::List<EventStreamHeader> &headers,

eventstreamrpc/source/EventStreamClient.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,31 +273,31 @@ namespace Aws
273273
std::future<RpcError> ClientConnection::Connect(
274274
const ConnectionConfig &connectionConfig,
275275
ConnectionLifecycleHandler *connectionLifecycleHandler,
276-
ConnectMessageAmender connectMessageAmender,
277276
Crt::Io::ClientBootstrap &clientBootstrap) noexcept
278277
{
279278
m_connectAckedPromise.Reset();
280279
m_closedPromise = {};
280+
m_connectionConfig = connectionConfig;
281281
m_lifecycleHandler = connectionLifecycleHandler;
282282
EventStreamRpcStatusCode baseError = EVENT_STREAM_RPC_SUCCESS;
283283

284-
m_onConnectRequestCallback = connectionConfig.GetConnectRequestCallback();
284+
m_onConnectRequestCallback = m_connectionConfig.GetConnectRequestCallback();
285285

286286
struct aws_event_stream_rpc_client_connection_options connOptions;
287287
AWS_ZERO_STRUCT(connOptions);
288288
Crt::String hostName;
289-
if (connectionConfig.GetHostName().has_value())
289+
if (m_connectionConfig.GetHostName().has_value())
290290
{
291-
hostName = connectionConfig.GetHostName().value();
291+
hostName = m_connectionConfig.GetHostName().value();
292292
connOptions.host_name = hostName.c_str();
293293
}
294294
else
295295
{
296296
baseError = EVENT_STREAM_RPC_NULL_PARAMETER;
297297
}
298-
if (connectionConfig.GetPort().has_value())
298+
if (m_connectionConfig.GetPort().has_value())
299299
{
300-
connOptions.port = connectionConfig.GetPort().value();
300+
connOptions.port = m_connectionConfig.GetPort().value();
301301
}
302302
else
303303
{
@@ -312,25 +312,23 @@ namespace Aws
312312
return m_connectAckedPromise.GetFuture();
313313
}
314314

315-
if (connectionConfig.GetSocketOptions().has_value())
315+
if (m_connectionConfig.GetSocketOptions().has_value())
316316
{
317-
m_socketOptions = connectionConfig.GetSocketOptions().value();
317+
m_socketOptions = m_connectionConfig.GetSocketOptions().value();
318318
}
319319
connOptions.socket_options = &m_socketOptions.GetImpl();
320320

321321
connOptions.on_connection_setup = ClientConnection::s_onConnectionSetup;
322322
connOptions.on_connection_protocol_message = ClientConnection::s_onProtocolMessage;
323323
connOptions.on_connection_shutdown = ClientConnection::s_onConnectionShutdown;
324324
connOptions.user_data = reinterpret_cast<void *>(this);
325+
325326
m_lifecycleHandler = connectionLifecycleHandler;
326-
if (connectMessageAmender)
327-
{
328-
m_connectMessageAmender = connectMessageAmender;
329-
}
327+
m_connectMessageAmender = m_connectionConfig.GetConnectMessageAmender();
330328

331-
if (connectionConfig.GetTlsConnectionOptions().has_value())
329+
if (m_connectionConfig.GetTlsConnectionOptions().has_value())
332330
{
333-
connOptions.tls_options = connectionConfig.GetTlsConnectionOptions()->GetUnderlyingHandle();
331+
connOptions.tls_options = m_connectionConfig.GetTlsConnectionOptions()->GetUnderlyingHandle();
334332
}
335333

336334
int crtError = aws_event_stream_rpc_client_connection_connect(m_allocator, &connOptions);

ipc/include/aws/greengrass/GreengrassCoreIpcClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Aws
2828
Aws::Crt::Allocator *allocator = Aws::Crt::g_allocator) noexcept;
2929
std::future<RpcError> Connect(
3030
ConnectionLifecycleHandler &lifecycleHandler,
31-
ConnectionConfig connectionConfig = DefaultConnectionConfig()) noexcept;
31+
const ConnectionConfig &connectionConfig = DefaultConnectionConfig()) noexcept;
3232
void Close() noexcept;
3333
SubscribeToIoTCoreOperation NewSubscribeToIoTCore(SubscribeToIoTCoreStreamHandler &) noexcept;
3434
PublishToIoTCoreOperation NewPublishToIoTCore() noexcept;

ipc/source/GreengrassCoreIpcClient.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,9 @@ namespace Aws
3838

3939
std::future<RpcError> GreengrassCoreIpcClient::Connect(
4040
ConnectionLifecycleHandler &lifecycleHandler,
41-
ConnectionConfig connectionConfig) noexcept
41+
const ConnectionConfig &connectionConfig) noexcept
4242
{
43-
/* If a client bootstrap has not been set in the config, use the one from the client. */
44-
if (connectionConfig.GetClientBootstrap() == nullptr)
45-
{
46-
connectionConfig.SetClientBootstrap(&m_clientBootstrap);
47-
}
48-
49-
return m_connection.Connect(
50-
connectionConfig, &lifecycleHandler, connectionConfig.GetConnectMessageAmender(), m_clientBootstrap);
43+
return m_connection.Connect(connectionConfig, &lifecycleHandler, m_clientBootstrap);
5144
}
5245

5346
void GreengrassCoreIpcClient::Close() noexcept { m_connection.Close(); }

ipc/tests/CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ set(TEST_BINARY_NAME ${PROJECT_NAME}-tests)
4343
aws_use_package(aws-crt-cpp)
4444
aws_use_package(GreengrassIpc-cpp)
4545

46-
if (UNIX AND NOT APPLE)
47-
add_test_case(EventStreamConnect)
48-
generate_cpp_test_driver(${TEST_BINARY_NAME})
49-
target_include_directories(${TEST_BINARY_NAME} PUBLIC
50-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
51-
$<INSTALL_INTERFACE:include>)
52-
endif()
46+
add_test_case(EventStreamConnect)
47+
generate_cpp_test_driver(${TEST_BINARY_NAME})
48+
target_include_directories(${TEST_BINARY_NAME} PUBLIC
49+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
50+
$<INSTALL_INTERFACE:include>)

ipc/tests/DefaultConnectionConfig.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ namespace Awstest
1010
socketOptions.SetSocketDomain(Aws::Crt::Io::SocketDomain::IPv4);
1111
socketOptions.SetSocketType(Aws::Crt::Io::SocketType::Stream);
1212
m_socketOptions = std::move(socketOptions);
13+
m_connectAmendment.AddHeader(EventStreamHeader(
14+
Aws::Crt::String("client-name"), Aws::Crt::String("accepted.testy_mc_testerson")));
1315
}
1416
} // namespace Awstest

ipc/tests/EchoClientTest.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ static int s_connectToServer(struct aws_allocator *allocator, void *ctx)
3535
Aws::Crt::Io::ClientBootstrap clientBootstrap(eventLoopGroup, socketResolver, allocator);
3636
ASSERT_TRUE(clientBootstrap);
3737
clientBootstrap.EnableBlockingShutdown();
38-
MessageAmendment connectionAmendment;
39-
auto messageAmender = [&](void) -> MessageAmendment & { return connectionAmendment; };
4038

4139
ConnectionLifecycleHandler lifecycleHandler;
42-
Awstest::EchoTestRpcClient client(clientBootstrap);
40+
Awstest::EchoTestRpcClient client(clientBootstrap, allocator);
4341
auto connectedStatus = client.Connect(lifecycleHandler);
4442
ASSERT_TRUE(connectedStatus.get().baseStatus == EVENT_STREAM_RPC_SUCCESS);
4543

ipc/tests/EchoTestRpcClient.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,9 @@ namespace Awstest
1414

1515
std::future<RpcError> EchoTestRpcClient::Connect(
1616
ConnectionLifecycleHandler &lifecycleHandler,
17-
ConnectionConfig connectionConfig) noexcept
17+
const ConnectionConfig &connectionConfig) noexcept
1818
{
19-
/* If a client bootstrap has not been set in the config, use the one from the client. */
20-
if (connectionConfig.GetClientBootstrap() == nullptr)
21-
{
22-
connectionConfig.SetClientBootstrap(&m_clientBootstrap);
23-
}
24-
25-
return m_connection.Connect(
26-
connectionConfig, &lifecycleHandler, connectionConfig.GetConnectMessageAmender(), m_clientBootstrap);
19+
return m_connection.Connect(connectionConfig, &lifecycleHandler, m_clientBootstrap);
2720
}
2821

2922
void EchoTestRpcClient::Close() noexcept { m_connection.Close(); }

ipc/tests/include/awstest/EchoTestRpcClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Awstest
2626
Aws::Crt::Allocator *allocator = Aws::Crt::g_allocator) noexcept;
2727
std::future<RpcError> Connect(
2828
ConnectionLifecycleHandler &lifecycleHandler,
29-
ConnectionConfig connectionConfig = DefaultConnectionConfig()) noexcept;
29+
const ConnectionConfig &connectionConfig = DefaultConnectionConfig()) noexcept;
3030
void Close() noexcept;
3131
GetAllProductsOperation NewGetAllProducts() noexcept;
3232
CauseServiceErrorOperation NewCauseServiceError() noexcept;

0 commit comments

Comments
 (0)