void register_service(DNSServiceRef service) { // Run until break. int dns_sd_fd = DNSServiceRefSockFD(service); fd_set readfds; struct timeval tv; int result; while (should_run()) { FD_ZERO(&readfds); FD_SET(dns_sd_fd, &readfds); tv.tv_sec = LONG_TIME; tv.tv_usec = 0; // highest fd in set + 1 result = select(dns_sd_fd+1, &readfds, (fd_set*)NULL, (fd_set*)NULL, &tv); if (result > 0) { DNSServiceErrorType err = kDNSServiceErr_NoError; // Execute callback if (FD_ISSET(dns_sd_fd, &readfds)) err = DNSServiceProcessResult(service); if (err) { // An error occured. Halt. fprintf(stderr, "DNSServiceProcessResult returned %d\n", err); quit(); } } else if (errno != EINTR) { // Error. fprintf(stderr, "ZeroConf error (%d %s)\n", errno, strerror(errno)); if (errno != EINTR) quit(); } } }
static int run_tests(struct test *tests, int argc, char **argv) { int result = EXIT_SUCCESS; list_for_each(t, tests) { if (! should_run(t->name, argc, argv)) continue; if (run_one_test(t) < 0) result = EXIT_FAILURE; } return result; }
void Backtester::run_one_step() { MatrixQuery dq = make_query(); // Get Available Data Row lp = last_price(); // Get Last price // Making public data available DataStruct ds(_price_matrix); ds.data_manager = &dq; //ds.predictors = &this->_GlobalPredictors; //ds.securities = this->_SecurityDatabase; const TransactionWeight* w; Eigen::IOFormat fmt; for(Index k = 0, n = _strategies.size(); k < n; k++) { if (should_run(k)) { // Compute Target owning w = (*get_strategy(k))(ds); // log current target log_weights(title(k), *w); // Compute effective Buy/Sell Matrix orders = get_portfolio(k)->transaction_weight(_time, lp, *w); log_orders(title(k), orders); // update portfolio state get_portfolio(k)->transaction_answer(orders, lp); // Log current holdings log_portfolio_state(title(k), get_portfolio(k)->state()); } MPortfolio& p = get_portfolio(k); // log current portfolio value log_portfolio_values(title(k), p->invested(lp), p->cash(), p->liability(lp)); } // one period has passed _time++; }