Skip to content

Instantly share code, notes, and snippets.

@redboltz
redboltz / error_client.cpp
Last active August 29, 2015 14:17
Websocket++ and coroutine SEGV
#include <iostream>
#define _WEBSOCKETPP_CPP11_STL_
//#define _WEBSOCKETPP_RVALUE_REFERENCES_
//#define _WEBSOCKETPP_DELETED_FUNCTIONS_
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/client.hpp>
#include <boost/coroutine/all.hpp>
@redboltz
redboltz / valgrind.log
Created January 1, 2015 06:32
websocket++ valgrind log
==2009== Memcheck, a memory error detector
==2009== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==2009== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==2009== Command: ./server 9001
==2009==
[2015-01-01 08:21:53] [connect] WebSocket Connection 127.0.0.1:34928 v13 "WebSocket++/0.4.0" / 101
==2009== Invalid read of size 8
==2009== at 0x4162F5: boost::asio::detail::reactive_socket_service_base::destroy(boost::asio::detail::reactive_socket_service_base::base_implementation_type&) (in /home/kondo/work/training/code/cpp/websockets/server)
==2009== by 0x435D08: boost::asio::socket_acceptor_service<boost::asio::ip::tcp>::destroy(boost::asio::detail::reactive_socket_service<boost::asio::ip::tcp>::implementation_type&) (in /home/kondo/work/training/code/cpp/websockets/server)
==2009== by 0x431E6C: boost::asio::basic_io_object<boost::asio::socket_acceptor_service<boost::asio::ip::tcp>, true>::~basic_io_object() (in /home/kondo/work/training/code/cpp/websockets/server)
@redboltz
redboltz / msgpack_overload.cpp
Created October 16, 2014 03:31
msgpack-c user overloading example.
#include <sstream>
#include <iostream>
// -------------------------------------------------
// You need to include msgpack_fwd.hpp for overload.
#include <msgpack_fwd.hpp>
// -------------------------------------------------
struct my {
int i;
@redboltz
redboltz / gist:dd0a5d34ad1846a5897d
Created September 27, 2014 01:08
versioning by namespace
// Powerd by
// http://stackoverflow.com/questions/11632219/c-preprocessor-macro-specialisation-based-on-an-argument
// For both C++03 and C++11
#include <iostream>
// --- begin client code ---
#define MSGPACK_API_VERSION 1
// --- end client code ---
@redboltz
redboltz / soci_sqlite.cpp
Last active August 29, 2015 14:03
An example of sqlite access using SOCI
#include <soci.h>
#include <sqlite3/soci-sqlite3.h>
#include <boost-fusion.h>
#include <iostream>
#include <boost/fusion/include/define_struct.hpp>
#include <boost/fusion/include/for_each.hpp>
using namespace soci;
@redboltz
redboltz / variant.cpp
Created June 28, 2014 16:14
msgpack-c boost::variant example
#include <boost/variant.hpp>
#include <msgpack.hpp>
// Definition of the variant type.
// The types appear the following example are supported.
// {'metadata': {'date': '2014-06-25', 'user_id': 501},
// 'values': [3.1, 4.1, 5.1],
// 'version': 1}
@redboltz
redboltz / msgpack_bin_str.cpp
Last active November 27, 2023 19:11
msgpack bin/str pack/unpack example.
// This program requires the C++11 compiler,
// e.g.) g++ -std=c++11 ...
// clang++ -std=c++11 ...
#include <iostream>
#include <iomanip>
#include <string>
#include <msgpack.hpp>
void print(char const* buf, std::size_t size) {
@redboltz
redboltz / non_consume.c
Created June 17, 2014 02:31
msgpack-c: error data is not consumed
#include <msgpack.h>
#include <stdio.h>
#include <assert.h>
int main(void)
{
msgpack_unpacker* unp = msgpack_unpacker_new(100);
msgpack_unpacked result;
bool ret;
char* buf;
@redboltz
redboltz / gist:6af6382400b62526abb6
Created June 13, 2014 01:28
diff 0af09a4a4caaf43f9641814e0ffc2b6458be81fe 91ae059e162a938c69b7dfe2cfed1746f580b25b.diff
diff --git a/src/msgpack/cpp_config.hpp b/src/msgpack/cpp_config.hpp
index b80573a..8db6d25 100644
--- a/src/msgpack/cpp_config.hpp
+++ b/src/msgpack/cpp_config.hpp
@@ -45,6 +45,15 @@ T const& move(T const& t)
return t;
}
+template <bool P, typename T = void>
+struct enable_if {
@redboltz
redboltz / step1.cpp
Created May 27, 2014 04:12
msgpack migration
#include <iostream>
// ---- library code ----
namespace msgpack {
void foo(int) { std::cout << "v1::foo(int)" << std::endl; }
}
// ---- client code ----