Changeset 4866 for source/ariba/utility/bootstrap/modules
- Timestamp:
- Jul 13, 2009, 9:42:32 AM (15 years ago)
- Location:
- source/ariba/utility/bootstrap/modules/periodicbroadcast
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.cpp
r4853 r4866 59 59 use_logging_cpp(PeriodicBroadcast); 60 60 const long PeriodicBroadcast::timerinterval = 1000; 61 const long PeriodicBroadcast::servicetimeout = 3000; 61 62 const unsigned int PeriodicBroadcast::serverport_v4 = 5634; 62 63 const unsigned int PeriodicBroadcast::serverport_v6 = 5636; … … 130 131 void PeriodicBroadcast::updateRemoteServices(){ 131 132 133 // cleanup the services that timed out 134 // so they are seen of as new after timeout 135 { 136 boost::mutex::scoped_lock lock( remoteServicesMutex ); 137 bool deleted; 138 139 do { 140 deleted = false; 141 142 ServiceList::iterator i = remoteServices.begin(); 143 ServiceList::iterator iend = remoteServices.end(); 144 145 for( ; i != iend; i++ ){ 146 147 if( time(NULL) > (i->second.lastseen + servicetimeout) ){ 148 remoteServices.erase( i ); 149 deleted = true; 150 break; 151 } 152 } 153 154 }while(deleted); 155 } 156 157 // check if we received new services: 158 // check remoteServices against newRemoteServices 159 { 160 boost::mutex::scoped_lock lock( newRemoteServicesMutex ); 161 typedef std::pair<string,Service> mapitem; 162 163 BOOST_FOREACH( mapitem item, newRemoteServices ){ 164 165 string name = item.first; 166 Service service = item.second; 167 168 ServiceList::iterator i = remoteServices.find( name ); 169 if( i != remoteServices.end() ) { 170 // update the item lastseen time 171 i->second.lastseen = service.lastseen; 172 continue; 173 } 174 175 { 176 // insert the new item as new, lastseen has been set in the 177 // receive function, as this timer only runs in intervals 178 boost::mutex::scoped_lock lock2( remoteServicesMutex ); 179 remoteServices.insert( std::make_pair(name, service) ); 180 } 181 182 callback->onBootstrapServiceFound(name, service.info1, service.info2, service.info3); 183 } 184 185 // we have checked and transfered all new items 186 newRemoteServices.clear(); 187 } 132 188 } 133 189 -
source/ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.h
r4853 r4866 44 44 #include <map> 45 45 #include <string> 46 #include <ctime> 46 47 #include <iostream> 47 48 #include <boost/asio.hpp> … … 56 57 using std::map; 57 58 using std::string; 59 using std::cout; 58 60 using boost::asio::ip::udp; 59 61 … … 83 85 void updateRemoteServices(); 84 86 85 static const long timerinterval; 87 static const long timerinterval; // used to send out updates on our services and check for new services 88 static const long servicetimeout; // timeout after that a service is dead when we did not receive updates 86 89 static const unsigned int serverport_v4; 87 90 static const unsigned int serverport_v6; … … 92 95 string info2; 93 96 string info3; 97 time_t lastseen; 98 99 _Service() 100 : name(""), info1(""), info2(""), info3(""), lastseen(0){ 101 } 94 102 } Service; 95 103 … … 133 141 Data data = data_serialize( msg, DEFAULT_V ); 134 142 uint8_t* pnt = data.getBuffer(); 135 size_t len = data.getLength() ;143 size_t len = data.getLength() / 8; 136 144 boost::system::error_code ignored_error; 145 146 cout << "-----------> sending out " << data << std::endl; 137 147 138 148 { … … 172 182 data_deserialize( msg, data ); 173 183 184 cout << "-----------> received " << data << std::endl; 185 174 186 { // insert new found service 175 187 boost::mutex::scoped_lock( *servicesmutex ); … … 182 194 s.info2 = msg.getInfo2(); 183 195 s.info3 = msg.getInfo3(); 196 s.lastseen = time(NULL); 184 197 services->insert( std::make_pair(msg.getName(), s) ); 185 198 }
Note:
See TracChangeset
for help on using the changeset viewer.