This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pcg-based rand32() and rand64() | |
#include <stdint.h> | |
struct pcg32_random_t | |
{ | |
uint64_t state; | |
}; | |
static const uint64_t inc = 997; | |
static struct pcg32_random_t rndState = {99991}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check TCP connect to port/host | |
var sock = require('net').connect({ port: 443, host: '127.0.0.1' }).on('connect', () => { console.log('connect OK'); sock.end(); }).on('error', (e) => { console.log('connect error (code:'+e.code+')'); }) | |
// listen for TCP connect on port/host | |
var server = require('net').createServer((sock) => { console.log('client connected'); sock.end(); }).listen({ port: 443, host: '127.0.0.1' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run node server.js | |
then build and run curl-test.cpp | |
Everything will be ok: | |
``` | |
CURLINFO_ACTIVESOCKET, ret:0 sockWs:276 | |
curl_easy_send ret:0 sentSize:194 | |
curl_easy_recv ret:0 recvSize:167 | |
CURLINFO_ACTIVESOCKET, ret:0 sockWs:296 | |
curl_easy_send ret:0 sentSize:194 | |
curl_easy_recv ret:0 recvSize:167 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#undef NDEBUG | |
#include "compositecodec.h" | |
#include "simdfastpfor.h" | |
#include "variablebyte.h" | |
#include <stdlib.h> | |
#include <vector> | |
// typedef for simdfastpfor128 codec from FastPFor | |
typedef FastPForLib::CompositeCodec<FastPForLib::SIMDFastPFor<4>, FastPForLib::VariableByte> IntCodec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef _WIN32 | |
#include <windows.h> | |
#if !defined(PLATFORM_XBOX) && !defined(PLATFORM_UWP) | |
#include <wincrypt.h> | |
#else | |
#include <bcrypt.h> | |
#pragma comment(lib, "bcrypt.lib") | |
#endif | |
int computeHash(const void* data, unsigned dataSize, unsigned char hashBuf[64], const void *hmacSecret, unsigned hmacSecretSize, bool isMD5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note, bsf/bsr are used by default. | |
// Enable /arch:AVX2 compilation for better optimizations | |
#if defined(_MSC_VER) && !defined(__clang__) | |
#include <intrin.h> | |
static __forceinline int __builtin_ctz(unsigned x) | |
{ | |
#if defined(_M_ARM) || defined(_M_ARM64) || defined(_M_HYBRID_X86_ARM64) || defined(_M_ARM64EC) | |
return (int)_CountTrailingZeros(x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _WS2DEF_ | |
#include "inaddr.h" | |
#include "MSTcpIP.h" | |
void startServer(); | |
void startClient_6_to_4(short xxport); | |
void startClient_4_to_4(short xxport); | |
void startClient_6_to_6(short xxport); | |
short xxport = 8112; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef _WIN32 // inet_pton is available from Vista only (based on inet_pton.c from wireshark) | |
#define NS_INADDRSZ_ 4 | |
#define NS_IN6ADDRSZ_ 16 | |
#define NS_INT16SZ_ 2 | |
static int inet_pton4(const char *src, unsigned char *dst) | |
{ | |
char saw_digit = 0, octets = 0, ch; | |
unsigned char tmp[NS_INADDRSZ_], *tp = tmp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <tlhelp32.h> | |
// Pass 0 as the targetProcessId to suspend threads in the current process | |
void DoSuspendThread(DWORD targetProcessId, DWORD targetThreadId) | |
{ | |
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); | |
if (h != INVALID_HANDLE_VALUE) | |
{ | |
THREADENTRY32 te; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <stdio.h> | |
// fullDump enables MiniDumpWithFullMemory, and results in dmp files to be over 100MB in size (as opposed to default which is only 100KB). | |
// With fullDump Visual Studio is able to display proper backtrace for unhandled c++ exception. Without fullDump WinDBG has to be used. | |
static int WriteMinidumpForException(EXCEPTION_POINTERS* e, bool fullDump) | |
{ | |
HMODULE dbghelp = LoadLibraryA("DbgHelp.dll"); // Note: no matching FreeLibrary | |
if (!dbghelp) | |
return EXCEPTION_CONTINUE_SEARCH; |