How to make Typhoeus collaborate with Celluloid::IO

23 views
Skip to first unread message

Omer Katz

unread,
Jun 15, 2016, 6:31:13 AM6/15/16
to Celluloid
Typhoeus uses a Curl to send HTTP requests. Curl exposes the socket(s) fds it uses through callbacks but I'm not sure if there's a way to register the fds to the event loop.
It's pretty straight forward to integrate Curl Multi with gevent in Python. See https://gist.github.com/GuoJing/5875326

From the code example above I figured out that the secret sauce is to set M_TIMERFUNCTION and M_SOCKETFUNCTION.

Has anyone tried doing such a thing before?
If not, would writing the integration directly to NIO in C do the trick? 

Tony Arcieri

unread,
Jun 15, 2016, 10:59:27 AM6/15/16
to cellulo...@googlegroups.com
In the past http.rb supported Celluloid::IO, however we removed it when we added the current timeout backend. It could be added back if we wrote a timeout backend for Celluloid::IO.

It's not really possible to adapt a C library in a similar way: Celluloid::IO provides alternatives for the Ruby standard library's TCPSocket/UDPSocket. You can't exactly drop those into C code.

--
You received this message because you are subscribed to the Google Groups "Celluloid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to celluloid-rub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Tony Arcieri

Omer Katz

unread,
Jun 16, 2016, 5:16:19 AM6/16/16
to Celluloid
You can however, make Curl collaborate with NIO through the callbacks I mentioned. That's exactly what is being done with gevent. The file descriptors are registered to gevent's watcher which is a wrapper for libev.
This will allow Ruby code to run while handling the HTTP request(s).
Reply all
Reply to author
Forward
0 new messages