Skip to content

Commit

Permalink
added check to prevent yarp read stealing ports already in use
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed Apr 21, 2022
1 parent f3c8294 commit 3ed0608
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <yarp/companion/impl/BottleReader.h>
#include <yarp/os/ContactStyle.h>
#include <yarp/os/Network.h>
#include <yarp/os/LogStream.h>

#include <cstring>

Expand Down Expand Up @@ -77,5 +78,14 @@ int Companion::cmdRead(int argc, char *argv[])
argc--;
argv++;
}

//the following check prevents opening as local port a port which is already registered (and active) on the yarp nameserver
bool e = NetworkBase::exists(name, true);
if (e)
{
yCError(COMPANION) << "Port"<< name << "already exists! Do you mean yarp read ..."<< name <<"?";
return 1;
}

return read(name, src, showEnvelope, trim);
}

0 comments on commit 3ed0608

Please sign in to comment.