@ -160,6 +160,7 @@ QString UDPLink::getName() const
@@ -160,6 +160,7 @@ QString UDPLink::getName() const
void UDPLink : : _writeBytes ( const QByteArray data )
{
< < < < < < < HEAD
if ( ! _socket )
return ;
// Send to all manually targeted systems
@ -167,6 +168,37 @@ void UDPLink::_writeBytes(const QByteArray data)
@@ -167,6 +168,37 @@ void UDPLink::_writeBytes(const QByteArray data)
// Skip it if it's part of the session clients below
if ( ! contains_target ( _sessionTargets , target - > address , target - > port ) ) {
_writeDataGram ( data , target ) ;
= = = = = = =
if ( _socket ) {
QStringList goneHosts ;
// Send to all connected systems
QString host ;
int port ;
if ( _udpConfig - > firstHost ( host , port ) ) {
do {
QHostAddress currentHost ( host ) ;
if ( _socket - > writeDatagram ( data , currentHost , ( quint16 ) port ) < 0 ) {
// This host is gone. Add to list to be removed
// We should keep track of hosts that were manually added (static) and
// hosts that were added because we heard from them (dynamic). Only
// dynamic hosts should be removed and even then, after a few tries, not
// the first failure. In the mean time, we don't remove anything.
if ( REMOVE_GONE_HOSTS ) {
goneHosts . append ( host ) ;
}
} else {
// Only log rate if data actually got sent. Not sure about this as
// "host not there" takes time too regardless of size of data. In fact,
// 1 byte or "UDP frame size" bytes are the same as that's the data
// unit sent by UDP.
_logOutputDataRate ( data . size ( ) , QDateTime : : currentMSecsSinceEpoch ( ) ) ;
}
} while ( _udpConfig - > nextHost ( host , port ) ) ;
//-- Remove hosts that are no longer there
foreach ( const QString & ghost , goneHosts ) {
_udpConfig - > removeHost ( ghost ) ;
}
> > > > > > > b4f4085c6733b934358b00389d734600eab87bf7
}
}
// Send to all connected systems
@ -193,9 +225,9 @@ void UDPLink::_writeDataGram(const QByteArray data, const UDPCLient* target)
@@ -193,9 +225,9 @@ void UDPLink::_writeDataGram(const QByteArray data, const UDPCLient* target)
* */
void UDPLink : : readBytes ( )
{
if ( _socket ) {
QByteArray databuffer ;
while ( _socket - > hasPendingDatagrams ( ) )
{
while ( _socket - > hasPendingDatagrams ( ) ) {
QByteArray datagram ;
datagram . resize ( _socket - > pendingDatagramSize ( ) ) ;
QHostAddress sender ;
@ -208,6 +240,18 @@ void UDPLink::readBytes()
@@ -208,6 +240,18 @@ void UDPLink::readBytes()
databuffer . clear ( ) ;
}
_logInputDataRate ( datagram . length ( ) , QDateTime : : currentMSecsSinceEpoch ( ) ) ;
// TODO This doesn't validade the sender. Anything sending UDP packets to this port gets
// added to the list and will start receiving datagrams from here. Even a port scanner
// would trigger this.
// Add host to broadcast list if not yet present, or update its port
_udpConfig - > addHost ( sender . toString ( ) , ( int ) senderPort ) ;
}
//-- Send whatever is left
if ( databuffer . size ( ) ) {
emit bytesReceived ( this , databuffer ) ;
}
< < < < < < < HEAD
_logInputDataRate ( datagram . length ( ) , QDateTime : : currentMSecsSinceEpoch ( ) ) ;
// TODO: This doesn't validade the sender. Anything sending UDP packets to this port gets
// added to the list and will start receiving datagrams from here. Even a port scanner
// would trigger this.
@ -225,6 +269,8 @@ void UDPLink::readBytes()
@@ -225,6 +269,8 @@ void UDPLink::readBytes()
//-- Send whatever is left
if ( databuffer . size ( ) ) {
emit bytesReceived ( this , databuffer ) ;
= = = = = = =
> > > > > > > b4f4085c6733b934358b00389d734600eab87bf7
}
}
@ -272,7 +318,7 @@ bool UDPLink::_hardwareConnect()
@@ -272,7 +318,7 @@ bool UDPLink::_hardwareConnect()
_socket = NULL ;
}
QHostAddress host = QHostAddress : : AnyIPv4 ;
_socket = new QUdpSocket ( ) ;
_socket = new QUdpSocket ( this ) ;
_socket - > setProxy ( QNetworkProxy : : NoProxy ) ;
_connectState = _socket - > bind ( host , _udpConfig - > localPort ( ) , QAbstractSocket : : ReuseAddressHint | QUdpSocket : : ShareAddress ) ;
if ( _connectState ) {