Skip to content

Commit

Permalink
Merge branch 'develop' into http-server
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan committed Jun 19, 2017
2 parents d4d131d + 2789b75 commit 961adb1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 55 deletions.
33 changes: 15 additions & 18 deletions jb/cpu_set.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "jb/cpu_set.hpp"
#include <jb/strtonum.hpp>

#include <boost/tokenizer.hpp>

#include <iostream>
#include <sstream>
#include <stdexcept>
Expand All @@ -26,26 +24,25 @@ jb::cpu_set& jb::cpu_set::clear(int cpulo, int cpuhi) {
jb::cpu_set jb::cpu_set::parse(std::string const& value) {
cpu_set tmp;

typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
tokenizer tok(value, boost::char_separator<char>(","));
std::vector<std::string> range;
for (auto const& r : tok) {
tokenizer num(r, boost::char_separator<char>("-"));
range.assign(num.begin(), num.end());
if (range.size() == 1) {
std::string element;
for (std::istringstream is(value);
is.good() and std::getline(is, element, ',');) {
std::istringstream el(element);
std::string lo, hi;
std::getline(el, lo, '-');
if (el.eof()) {
int cpu;
if (not jb::strtonum(range[0], cpu)) {
if (not jb::strtonum(lo, cpu)) {
parse_error(value);
}
tmp.set(cpu);
} else if (range.size() == 2) {
int cpulo, cpuhi;
if (not jb::strtonum(range[0], cpulo)) {
parse_error(value);
}
if (not jb::strtonum(range[1], cpuhi)) {
parse_error(value);
}
continue;
}
if (not std::getline(el, hi, '-') or not el.eof()) {
parse_error(value);
}
int cpulo, cpuhi;
if (jb::strtonum(lo, cpulo) and jb::strtonum(hi, cpuhi)) {
tmp.set(cpulo, cpuhi);
} else {
parse_error(value);
Expand Down
4 changes: 2 additions & 2 deletions jb/cpu_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace jb {
* The iostream operators (used for tests, and conversions everywhere)
* use this format.
*
* TODO(JB-54) this is a portability problem. Many platforms can
* TODO(#151) this is a portability problem. Many platforms can
* specify cpu affinity, but they all use different constructs for
* it.
* TODO(JB-54) we only support up to CPU_SETSIZE cpus, it is possible
* TODO(#152) we only support up to CPU_SETSIZE cpus, it is possible
* to control more CPUs in Linux, but the application that has access
* to more than 1024 cpus is rare indeed.
*/
Expand Down
3 changes: 2 additions & 1 deletion jb/ut_config_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ class config4 : public jb::config_object {
*/
BOOST_AUTO_TEST_CASE(config_object_nested_by_class) {
char const contents[] = R"""(# YAML overrides
# This override applies to all objects of type config0, wherever they are found...
# This override applies to all objects of type config0, wherever
# they are found...
:config0:
x: -1
y: -1
Expand Down
70 changes: 36 additions & 34 deletions tools/itch5inside.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,47 +78,49 @@ void run_inside(config const& cfg, cfg_book_t const& cfg_book) {

using callback_type =
typename jb::itch5::compute_book<book_type_t>::callback_type;
callback_type cb = [&stats, &out, stop_after](
jb::itch5::message_header const& header,
jb::itch5::order_book<book_type_t> const& updated_book,
jb::itch5::book_update const& update) {
if (stop_after != std::chrono::seconds(0) and
stop_after <= header.timestamp.ts) {
throw abort_process_iostream{};
}
auto pl = std::chrono::steady_clock::now() - update.recvts;
(void)jb::itch5::generate_inside(
stats, out, header, updated_book, update, pl);
};
callback_type cb = std::move(
[&stats, &out, stop_after](
jb::itch5::message_header const& header,
jb::itch5::order_book<book_type_t> const& updated_book,
jb::itch5::book_update const& update) {
if (stop_after != std::chrono::seconds(0) and
stop_after <= header.timestamp.ts) {
throw abort_process_iostream{};
}
auto pl = std::chrono::steady_clock::now() - update.recvts;
(void)jb::itch5::generate_inside(
stats, out, header, updated_book, update, pl);
});

if (cfg.enable_symbol_stats()) {
// ... replace the calback with one that also records the stats
// for each symbol ...
jb::offline_feed_statistics::config symcfg(cfg.symbol_stats());
cb = [&stats, &out, &per_symbol, symcfg, stop_after](
jb::itch5::message_header const& header,
jb::itch5::order_book<book_type_t> const& updated_book,
jb::itch5::book_update const& update) {
if (stop_after != std::chrono::seconds(0) and
stop_after <= header.timestamp.ts) {
throw abort_process_iostream{};
}
auto pl = std::chrono::steady_clock::now() - update.recvts;
if (not jb::itch5::generate_inside(
stats, out, header, updated_book, update, pl)) {
return;
}
auto location = per_symbol.find(update.stock);
if (location == per_symbol.end()) {
auto p = per_symbol.emplace(
update.stock, jb::offline_feed_statistics(symcfg));
location = p.first;
}
location->second.sample(header.timestamp.ts, pl);
};
cb = std::move(
[&stats, &out, &per_symbol, symcfg, stop_after](
jb::itch5::message_header const& header,
jb::itch5::order_book<book_type_t> const& updated_book,
jb::itch5::book_update const& update) {
if (stop_after != std::chrono::seconds(0) and
stop_after <= header.timestamp.ts) {
throw abort_process_iostream{};
}
auto pl = std::chrono::steady_clock::now() - update.recvts;
if (not jb::itch5::generate_inside(
stats, out, header, updated_book, update, pl)) {
return;
}
auto location = per_symbol.find(update.stock);
if (location == per_symbol.end()) {
auto p = per_symbol.emplace(
update.stock, jb::offline_feed_statistics(symcfg));
location = p.first;
}
location->second.sample(header.timestamp.ts, pl);
});
}

jb::itch5::compute_book<book_type_t> handler(cb, cfg_book);
jb::itch5::compute_book<book_type_t> handler(std::move(cb), cfg_book);
try {
jb::itch5::process_iostream(in, handler);
} catch (abort_process_iostream const&) {
Expand Down

0 comments on commit 961adb1

Please sign in to comment.