Skip to content

Commit fb196be

Browse files
authoredAug 18, 2017
server.cpp: unroll setting when sending mapblocks (#6265)
* server.cpp: unroll setting when sending mapblocks * Improve a little bit performance when sending mapblocks massively * Use a range based for * Code style fixes
1 parent 1d055aa commit fb196be

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed
 

‎src/server.cpp

+20-27
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ void *ServerThread::run()
9595

9696
while (!stopRequested()) {
9797
try {
98-
//TimeTaker timer("AsyncRunStep() + Receive()");
99-
10098
m_server->AsyncRunStep();
10199

102100
m_server->Receive();
@@ -989,23 +987,17 @@ void Server::Receive()
989987
m_con.Receive(&pkt);
990988
peer_id = pkt.getPeerId();
991989
ProcessData(&pkt);
992-
}
993-
catch(con::InvalidIncomingDataException &e) {
994-
infostream<<"Server::Receive(): "
995-
"InvalidIncomingDataException: what()="
996-
<<e.what()<<std::endl;
997-
}
998-
catch(SerializationError &e) {
999-
infostream<<"Server::Receive(): "
1000-
"SerializationError: what()="
1001-
<<e.what()<<std::endl;
1002-
}
1003-
catch(ClientStateError &e) {
990+
} catch (const con::InvalidIncomingDataException &e) {
991+
infostream << "Server::Receive(): InvalidIncomingDataException: what()="
992+
<< e.what() << std::endl;
993+
} catch (const SerializationError &e) {
994+
infostream << "Server::Receive(): SerializationError: what()="
995+
<< e.what() << std::endl;
996+
} catch (const ClientStateError &e) {
1004997
errorstream << "ProcessData: peer=" << peer_id << e.what() << std::endl;
1005998
DenyAccess_Legacy(peer_id, L"Your client sent something server didn't expect."
1006999
L"Try reconnecting or updating your client");
1007-
}
1008-
catch(con::PeerNotFoundException &e) {
1000+
} catch (const con::PeerNotFoundException &e) {
10091001
// Do nothing
10101002
}
10111003
}
@@ -2259,29 +2251,30 @@ void Server::SendBlocks(float dtime)
22592251
std::sort(queue.begin(), queue.end());
22602252

22612253
m_clients.lock();
2262-
for(u32 i=0; i<queue.size(); i++)
2263-
{
2254+
s32 max_blocks_to_send =
2255+
g_settings->getS32("max_simultaneous_block_sends_server_total");
2256+
2257+
for (const PrioritySortedBlockTransfer &block_to_send : queue) {
22642258
//TODO: Calculate limit dynamically
2265-
if(total_sending >= g_settings->getS32
2266-
("max_simultaneous_block_sends_server_total"))
2259+
if (total_sending >= max_blocks_to_send)
22672260
break;
22682261

2269-
PrioritySortedBlockTransfer q = queue[i];
2270-
22712262
MapBlock *block = nullptr;
22722263
try {
2273-
block = m_env->getMap().getBlockNoCreate(q.pos);
2274-
} catch(const InvalidPositionException &e) {
2264+
block = m_env->getMap().getBlockNoCreate(block_to_send.pos);
2265+
} catch (const InvalidPositionException &e) {
22752266
continue;
22762267
}
22772268

2278-
RemoteClient *client = m_clients.lockedGetClientNoEx(q.peer_id, CS_Active);
2269+
RemoteClient *client = m_clients.lockedGetClientNoEx(block_to_send.peer_id,
2270+
CS_Active);
22792271
if (!client)
22802272
continue;
22812273

2282-
SendBlockNoLock(q.peer_id, block, client->serialization_version, client->net_proto_version);
2274+
SendBlockNoLock(block_to_send.peer_id, block, client->serialization_version,
2275+
client->net_proto_version);
22832276

2284-
client->SentBlock(q.pos);
2277+
client->SentBlock(block_to_send.pos);
22852278
total_sending++;
22862279
}
22872280
m_clients.unlock();

0 commit comments

Comments
 (0)