Skip to content

Instantly share code, notes, and snippets.

View cablehead's full-sized avatar

Andy Gayton cablehead

View GitHub Profile
@cablehead
cablehead / s.lua
Last active January 9, 2017 21:58
r:stream():line() --> `err`, `Slice`
-- a slice is a restricted `off`, `len` window into a buffer. offers all methods buffer does.
-- is bump / growable, if `len` extends to the end of the buffer's current contents.
-- this allows you to make use of the line without incurring and additional copy
-- you call `:trim` when done with the line.
-- buffer (and so slice) will get two new methods
local ffi = require("ffi")
local levee = require("levee")
ffi.cdef([[
typedef struct { int len; } myproto_prefix_t;
]])
local ffi = require("ffi")
local levee = require("levee")
ffi.cdef([[
typedef struct { int len; } myproto_prefix_t;
]])
local ffi = require("ffi")
local levee = require("levee")
ffi.cdef([[
typedef struct { int len; } myproto_prefix_t;
]])
local ffi = require("ffi")
local levee = require("levee")
ffi.cdef([[
typedef struct { int len; } myproto_prefix_t;
]])
local ffi = require("ffi")
local levee = require("levee")
local d = levee.d
ffi.cdef([[
typedef struct { int len; } myproto_prefix_t;
]])
#include <assert.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <netdb.h>
#include <string.h>
#include <errno.h>
local levee = require("levee")
local _ = levee._
local RPCThreadPool_mt = {}
function RPCThreadPool_mt:__index(name)
return function(self, ...)
local sender, recver = self.h:pipe()
local levee = require("levee")
local _ = levee._
local ThreadPool_mt = {}
function ThreadPool_mt:__index(name)
return function(self, ...)
local sender, recver = self.h:pipe()
local levee = require("levee")
local _ = levee._
local h = levee.Hub()
_.fcntl_nonblock(0); h.stdin = h.io:r(0)
_.fcntl_nonblock(1); h.stdout = h.io:w(1)
local stream = h.stdin:stream()