Skip to content

Instantly share code, notes, and snippets.

@Jackarain
Jackarain / yield_cancellation_slot_bind.hpp
Created March 7, 2022 04:22
用于 asio 的 basic_yield_context 绑定 cancellation 信号
//
// yield_cancellation_slot_bind.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2019 Jack (jack dot wgm at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
@Jackarain
Jackarain / command key map
Last active January 11, 2022 20:12
Command autohotkey 键映射
#c::
Send,^{c}
Return
#v::
Send,^{v}
Return
#s::
Send,^{s}
@Jackarain
Jackarain / multipart.hpp
Last active September 13, 2021 06:25
This is a parser for multipart written in C++
//
// Copyright (C) 2021 Jack.
//
// Author: jack
// Email: jack.wgm at gmail dot com
//
#pragma once
#include <boost/exception/all.hpp>
@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
##