mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 17:38:53 +08:00
simulator: fix TCP connection init on macOS
When `connect()` fails, the state of the socket is unspecified and we need to close the it and create it again. It turns out retrying connect worked on Linux but it didn't on macOS.
This commit is contained in:
@@ -683,20 +683,22 @@ void Simulator::pollForMAVLinkMessages(bool publish, InternetProtocol ip, int po
|
||||
PX4_INFO("Simulator connected on UDP port %u.", port);
|
||||
|
||||
} else {
|
||||
if ((_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
PX4_ERR("Creating TCP socket failed: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
PX4_INFO("Waiting for simulator to connect on TCP port %u", port);
|
||||
|
||||
while (true) {
|
||||
if ((_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
PX4_ERR("Creating TCP socket failed: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = connect(_fd, (struct sockaddr *)&_myaddr, sizeof(_myaddr));
|
||||
|
||||
if (ret == 0) {
|
||||
break;
|
||||
|
||||
} else {
|
||||
close(_fd);
|
||||
system_sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user