/* Connection Threads */
/******************************************************************************/
-ConnectionSendThread::ConnectionSendThread(Connection* parent,
- unsigned int max_packet_size,
+ConnectionSendThread::ConnectionSendThread( unsigned int max_packet_size,
float timeout) :
- m_connection(parent),
+ m_connection(NULL),
m_max_packet_size(max_packet_size),
m_timeout(timeout),
m_max_commands_per_iteration(1),
void * ConnectionSendThread::Thread()
{
+ assert(m_connection != NULL);
ThreadStarted();
log_register_thread("ConnectionSend");
{
std::list<u16> peerIds = m_connection->getPeerIDs();
- if ((this->m_outgoing_queue.size() > 0) && (peerIds.size() > 0))
+ if (!m_outgoing_queue.empty() && !peerIds.empty())
return true;
for(std::list<u16>::iterator j = peerIds.begin();
m_outgoing_queue.push_back(packet);
}
-ConnectionReceiveThread::ConnectionReceiveThread(Connection* parent,
- unsigned int max_packet_size) :
- m_connection(parent)
+ConnectionReceiveThread::ConnectionReceiveThread(unsigned int max_packet_size) :
+ m_connection(NULL)
{
}
void * ConnectionReceiveThread::Thread()
{
+ assert(m_connection != NULL);
ThreadStarted();
log_register_thread("ConnectionReceive");
u8 type = readU8(&(packetdata[0]));
+ if (MAX_UDP_PEERS <= 65535 && peer_id >= MAX_UDP_PEERS) {
+ errorstream << "Something is wrong with peer_id" << std::endl;
+ assert(0);
+ }
+
if(type == TYPE_CONTROL)
{
if(packetdata.getSize() < 2)
u8 controltype = readU8(&(packetdata[1]));
- if( (controltype == CONTROLTYPE_ACK)
- && (peer_id <= MAX_UDP_PEERS))
+ if(controltype == CONTROLTYPE_ACK)
{
assert(channel != 0);
if(packetdata.getSize() < 4)
}
throw ProcessedSilentlyException("Got an ACK");
}
- else if((controltype == CONTROLTYPE_SET_PEER_ID)
- && (peer_id <= MAX_UDP_PEERS))
+ else if(controltype == CONTROLTYPE_SET_PEER_ID)
{
// Got a packet to set our peer id
if(packetdata.getSize() < 4)
throw ProcessedSilentlyException("Got a SET_PEER_ID");
}
- else if((controltype == CONTROLTYPE_PING)
- && (peer_id <= MAX_UDP_PEERS))
+ else if(controltype == CONTROLTYPE_PING)
{
// Just ignore it, the incoming data already reset
// the timeout counter
throw ProcessedSilentlyException("Got a DISCO");
}
- else if((controltype == CONTROLTYPE_ENABLE_BIG_SEND_WINDOW)
- && (peer_id <= MAX_UDP_PEERS))
+ else if(controltype == CONTROLTYPE_ENABLE_BIG_SEND_WINDOW)
{
dynamic_cast<UDPPeer*>(&peer)->setNonLegacyPeer();
throw ProcessedSilentlyException("Got non legacy control");
//TODO throw some error
}
}
- else if((peer_id <= MAX_UDP_PEERS) && (type == TYPE_RELIABLE))
+ else if(type == TYPE_RELIABLE)
{
assert(channel != 0);
// Recursive reliable packets not allowed
m_event_queue(),
m_peer_id(0),
m_protocol_id(protocol_id),
- m_sendThread(this, max_packet_size, timeout),
- m_receiveThread(this, max_packet_size),
+ m_sendThread(max_packet_size, timeout),
+ m_receiveThread(max_packet_size),
m_info_mutex(),
m_bc_peerhandler(0),
m_bc_receive_timeout(0),
{
m_udpSocket.setTimeoutMs(5);
+ m_sendThread.setParent(this);
+ m_receiveThread.setParent(this);
+
m_sendThread.Start();
m_receiveThread.Start();
}
m_event_queue(),
m_peer_id(0),
m_protocol_id(protocol_id),
- m_sendThread(this, max_packet_size, timeout),
- m_receiveThread(this, max_packet_size),
+ m_sendThread(max_packet_size, timeout),
+ m_receiveThread(max_packet_size),
m_info_mutex(),
m_bc_peerhandler(peerhandler),
m_bc_receive_timeout(0),
{
m_udpSocket.setTimeoutMs(5);
+ m_sendThread.setParent(this);
+ m_receiveThread.setParent(this);
+
m_sendThread.Start();
m_receiveThread.Start();