Skip to content

Instantly share code, notes, and snippets.

@jmorrill
jmorrill / gist:4d21bdfbea6b7ad4d6b2
Created November 7, 2014 00:39
C++ libuv library
/* OUTPUT
tick tock
I'm the second handler of the tick event
I'm on the dispatcher thread
I'm on a thread pool thread
I just got value 42 sent to me and I'm on the dispatcher loop thread
I'm on a thread pool thread and shutting down dispatcher safely
exiting...
@jmorrill
jmorrill / libuvxx.cpp
Last active August 29, 2015 14:09
some networking in my libuv c++ wrapper
/*
OUTPUT
initial thread id - 15684
thread id - 15684
got ip address - 74.125.224.165
connected !
*/
int _tmain(int argc, _TCHAR* argv[])
@jmorrill
jmorrill / uvxxnetwork.cpp
Last active August 29, 2015 14:09
libuv C++ library
int _tmain(int argc, _TCHAR* argv[])
{
cout << "initial thread id - " << this_thread::get_id() << endl;
/* dns resolver */
auto dns = net::dns();
/* socket client */
auto socket = net::stream_socket();
@jmorrill
jmorrill / modern.cpp
Created November 19, 2014 01:07
modern
int main()
{
Modern::Initialize();
Uri uri(L"http://moderncpp.com/about/");
auto socket = Modern::Windows::Networking::Sockets::StreamSocket();
printf("port: %d\n", uri.Port());
@jmorrill
jmorrill / modern2.cpp
Created November 19, 2014 03:40
modern2.cpp
#include "Precompiled.h"
#include <stdio.h>
#include <ppltasks.h>
#include <iostream>
#include <string>
using namespace Modern::Windows::Foundation;
using namespace Modern::Windows::Networking::Connectivity;
using namespace Modern::Windows::Networking;
using namespace Modern::Windows::Networking::Sockets;
@jmorrill
jmorrill / _uv_loop.cpp
Last active August 29, 2015 14:10
libuv c++ wrapper impl
#include "details/_uv_async.hpp"
#include "details/_uv_loop.hpp"
#include "details/_utilities.hpp"
#include "details/_uv_work.hpp"
namespace uvxx { namespace details
{
_uv_loop::_uv_loop(bool use_default /*= false*/) :
__uv_loop_(use_default ? uv_default_loop() : uv_loop_new()),
/* uv_async_init */
@jmorrill
jmorrill / iterative_task.cpp
Created December 10, 2014 23:14
optimized create_iterative_task
#pragma once
#include <memory>
#include <chrono>
#include <atomic>
#include <vector>
#include <mutex>
#include <functional>
#include <type_traits>
#include "pplxtasks.h"
#include <event_dispatcher_timer.hpp>
int read_pass_counter = 0;
uint64_t total_bytes_read = 0;
string host_name = "10.1.30.151";
int host_port = 80;
string http_command = "GET /movie.mp4 HTTP/1.0\r\n\r\n";
void test_method()
@jmorrill
jmorrill / maybe_bug.cpp
Last active August 29, 2015 14:22
vs2013 vc++ bug?
/////VS 2013 /////
//////////////////
#include "stdafx.h"
#include <assert.h>
#include <thread>
#define __thread_local __declspec(thread)
const int some_int = 5;
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdint.h>
#include <vector>
#include <algorithm>
#include <filesystem>
#include <random>