libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fix_client.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2019 by J.M.McGuiness, isimud@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #include "fix_client.hpp"
20 
21 #include <cassert>
22 #include <chrono>
23 
24 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace FIX { namespace v5_0sp2 {
25 
26 fix_client::fix_client(boost::asio::ip::address const &addr, unsigned short port_num, libjmmcg::socket::socket_priority priority, std::size_t incoming_cpu, libjmmcg::latency_timestamps_itf &ts) noexcept(false)
27 : base_t(),
28  client(
32  )
33  ),
34  priority,
36  ),
37  timestamps(ts) {
38  assert(send_fix_msg.is_valid());
39 }
40 
41 std::pair<fix_client::timed_results_t, bool>
42 fix_client::in_order_tx_rx_stats(unsigned long num_loops, unsigned short loops_for_conv, double perc_conv_estimate) noexcept(false) {
43  const std::pair<timed_results_t, bool> timed_results(libjmmcg::compute_average_deviation<timed_results_t::value_type>(
44  perc_conv_estimate,
45  loops_for_conv,
46  [this, &num_loops]() {
47  if (!signal_status()) {
48  const auto t1=std::chrono::high_resolution_clock::now();
49  in_order_tx_rx(num_loops);
50  const auto t2=std::chrono::high_resolution_clock::now();
51  assert(receive_fix_msg.is_valid());
52  return timed_results_t::value_type(static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count())/num_loops);
53  } else {
54  return timed_results_t::value_type();
55  }
56  }
57  ));
58  return timed_results;
59 }
60 
61 std::ostream&
62 operator<<(std::ostream &os, fix_client const &fc) noexcept(false) {
63  os
64  <<"Fix message to send: "<<fc.fix_buffer
65  <<", client connection details: "<< fc.client;
66  return os;
67 }
68 
69 } } } } }