Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
90e41336
Commit
90e41336
authored
Mar 19, 2015
by
Lorenz Meier
Browse files
Merge pull request #1374 from dogmaphobic/udpFix
UPD Link Fix
parents
42040794
3ba09b4d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/comm/UDPLink.cc
View file @
90e41336
...
...
@@ -94,7 +94,6 @@ QString UDPLink::getName() const
void
UDPLink
::
addHost
(
const
QString
&
host
)
{
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
host
;
_config
->
addHost
(
host
);
}
...
...
@@ -176,8 +175,7 @@ void UDPLink::readBytes()
// 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
QString
host
(
sender
.
toString
()
+
":"
+
QString
(
"%1"
).
arg
((
int
)
senderPort
));
_config
->
addHost
(
host
);
_config
->
addHost
(
sender
.
toString
(),
(
int
)
senderPort
);
}
}
...
...
@@ -285,7 +283,6 @@ UDPConfiguration::UDPConfiguration(UDPConfiguration* source) : LinkConfiguration
void
UDPConfiguration
::
copyFrom
(
LinkConfiguration
*
source
)
{
_confMutex
.
lock
();
LinkConfiguration
::
copyFrom
(
source
);
UDPConfiguration
*
usource
=
dynamic_cast
<
UDPConfiguration
*>
(
source
);
Q_ASSERT
(
usource
!=
NULL
);
...
...
@@ -297,7 +294,6 @@ void UDPConfiguration::copyFrom(LinkConfiguration *source)
addHost
(
host
,
port
);
}
while
(
usource
->
nextHost
(
host
,
port
));
}
_confMutex
.
unlock
();
}
/**
...
...
@@ -305,7 +301,6 @@ void UDPConfiguration::copyFrom(LinkConfiguration *source)
*/
void
UDPConfiguration
::
addHost
(
const
QString
&
host
)
{
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
host
;
if
(
host
.
contains
(
":"
))
{
QHostInfo
info
=
QHostInfo
::
fromName
(
host
.
split
(
":"
).
first
());
...
...
@@ -316,33 +311,44 @@ void UDPConfiguration::addHost(const QString& host)
QHostAddress
address
;
for
(
int
i
=
0
;
i
<
hostAddresses
.
size
();
i
++
)
{
// Exclude
loopback IPv4 and
all IPv6 addresses
// Exclude all IPv6 addresses
if
(
!
hostAddresses
.
at
(
i
).
toString
().
contains
(
":"
))
{
address
=
hostAddresses
.
at
(
i
);
}
}
_confMutex
.
lock
();
_hosts
[
address
.
toString
()]
=
host
.
split
(
":"
).
last
().
toInt
();
_confMutex
.
unlock
();
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
address
.
toString
()
<<
":"
<<
host
.
split
(
":"
).
last
();
}
}
else
{
QHostInfo
info
=
QHostInfo
::
fromName
(
host
);
if
(
info
.
error
()
==
QHostInfo
::
NoError
)
{
// Set port according to default (same as local port)
_hosts
[
info
.
addresses
().
first
().
toString
()]
=
(
int
)
_localPort
;
}
addHost
(
host
,
(
int
)
_localPort
);
}
}
void
UDPConfiguration
::
addHost
(
const
QString
&
host
,
int
port
)
{
_hosts
[
host
.
trimmed
()]
=
port
;
QMutexLocker
locker
(
&
_confMutex
);
if
(
_hosts
.
contains
(
host
))
{
if
(
_hosts
[
host
]
!=
port
)
{
_hosts
[
host
]
=
port
;
}
}
else
{
QHostInfo
info
=
QHostInfo
::
fromName
(
host
);
if
(
info
.
error
()
==
QHostInfo
::
NoError
)
{
_hosts
[
info
.
addresses
().
first
().
toString
()]
=
port
;
qDebug
()
<<
"UDP:"
<<
"ADDING HOST:"
<<
info
.
addresses
().
first
().
toString
()
<<
":"
<<
port
;
}
}
}
void
UDPConfiguration
::
removeHost
(
const
QString
&
host
)
{
QMutexLocker
locker
(
&
_confMutex
);
QString
tHost
=
host
;
if
(
tHost
.
contains
(
":"
))
{
tHost
=
tHost
.
split
(
":"
).
first
();
...
...
@@ -356,15 +362,19 @@ void UDPConfiguration::removeHost(const QString& host)
bool
UDPConfiguration
::
firstHost
(
QString
&
host
,
int
&
port
)
{
_confMutex
.
lock
();
_it
=
_hosts
.
begin
();
if
(
_it
==
_hosts
.
end
())
{
_confMutex
.
unlock
();
return
false
;
}
_confMutex
.
unlock
();
return
nextHost
(
host
,
port
);
}
bool
UDPConfiguration
::
nextHost
(
QString
&
host
,
int
&
port
)
{
QMutexLocker
locker
(
&
_confMutex
);
if
(
_it
!=
_hosts
.
end
())
{
host
=
_it
.
key
();
port
=
_it
.
value
();
...
...
@@ -402,8 +412,9 @@ void UDPConfiguration::saveSettings(QSettings& settings, const QString& root)
void
UDPConfiguration
::
loadSettings
(
QSettings
&
settings
,
const
QString
&
root
)
{
_confMutex
.
lock
();
settings
.
beginGroup
(
root
);
_hosts
.
clear
();
_confMutex
.
unlock
();
settings
.
beginGroup
(
root
);
_localPort
=
(
quint16
)
settings
.
value
(
"port"
,
QGC_UDP_LOCAL_PORT
).
toUInt
();
int
hostCount
=
settings
.
value
(
"hostCount"
,
0
).
toInt
();
for
(
int
i
=
0
;
i
<
hostCount
;
i
++
)
{
...
...
@@ -414,7 +425,6 @@ void UDPConfiguration::loadSettings(QSettings& settings, const QString& root)
}
}
settings
.
endGroup
();
_confMutex
.
unlock
();
}
void
UDPConfiguration
::
updateSettings
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment