Пример #1
0
		void IPNDAgent::eventNotify(const ibrcommon::LinkEvent &evt)
		{
			// check first if we are really bound to the interface
			{
				ibrcommon::MutexLock l(_interface_lock);
				if (_interfaces.find(evt.getInterface()) == _interfaces.end()) return;
			}

			switch (evt.getAction())
			{
				case ibrcommon::LinkEvent::ACTION_ADDRESS_ADDED:
				{
					const ibrcommon::vaddress &bindaddr = evt.getAddress();
					ibrcommon::udpsocket *sock = new ibrcommon::udpsocket(bindaddr);
					try {
						sock->up();
						_send_socket.add(sock, evt.getInterface());
						join_interface(evt.getInterface());
					} catch (const ibrcommon::socket_exception&) {
						delete sock;
					}
					break;
				}

				case ibrcommon::LinkEvent::ACTION_ADDRESS_REMOVED:
				{
					ibrcommon::socketset socks = _send_socket.get(evt.getInterface());
					for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
						ibrcommon::udpsocket *sock = dynamic_cast<ibrcommon::udpsocket*>(*iter);
						if (sock->get_address().address() == evt.getAddress().address()) {
							// leave interfaces if a interface is totally gone
							if (socks.size() == 1) {
								leave_interface(evt.getInterface());
							}

							_send_socket.remove(sock);
							sock->down();
							delete sock;
							break;
						}
					}
					break;
				}

				case ibrcommon::LinkEvent::ACTION_LINK_DOWN:
				{
					// leave the multicast groups on the interface
					leave_interface(evt.getInterface());

					// remove all sockets on this interface
					unlisten(evt.getInterface());
					break;
				}

				default:
					break;
			}
		}
Пример #2
0
		void IPNDAgent::eventNotify(const ibrcommon::LinkEvent &evt)
		{
			// check first if we are really bound to the interface
			{
				ibrcommon::MutexLock l(_interface_lock);
				if (_interfaces.find(evt.getInterface()) == _interfaces.end()) return;
			}

			switch (evt.getAction())
			{
				case ibrcommon::LinkEvent::ACTION_ADDRESS_ADDED:
				{
					ibrcommon::vaddress addr = evt.getAddress();
					join(evt.getInterface(), addr);
					break;
				}

				case ibrcommon::LinkEvent::ACTION_ADDRESS_REMOVED:
				{
					ibrcommon::vaddress addr = evt.getAddress();
					leave(evt.getInterface(), addr);
					break;
				}

				default:
					break;
			}
		}