// this has to be thread safe and atomic. i.e. on posix systems it has to be // turned into a series of pread() calls std::int64_t file::readv(std::int64_t file_offset, span<iovec_t const> bufs , error_code& ec, open_mode_t flags) { if (m_file_handle == INVALID_HANDLE_VALUE) { #ifdef TORRENT_WINDOWS ec = error_code(ERROR_INVALID_HANDLE, system_category()); #else ec = error_code(boost::system::errc::bad_file_descriptor, generic_category()); #endif return -1; } TORRENT_ASSERT((m_open_mode & open_mode::rw_mask) == open_mode::read_only || (m_open_mode & open_mode::rw_mask) == open_mode::read_write); TORRENT_ASSERT(!bufs.empty()); TORRENT_ASSERT(is_open()); #if TORRENT_USE_PREADV TORRENT_UNUSED(flags); std::int64_t ret = iov(&::preadv, native_handle(), file_offset, bufs, ec); #else // there's no point in coalescing single buffer writes if (bufs.size() == 1) { flags &= ~open_mode::coalesce_buffers; } iovec_t tmp; span<iovec_t const> tmp_bufs = bufs; if (flags & open_mode::coalesce_buffers) { if (!coalesce_read_buffers(tmp_bufs, tmp)) // ok, that failed, don't coalesce this read flags &= ~open_mode::coalesce_buffers; } #if TORRENT_USE_PREAD std::int64_t ret = iov(&::pread, native_handle(), file_offset, tmp_bufs, ec); #else std::int64_t ret = iov(&::read, native_handle(), file_offset, tmp_bufs, ec); #endif if (flags & open_mode::coalesce_buffers) coalesce_read_buffers_end(bufs , tmp.data(), !ec); #endif return ret; }
int SpdyStream::writev(IOVec &vector, int total) { int size; int ret; if (getState() == HIOS_DISCONNECTED) return LS_FAIL; if (getFlag(HIO_FLAG_BUFF_FULL)) return 0; size = getDataFrameSize(total); if (size <= 0) return 0; if (size < total) { //adjust vector IOVec iov(vector); total = iov.shrinkTo(size, 0); ret = sendData(&iov, size); } else ret = sendData(&vector, size); if (ret == -1) return LS_FAIL; return size; }
int cond::ListIOVUtilities::execute(){ initializePluginManager(); bool listAll = hasOptionValue("all"); cond::DbSession session = openDbSession( "connect", true ); if( listAll ){ cond::MetaData metadata_svc(session); std::vector<std::string> alltags; cond::DbScopedTransaction transaction(session); transaction.start(true); metadata_svc.listAllTags(alltags); transaction.commit(); std::copy (alltags.begin(), alltags.end(), std::ostream_iterator<std::string>(std::cout,"\n") ); }else{ std::string tag = getOptionValue<std::string>("tag"); cond::MetaData metadata_svc(session); std::string token; cond::DbScopedTransaction transaction(session); transaction.start(true); token=metadata_svc.getToken(tag); transaction.commit(); { bool verbose = hasOptionValue("verbose"); bool details = hasOptionValue("summary"); TFile * xml=0; if (details) { xml = TFile::Open(std::string(tag+".xml").c_str(),"recreate"); } cond::IOVProxy iov( session, token, !details, details); unsigned int counter=0; std::string payloadContainer=iov.payloadContainerName(); std::cout<<"Tag "<<tag; if (verbose) std::cout << "\nStamp: " << iov.iov().comment() << "; time " << cond::time::to_boost(iov.iov().timestamp()) << "; revision " << iov.iov().revision(); std::cout <<"\nTimeType " << cond::timeTypeSpecs[iov.timetype()].name <<"\nPayloadContainerName "<<payloadContainer<<"\n" <<"since \t till \t payloadToken"<<std::endl; for (cond::IOVProxy::const_iterator ioviterator=iov.begin(); ioviterator!=iov.end(); ioviterator++) { std::cout<<ioviterator->since() << " \t "<<ioviterator->till() <<" \t "<<ioviterator->wrapperToken(); if (details) { ora::Object obj = session.getObject(ioviterator->wrapperToken()); std::ostringstream ss; ss << tag << '_' << ioviterator->since(); xml->WriteObjectAny(obj.address(),obj.typeName().c_str(), ss.str().c_str()); obj.destruct(); } std::cout<<std::endl; ++counter; } if (xml) xml->Close(); std::cout<<"Total # of payload objects: "<<counter<<std::endl; } } return 0; }
int BufferedOS::writeEx(const char *pBuf, int size, int avoidCache) { assert(m_pOS != NULL); int ret = 0; if (m_buf.empty()) { ret = m_pOS->write(pBuf, size); if ((ret < size) && (ret >= avoidCache)) ret = m_buf.cache(pBuf, size, ret); // LS_DBG_H( "bufferedOS::write() return %d, %d bytes in cache\n", ret, m_buf.size()); return ret; } else { IOVec iov(pBuf, size); return writevEx(iov, avoidCache); } }
int BufferedOS::writeEx( const char * pBuf, int size, int avoidCache ) { assert( m_pOS != NULL ); int ret = 0; if ( m_buf.empty() ) { ret = m_pOS->write( pBuf, size ); if ( ret >= avoidCache ) { ret = m_buf.cache( pBuf, size, ret ); } // if ( D_ENABLED( DL_MORE ) ) // LOG_D(( "bufferedOS::write() return %d, %d bytes in cache\n", ret, m_buf.size() )); return ret; } else { IOVec iov( pBuf, size ); return writevEx( iov, avoidCache ); } }
int SpdyStream::writev(const struct iovec *vec, int count) { IOVec iov(vec, count); return writev(iov.get(), iov.bytes()); }
int BufferedOS::writev(const struct iovec *vector, int len) { IOVec iov(vector, len); return writevEx(iov, 1); }
// This has to be thread safe, i.e. atomic. // that means, on posix this has to be turned into a series of // pwrite() calls std::int64_t file::writev(std::int64_t file_offset, span<iovec_t const> bufs , error_code& ec, open_mode_t flags) { if (m_file_handle == INVALID_HANDLE_VALUE) { #ifdef TORRENT_WINDOWS ec = error_code(ERROR_INVALID_HANDLE, system_category()); #else ec = error_code(boost::system::errc::bad_file_descriptor, generic_category()); #endif return -1; } TORRENT_ASSERT((m_open_mode & open_mode::rw_mask) == open_mode::write_only || (m_open_mode & open_mode::rw_mask) == open_mode::read_write); TORRENT_ASSERT(!bufs.empty()); TORRENT_ASSERT(is_open()); ec.clear(); #if TORRENT_USE_PREADV TORRENT_UNUSED(flags); std::int64_t ret = iov(&::pwritev, native_handle(), file_offset, bufs, ec); #else // there's no point in coalescing single buffer writes if (bufs.size() == 1) { flags &= ~open_mode::coalesce_buffers; } iovec_t tmp; if (flags & open_mode::coalesce_buffers) { if (!coalesce_write_buffers(bufs, tmp)) // ok, that failed, don't coalesce writes flags &= ~open_mode::coalesce_buffers; } #if TORRENT_USE_PREAD std::int64_t ret = iov(&::pwrite, native_handle(), file_offset, bufs, ec); #else std::int64_t ret = iov(&::write, native_handle(), file_offset, bufs, ec); #endif if (flags & open_mode::coalesce_buffers) delete[] tmp.data(); #endif #if TORRENT_USE_FDATASYNC \ && !defined F_NOCACHE && \ !defined DIRECTIO_ON if (m_open_mode & open_mode::no_cache) { if (::fdatasync(native_handle()) != 0 && errno != EINVAL && errno != ENOSYS) { ec.assign(errno, system_category()); } } #endif return ret; }
int main(int csize, char** cline ) { seal::PluginManager::get()->initialise(); seal::TimingReport timRep; try { // Loads the seal message stream LockMutex::Mutex mutex; pool::POOLContext::loadComponent( "SEAL/Services/MessageService" ); pool::POOLContext::loadComponent( "POOL/Services/EnvironmentAuthenticationService" ); pool::URIParser p; p.parse(); pool::IFileCatalog lcat; pool::IFileCatalog * cat = &lcat; cat->setWriteCatalog(p.contactstring()); cat->connect(); cat->start(); own_ptr<pool::IPersistencySvc> oriper; own_ptr<pool::IPersistencySvc> safeper; own_ptr<pool::IDataSvc> datasvc; // Persil::TCPGetter tcpGetter; Persil::TCPGetterFactory tcpGetter; pool::IPersistencySvcFactory* psfactory = pool::IPersistencySvcFactory::get(); oriper.reset(psfactory->create( "PersistencySvc", lcat )); safeper.reset(new StreamPersistencySvc(*oriper.get(), tcpGetter, mutex)); datasvc.reset(pool::DataSvcFactory::instance(safeper.get())); pool::IDataSvc *svc = datasvc.get(); Persil::currentCache() = &svc->cacheSvc(); svc->transaction().start(pool::ITransaction::READ); if (csize==2) { // peds std::string iovToken(cline[1]); svc->transaction().start(pool::ITransaction::READ); pool::Ref<CalibTests::IOV> iov(svc,iovToken); std::cout << "first iov " << (*iov->iov.begin()).first << " " << (*iov->iov.begin()).second << std::endl; std::cout << "last iov " << (*iov->iov.rbegin()).first << " " << (*iov->iov.rbegin()).second << std::endl; for (int t=253; t<290; t+=15) { std::cout << "at time " << t << " used " << (*iov->iov.lower_bound(t)).first << std::endl; std::string pedCid = (*iov->iov.lower_bound(t)).second; std::cout << "ped Cid " << pedCid << std::endl; pool::Ref<CalibTests::SimplePedestals> peds(svc,pedCid); std::cout << "peds size " << peds->m_pedestals.size() << std::endl; int l=2000; int le=2050; std::cout << "peds from " << l; for (CalibTests::SimplePedestals::ItemIterator p= peds->m_pedestals.begin()+l; p!= peds->m_pedestals.begin()+le;p++) std::cout << " " << (*p).m_mean << "," << (*p).m_variance; std::cout << std::endl; } /* std::string iovToken(cline[1]); pool::Ref<CalibTests::IOV> iov(svc,iovToken); std::string pedCid = (*iov->iov.lower_bound(253)).second; std::cout << "ped Cid " << pedCid << std::endl; pool::Ref<CalibTests::Pedestals> peds(svc,pedCid); int l=2000; CalibTests::Pedestals::ItemRange r=peds->get(l); std::cout << "peds from " << l; for (CalibTests::Pedestals::ItemIterator p=r.first; p!=r.second;p++) std::cout << " " << (*p).m_mean << "," << (*p).m_variance; std::cout << std::endl; */ } if (csize==3) { // align std::string iovAToken(cline[1]); std::string iovIToken(cline[2]); pool::Ref<CalibTests::IOV> iovA(svc,iovAToken); pool::Ref<CalibTests::IOV> iovI(svc,iovIToken); std::cout << "iov size " << iovA->iov.size() << std::endl; std::string alignCid = (*iovA->iov.lower_bound(25)).second; std::string indexCid = (*iovI->iov.lower_bound(25)).second; std::cout << "align Cid " << alignCid << std::endl; std::cout << "index Cid " << indexCid << std::endl; pool::Ref<Alignments> align(svc,alignCid); pool::Ref<Geom2Index> index(svc,indexCid); Geom2Index::GeomId id=500+20+7; std::cout << "align for " << id; int i= index->m_indexTable[id]; std::cout << " " << (*align).m_align[i].translation() << "," << (*align).m_align[i].eulerAngles(); std::cout << std::endl; } svc->transaction().commit(); svc->session().disconnectAll(); std::cout << "committed" << std::endl; std::cout << "commit catalog" << std::endl; cat->commit(); } catch ( seal::Exception& e ) { std::cout << "seal error " << e.what() << std::endl; return 1; } catch ( std::exception& e ) { std::cout << "std error " << e.what() << std::endl; return 1; } catch ( ... ) { std::cout << "Funny error" << std::endl; return 1; } return 0; }