[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "ratchet" socket control library
- From: Josh Simmons <simmons.44@...>
- Date: Sat, 22 Oct 2011 14:50:19 +1100
On Thu, Sep 29, 2011 at 12:10 AM, Ian Good <email@example.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, " != [%s] (%s)":format(code, message))
> Â Âprint(i .. ": Received html data from google.com.")
> kernel = ratchet.new()
> for i=1,10 do
> Â Âkernel:attach(http_query, i)
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.