|
1 | 1 | /* |
2 | | -* Copyright (c) 2013-2020, The PurpleI2P Project |
| 2 | +* Copyright (c) 2013-2021, The PurpleI2P Project |
3 | 3 | * |
4 | 4 | * This file is part of Purple i2pd project and licensed under BSD3 |
5 | 5 | * |
@@ -1115,19 +1115,9 @@ namespace client |
1115 | 1115 | if (ep) |
1116 | 1116 | { |
1117 | 1117 | // udp forward enabled |
1118 | | - size_t bsz = base64.size(); |
1119 | | - size_t sz = bsz + 1 + len; |
1120 | | - // build datagram body |
1121 | | - uint8_t * data = new uint8_t[sz]; |
1122 | | - // Destination |
1123 | | - memcpy(data, base64.c_str(), bsz); |
1124 | | - // linefeed |
1125 | | - data[bsz] = '\n'; |
1126 | | - // Payload |
1127 | | - memcpy(data+bsz+1, buf, len); |
1128 | | - // send to remote endpoint |
1129 | | - m_Owner.SendTo(data, sz, ep); |
1130 | | - delete [] data; |
| 1118 | + const char lf = '\n'; |
| 1119 | + // send to remote endpoint, { destination, linefeed, payload } |
| 1120 | + m_Owner.SendTo({ {(const uint8_t *)base64.c_str(), base64.size()}, {(const uint8_t *)&lf, 1}, {buf, len} }, *ep); |
1131 | 1121 | } |
1132 | 1122 | else |
1133 | 1123 | { |
@@ -1156,7 +1146,7 @@ namespace client |
1156 | 1146 | auto ep = session->UDPEndpoint; |
1157 | 1147 | if (ep) |
1158 | 1148 | // udp forward enabled |
1159 | | - m_Owner.SendTo(buf, len, ep); |
| 1149 | + m_Owner.SendTo({ {buf, len} }, *ep); |
1160 | 1150 | else |
1161 | 1151 | { |
1162 | 1152 | #ifdef _MSC_VER |
@@ -1453,14 +1443,11 @@ namespace client |
1453 | 1443 | return list; |
1454 | 1444 | } |
1455 | 1445 |
|
1456 | | - void SAMBridge::SendTo(const uint8_t * buf, size_t len, std::shared_ptr<boost::asio::ip::udp::endpoint> remote) |
| 1446 | + void SAMBridge::SendTo (const std::vector<boost::asio::const_buffer>& bufs, const boost::asio::ip::udp::endpoint& ep) |
1457 | 1447 | { |
1458 | | - if(remote) |
1459 | | - { |
1460 | | - m_DatagramSocket.send_to(boost::asio::buffer(buf, len), *remote); |
1461 | | - } |
1462 | | - } |
1463 | | - |
| 1448 | + m_DatagramSocket.send_to (bufs, ep); |
| 1449 | + } |
| 1450 | + |
1464 | 1451 | void SAMBridge::ReceiveDatagram () |
1465 | 1452 | { |
1466 | 1453 | m_DatagramSocket.async_receive_from ( |
|
0 commit comments