Git Product home page Git Product logo

lua-lluv's Introduction

lua-lluv

Licence Build Status

Lua low level binding to libuv

Compatible with libuv>=1.0.0

Install

Stable version

luarocks install lluv

Current master

luarocks install --server=http://luarocks.org/dev lluv

Related projects

Example

Basic tcp/pipe echo server

local uv = require "lluv"

local function on_write(cli, err)
  if err then return cli:close() end
end

local function on_read(cli, err, data)
  if err then return cli:close() end
  cli:write(data, on_write)
end

local function on_connection(server, err)
  if err then return server:close() end
  server
    :accept()
    :start_read(on_read)
end

local function on_bind(server, err, host, port)
  if err then
    print("Bind fail:" .. tostring(err))
    return server:close()
  end

  if port then host = host .. ":" .. port end
  print("Bind on: " .. host)

  server:listen(on_connection)
end

uv.tcp():bind("127.0.0.1", 5555, on_bind)

uv.pipe():bind([[\\.\pipe\sock.echo]], on_bind)

uv.run()

Coroutine based echo server

local uv     = require "lluv"
local ut     = require "lluv.utils"
local socket = require "lluv.luasocket"

local function echo(cli)
  while true do
    local msg, err = cli:receive("*r")
    if not msg then break end
    cli:send(msg)
  end
  cli:close()
end

local function server(host, port, fn)
  local srv = socket.tcp()

  srv:bind(host, port)

  while true do
    local cli = srv:accept()

    ut.corun(function()
      -- attach socket to current coroutine
      fn(cli:attach())
    end)
  end
end

ut.corun(server, "127.0.0.1", 5555, echo)

uv.run()

Using lluv.luasocket with origin LuaSocket modules.

The main problem that LuaSocket uses protect function to wrap its functions (e.g. http.request) So there may be problem with yield from such functions. The problem solved since commit 5edf093 and only for Lua >= 5.2. So if you use Lua 5.1/LuaJIT or you can not update LuaSocket you have trouble with using lluv.luasocket module.

To solve this problem you can use try or try-lua modules. This modules implement same functionality as LuaSocket's protect function. To replace LuaSocket implementation with this module you can use this code.

local socket = require "socket"
local try    = require "try"

socket.newtry  = try.new
socket.protect = try.protect
socket.try     = try.new()

This allows you use old version of LuaSocket with Lua >=5.2. Also if you use try-lua and bacause of it uses pcall function to implement protect this allows use lluv.luasocket on LuaJIT and on Lua 5.1 with Coco patch.

But this is not help solve problem with stock Lua 5.1. I do not know full solution for this but with using try.co module you can use socket.http, socket.smtp moudules.

At first you should replace socket.protect with try.co implementation

local socket = require "socket"
local try    = require "try.co"

socket.newtry  = try.new
socket.protect = try.protect
socket.try     = try.new()

And when you have to use socket object from lluv.luasocket module you should manually attach it to work coroutine.

local function http_request(url)
  -- this is work coroutine
  local co = coroutine.running()
  http.request{
    ...
    create = function()
      -- attach to work coroutine
      return socket.tcp():attach(co)
    end;
  }
end

You can also check out full example cohttp

lua-lluv's People

Contributors

moteus avatar zhaozg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lua-lluv's Issues

libuv real path

Can you add uv real path support? A simple change to lluv_fs.c worked for me under linux:

80a81
>     case UV_FS_REALPATH:
170a172
>     case UV_FS_REALPATH:
465a468,477
> LLUV_IMPL_SAFE(lluv_fs_realpath) {
>   LLUV_CHECK_LOOP_FS()
> 
>   const char *path = luaL_checkstring(L, ++argc);
> 
>   LLUV_PRE_FS();
>   err = uv_fs_realpath(loop->handle, &req->req, path, cb);
>   LLUV_POST_FS();
> }
> 
946a959
>   { "fs_realpath", lluv_fs_realpath_##F },  \
953c966
< static const struct luaL_Reg lluv_fs_functions[][17] = {

---
> static const struct luaL_Reg lluv_fs_functions[][18] = {

Missing libs with lua 5.3 and windows x64

Hey I couldn't install this from luarocks because I got some linker errors.

Error 8 error LNK2001: unresolved external symbol GetAdaptersAddresses C:\Users\Lenny\Documents\GitHub\lua-lluv\msvc\libuv.lib(util.obj) lluv
Error 7 error LNK2001: unresolved external symbol GetProcessMemoryInfo C:\Users\Lenny\Documents\GitHub\lua-lluv\msvc\libuv.lib(util.obj) lluv

I cloned it and changed the linker config to this:
linker config

I'm using the latest master from the libuv repo build in x64 and lua 5.3 x64.
I had to add Iphlpapi.lib and Psapi.lib to the linker and ignore the LIBCMT default lib.

Is that fixable?

Context argument for stream write operation

This may be helpful to implement wrapper classes

E.g. SSL socket

function SSLSocket:write(msg,cb)
  -- here we have to make closure for each call 
  -- (or use table to cache them with `cb` as key)
  self._sock:write(msg, function(_, ...) cb(self, ...) end)
end

I suggest allow pass additional context argument to write function

function SSLSocket:__init()
  self._on_write_done = function(_, err, cb) cb(self, err) end
end

function SSLSocket:write(msg,cb)
  -- here we can use same closure for all calls
  self._sock:write(msg, self._on_write_done, cb)
end

Add context to other callbacks I see no reason because they do not call as often as write.
But this adds some inconsistent to API. Also I do not think it possible make multiple variables as context because for this we need some table and user code can do this by self.

"recursive" flag in fs_event:start doesn't work

local uv = require"lluv"

local exports = {}

local function reloader(self, err, filename, idk)
    if filename:sub(-4, -1) ~= ".lua" then return end

    local path = self:path()
    path = path:sub(-4, -1) == ".lua" and path or path..filename

    dofile(path)
end

function exports.watchDir(path, recursive)
    local lastchar = path:sub(-1)
    path = lastchar == "/" and path or lastchar == "\\" and path or path.."/"

    return uv.fs_event():start(path, {recursive and "recursive"}, reloader) --for some reason rescurive doesn't work
end

exports.watchDir("towatch/", true)

uv.run()

That's the code used

Do not clone table for write operation

In case when client try send array ast = {"aaa","bbb"} stream:write(t, ...) lluv clone table to prevent gc'ed strings inside this table.
If lluv just store table itself it fine in almost any cases except if some one try change table after call write method.

stream:write{...} -- works
local msg = {}
-- accumulate chunks in msg
stream:write(msg) -- works

local msg = {"aaa","bbb"}
stream:write(clone(msg)) -- works
stream:write(msg) -- may crash
msg[1]=nil  -- because here we remove reference to string "aaa"

Timers never called with uv.run(uv.RUN_ONCE)

Hey, I'm trying to run my event loop interleaved with uv.run() like this:

local function run()
  while step() do
    uv.run(uv.RUN_ONCE)
  end
end

But uv.run(uv.RUN_ONCE) never calls my callbacks. If I change to uv.run() the callbacks are called correctly, but then I cannot call step() every loop. Any idea why uv.RUN_ONCE doesn't work?

I could set an idle callback, but then uv.run() would never block to wait for IO, which is something I want. All I want is for step() to be called after every uv loop, and uv should block. Any idea? Neither uv.check() nor uv.prepare() worked as I expected.

Thanks for the help!

Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.

Greetings,

Thanks for you work on lluv, it is neat to have a lightweight libuv binding for Lua with modules for various protocols that work out of the box.

I have tried to integrate a libuv event loop into a consequent existing Lua app, using lua-lluv-poll-zmq for message passing and multithreading, and lua-lluv-redis.

The basic functionality works well, however, I have a fair amount of the same assertion repeating in various files:

PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_handle.c:498: lluv_on_handle_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_handle.c:498: lluv_on_handle_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_handle.c:498: lluv_on_handle_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_handle.c:498: lluv_on_handle_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_handle.c:498: lluv_on_handle_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_stream.c:288: lluv_on_stream_read_cb: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_handle.c:498: lluv_on_handle_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_handle.c:498: lluv_on_handle_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
PANIC: unprotected error in call to Lua API (not enough memory)
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.
luajit: src/lluv_poll.c:79: lluv_on_poll_start: Assertion `"Some one use invalid callback handler" && (lua_gettop(L) == 0)' failed.

I would like to know if you had already heard of or encountered this issue?

There are also errors about memory usage, but I guess it may be more about the design of the application itself (message queue filling up etc.).

Thanks

memory leaks, howto solve

please check

local uv = require 'lluv'

function memleaks()
    local socket = uv.tcp()
    socket:close()
    socket = nil
    collectgarbage()
end

for i=1,1000000 do
    memleaks()
end
print('DONE')

image

memory leak in timer ?

Run the benchmark-million-timers.lua with

while uv.run() == 1 do end
collectgarbage()
io.read()

at the end, memory seem never freed

Warning when build on ubuntu

gcc -O2 -fPIC -I/usr/include/ujit -c src/lluv_handle.c -o src/lluv_handle.o -I/usr/include
src/lluv_handle.c: In function ‘lluv_handle_index’:
src/lluv_handle.c:70:11: warning: implicit declaration of function ‘strcmp’ [-Wimplicit-function-declaration]
   if(0 == strcmp("data", key)){
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.10' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 

Can you finger out why tcp_c.lua why not work as design, it should generate error, but now crash.

server

local uv = require'lluv'
io.read()
local host = arg[1] or '127.0.0.1'
local port = arg[2] and tonumber(arg[2]) or 8080

local loop = uv.default_loop()
local server = uv.tcp()

local count = 0

local function setInterval(fn, ms)
  local handle = uv.timer()

  handle:start(1000, 1000, function(timer)
    fn()
  end)  

  return handle
end

setInterval(function()
    print(os.date(),count)
    collectgarbage()
end,
1000)

server:bind(host, port)

server:listen(function(server, err)
  --print("LISTEN: ", err or "OK")
  if err then return end

  -- create client socket in same loop as server
  local cli, err = server:accept()
  --if not cli then print("ACCEPT: ", err) else print("ACCEPT: ", cli:getpeername()) end
  if not cli then print("ACCEPT: ", err)   end
  count = count + 1

  cli:start_read(function(cli, err, data)
    if err then
      print("READ: ", err)
      return cli:close()
    end
    if(data=='quit') then
      cli:close()
    end
  end)

end)

uv.run()
print("done")

client

local uv = require'lluv'
io.read()

local host = arg[1] or '127.0.0.1'
local port = arg[2] and tonumber(arg[2]) or 8080
local step = arg[3] and tonumber(arg[3]) or 1

local count = 0
local keep = true

local function setInterval(fn, ms)
  local handle = uv.timer()

  handle:start(1000, 1000, function(timer)
    fn()
  end)  

  return handle
end

setInterval(function()
    print(os.date(),count)
    --collectgarbage()
    if count < 16000 then
      for i=1,step do 
          newconnection()
      end
    end
end, 1000)

newconnection = nil
function newconnection()
    local client = uv.tcp()

    client:connect(host, port, function(client, err)
      --print('Connect', err and err or 'OK')
      if err then return end

      client:start_read(function(cli, err, data)
        if err then
          --print("READ: ", err)
          return cli:close()
        end
        if(data=='quit') then
          cli:close()
        end
      end)

      client:write('quit')
      --[[
      client:write('quit',function(cli, err)
        if err then
          print("WRITE: ", err)
          return cli:close()
        end
      end)
      --]]
    end)

    return client
end

all = {}
for i=1,step do 
    newconnection()
end

uv.run()
print("done")

Installing with luarocks does not work

# luarocks install lluv '--server=https://rocks.moonscript.org/dev'
Warning: Failed searching manifest: Failed fetching manifest for https://rocks.moonscript.org/dev - Failed downloading https://rocks.moonscript.org/dev/manifest - /root/.cache/luarocks/https___rocks.moonscript.org_dev/manifest
Warning: Failed searching manifest: Failed fetching manifest for https://luarocks.org - Failed downloading https://luarocks.org/manifest - /root/.cache/luarocks/https___luarocks.org/manifest
Warning: Failed searching manifest: Failed fetching manifest for https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/ - Failed downloading https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/manifest - /root/.cache/luarocks/https___raw.githubusercontent.com_rocks-moonscript-org_moonrocks-mirror_master_/manifest
Warning: Failed searching manifest: Failed fetching manifest for http://luafr.org/moonrocks/ - Failed downloading http://luafr.org/moonrocks/manifest - /root/.cache/luarocks/http___luafr.org_moonrocks_/manifest
Warning: Failed searching manifest: Failed fetching manifest for http://luarocks.logiceditor.com/rocks - Failed downloading http://luarocks.logiceditor.com/rocks/manifest - /root/.cache/luarocks/http___luarocks.logiceditor.com_rocks/manifest
Warning: Failed searching manifest: Failed fetching manifest for https://rocks.moonscript.org/dev - Failed downloading https://rocks.moonscript.org/dev/manifest - /root/.cache/luarocks/https___rocks.moonscript.org_dev/manifest
Warning: Failed searching manifest: Failed fetching manifest for https://rocks.moonscript.org/dev - Failed downloading https://rocks.moonscript.org/dev/manifest - /root/.cache/luarocks/https___rocks.moonscript.org_dev/manifest

Might invalid SSL certificate be the reason? Firefox gives this error from the URL:

rocks.moonscript.org uses an invalid security certificate.
The certificate is only valid for the following names: www.luarocks.org, luarocks.org
Error code: SSL_ERROR_BAD_CERT_DOMAIN

API_CHECK fail with luajit

I'm just enable luajit api check and hit assert

Assertion failed: idx != 0 && -idx <= L->top - L->base, file \src\lj_api.c, line 67

my build:
luajit master with preprocessor: LUAJIT_ENABLE_LUA52COMPAT LUA_USE_APICHECK
just run some code and you will hit assert

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.