Skip to content

Commit 2484ad3

Browse files
committed
完善细节
1 parent cbc6a17 commit 2484ad3

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

include/network/network.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ namespace cs_impl {
8686

8787
std::string receive(std::size_t maximum)
8888
{
89-
buffer<> buff_guard(maximum + 1);
90-
char *buff = buff_guard.get();
91-
buff[sock.receive(asio::buffer(buff, maximum))] = '\0';
92-
return buff;
89+
buffer<> buff(maximum);
90+
std::size_t actually = sock.receive(asio::buffer(buff.get(), maximum));
91+
return std::string(buff.get(), actually);
9392
}
9493

9594
void send(const std::string &s)
@@ -151,10 +150,9 @@ namespace cs_impl {
151150

152151
std::string receive_from(std::size_t maximum, udp::endpoint &ep)
153152
{
154-
buffer<> buff_guard(maximum + 1);
155-
char *buff = buff_guard.get();
156-
buff[sock.receive_from(asio::buffer(buff, maximum), ep)] = '\0';
157-
return buff;
153+
buffer<> buff(maximum);
154+
std::size_t actually = sock.receive_from(asio::buffer(buff.get(), maximum), ep);
155+
return std::string(buff.get(),actually);
158156
}
159157

160158
void send_to(const std::string &s, const udp::endpoint &ep)

0 commit comments

Comments
 (0)