Skip to content

Instantly share code, notes, and snippets.

@Jackarain
Jackarain / asio.md
Last active March 16, 2019 18:09
asio中associated_allocator和associated_executor的精巧设计

在asio中,设计了associated_allocator和associated_executor用于用户管理handler统一分配内存和统一调用,通过adl实现hook结构。

如用户提交一个异步操作,此时用户的handler需要保存在asio的内部op队列中,待操作完成,asio将从op队列中取出该op(不一定要直接取,像iocp中,可以绑定在OVERLAPPED结构中,事件完成,直接可以OVERLAPPED中拿到),然后通过op中的handler回调用户,通知异步操作完成。

其中,asio使用了associated_allocator和associated_executor这2个设计,在asio内部存取用户handler到op队列的时候用到,以实现用户定义的allocator和executor的调用。

下面是关于iocp(默认proactor模型更易于分析)中async_receive异步处理的分析(async_send类似),非关键部分代码省略,只例出与主题相关的代码。

// 文件 boost/boost/asio/detail/win_iocp_operation.hpp
@Jackarain
Jackarain / anycall.cpp
Created March 12, 2019 06:09
anycall.cpp
template <typename Handler, typename Request, typename Reply>
class type_erasure_handler
{
public:
type_erasure_handler(Handler&& handler)
: handler_(std::forward<Handler>(handler))
{}
~type_erasure_handler()
{}
@Jackarain
Jackarain / README.md
Created December 19, 2018 19:32 — forked from mildsunrise/README.md
Helper program to add HTTP/SOCKS proxy support to SSH

ssh-proxy-dialer

This program adds proxy support to ssh. Once installed, ssh will obey the ssh_proxy environment variable (or all_proxy as a fallback) and will try to connect to the server through that proxy. Example:

export ssh_proxy="socks5://10.139.2.1:8066"
ssh example.com  # will connect through SOCKS5 proxy
@Jackarain
Jackarain / test.cpp
Last active August 23, 2018 19:58
adventofcode day 7
// 保存一下 http://adventofcode.com/2015/day/7
#include <algorithm>
#include <chrono>
#include <iostream>
#include <string>
#include <vector>
std::string s1 =
R"(123 -> x
456 -> y
@Jackarain
Jackarain / gist:ecc6594ef6930db7fa7f
Created March 23, 2015 04:50
Linking libstdc++ statically
Linking libstdc++ statically
Christopher Baus writes about his problems linking libstdc++ statically. Yes, making C++ binaries that will work properly in different Linux distributions is somewhat painful. The problem is not so much linking libstdc++ statically – it is just a library, after all – but the runtime support required by C++ code in general, to enable features like RTTI and exception handling.
The runtime support code used by different parts of a C++ application needs to be compatible. If one part of the program needs to dynamic_cast or catch objects provided by another, both parts must agree on certain implementation details: how to find vtables, how to unwind the stack, and so on.
For C++ and a few other GCC-supported languages with similar features, such details are specified by a C++ ABI. Whenever the ABI used by GCC changes you'll end up with incompatible libraries produced by the different GCC versions. The same is true for plain C, but the C ABI is much simpler and has been around a lot lon
@Jackarain
Jackarain / logger.hpp
Last active March 7, 2022 04:35
一个简单的日志类实现.
//
// Copyright (C) 2019 Jack.
//
// Author: jack
// Email: jack.wgm at gmail dot com
//
#pragma once
#include <clocale>
@Jackarain
Jackarain / cacert.pem
Created November 29, 2013 02:40
cacert.pem
##
## ca-bundle.crt -- Bundle of CA Root Certificates
##
## Certificate data from Mozilla as of: Sat Dec 29 20:03:40 2012
##
## This is a bundle of X.509 certificates of public Certificate Authorities
## (CA). These were automatically extracted from Mozilla's root certificates
## file (certdata.txt). This file can be found in the mozilla source tree:
## http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1
##
//
// async_read_body.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2013 Jack (jack dot wgm at gmail dot com)
// Copyright (C) 2012 - 2013 微蔡 <[email protected]>
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// path LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
From 81a6a51c0cb66de6bc77e1fa5dcd46b2794995e4 Mon Sep 17 00:00:00 2001
From: Christopher Kohlhoff <[email protected]>
Date: Wed, 23 Mar 2011 15:03:56 +1100
Subject: [PATCH] On Windows, ensure the count of outstanding work is decremented for
abandoned operations (i.e. operations that are being cleaned up within
the io_service destructor).
---
asio/include/asio/detail/impl/dev_poll_reactor.ipp | 2 ++
asio/include/asio/detail/impl/epoll_reactor.ipp | 2 ++
@Jackarain
Jackarain / gist:5589590
Last active December 17, 2015 09:48
json格式化
#include <boost/foreach.hpp>
#include <boost/property_tree/json_parser.hpp>
namespace pt = boost::property_tree;
using pt::ptree;
template <class Stream>
void list_json(ptree json, Stream &stream, int level = 0)
{
if (level == 0)
{