mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Connection::Receive(): receive Network Packet instead of SharedBuffer<u8>.
Because we get a Buffer<u8> from ConnectionEvent, don't convert it to SharedBuffer<u8> and return it to Server/Client::Receive which will convert it to NetworkPacket Instead, put the Buffer<u8> directly to NetworkPacket and return it to packet processing This remove a long existing memory copy Also check the packet size directly into Connection::Receive instead of packet processing
This commit is contained in:
parent
ab77bf98ee
commit
1fe4256462
9 changed files with 104 additions and 98 deletions
|
@ -1018,10 +1018,11 @@ void Server::Receive()
|
|||
DSTACK(__FUNCTION_NAME);
|
||||
SharedBuffer<u8> data;
|
||||
u16 peer_id;
|
||||
u32 datasize;
|
||||
try {
|
||||
datasize = m_con.Receive(peer_id,data);
|
||||
ProcessData(*data, datasize, peer_id);
|
||||
NetworkPacket pkt;
|
||||
m_con.Receive(&pkt);
|
||||
peer_id = pkt.getPeerId();
|
||||
ProcessData(&pkt);
|
||||
}
|
||||
catch(con::InvalidIncomingDataException &e) {
|
||||
infostream<<"Server::Receive(): "
|
||||
|
@ -1149,13 +1150,14 @@ inline void Server::handleCommand(NetworkPacket* pkt)
|
|||
(this->*opHandle.handler)(pkt);
|
||||
}
|
||||
|
||||
void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
||||
void Server::ProcessData(NetworkPacket *pkt)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
// Environment is locked first.
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
|
||||
ScopeProfiler sp(g_profiler, "Server::ProcessData");
|
||||
u32 peer_id = pkt->getPeerId();
|
||||
|
||||
try {
|
||||
Address address = getPeerAddress(peer_id);
|
||||
|
@ -1179,18 +1181,13 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
* respond for some time, your server was overloaded or
|
||||
* things like that.
|
||||
*/
|
||||
infostream << "Server::ProcessData(): Cancelling: peer "
|
||||
infostream << "Server::ProcessData(): Canceling: peer "
|
||||
<< peer_id << " not found" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if(datasize < 2)
|
||||
return;
|
||||
|
||||
NetworkPacket pkt(data, datasize, peer_id);
|
||||
|
||||
ToServerCommand command = (ToServerCommand) pkt.getCommand();
|
||||
ToServerCommand command = (ToServerCommand) pkt->getCommand();
|
||||
|
||||
// Command must be handled into ToServerCommandHandler
|
||||
if (command >= TOSERVER_NUM_MSG_TYPES) {
|
||||
|
@ -1199,7 +1196,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
}
|
||||
|
||||
if (toServerCommandTable[command].state == TOSERVER_STATE_NOT_CONNECTED) {
|
||||
handleCommand(&pkt);
|
||||
handleCommand(pkt);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1214,7 +1211,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
|
||||
/* Handle commands related to client startup */
|
||||
if (toServerCommandTable[command].state == TOSERVER_STATE_STARTUP) {
|
||||
handleCommand(&pkt);
|
||||
handleCommand(pkt);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1227,7 +1224,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
return;
|
||||
}
|
||||
|
||||
handleCommand(&pkt);
|
||||
handleCommand(pkt);
|
||||
}
|
||||
catch(SendFailedException &e) {
|
||||
errorstream << "Server::ProcessData(): SendFailedException: "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue