lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Sep 29, 2011 at 12:10 AM, Ian Good <ian.good@rackspace.com> wrote:
> Hey all,
>
> Wanted to introduce ratchet, a new library I've been working on. Ratchet is a socket mechanism similar to Python's gevent or a combination of Lua's luasocket+copas+ssl. The idea is, your code looks synchronous, but while waiting for one event it works on another. I attached an example at the bottom of this message.
>
> Asynchronous, "thread-like" access to:
>  * TCP/UDP socket client and server support
>  * SSL socket wrapper
>  * DNS queries (thanks to dns.c: http://25thandclement.com/~william/projects/dns.c.html)
>  * Timing mechanisms (via timerfd)
>  * ZeroMQ messaging library
>
> Extra mechanisms:
>  * Buffered sockets
>  * HTTP/1.0 client and server sample library
>  * SMTP client and server sample library
>
> The code includes 20 integration-style tests covering all major features and extensive API documentation. The website includes an extensive usage manual and the API docs.
>
> Website: http://ratchet.icgood.net/
> Source: http://github.com/icgood/ratchet
>
> Ian Good
>
>
>
> ------------------------------------------------------------------------
>
> require "ratchet"
> require "ratchet.http.client"
>
> function http_query(i)
>    local rec = ratchet.socket.prepare_uri("tcp://google.com:80")
>    local socket = ratchet.socket.new(rec.family, rec.socktype, rec.protocol)
>    if not socket:connect(rec.addr) then
>        error("Could not connect to google.com on port 80!")
>    end
>
>    local client = ratchet.http.client.new(socket)
>    local code, message, headers, data = client:query("GET", "/")
>
>    assert(200 == code, "[200] != [%s] (%s)":format(code, message))
>    print(i .. ": Received html data from google.com.")
> end
>
> kernel = ratchet.new()
> for i=1,10 do
>    kernel:attach(http_query, i)
> end
> kernel:loop()
>
>
>
>

This looks really fantastic, I'm getting it set up to have a play now.

One minor and bloody annoying (damn you lua package maintainers
everywhere) thing is that the .pc file is named lua5.1 on debian based
systems, and lua51 on some others iirc. Not sure if there's an easy
way to support these various names in the autotools script.

The lua detection seems a bit hairy too, I had to patch it slightly to
get it to detect interpreter version properly, would it not be easier
to just search with pkg-config and be done with it? It wasn't finding
the right headers either but I gave up on that problem and just
inserted a pkg-config lua check into the build.

I had to disable SSLv2 as well because it has been removed from debian
OpenSSL due to vulnerabilities.

It has built now though! So I'll get to the real business.

Cheers,
Josh.