std::string_view 的使用
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "UDP_Server.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
namespace Psc::asio_socket {
|
||||
|
||||
@@ -160,14 +161,14 @@ std::vector<UDP_Server::Read_Info> UDP_Server::read() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void UDP_Server::reply_last_peer(const std::string &data) {
|
||||
void UDP_Server::reply_last_peer(std::string_view data) {
|
||||
if (!has_last_peer)
|
||||
return;
|
||||
send_to(last_peer.ip, static_cast<uint16_t>(last_peer.port), data);
|
||||
}
|
||||
|
||||
void UDP_Server::send_to(const std::string &ip, uint16_t port,
|
||||
const std::string &data) {
|
||||
void UDP_Server::send_to(std::string_view ip, uint16_t port,
|
||||
std::string_view data) {
|
||||
if (data.empty())
|
||||
return;
|
||||
if (!bound && !bind())
|
||||
@@ -183,7 +184,7 @@ void UDP_Server::send_to(const std::string &ip, uint16_t port,
|
||||
start_write();
|
||||
}
|
||||
|
||||
void UDP_Server::write_to_all_clients(const std::string &msg) {
|
||||
void UDP_Server::write_to_all_clients(std::string_view msg) {
|
||||
for (const auto &client : clients) {
|
||||
send_to(client.ip, static_cast<uint16_t>(client.port), msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user