-
-
Save Zeno-/16a64bfc8eae435c5840 to your computer and use it in GitHub Desktop.
Avoid halting server for non-fatal warning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Author: Craig Robbins <kde.psych@gmail.com> 2014-10-12 19:42:39 | |
Committer: Craig Robbins <kde.psych@gmail.com> 2014-10-12 19:42:39 | |
Parent: d1ccc64e1ecfd00df36d2b8a8b3420b70434fefd (Make sure PRECISION_SECONDS corresponds to the integer 0) | |
Branch: meh | |
Follows: 0.4.10 | |
Precedes: | |
Avoid halting server for non-fatal warning | |
------------------------------ src/connection.cpp ------------------------------ | |
index ee5b1eb..7300a0a 100644 | |
@@ -2237,14 +2237,16 @@ void ConnectionReceiveThread::receive() | |
SharedBuffer<u8> resultdata = processPacket | |
(channel, strippeddata, peer_id, channelnum, false); | |
- LOG(dout_con<<m_connection->getDesc() | |
- <<" ProcessPacket from peer_id: " << peer_id | |
- << ",channel: " << (channelnum & 0xFF) << ", returned " | |
- << resultdata.getSize() << " bytes" <<std::endl); | |
+ if (resultdata.getSize() != 0) { | |
+ LOG(dout_con<<m_connection->getDesc() | |
+ <<" ProcessPacket from peer_id: " << peer_id | |
+ << ",channel: " << (channelnum & 0xFF) << ", returned " | |
+ << resultdata.getSize() << " bytes" <<std::endl); | |
- ConnectionEvent e; | |
- e.dataReceived(peer_id, resultdata); | |
- m_connection->putEvent(e); | |
+ ConnectionEvent e; | |
+ e.dataReceived(peer_id, resultdata); | |
+ m_connection->putEvent(e); | |
+ } | |
}catch(ProcessedSilentlyException &e){ | |
}catch(ProcessedQueued &e){ | |
packet_queued = true; | |
@@ -2313,7 +2315,7 @@ bool ConnectionReceiveThread::checkIncomingBuffers(Channel *channel, | |
memcpy(*payload, &p.data[headers_size], payload.getSize()); | |
dst = processPacket(channel, payload, peer_id, channelnum, true); | |
- return true; | |
+ return dst.getSize() != 0; | |
} | |
} | |
return false; | |
@@ -2322,7 +2324,13 @@ bool ConnectionReceiveThread::checkIncomingBuffers(Channel *channel, | |
SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel, | |
SharedBuffer<u8> packetdata, u16 peer_id, u8 channelnum, bool reliable) | |
{ | |
- PeerHelper peer = m_connection->getPeer(peer_id); | |
+ bool peerOk; | |
+ PeerHelper peer = m_connection->getPeer(peer_id, &peerOk); | |
+ | |
+ if (!peerOk) { | |
+ errorstream << "Warning: getPeer(): Peer not found (possible timeout)"; | |
+ return SharedBuffer<u8>(0); | |
+ } | |
if(packetdata.getSize() < 1) | |
throw InvalidIncomingDataException("packetdata.getSize() < 1"); | |
@@ -2722,18 +2730,20 @@ void Connection::putEvent(ConnectionEvent &e) | |
m_event_queue.push_back(e); | |
} | |
-PeerHelper Connection::getPeer(u16 peer_id) | |
+PeerHelper Connection::getPeer(u16 peer_id, bool *success) | |
{ | |
JMutexAutoLock peerlock(m_peers_mutex); | |
std::map<u16, Peer*>::iterator node = m_peers.find(peer_id); | |
- if(node == m_peers.end()){ | |
- throw PeerNotFoundException("GetPeer: Peer not found (possible timeout)"); | |
+ if(node == m_peers.end()) { | |
+ *success = false; | |
+ return PeerHelper(NULL); | |
} | |
// Error checking | |
assert(node->second->id == peer_id); | |
+ *success = true; | |
return PeerHelper(node->second); | |
} | |
------------------------------- src/connection.h ------------------------------- | |
index 516702c..57f3855 100644 | |
@@ -1035,7 +1035,7 @@ class Connection | |
void DisconnectPeer(u16 peer_id); | |
protected: | |
- PeerHelper getPeer(u16 peer_id); | |
+ PeerHelper getPeer(u16 peer_id, bool *success); | |
PeerHelper getPeerNoEx(u16 peer_id); | |
u16 lookupPeer(Address& sender); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment