mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
net: don't use get_message() when constructing datagram header
This is causing an unnecessary copy operation.
This commit is contained in:
parent
7125a3e587
commit
de6d753f79
@ -24,23 +24,23 @@
|
|||||||
*/
|
*/
|
||||||
DatagramTCPHeader::
|
DatagramTCPHeader::
|
||||||
DatagramTCPHeader(const NetDatagram &datagram, int header_size) {
|
DatagramTCPHeader(const NetDatagram &datagram, int header_size) {
|
||||||
const string &str = datagram.get_message();
|
size_t length = datagram.get_length();
|
||||||
switch (header_size) {
|
switch (header_size) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case datagram_tcp16_header_size:
|
case datagram_tcp16_header_size:
|
||||||
{
|
{
|
||||||
uint16_t size = str.length();
|
uint16_t size = (uint16_t)length;
|
||||||
nassertv(size == str.length());
|
nassertv((size_t)size == length);
|
||||||
_header.add_uint16(size);
|
_header.add_uint16(size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case datagram_tcp32_header_size:
|
case datagram_tcp32_header_size:
|
||||||
{
|
{
|
||||||
uint32_t size = str.length();
|
uint32_t size = (uint32_t)length;
|
||||||
nassertv(size == str.length());
|
nassertv((size_t)size == length);
|
||||||
_header.add_uint32(size);
|
_header.add_uint32(size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -93,8 +93,7 @@ verify_datagram(const NetDatagram &datagram, int header_size) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const string &str = datagram.get_message();
|
int actual_size = (int)datagram.get_length();
|
||||||
int actual_size = str.length();
|
|
||||||
int expected_size = get_datagram_size(header_size);
|
int expected_size = get_datagram_size(header_size);
|
||||||
if (actual_size == expected_size) {
|
if (actual_size == expected_size) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -24,10 +24,11 @@
|
|||||||
*/
|
*/
|
||||||
DatagramUDPHeader::
|
DatagramUDPHeader::
|
||||||
DatagramUDPHeader(const NetDatagram &datagram) {
|
DatagramUDPHeader(const NetDatagram &datagram) {
|
||||||
const string &str = datagram.get_message();
|
const unsigned char *begin = (const unsigned char *)datagram.get_data();
|
||||||
|
const unsigned char *end = begin + datagram.get_length();
|
||||||
uint16_t checksum = 0;
|
uint16_t checksum = 0;
|
||||||
for (size_t p = 0; p < str.size(); p++) {
|
for (const unsigned char *p = begin; p != end; ++p) {
|
||||||
checksum += (uint16_t)(uint8_t)str[p];
|
checksum += (uint16_t)(uint8_t)*p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now pack the header.
|
// Now pack the header.
|
||||||
@ -49,11 +50,11 @@ DatagramUDPHeader(const void *data) : _header(data, datagram_udp_header_size) {
|
|||||||
*/
|
*/
|
||||||
bool DatagramUDPHeader::
|
bool DatagramUDPHeader::
|
||||||
verify_datagram(const NetDatagram &datagram) const {
|
verify_datagram(const NetDatagram &datagram) const {
|
||||||
const string &str = datagram.get_message();
|
const unsigned char *begin = (const unsigned char *)datagram.get_data();
|
||||||
|
const unsigned char *end = begin + datagram.get_length();
|
||||||
uint16_t checksum = 0;
|
uint16_t checksum = 0;
|
||||||
for (size_t p = 0; p < str.size(); p++) {
|
for (const unsigned char *p = begin; p != end; ++p) {
|
||||||
checksum += (uint16_t)(uint8_t)str[p];
|
checksum += (uint16_t)(uint8_t)*p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checksum == get_datagram_checksum()) {
|
if (checksum == get_datagram_checksum()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user