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.
Install lua 5.3 or newer(for lua5.2 and older, see branch lua5.2).
Clone the repository.
Post feedback and issues on the bug tracker,
Need cmake 2.8 or newer.
Modify cmake.config properly and then run:
git submodule update --init --recursive
cmake .
make
ways to build on windows, ref to blog
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
for multi-thread see tests/test_socket_thread.lua
.
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
coming soon~~
The MIT License (MIT) Copyright (c) 2014 xjdrew