Skip to content

Commit

Permalink
server.cpp: unroll setting when sending mapblocks (#6265)
Browse files Browse the repository at this point in the history
* server.cpp: unroll setting when sending mapblocks

* Improve a little bit performance when sending mapblocks massively
* Use a range based for
* Code style fixes
  • Loading branch information
nerzhul committed Aug 18, 2017
1 parent 1d055aa commit fb196be
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions src/server.cpp
Expand Up @@ -95,8 +95,6 @@ void *ServerThread::run()

while (!stopRequested()) {
try {
//TimeTaker timer("AsyncRunStep() + Receive()");

m_server->AsyncRunStep();

m_server->Receive();
Expand Down Expand Up @@ -989,23 +987,17 @@ void Server::Receive()
m_con.Receive(&pkt);
peer_id = pkt.getPeerId();
ProcessData(&pkt);
}
catch(con::InvalidIncomingDataException &e) {
infostream<<"Server::Receive(): "
"InvalidIncomingDataException: what()="
<<e.what()<<std::endl;
}
catch(SerializationError &e) {
infostream<<"Server::Receive(): "
"SerializationError: what()="
<<e.what()<<std::endl;
}
catch(ClientStateError &e) {
} catch (const con::InvalidIncomingDataException &e) {
infostream << "Server::Receive(): InvalidIncomingDataException: what()="
<< e.what() << std::endl;
} catch (const SerializationError &e) {
infostream << "Server::Receive(): SerializationError: what()="
<< e.what() << std::endl;
} catch (const ClientStateError &e) {
errorstream << "ProcessData: peer=" << peer_id << e.what() << std::endl;
DenyAccess_Legacy(peer_id, L"Your client sent something server didn't expect."
L"Try reconnecting or updating your client");
}
catch(con::PeerNotFoundException &e) {
} catch (const con::PeerNotFoundException &e) {
// Do nothing
}
}
Expand Down Expand Up @@ -2259,29 +2251,30 @@ void Server::SendBlocks(float dtime)
std::sort(queue.begin(), queue.end());

m_clients.lock();
for(u32 i=0; i<queue.size(); i++)
{
s32 max_blocks_to_send =
g_settings->getS32("max_simultaneous_block_sends_server_total");

for (const PrioritySortedBlockTransfer &block_to_send : queue) {
//TODO: Calculate limit dynamically
if(total_sending >= g_settings->getS32
("max_simultaneous_block_sends_server_total"))
if (total_sending >= max_blocks_to_send)
break;

PrioritySortedBlockTransfer q = queue[i];

MapBlock *block = nullptr;
try {
block = m_env->getMap().getBlockNoCreate(q.pos);
} catch(const InvalidPositionException &e) {
block = m_env->getMap().getBlockNoCreate(block_to_send.pos);
} catch (const InvalidPositionException &e) {
continue;
}

RemoteClient *client = m_clients.lockedGetClientNoEx(q.peer_id, CS_Active);
RemoteClient *client = m_clients.lockedGetClientNoEx(block_to_send.peer_id,
CS_Active);
if (!client)
continue;

SendBlockNoLock(q.peer_id, block, client->serialization_version, client->net_proto_version);
SendBlockNoLock(block_to_send.peer_id, block, client->serialization_version,
client->net_proto_version);

client->SentBlock(q.pos);
client->SentBlock(block_to_send.pos);
total_sending++;
}
m_clients.unlock();
Expand Down

0 comments on commit fb196be

Please sign in to comment.