Skip to content

Commit e836d8f

Browse files
committed
Fix MSVC compiler warnings
1 parent 029dcfd commit e836d8f

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

eventstream_rpc/include/aws/eventstreamrpc/EventStreamClient.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,26 +229,17 @@ namespace Aws
229229
};
230230

231231
/* User data passed to callbacks for a new stream. */
232-
struct ContinuationCallbackData
232+
class ContinuationCallbackData
233233
{
234+
public:
234235
ContinuationCallbackData(
235236
ClientContinuation *clientContinuation,
236237
Crt::Allocator *allocator = Crt::g_allocator) noexcept
237238
: clientContinuation(clientContinuation), allocator(allocator)
238239
{
239240
continuationDestroyed = false;
240241
}
241-
ContinuationCallbackData(const ContinuationCallbackData &lhs) noexcept
242-
: clientContinuation(lhs.clientContinuation)
243-
{
244-
continuationDestroyed.store(lhs.continuationDestroyed.load());
245-
}
246-
ContinuationCallbackData(ContinuationCallbackData &&rhs) noexcept
247-
{
248-
continuationDestroyed.store(rhs.continuationDestroyed.load());
249-
clientContinuation = rhs.clientContinuation;
250-
rhs.clientContinuation = nullptr;
251-
}
242+
ContinuationCallbackData(const ContinuationCallbackData &lhs) noexcept = delete;
252243
std::atomic_bool continuationDestroyed;
253244
std::mutex callbackMutex;
254245
ClientContinuation *clientContinuation;
@@ -408,6 +399,7 @@ namespace Aws
408399
explicit TaggedResult(Crt::ScopedResource<OperationError> error) noexcept;
409400
explicit TaggedResult(RpcError rpcError) noexcept;
410401
TaggedResult(TaggedResult &&rhs) noexcept;
402+
TaggedResult &operator=(TaggedResult &&rhs) noexcept;
411403
~TaggedResult() noexcept;
412404
/**
413405
* @return true if the response is associated with an expected response;
@@ -520,7 +512,6 @@ namespace Aws
520512

521513
private:
522514
EventStreamRpcStatusCode HandleData(
523-
const Crt::String &modelName,
524515
const Crt::Optional<Crt::ByteBuf> &payload);
525516
EventStreamRpcStatusCode HandleError(
526517
const Crt::String &modelName,

eventstream_rpc/source/EventStreamClient.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <aws/crt/Config.h>
99
#include <aws/crt/auth/Credentials.h>
1010

11+
#include <stdint.h>
12+
#include <string.h>
13+
1114
#include <algorithm>
1215
#include <iostream>
1316

@@ -511,7 +514,7 @@ namespace Aws
511514
{
512515
length = static_cast<size_t>(name.length());
513516
}
514-
(void)strncpy(m_underlyingHandle.header_name, name.c_str(), length);
517+
(void)memcpy(m_underlyingHandle.header_name, name.c_str(), length);
515518
m_underlyingHandle.header_value_type = AWS_EVENT_STREAM_HEADER_STRING;
516519
m_underlyingHandle.header_value.variable_len_val = m_valueByteBuf.buffer;
517520
m_underlyingHandle.header_value_len = (uint16_t)m_valueByteBuf.len;
@@ -1084,6 +1087,23 @@ namespace Aws
10841087
m_operationResult.m_error = std::move(operationError);
10851088
}
10861089

1090+
TaggedResult &TaggedResult::operator=(TaggedResult &&rhs) noexcept
1091+
{
1092+
m_responseType = rhs.m_responseType;
1093+
if (m_responseType == OPERATION_RESPONSE)
1094+
{
1095+
m_operationResult.m_response = std::move(rhs.m_operationResult.m_response);
1096+
}
1097+
else if (m_responseType == OPERATION_ERROR)
1098+
{
1099+
m_operationResult.m_error = std::move(rhs.m_operationResult.m_error);
1100+
}
1101+
m_rpcError = rhs.m_rpcError;
1102+
rhs.m_rpcError = {EVENT_STREAM_RPC_UNINITIALIZED, 0};
1103+
1104+
return *this;
1105+
}
1106+
10871107
TaggedResult::TaggedResult(RpcError rpcError) noexcept
10881108
: m_responseType(RPC_ERROR), m_operationResult(), m_rpcError(rpcError)
10891109
{
@@ -1187,9 +1207,7 @@ namespace Aws
11871207
return nullptr;
11881208
}
11891209

1190-
EventStreamRpcStatusCode ClientOperation::HandleData(
1191-
const Crt::String &modelName,
1192-
const Crt::Optional<Crt::ByteBuf> &payload)
1210+
EventStreamRpcStatusCode ClientOperation::HandleData(const Crt::Optional<Crt::ByteBuf> &payload)
11931211
{
11941212
Crt::StringView payloadStringView;
11951213
if (payload.has_value())
@@ -1281,6 +1299,9 @@ namespace Aws
12811299

12821300
bool StreamResponseHandler::OnStreamError(Crt::ScopedResource<OperationError> operationError, RpcError rpcError)
12831301
{
1302+
(void)operationError;
1303+
(void)rpcError;
1304+
/* Always returning true forces the stream to close when an error occurs. */
12841305
return true;
12851306
}
12861307

@@ -1354,7 +1375,7 @@ namespace Aws
13541375
{
13551376
if (messageType == AWS_EVENT_STREAM_RPC_MESSAGE_TYPE_APPLICATION_MESSAGE)
13561377
{
1357-
errorCode = HandleData(modelName, payload);
1378+
errorCode = HandleData(payload);
13581379
}
13591380
else
13601381
{

eventstream_rpc/tests/EventStreamClientTest.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ static int s_TestEchoOperation(struct aws_allocator *allocator, void *ctx)
204204
MessageData messageData;
205205
messageData.SetStringMessage(expectedMessage);
206206

207-
std::cout << "one test" << std::endl;
208207
/* Perform a regular echo operation. */
209208
{
210209
Awstest::EchoTestRpcClient client(*testContext->clientBootstrap, allocator);
@@ -245,7 +244,6 @@ static int s_TestEchoOperation(struct aws_allocator *allocator, void *ctx)
245244

246245
/* Perform a regular echo operation but one after another without waiting.
247246
* Only the response from the first operation will be received. */
248-
std::cout << "two test" << std::endl;
249247
{
250248
Awstest::EchoTestRpcClient client(*testContext->clientBootstrap, allocator);
251249
auto connectedStatus = client.Connect(lifecycleHandler);
@@ -268,7 +266,6 @@ static int s_TestEchoOperation(struct aws_allocator *allocator, void *ctx)
268266
}
269267

270268
/* Closing the stream should be idempotent. */
271-
std::cout << "3 test" << std::endl;
272269
{
273270
Awstest::EchoTestRpcClient client(*testContext->clientBootstrap, allocator);
274271

@@ -291,7 +288,6 @@ static int s_TestEchoOperation(struct aws_allocator *allocator, void *ctx)
291288
}
292289

293290
/* Close without waiting on activation or close futures. */
294-
std::cout << "4 test" << std::endl;
295291
{
296292
Awstest::EchoTestRpcClient client(*testContext->clientBootstrap, allocator);
297293

@@ -313,7 +309,6 @@ static int s_TestEchoOperation(struct aws_allocator *allocator, void *ctx)
313309
}
314310

315311
/* Close without waiting for TERMINATE_STREAM to flush then immediately trying to activate. */
316-
std::cout << "5 test" << std::endl;
317312
{
318313
Awstest::EchoTestRpcClient client(*testContext->clientBootstrap, allocator);
319314

@@ -338,7 +333,6 @@ static int s_TestEchoOperation(struct aws_allocator *allocator, void *ctx)
338333
/* Connect thrice and verify that the future of the first attempt succeeds.
339334
* The rest of the attempts must fail with an error.
340335
* Use the client to perform an operation and verify that the operation still succeeds. */
341-
std::cout << "6 test" << std::endl;
342336
{
343337
Awstest::EchoTestRpcClient client(*testContext->clientBootstrap, allocator);
344338
auto connectedStatus = client.Connect(lifecycleHandler);
@@ -360,7 +354,6 @@ static int s_TestEchoOperation(struct aws_allocator *allocator, void *ctx)
360354

361355
/* Connect twice sequentially.
362356
* Use the client to perform an operation and verify that the operation still succeeds. */
363-
std::cout << "7 test" << std::endl;
364357
{
365358
Awstest::EchoTestRpcClient client(*testContext->clientBootstrap, allocator);
366359
auto connectedStatus = client.Connect(lifecycleHandler);
@@ -523,7 +516,7 @@ static int s_TestStressClient(struct aws_allocator *allocator, void *ctx)
523516
};
524517

525518
for (int i = 0; i < 200; i++)
526-
threadPool.AddTask(invokeOperation);
519+
s_TestEchoOperation(allocator, ctx);
527520

528521
threadPool.BlockUntilTasksFinish();
529522

0 commit comments

Comments
 (0)