51 const std::string TCPConvergenceLayer::TAG =
"TCPConvergenceLayer";
53 const int TCPConvergenceLayer::DEFAULT_PORT = 4556;
56 : _vsocket_state(false), _any_port(0)
74 if (_any_port > 0)
return;
93 if (_interfaces.find(net) != _interfaces.end())
return;
96 _interfaces.insert(net);
105 _portmap[net] = port;
110 std::list<ibrcommon::vaddress> addrs = net.getAddresses();
113 std::stringstream ss; ss << port;
115 for (std::list<ibrcommon::vaddress>::iterator iter = addrs.begin(); iter != addrs.end(); ++iter) {
127 if (_vsocket_state) sock->
up();
128 _vsocket.add(sock, net);
150 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
152 _vsocket.remove(sock);
163 _portmap.erase(iface);
179 if (_interfaces.empty() && (_any_port > 0)) {
180 std::stringstream service;
183 service <<
"port=" << _portmap[iface] <<
";";
192 bool announced =
false;
195 for (std::set<ibrcommon::vinterface>::const_iterator it = _interfaces.begin(); it != _interfaces.end(); ++it)
198 if (it_iface == iface)
205 std::list<ibrcommon::vaddress> list = it_iface.
getAddresses();
210 for (std::list<ibrcommon::vaddress>::const_iterator addr_it = list.begin(); addr_it != list.end(); ++addr_it)
218 sa_family_t f = addr.
family();
219 if ((f != AF_INET) && (f != AF_INET6))
continue;
221 std::stringstream service;
224 service <<
"ip=" << addr.
address() <<
";port=" << _portmap[iface] <<
";";
240 std::stringstream service;
243 service <<
"port=" << _portmap[iface] <<
";";
255 return TCPConvergenceLayer::TAG;
268 listen(dialup.
iface, 4556);
279 if (_interfaces.find(dialup.
iface) == _interfaces.end())
return;
282 _interfaces.erase(dialup.
iface);
289 unlisten(dialup.
iface);
293 }
catch (std::bad_cast&) {
301 if (_any_port > 0)
return;
305 if (_interfaces.find(evt.
getInterface()) == _interfaces.end())
return;
315 std::stringstream ss; ss << _portmap[evt.
getInterface()];
330 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
348 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
371 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
397 _connections.push_back( conn );
403 _connections_cond.
signal(
true);
414 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
443 _connections.push_back( conn );
452 _connections_cond.
signal(
true);
463 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
472 _connections.push_back( conn );
475 _connections_cond.
signal(
true);
480 void TCPConvergenceLayer::connectionDown(
TCPConnection *conn)
483 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
487 _connections.erase(iter);
491 _connections_cond.
signal(
true);
505 _vsocket.
select(&readfds, NULL, NULL, NULL);
507 for (ibrcommon::socketset::iterator iter = readfds.begin(); iter != readfds.end(); ++iter) {
523 const std::string uri =
"ip=" + peeraddr.
address() +
";port=" + peeraddr.
service() +
";";
542 }
catch (
const std::bad_cast&) {
550 }
catch (
const std::exception&) {
561 void TCPConvergenceLayer::closeAll()
565 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
583 _vsocket_state =
true;
598 _vsocket_state =
false;
609 while (_connections.size() > 0) _connections_cond.
wait();
622 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
631 addStats(
"out", out);
633 return ConvergenceLayer::getStats();
636 void TCPConvergenceLayer::resetStats()
641 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)