wilsonloo / levent

base on https://github.com/xjdrew/levent.git

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

levent

levent is a lua concurrency networking library inspired by gevent.

Features include:

  • Fast event loop based on libev.
  • Simple and clean socket library
  • Cooperative dns client by pure lua
  • Similar api and components with gevent but with much more simpler implementation and better performance.

levent is licensed under MIT license.

get levent

Install lua 5.3 or newer(for lua5.2 and older, see branch lua5.2). LUA_INCLUDE_DIR default /usr/local/include/

Clone the repository.

Read test case and examples.

Post feedback and issues on the bug tracker,

build

Need cmake 2.8 or newer.

Modify CMakeLists.txt add your lua include dir Modify cmake.config properly and then run:

cmake .
make

ways to build on windows, ref to blog

code example

levent's api is clean, to request http concurrently is as simple as below:

lua <<SCRIPT
local levent = require "levent.levent"
local http   = require "levent.http"

local urls = {
    "http://www.google.com",
    "http://yahoo.com",
    "http://example.com",
    "http://qq.com",
}

function request(url)
    local response, err = http.get(url)
    if not response then
        print(url, "error:", err)
    else
        print(url, response:get_code())
    end
end

function main()
    for _, url in ipairs(urls) do
        levent.spawn(request, url)
    end
end

levent.start(main)
SCRIPT

running tests

there are some tests and examples under tests and examples to illustrate how to use levent, you can run tests and examples from root folder of levent as below.

lua tests/test_socket.lua
lua examples/dns_mass_resolve.lua

documents

coming soon~~

licence

The MIT License (MIT) Copyright (c) 2014 xjdrew

About

base on https://github.com/xjdrew/levent.git

License:MIT License


Languages

Language:C 49.9%Language:Lua 49.1%Language:CMake 1.0%