pDest DestHashFiles::getDest_( char_ptr & bucket ) { if( d_->onefd_ ) { pDest raw = d_->destFactory_->getFileDest( bucket.get()); pDest buffered( new DestBuffered( 1024, raw, false )); return buffered; } mcpd_t::iterator desti; mcpd_t::iterator deste=d_->mdest_.end(); desti=d_->mdest_.find( bucket.get() ); if( desti==deste ) { d_->names_.push_front( bucket ); char filename[FILENAME_MAX]; memset(filename,'\0', FILENAME_MAX ); snprintf(filename,FILENAME_MAX,d_->template_.get(),bucket.get()); pDest f = d_->destFactory_->getFileDest( filename ); pDest b = DestThreadedBuffer::factory( f, d_->cfg_ ); return ( *( d_->mdest_.insert( pair<const char *, pDest>( bucket.get(), b ) ).first ) ).second; } return (*desti).second ; }
void PushToSubscriberRunnable::run() { while(1) { try { // the elements method blocks on the ServiceStatusMaps's mutex ptr<Service::ServiceStatusList> pServiceStatusList = serviceStatusMap_->elements(serviceName_.get(), host_.get()); APPLOG_INFO("Pushing ServiceStatusList with %d entries to %s %s, which requested host:%s, service:%s", pServiceStatusList->length(), serviceRef_.serviceName.in(), serviceRef_.url.in(), host_.get(), serviceName_.get()); Service::NodeMonitorPushConsumer_var nodeMonitorPushConsumer ; if( ! SharedServiceMain::instance()->resolve_consumer( nodeMonitorPushConsumer, serviceRef_.ior.in()) && ! SharedServiceMain::instance()->resolve_consumer( nodeMonitorPushConsumer, serviceRef_.url.in()) ) { PANICV("could not resolve url or ior for %s.", serviceRef_.url.in()); } APPLOG_DBG("resolved reference, pushing status" ); nodeMonitorPushConsumer->pushStatusList(*pServiceStatusList); APPLOG_DBG("reset ior" ); serviceRef_.ior = SharedServiceMain::instance()->getORB()->object_to_string( nodeMonitorPushConsumer ); } catch (CORBA::Exception &ce) { //AppExceptionHandler really needs to learn about CORBA... APPLOG_ABORT("caught CORBA::Exception trying to push to subscriber %s [%s][%s]", serviceRef_.url.in(), ce._rep_id(), ce._name() ); } catch (std::exception &e) { AppExceptionHandler::instance()->handleLogOnly( e ); } catch ( ... ) { AppExceptionHandler::instance()->handleLogOnly(); } APPLOG_DBG("usleep(%d)", sleeptime_); usleep (sleeptime_); } }
inline bool Read(HANDLE Pipe, char_ptr& Data) { bool Result=false; size_t DataSize = 0; if(ReadPipe(Pipe, &DataSize, sizeof(DataSize))) { if(DataSize) { Data.reset(DataSize); if(ReadPipe(Pipe, Data.get(), DataSize)) { Result=true; } } else { Result=true; } } return Result; }
int FileHandle::readBytes (char_ptr &c) { int Length = (int) length(); if (Length == 0) Length = 512; int bufferlength = Length; char* buf = (char*) malloc(bufferlength); int position = 0; ifstream_ptr input = read(); try { while (true) { int count = 0; input->read( buf + position, Length - position); count = input->gcount(); position += count; if(input->eof() || !count || input->peek() == EOF) { break; } if (position == bufferlength) { // Grow buffer. buf = (char * ) realloc(buf, bufferlength * 2); assert(buf); bufferlength *= 2; } } } catch(std::runtime_error e) { if(input->is_open()) input->close(); throw std::runtime_error("Error reading file: " + this->toString()); } if(input->is_open()) { input->close(); } if(position < bufferlength) { buf = (char *) realloc(buf, position); assert(buf); } char_ptr new_ptr = char_ptr(buf, shared_ptr_free_deleter()); c.swap(new_ptr); return position; }