Skip to content

Instantly share code, notes, and snippets.

View madmongo1's full-sized avatar

Richard Hodges madmongo1

View GitHub Profile
auto connection_impl::async_co_connect(std::string host,
std::string port,
std::string path)
-> net::awaitable< void, executor_type >
{
assert(websocket_state_.active< websocket_initial >());
try
{
websocket_state_.enter< websocket_connecting >();
auto &connecting = websocket_state_.get< websocket_connecting >();
#pragma once
#include <util/async/lowest_layer.hpp>
#include <util/async/ssl_stream_connect_state_impl.hpp>
#include <util/net.hpp>
#include <util/websocket.hpp>
namespace util::async
{
template < class NextLayer >
struct basic_websocket_connect_state_impl
#pragma once
#include <mutex>
#include <optional>
#include <powertrade/util/async/cheap_work_guard.hpp>
#include <powertrade/util/async/poly_handler.hpp>
#include <tuple>
namespace powertrade::util::async
{
struct async_join_impl_base
#pragma once
#include <powertrade/util/async/async_join_impl.hpp>
#include <powertrade/util/websocket.hpp>
namespace powertrade::util::async
{
template < class NextLayer >
struct websocket_state_impl
{
using stream_type = websocket::stream< NextLayer >;
auto application::run_test() -> net::awaitable< void, executor_type >
{
co_await rpc_state_.connect("test.deribit.com", "https", "/ws/api/v2");
spdlog::info("rpc connection up");
auto response = co_await rpc_state_.async_call(
"public/auth",
deribit::build_auth_request_signature(
"Y-fIt7RU"sv, "rq3mYx9j2u1hrTH3Lgwqtgs0ouMGyZ8drDeRXbULluM"sv),
net::use_awaitable_t< executor_type >());
@madmongo1
madmongo1 / gist:8bc2e18fed0715e0f38eda6a783361cc
Created June 23, 2020 14:15
json_rpc state machine with boost.json, boost.beast and boost.asio
#pragma once
#include "remote_result.hpp"
#include <powertrade/util/async/poly_handler.hpp>
#include <powertrade/util/async/websocket_state_impl.hpp>
#include <powertrade/util/json.hpp>
#include <powertrade/util/json_rpc/remote_result.hpp>
#include <spdlog/spdlog.h>
#include <unordered_map>
@madmongo1
madmongo1 / work_guard.hpp
Created June 25, 2020 10:34
A proposed automatic adapator for the concept of guarding work agnostic of whether we are in net.ts or not
#ifndef BOOST_BEAST_CORE_DETAIL_WORK_GUARD_HPP
#define BOOST_BEAST_CORE_DETAIL_WORK_GUARD_HPP
#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/execution.hpp>
namespace boost {
namespace beast {
namespace detail {
// (C) Copyright 2002-2008, Fernando Luis Cacciola Carballal.
// (C) Copyright 2007-2009 Andrew Sutton
// (C) Copyright 2008-9 Anthony Williams
// (C) Copyright 2009 Eric Bose-Wolf
// (C) Copyright Andrew Sutton 2007
// (C) Copyright Andrey Semashev 2017.
// (C) Copyright Antony Polukhin 2014.
// (C) Copyright Beman Dawes 1999.
// (C) Copyright Beman Dawes 2000. Distributed under the Boost
// (C) Copyright Boris Rasin 2014.
@madmongo1
madmongo1 / something.qbk
Created July 2, 2020 09:13
Updates for beast release 1.74
* [phrase library..[@/libs/beast/ Beast]:]
* Accommodate upstream changes in Asio.
* [github context 1913] Fix standalone compilation error with std::string_view.
* [github context 1925] [1916] Fix compile errors on Visual Studio with /std:c++latest.
* [github context 1924] Fix c++20 deprecation warning in span_body.
* [github context 1920] Fix use buffered_read_stream with use_awaitable.
* [github context 1918] Fix async_detect_ssl with use_awaitable.
* [github context 1944] Fix FILE namespace qualification.
* [github context 1942] Fix http read bytes_transferred.
* [github context 1943] Fix basic_stream expires_after.
* [phrase library..[@/libs/beast/ Beast]:]
* This update brings bug fixes and support for the following changes changes in Boost.Asio:
* Beast supports `BOOST_ASIO_NO_DEPRECATED`. Define this to help identify areas of your
Beast and Asio code which use deprecated Asio interfaces.
* Beast also supports `BOOST_ASIO_NO_TS_EXECUTORS`. Define this to identify uses of executors from
the now potentially outdated [@https://cplusplus.github.io/networking-ts/draft.pdf Networking TS]
* Asio will use the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0443r11.html Standard Executors]
model by default. You can prevent this behaviour by defining `BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT` in which
the Networking TS model will be used by default. Setting this flag does not prevent a program from using executors
from the Standard Executors model explicitly.