Commit 38a859b8 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

[unet-multicast]: added 'setLoopback' function

parent b9411d81
......@@ -227,6 +227,12 @@ std::vector<Poco::Net::IPAddress> MulticastReceiveTransport::getGroups()
{
return groups;
}
// -------------------------------------------------------------------------
void MulticastReceiveTransport::setLoopBack( bool state )
{
if( udp )
udp->setLoopback(state);
}
// -------------------------------------------------------------------------
/*
......@@ -346,6 +352,12 @@ void MulticastSendTransport::setTimeToLive( int _ttl )
udp->setTimeToLive(_ttl);
}
// -------------------------------------------------------------------------
void MulticastSendTransport::setLoopBack( bool state )
{
if( udp )
udp->setLoopback(state);
}
// -------------------------------------------------------------------------
bool MulticastSendTransport::createConnection( bool throwEx, timeout_t sendTimeout )
{
try
......
......@@ -45,6 +45,7 @@ namespace uniset
virtual void disconnect() override;
virtual int getSocket() const override;
std::vector<Poco::Net::IPAddress> getGroups();
void setLoopBack( bool state );
bool isReadyForReceive( timeout_t tout ) override;
virtual ssize_t receive(void* r_buf, size_t sz) override;
......@@ -78,6 +79,7 @@ namespace uniset
virtual ssize_t send(const void* buf, size_t sz) override;
void setTimeToLive( int ttl );
void setLoopBack( bool state );
protected:
std::unique_ptr <MulticastSocketU> udp;
......
......@@ -30,6 +30,7 @@ static struct option longopts[] =
{ "a-data", required_argument, 0, 'a' },
{ "d-data", required_argument, 0, 'i' },
{ "group", required_argument, 0, 'g' },
{ "loopback", no_argument, 0, 'b' },
{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
......@@ -80,10 +81,11 @@ int main(int argc, char* argv[])
std::string d_data = "";
std::string a_data = "";
std::vector<Poco::Net::IPAddress> groups;
bool loopback = false;
while(1)
{
opt = getopt_long(argc, argv, "hs:c:r:p:n:t:x:blvdz:y:a:i:g:", longopts, &optindex);
opt = getopt_long(argc, argv, "hbs:c:r:p:n:t:x:blvdz:y:a:i:g:", longopts, &optindex);
if( opt == -1 )
break;
......@@ -96,6 +98,7 @@ int main(int argc, char* argv[])
cout << "[-c|--data-count] num - Send num count of value. Default: 50." << endl;
cout << "[-r|--receive] host:port - Receive message." << endl;
cout << "[-g|--group] ip - Multicast group address (can be specified many times)" << endl;
cout << "[-b|--loopback] - Enable multicast loopback." << endl;
cout << "[-p|--proc-id] id - Set packet header. From 'procID'. Default: 1" << endl;
cout << "[-n|--node-id] id - Set packet header. From 'nodeID'. Default: 1" << endl;
cout << "[-t|--timeout] msec - timeout for receive. Default: 0 msec (waitup)." << endl;
......@@ -132,6 +135,10 @@ int main(int argc, char* argv[])
tout = atoi(optarg);
break;
case 'b':
loopback = true;
break;
case 'x':
usecpause = atoi(optarg) * 1000;
break;
......@@ -230,6 +237,14 @@ int main(int argc, char* argv[])
udp.createConnection(true, 500, true);
if( loopback )
udp.setLoopBack(true);
msleep(5000);
udp.disconnect();
return 0;
UniSetUDP::UDPMessage pack;
UniSetUDP::UDPPacket buf;
unsigned long prev_num = 1;
......
......@@ -62,6 +62,10 @@ namespace uniset
Poco::Net::MulticastSocket(Poco::Net::IPAddress::IPv4)
{}
MulticastSocketU( int port ):
Poco::Net::MulticastSocket(Poco::Net::SocketAddress(Poco::Net::IPAddress(), port), true)
{}
MulticastSocketU( const std::string& bind, int port ):
Poco::Net::MulticastSocket(Poco::Net::SocketAddress(bind, port), true)
{}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment