node.js function access to libmill
go style concurrency for node.
an experiment
#install libmill and libsodium dependencies $ git clone https://github.com/sustrik/libmill.git$ cd libmill && ./autogen.sh && ./configure && make -j 8 && sudo make install$ sudo /sbin/ldconfig # linux only $ git clone https://github.com/jedisct1/libsodium.git$ cd libsodium && ./autogen.sh && ./configure && make -j 8 && sudo make install$ sudo /sbin/ldconfig # linux only $ npm i && npm t
tcp library
for msgs over tcp/ip, a server can use tcplisten()
. once a client connects, the server can use tcpaccept()
to establish bidirectional tcp streams.
tcplisten()
and tcpaccept()
var lib = ; /* create an ipaddr */var ipaddr = lib; /* listen on the ipaddr */var ls = lib;console; while1 /* accept and establish tcp connection */ var as = lib; console; /* close tcp connection */ lib;
tcpconnect()
var lib = ; /* create an ipaddr */var ipaddr = lib; /* connect over the ipaddr */var cs = lib;var str = 'go style concurrency for node' num = 1; /* send a few msg before tcpflush *//* delimiter is set to '\r', tells tcprecvuntil when to finish */;;;{ n+= num+++msg+'\n'; lib;} /* tcpsend() stores data in user space and tcpflush() pushes it to kernel */lib;
udp library
udplisten()
and udprecv()
var lib = ; /* create an ipaddr */var ipaddr = lib; /* listen on ipaddr */var ls = lib;processstdout; /* next, to get udp msgs, use udprecv if you pass a cb function as the 3rd param, the call will use libuv async the callback's param will contain your msg otherwise w/out a cb, it will block and udprecv's return value is your msg */ /* the non-blocking way (a for async) */lib; /* the blocking way */while 1 var sz = 13; var deadline = 10; var msg = lib; /* deadline is optional param */ processstdout;
udpsend()
var s = lib;var buf = 'Hello, world!'; lib;
test
see test
directory
license
MIT
tested on circleci linux and osx.