NetworkAddress::NetworkAddress (string const &server) { auto off = server.find(':'); if (off == server.npos || off + 1 >= server.size()) { h = server; p = -1; } else { h = server.substr(0, off); p = boost::lexical_cast<int>(server.substr(off+1)); } // translate hostname to IP address struct in_addr in; int r = inet_aton(h.c_str(), &in); if (r == 0) { // invalid IP address, use getent to convert to IP address string cmd(format("getent ahostsv4 %s", h)); FILE *fp = popen(cmd.c_str(), "r"); BOOST_VERIFY(fp); char line[4000]; while (fgets(line, 4000, fp)) { if (strstr(line, "STREAM") && strstr(line, h.c_str())) { char *sp = strchr(line, ' '); string ip(line, sp); LOG(info) << "IP resolving " << h << " to " << ip; h = ip; break; } } pclose(fp); } }
void set_current_thread_data(detail::thread_data_base* new_data) { boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key); if (current_thread_tls_key!=TLS_OUT_OF_INDEXES) { BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data)); } else { // If we attempted to set the data to a null pointer, don't flag an error. // This happens at shutdown, where boost has a race between thread and // process exit handlers. BOOST_VERIFY(!new_data); //boost::throw_exception(thread_resource_error()); } }
BOOST_LOG_API bool once_block_sentry::enter_once_block() const { AcquireSRWLockExclusive(&g_OnceBlockMutex); once_block_flag volatile& flag = m_Flag; while (flag.status != once_block_flag::initialized) { if (flag.status == once_block_flag::uninitialized) { flag.status = once_block_flag::being_initialized; ReleaseSRWLockExclusive(&g_OnceBlockMutex); // Invoke the initializer block return false; } else { while (flag.status == once_block_flag::being_initialized) { BOOST_VERIFY(SleepConditionVariableSRW( &g_OnceBlockCond, &g_OnceBlockMutex, INFINITE, 0)); } } } ReleaseSRWLockExclusive(&g_OnceBlockMutex); return true; }
// reset buffer chain to initial state void disable() { if (enabled) { BOOST_VERIFY(&buffer_data == sink.chain_buffering(prev_buffer)); enabled = false; } }
int UDPSocket::recv(void * data, int size) { int bytes; struct sockaddr_storage saddr; socklen_t length = sizeof (saddr); BOOST_ASSERT(data != NULL); BOOST_ASSERT(sock >= 0); bytes = ::recvfrom(sock, data, size, 0, (struct sockaddr *) &saddr, &length); // TODO: Implement status error (eg. Conn closed, ...) if (bytes < 0) throw ErrException("UDPSocket", "recvfrom"); if (bytes == 0) { //Socket is now closed BOOST_VERIFY(sock < 0); return 0; } /** * recv doesn't set the after-the-last byte to zero. We must do it to * avoid some issues. * (writing into a prefilled longer data buffer f***s everything up) */ if (bytes < size) ((char*) data)[bytes] = 0; lastRecvAddr = SockAddress((const sockaddr *) &saddr); return bytes; }
void PGMImageWriter::beginOfImage(int cols, int rows) { _cols = cols; _outputRow = pgm_allocrow(cols); BOOST_VERIFY(_outputRow != NULL); pgm_writepgminit(_output, cols, rows, 255, 1); }
void release_shared_waiters(state_data old_state) { if(old_state.shared_waiting || old_state.exclusive_waiting) { BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[unlock_sem],old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0); } }
virtual void rebuild () { // insert must not happen at this time if (flavor == KGRAPH_LINEAR) { BOOST_VERIFY(indexed_size == 0); return; } if (entries.size() == indexed_size) return; if (flavor == KGRAPH_LITE) { indexed_size = 0; delete kg_index; kg_index = nullptr; return; } KGraph *kg = nullptr; if (entries.size() >= min_index_size) { kg = KGraph::create(); LOG(info) << "Rebuilding index for " << entries.size() << " features."; IndexOracle oracle(this, index_params_l1); kg->build(oracle, index_params, NULL); LOG(info) << "Swapping on new index..."; } indexed_size = entries.size(); std::swap(kg, kg_index); if (kg) { delete kg; } }
void test_on_the_fly_merge (const Container & values) { using nested_container_type = typename Container::value_type; std::vector<boost::iterator_range<typename nested_container_type::const_iterator>> ranges; boost::for_each(values, [& ranges] (const nested_container_type & values) { ranges.push_back(boost::make_iterator_range(values)); }); clock_t merge_time = clock(); auto merged_range = burst::merge(boost::make_iterator_range(ranges)); auto distance = static_cast<std::size_t>(std::distance(merged_range.begin(), merged_range.end())); merge_time = clock() - merge_time; BOOST_VERIFY ( distance == std::accumulate(values.begin(), values.end(), 0ul, [] (std::size_t current_value, const nested_container_type & vector) { return current_value + vector.size(); }) ); std::cout << "Слияние на лету:" << std::endl; std::cout << "\t" << static_cast<double>(merge_time) / CLOCKS_PER_SEC << std::endl; std::cout << std::endl; }
void cleanup() { if(handle_to_manage && handle_to_manage!=invalid_handle_value) { BOOST_VERIFY(CloseHandle(handle_to_manage)); } }
void SegmentFetcher::sendInterest(uint64_t segNum, const Interest& interest, bool isRetransmission) { weak_ptr<SegmentFetcher> weakSelf = m_this; ++m_nSegmentsInFlight; auto pendingInterest = m_face.expressInterest(interest, [this, weakSelf] (const Interest& interest, const Data& data) { afterSegmentReceivedCb(interest, data, weakSelf); }, [this, weakSelf] (const Interest& interest, const lp::Nack& nack) { afterNackReceivedCb(interest, nack, weakSelf); }, nullptr); auto timeout = m_options.useConstantInterestTimeout ? m_options.maxTimeout : getEstimatedRto(); auto timeoutEvent = m_scheduler.schedule(timeout, [this, interest, weakSelf] { afterTimeoutCb(interest, weakSelf); }); if (isRetransmission) { updateRetransmittedSegment(segNum, pendingInterest, timeoutEvent); return; } PendingSegment pendingSegment{SegmentState::FirstInterest, time::steady_clock::now(), pendingInterest, timeoutEvent}; bool isNew = m_pendingSegments.emplace(segNum, std::move(pendingSegment)).second; BOOST_VERIFY(isNew); m_highInterest = segNum; }
void JpegPayload::setMbz(boost::uint8_t mbz) { boost::uint_t<MBZ_BIT_SIZE>::fast MbzMaxValue = boost::low_bits_mask_t<MBZ_BIT_SIZE>::sig_bits; BOOST_VERIFY(mbz <= MbzMaxValue); m_mbz = mbz; }
void set_current_thread_data(detail::thread_data_base* new_data) { boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key); #if BOOST_PLAT_WINDOWS_RUNTIME current_thread_data_base = new_data; #else if (current_thread_tls_key != TLS_OUT_OF_INDEXES) { BOOST_VERIFY(TlsSetValue(current_thread_tls_key, new_data)); } else { BOOST_VERIFY(false); //boost::throw_exception(thread_resource_error()); } #endif }
void JpegPayload::setRestartInterval(boost::uint16_t restart_interval) { boost::uint_t<RESTART_INTERVAL_BIT_SIZE>::fast RestartIntervalMaxValue = boost::low_bits_mask_t<RESTART_INTERVAL_BIT_SIZE>::sig_bits; BOOST_VERIFY(restart_interval <= RestartIntervalMaxValue); m_restart_interval = restart_interval; }
void JpegPayload::setLength(boost::uint16_t length) { boost::uint_t<LENGTH_BIT_SIZE>::fast LengthMaxValue = boost::low_bits_mask_t<LENGTH_BIT_SIZE>::sig_bits; BOOST_VERIFY(length <= LengthMaxValue); m_length = length; }
inline typename boost::log::basic_core< CharT >::record_type make_record( boost::log::basic_attribute_set< CharT > const& src_attrs) { BOOST_VERIFY(!!aux::make_record_sink_holder< CharT >::instance); // to force sink registration typedef boost::log::basic_core< CharT > core_type; return core_type::get()->open_record(src_attrs); }
void JpegPayload::setWidth(boost::uint8_t width) { boost::uint_t<WIDTH_BIT_SIZE>::fast WidthMaxValue = boost::low_bits_mask_t<WIDTH_BIT_SIZE>::sig_bits; BOOST_VERIFY(width <= WidthMaxValue); m_width = width; }
void JpegPayload::setQ(boost::uint8_t q) { boost::uint_t<Q_BIT_SIZE>::fast QMaxValue = boost::low_bits_mask_t<Q_BIT_SIZE>::sig_bits; BOOST_VERIFY(q <= QMaxValue); m_q = q; }
void JpegPayload::setType(boost::uint8_t type) { boost::uint_t<TYPE_BIT_SIZE>::fast TypeMaxValue = boost::low_bits_mask_t<TYPE_BIT_SIZE>::sig_bits; BOOST_VERIFY(type <= TypeMaxValue); m_type = type; }
void JpegPayload::setFragmentOffset(boost::uint32_t fragment_offset) { boost::uint_t<FRAGMENT_OFFSET_BIT_SIZE>::fast FragmentOffsetMaxValue = boost::low_bits_mask_t<FRAGMENT_OFFSET_BIT_SIZE>::sig_bits; BOOST_VERIFY(fragment_offset <= FragmentOffsetMaxValue); m_fragment_offset = fragment_offset; }
void JpegPayload::setTypeSpecific(boost::uint8_t type_specific) { boost::uint_t<TYPE_SPECIFIC_BIT_SIZE>::fast TypeSpecificMaxValue = boost::low_bits_mask_t<TYPE_SPECIFIC_BIT_SIZE>::sig_bits; BOOST_VERIFY(type_specific <= TypeSpecificMaxValue); m_type_specific = type_specific; }
void JpegPayload::setRestartCount(boost::uint16_t restart_count) { boost::uint_t<RESTART_COUNT_BIT_SIZE>::fast RestartCountMaxValue = boost::low_bits_mask_t<RESTART_COUNT_BIT_SIZE>::sig_bits; BOOST_VERIFY(restart_count <= RestartCountMaxValue); m_restart_count = restart_count; }
void JpegPayload::setPrecision(boost::uint8_t precision) { boost::uint_t<PRECISION_BIT_SIZE>::fast PrecisionMaxValue = boost::low_bits_mask_t<PRECISION_BIT_SIZE>::sig_bits; BOOST_VERIFY(precision <= PrecisionMaxValue); m_precision = precision; }
void JpegPayload::setHeight(boost::uint8_t height) { boost::uint_t<HEIGHT_BIT_SIZE>::fast HeightMaxValue = boost::low_bits_mask_t<HEIGHT_BIT_SIZE>::sig_bits; BOOST_VERIFY(height <= HeightMaxValue); m_height = height; }
void set_current_thread_data(detail::thread_data_base* new_data) { boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key); if(current_thread_tls_key) BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data)); else boost::throw_exception(thread_resource_error()); }
void call_once(once_flag& flag,Function f) { static riakboost::uintmax_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE; static riakboost::uintmax_t const being_initialized=uninitialized_flag+1; riakboost::uintmax_t const epoch=flag.epoch; riakboost::uintmax_t& this_thread_epoch=detail::get_once_per_thread_epoch(); if(epoch<this_thread_epoch) { pthread::pthread_mutex_scoped_lock lk(&detail::once_epoch_mutex); while(flag.epoch<=being_initialized) { if(flag.epoch==uninitialized_flag) { flag.epoch=being_initialized; #ifndef BOOST_NO_EXCEPTIONS try { #endif pthread::pthread_mutex_scoped_unlock relocker(&detail::once_epoch_mutex); f(); #ifndef BOOST_NO_EXCEPTIONS } catch(...) { flag.epoch=uninitialized_flag; BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv)); throw; } #endif flag.epoch=--detail::once_global_epoch; BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv)); } else { while(flag.epoch==being_initialized) { BOOST_VERIFY(!pthread_cond_wait(&detail::once_epoch_cv,&detail::once_epoch_mutex)); } } } this_thread_epoch=detail::once_global_epoch; } }
void lock() { boost::pthread::pthread_mutex_scoped_lock const local_lock(&m); while(is_locked) { BOOST_VERIFY(!pthread_cond_wait(&cond,&m)); } is_locked=true; }
void unlock() { int ret; do { ret = pthread_mutex_unlock(&m); } while (ret == EINTR); BOOST_VERIFY(!ret); }
void unlock() { boost::pthread::pthread_mutex_scoped_lock const local_lock(&m); if(!--count) { is_locked=false; } BOOST_VERIFY(!pthread_cond_signal(&cond)); }
void OverrideConfig (std::vector<std::string> const &overrides, Config *config) { for (std::string const &D: overrides) { size_t o = D.find("="); if (o == D.npos || o == 0 || o + 1 >= D.size()) { std::cerr << "Bad parameter: " << D << std::endl; BOOST_VERIFY(0); } config->put<std::string>(D.substr(0, o), D.substr(o + 1)); } }