Skip to content

Commit 885aa3f

Browse files
Merge branch 'main' into ymq-pymod-tests-3
2 parents 40846e8 + 2298372 commit 885aa3f

File tree

14 files changed

+63
-83
lines changed

14 files changed

+63
-83
lines changed

.github/actions/compile-libraries/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ runs:
1313
if: inputs.os == 'Linux'
1414
shell: bash
1515
run: |
16-
CXX=$(which g++-14) ./scripts/build.sh
16+
./scripts/build.sh
1717
1818
- name: Build and test C++ Components (Windows)
1919
if: inputs.os == 'Windows'

examples/cpp/ymq/automated_echo_client.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11

2-
3-
// C++
4-
#include <stdio.h>
5-
62
#include <future>
3+
#include <iostream>
74
#include <memory>
85
#include <string>
96

@@ -25,7 +22,7 @@ int main()
2522
longStr += "1234567890";
2623

2724
auto clientSocket = syncCreateSocket(context, IOSocketType::Connector, "ClientSocket");
28-
printf("Successfully created socket.\n");
25+
std::cout << "Successfully created socket.\n";
2926

3027
constexpr size_t msgCnt = 100'000;
3128

@@ -34,9 +31,8 @@ int main()
3431
std::vector<std::promise<std::pair<Message, Error>>> recvPromises;
3532
recvPromises.reserve(msgCnt + 10);
3633

37-
// syncConnectSocket(clientSocket, "tcp://51.15.214.200:32912");
3834
syncConnectSocket(clientSocket, "tcp://127.0.0.1:8080");
39-
printf("Connected to server.\n");
35+
std::cout << "Connected to server.\n";
4036

4137
const std::string_view line = longStr;
4238

@@ -64,19 +60,19 @@ int main()
6460
auto future = x.get_future();
6561
future.wait();
6662
}
67-
printf("send completes\n");
63+
std::cout << "Send completes.\n";
6864

6965
for (auto&& x: recvPromises) {
7066
auto future = x.get_future();
7167
Message msg = future.get().first;
7268
if (msg.payload.as_string() != longStr) {
73-
printf("Checksum failed, %s\n", msg.payload.as_string()->c_str());
69+
std::cerr << "Checksum failed, " << *msg.payload.as_string() << std::endl;
7470
exit(1);
7571
}
7672
}
77-
printf("recv completes\n");
73+
std::cout << "Recv completes.\n";
7874

79-
printf("Send and recv %lu messages, checksum fits, exiting.\n", msgCnt);
75+
std::cout << "Send and recv " << msgCnt << " messages, checksum fits, exiting.\n";
8076

8177
context.removeIOSocket(clientSocket);
8278

examples/cpp/ymq/echo_client.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11

2-
// C++
3-
#include <stdio.h>
4-
52
#include <future>
63
#include <iostream>
74
#include <memory>
@@ -21,10 +18,10 @@ int main()
2118
IOContext context;
2219

2320
auto clientSocket = syncCreateSocket(context, IOSocketType::Connector, "ClientSocket");
24-
printf("Successfully created socket.\n");
21+
std::cout << "Successfully created socket.\n";
2522

2623
syncConnectSocket(clientSocket, "tcp://127.0.0.1:8080");
27-
printf("Connected to server.\n");
24+
std::cout << "Connected to server.\n";
2825

2926
for (int cnt = 0; cnt < 10; ++cnt) {
3027
std::string line;
@@ -48,7 +45,7 @@ int main()
4845
std::move(message), [&send_promise](std::expected<void, Error>) { send_promise.set_value({}); });
4946

5047
send_future.wait();
51-
printf("Message sent, waiting for response...\n");
48+
std::cout << "Message sent, waiting for response...\n";
5249

5350
auto recv_promise = std::promise<std::pair<Message, Error>>();
5451
auto recv_future = recv_promise.get_future();
@@ -58,7 +55,7 @@ int main()
5855

5956
Message reply = recv_future.get().first;
6057
std::string reply_str(reply.payload.data(), reply.payload.data() + reply.payload.len());
61-
printf("Received echo: '%s'\n", reply_str.c_str());
58+
std::cout << "Received echo: '" << reply_str << "'.\n";
6259
}
6360

6461
// TODO: remove IOSocket also needs a future

examples/cpp/ymq/echo_server.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

2-
#include <stdio.h>
3-
42
#include <future>
3+
#include <iostream>
54
#include <memory>
65

76
#include "scaler/io/ymq/error.h"
@@ -16,10 +15,10 @@ int main()
1615
IOContext context;
1716

1817
auto socket = syncCreateSocket(context, IOSocketType::Binder, "ServerSocket");
19-
printf("Successfully created socket.\n");
18+
std::cout << "Successfully created socket." << std::endl;
2019

2120
syncBindSocket(socket, "tcp://127.0.0.1:8080");
22-
printf("Successfully bound socket\n");
21+
std::cout << "Successfully bound socket." << std::endl;
2322

2423
while (true) {
2524
auto recv_promise = std::promise<std::pair<Message, Error>>();

examples/cpp/ymq/pingpong.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
2-
3-
// C++
4-
#include <stdio.h>
5-
61
#include <chrono>
72
#include <future>
3+
#include <iostream>
84
#include <memory>
9-
#include <print>
105
#include <string>
116
#include <thread>
127

@@ -23,7 +18,7 @@ using namespace std::chrono_literals;
2318
int main(int argc, char* argv[])
2419
{
2520
if (argc != 5) {
26-
printf("Usage: %s <Identity> <MessageSize> <MessageCount> <AddressString>\n", argv[0]);
21+
std::cout << "Usage: " << argv[0] << " <Identity> <MessageSize> <MessageCount> <AddressString>\n";
2722
exit(1);
2823
}
2924
const std::string identity(argv[1]);
@@ -34,10 +29,10 @@ int main(int argc, char* argv[])
3429
IOContext context;
3530

3631
auto clientSocket = syncCreateSocket(context, IOSocketType::Connector, identity);
37-
printf("Successfully created socket.\n");
32+
std::cout << "Successfully created socket.\n";
3833

3934
syncConnectSocket(clientSocket, address);
40-
printf("Connected to server.\n");
35+
std::cout << "Connected to server.\n";
4136

4237
const std::string_view line = longStr;
4338

@@ -62,10 +57,10 @@ int main(int argc, char* argv[])
6257

6358
time_point<system_clock> end = system_clock::now();
6459

65-
printf("Send and recv %lu messages with %lu bytes.\n", msgCnt, longStr.size());
60+
std::cout << "Send and recv " << msgCnt << " messages with " << longStr.size() << " bytes.\n";
6661
auto milli = duration_cast<milliseconds>(end - start);
67-
std::print("Spend {}\n", milli);
68-
std::print("Throughput {} Bpms\n", msgCnt * (longStr.size()) * 1.0 / milli.count());
62+
std::cout << "Spend " << milli.count() << "ms.\n";
63+
std::cout << "Throughput " << msgCnt * (longStr.size()) * 1.0 / milli.count() << " Bpms.\n";
6964

7065
context.removeIOSocket(clientSocket);
7166

examples/cpp/ymq/pub_server.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
2-
#include <stdio.h>
3-
41
#include <chrono>
52
#include <future>
3+
#include <iostream>
64
#include <memory>
75
#include <thread>
86

@@ -18,10 +16,10 @@ int main()
1816
IOContext context;
1917

2018
auto socket = syncCreateSocket(context, IOSocketType::Multicast, "ServerSocket");
21-
printf("Successfully created socket.\n");
19+
std::cout << "Successfully created socket.\n";
2220

2321
syncBindSocket(socket, "tcp://127.0.0.1:8080");
24-
printf("Successfully bound socket\n");
22+
std::cout << "Successfully bound socket.\n";
2523

2624
while (true) {
2725
std::string address("");
@@ -37,7 +35,7 @@ int main()
3735
std::move(publishContent), [&send_promise](std::expected<void, Error>) { send_promise.set_value({}); });
3836
send_future.wait();
3937

40-
printf("One message published, sleep for 10 sec\n");
38+
std::cout << "One message published, sleep for 10 sec.\n";
4139
using namespace std::chrono_literals;
4240
std::this_thread::sleep_for(10s);
4341
}

examples/cpp/ymq/remove_iosocket.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include <stdio.h>
2-
1+
#include <iostream>
32
#include <memory>
43
#include <string>
54

@@ -13,10 +12,10 @@ int main()
1312
{
1413
IOContext context;
1514
auto clientSocket = syncCreateSocket(context, IOSocketType::Connector, "ServerSocket");
16-
printf("Successfully created socket.\n");
15+
std::cout << "Successfully created socket.\n";
1716

1817
syncConnectSocket(clientSocket, "tcp://127.0.0.1:8080");
19-
printf("Connected to server.\n");
18+
std::cout << "Connected to server.\n";
2019

2120
context.removeIOSocket(clientSocket);
2221

examples/cpp/ymq/sub_client.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <stdio.h>
2-
31
#include <future>
42
#include <iostream>
53
#include <memory>
@@ -19,7 +17,7 @@ int main()
1917
IOContext context;
2018
auto clientSocket1 = syncCreateSocket(context, IOSocketType::Unicast, "ClientSocket1");
2119
auto clientSocket2 = syncCreateSocket(context, IOSocketType::Unicast, "ClientSocket2");
22-
printf("Successfully created sockets.\n");
20+
std::cout << "Successfully created sockets.\n";
2321

2422
syncConnectSocket(clientSocket1, "tcp://127.0.0.1:8080");
2523
syncConnectSocket(clientSocket2, "tcp://127.0.0.1:8080");
@@ -33,7 +31,7 @@ int main()
3331

3432
Message reply = recv_future.get().first;
3533
std::string reply_str(reply.payload.data(), reply.payload.data() + reply.payload.len());
36-
printf("clientSocket1 Received from publisher: '%s'\n", reply_str.c_str());
34+
std::cout << "clientSocket1 Received from publisher: '" << reply_str << "'.\n";
3735

3836
auto recv_promise2 = std::promise<std::pair<Message, Error>>();
3937
auto recv_future2 = recv_promise2.get_future();
@@ -43,7 +41,7 @@ int main()
4341

4442
Message reply2 = recv_future2.get().first;
4543
std::string reply_str2(reply2.payload.data(), reply2.payload.data() + reply2.payload.len());
46-
printf("clientSocket2 Received from publisher: '%s'\n", reply_str2.c_str());
44+
std::cout << "clientSocket2 Received from publisher: '" << reply_str2 << "'.\n";
4745
}
4846

4947
// TODO: remove IOSocket also needs a future

examples/cpp/ymq/timestamp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ int main()
1111
std::cout << ts.timestamp << std::endl;
1212
Timestamp three_seconds_later_than_ts = ts.createTimestampByOffsetDuration(3s);
1313
std::cout << three_seconds_later_than_ts.timestamp << std::endl;
14-
printf("%s\n", stringifyTimestamp(ts).c_str());
14+
std::cout << stringifyTimestamp(ts) << std::endl;
1515
// a timestamp is smaller iff it is closer to the beginning of the world
1616
if (ts < three_seconds_later_than_ts) {
17-
printf("ts happen before than three_seconds_later_than_ts\n");
17+
std::cout << "ts happen before than three_seconds_later_than_ts.\n";
1818
}
1919
}

scaler/io/ymq/error.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <exception> // std::terminate
55
#include <format>
66
#include <functional>
7-
#include <print>
7+
#include <iostream>
88
#include <string>
99

1010
#include "scaler/io/ymq/timestamp.h"
@@ -87,7 +87,7 @@ struct Error: public std::exception {
8787
case ErrorCode::BinderSendMessageWithNoAddress:
8888
return "You call sendMessage with a Binder IOSocket but failed to provide an address";
8989
}
90-
fprintf(stderr, "Unrecognized ErrorCode value, program exits\n");
90+
std::cerr << "Unrecognized ErrorCode value, program exits\n";
9191
std::exit(1);
9292
}
9393

@@ -119,7 +119,7 @@ using UnrecoverableErrorFunctionHookPtr = std::function<void(scaler::ymq::Error)
119119

120120
[[noreturn]] inline void defaultUnrecoverableError(scaler::ymq::Error e) noexcept
121121
{
122-
std::print(stderr, "{}\n", e);
122+
std::cerr << e.what() << '\n';
123123
std::exit(1);
124124
}
125125

0 commit comments

Comments
 (0)