Skip to content

Instantly share code, notes, and snippets.

if !defined (my.field.type)
echo "field
endif
if type = "number"
elsif type = "string"
elsif type = "longstr"
elsif type = "chunk" | type = "frame" | type = "msg" | type = "list" | type = "hash"
elsif type = "msg"
if type = "number"
@hintjens
hintjens / test_timer.c
Created November 15, 2014 10:45
test timers & tickets
/*
Shows relative performance of zloop timers vs tickets
The problem is when you have large numbers of DEALER clients talking
to a ROUTER server, and the server wants to expire idle clients with
some timeout, e.g. 30 seconds. Using zloop timers, this means deleting
and then recreating a timer for each received message. zloop does not
order its timers, and even if it did, finding a timer means searching
the list, an O(N) cost.
#include <czmq.h>
int main (void) {
int repeat;
for (repeat = 0; repeat < 1000; repeat++) {
zctx_t *ctx = zctx_new ();
void *backend = zsocket_new (ctx, ZMQ_DEALER);
void *frontend = zsocket_new (ctx, ZMQ_DEALER);
int rc = zsocket_bind (backend, "ipc://@/something:%d", repeat);
@hintjens
hintjens / issue.c
Last active January 1, 2017 17:26
Workaround for issue LIBZMQ-270
#include <zmq.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
int main (void)
{
void *ctx = zmq_ctx_new ();
assert (ctx);
@hintjens
hintjens / Makefile
Created November 6, 2013 12:51
ZeroMQ TIPC load-balancing example
all: srv.c
g++ srv.c /home/eerihug/dev/BakkaLinux/root/usr/local/lib/libzmq.a -lpthread -lrt -o srv
g++ cli.c /home/eerihug/dev/BakkaLinux/root/usr/local/lib/libzmq.a -lpthread -lrt -o cli
clean:
rm cli
rm srv
@hintjens
hintjens / gist:7302776
Last active December 27, 2015 09:19
Z85 decoder, waaaaay too slow
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
typedef unsigned char byte;
// Maps base 256 to base 85
static char encoder [85 + 1] = {
@hintjens
hintjens / gist:6634071
Created September 20, 2013 06:41
Multistage blackbox test
#include <czmq.h>
static void *
s_source (void *args)
{
zctx_t *ctx = zctx_new ();
void *pub = zsocket_new (ctx, ZMQ_PUB);
zsocket_bind (pub, "tcp://127.0.0.1:9000");
while (true) {
@hintjens
hintjens / gist:5830173
Last active December 18, 2015 19:00
ZMTP 3.0 subscriber
//
// ZMTP 3.0 subscriber proof-of-concept
// Implements http://rfc.zeromq.org/spec:23 with NULL mechanism
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "haywire.h"
#include "http_server.h"
#include "trie/radix.h"
#define CRLF "\r\n"
http_response *
@hintjens
hintjens / zwtfpd.c
Created April 29, 2013 09:49
Minimal WTFP server in ZeroMQ
// Minimal WTFP server in 0MQ
#include "czmq.h"
static void *
wtfp_server (void *args)
{
zctx_t *ctx = zctx_new ();
void *router = zsocket_new (ctx, ZMQ_ROUTER);
int rc = zsocket_bind (router, "tcp://*:8080");
assert (rc != -1);