Added some documentatio, run clang-format on iLink3 code.

This commit is contained in:
Pedro Pinto committed 2020-12-30 14:22:56 -05:00
1 parent 862df2efb6
commit d8a80419eb
5 files changed
+85 -17

No files matched your search

@@ -88,7 +88,6 @@ void GLBXiLink3ExecutionGateway::dispatch_incoming_fix_messages() {
case State::READY:
case State::CONNECTING:
me->reactor.do_work();
me->gw->on_time();
break;
}
}
+7 -4
View File
@@ -224,7 +224,8 @@ bool need_px(api::orderman::NativeOrderType order_type) {
order_type != api::orderman::NativeOrderType::NATIVE_ORDER_TYPE_STOP;
}
void IL3GW::send_order(const CreateOrderMsg &create, trace::CorID const &corid) {
void IL3GW::send_order(const CreateOrderMsg &create,
trace::CorID const &corid) {
_current_corid = corid;
auto now = utils::TimeStamp::now();
LOG(Latency, Info,
@@ -286,7 +287,8 @@ void IL3GW::send_order(const CreateOrderMsg &create, trace::CorID const &corid)
log_out(msg, msg.seqNum());
}
void IL3GW::send_cancel_replace(const CancelReplaceOrderMsg &replace, trace::CorID const &corid) {
void IL3GW::send_cancel_replace(const CancelReplaceOrderMsg &replace,
trace::CorID const &corid) {
_current_corid = corid;
const auto &create = replace.create_fields;
bts_assert_d(create.routing_record);
@@ -336,7 +338,8 @@ void IL3GW::send_cancel_replace(const CancelReplaceOrderMsg &replace, trace::Cor
log_out(msg, msg.seqNum());
}
void IL3GW::send_cancel(const CancelOrderMsg &cancel,trace::CorID const &corid) {
void IL3GW::send_cancel(const CancelOrderMsg &cancel,
trace::CorID const &corid) {
_current_corid = corid;
bts_assert_d(cancel.routing_record);
bts_assert_d(cancel.security);
@@ -373,7 +376,7 @@ void IL3GW::send_terminate(uint16_t code) {
}
void IL3GW::flush(bool publish) {
_buffer.flush(_connection,_current_corid);
_buffer.flush(_connection, _current_corid);
_current_corid = {};
if (publish)
publish_session_update();
+57 -9
View File
@@ -70,37 +70,85 @@ class IL3MessageFramer;
// Does not allow re-entrance
class IL3GW : IL3ConnectionHandler {
// CME session name, firm, logging function and wheter we should
// failover on disconnect
const Config _config;
// The current State of the GW, initially INIT
State _x_state;
// A helper class used to speed up allocation of MDP3 messages as
// well as manage their batching. Because the life time of the
// allocated messages might exceeed that of the this class, the
// IL3MessageFramer is passed from the outside.
IL3MessageFramer &_buffer;
// User callbacks
OnStateChange _on_state_change;
OnExecutionReport _on_exe_report;
OnSessionChange _on_session_change;
OnCancelReject _on_cancel_reject;
// A handle to the TCP connection used to reach this gateway. This
// class manages the life cycle of the connection which is expected
// to initially *not* be established.
IL3Connection &_connection;
// The current CME iLink3 session UID and the expected sequence
// numbers incoming and outgoing
Session _session;
// A buffer used to avoid allocation when generating a clorid
std::string _clorid_buffer;
// Used to generate unique order request ids for the CME
uint32_t _msg_count;
// Helper to return MDP3 style timesamps (elapsed time in
// nanoseconds since unix epoch)
TimeKeeper _time;
// A pool of pre-allocated ExecutionReport objcets, used to avoid
// allocation when processing an execution report.
boost::object_pool<ExecutionReport> _pool;
// A helper used to turn MDP3 messages into normalized execution
// report objects
IL3Parser _exe_parser;
std::queue<Retransmit> _retransmit;
// The current correlation id, received through a send_* call and
// buffered until flush() is called
trace::CorID _current_corid;
public:
IL3GW(IL3Connection &, IL3MessageFramer &, IL3SecDB *, const Session &,
const Config &, config::JetFIX::Connection const *);
IL3GW(IL3Connection &, // The connection which this class will manageg
IL3MessageFramer &, // A helper used to manage the MDP3 buffers
// generated by this class
IL3SecDB *, // A security database, necessary to
// parse execution reports
const Session &,
const Config &, // Configuration for this gateway,
// including sessio name, firm, etc.
config::JetFIX::Connection const * // Connection details
// (host/port), etc for
// this GW. Used when
// parsing execution
// reports
);
// The GW assumes its connection is initially not established. This
// method initiates the connection process. It is an error to call
// this method unless the connection is in fact not established.
void connect();
void send_order(const CreateOrderMsg &,trace::CorID const&);
void send_cancel_replace(const CancelReplaceOrderMsg &, trace::CorID const&);
void send_cancel(const CancelOrderMsg &, trace::CorID const&);
void send_order(const CreateOrderMsg &, trace::CorID const &);
void send_cancel_replace(const CancelReplaceOrderMsg &,
trace::CorID const &);
void send_cancel(const CancelOrderMsg &, trace::CorID const &);
void send_terminate(uint16_t code = 0);
void flush(bool publish = true);
void on_time(){
// Currently we just reply to a heartbeat with another heartbeat
// Probably better to track time and send them on demand
};
// state change
State state() { return _x_state; }
@@ -15,6 +15,13 @@ struct FramingHeader {
uint16_t encoding_type;
};
// Allocate memory for MDP3 messages, accumulating them in a buffer
// until the caller invokes flush(), at which the point the current
// allocated buffers are forwarded to the IL3Connection and the
// accumulation process restarts. Memory is never reused or
// de-allocated so the buffers managed by this class are immutable and
// never released and can therefore be shared freeling between
// threads.
class IL3MessageFramer {
std::vector<std::string_view> _buffer_ptrs;
IL3ReceiveBuffer _memory;
@@ -27,8 +34,11 @@ public:
}
~IL3MessageFramer() = default;
//
// Framing
// Allocate a new MDP3 message of type MSG, set its header and
// return a view on it. The message is buffered in an internal data
// structure until flush() is called, at which point the currently
// accumulatd buffers are forwarded to the IL3Connection and
// accumulation restarts.
template <class Msg>
Msg frame(size_t extra=0) {
auto size =
@@ -47,6 +57,8 @@ public:
return msg;
}
// Send all accumulated MDP3 messages out thrugh the passed
// connection and clear the internal message buffer.
void flush(IL3Connection& connection, trace::CorID const&corid) {
if (!_buffer_ptrs.empty()) {
connection.send(_buffer_ptrs, corid);
@@ -23,6 +23,8 @@ public:
memcpy(const_cast<char*>(dest.data()), data.data(), data.size());
}
// returns a block of memory capable of holding size bytes, if
// necessary copying the current active block to a bigger one.
std::string_view allocate(size_t size) {
// If we have enough space append the data
if (size <= available_write_space()) {
@@ -48,15 +50,19 @@ public:
}
}
// Advance the read position, that is the position at which the
// current data() block returns.
void advance(size_t consumed) {
read_pos += consumed;
bts_assert_d(read_pos <= write_pos);
}
// How many bytes are there in the current data() block
size_t unread() const {
return write_pos - read_pos;
}
// The current data() block
const std::string_view data() const {
return std::string_view(buffers.back().data()+read_pos, unread());
}