Skip to content

Commit

Permalink
Use new coroio api
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Dec 5, 2023
1 parent 0fbf04e commit b4612cc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion coroio
6 changes: 3 additions & 3 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
template<typename TSocket>
NNet::TValueTask<void> TWriter<TSocket>::Write(TMessageHolder<TMessage> message) {
auto payload = std::move(message.Payload);
char* p = (char*)message.Mes; // TODO: const char
const char* p = (const char*)message.Mes;
uint32_t len = message->Len;
while (len != 0) {
auto written = co_await Socket.WriteSome(p, len);
Expand All @@ -36,11 +36,11 @@ template<typename TSocket>
NNet::TValueTask<TMessageHolder<TMessage>> TReader<TSocket>::Read() {
decltype(TMessage::Type) type;
decltype(TMessage::Len) len;
auto s = co_await Socket.ReadSome((char*)&type, sizeof(type));
auto s = co_await Socket.ReadSome(&type, sizeof(type));
if (s != sizeof(type)) {
throw std::runtime_error("Connection closed");
}
s = co_await Socket.ReadSome((char*)&len, sizeof(len));
s = co_await Socket.ReadSome(&len, sizeof(len));
if (s != sizeof(len)) {
throw std::runtime_error("Connection closed");
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void test_message_send_recv(void** state) {
{
auto client = std::move(co_await server.Accept());
uint32_t type, len;
auto r = co_await client.ReadSome((char*)&type, sizeof(type));
r = co_await client.ReadSome((char*)&len, sizeof(len));
auto r = co_await client.ReadSome(&type, sizeof(type));
r = co_await client.ReadSome(&len, sizeof(len));
received = NewHoldedMessage<TMessage>(type, len);
r = co_await client.ReadSome(received->Value, len - sizeof(TMessage));
co_return;
Expand Down

0 comments on commit b4612cc

Please sign in to comment.