Home > Software > New curb patch, on_success, and on_failure

New curb patch, on_success, and on_failure

July 10th, 2008

I added a new callback hook to curb on_success and on_failure. They work as advertised and are esspecially useful when using the Curl::Multi interface from my last patch.

gc = Curl::Easy.new("http://www.google.com/")
gc.on_success{|curl| puts curl.body_str }
yc = Curl::Easy.new("http://www.yahoo.com/")
yc.on_success{|curl| puts curl.body_str }

mc = Curl::Multi.new
mc.add(gc)
mc.add(yc)

mc.perform


What’s nice about this, is imagine you have some process running and want to add requests to it. When you add the request you also want to register a callback to handle the success or failure cases. Before this patch you’d have to check the content length and listen to the on_body handler. The problem with that, is the content length header is not always correct. These callbacks are guaranteed, because they happen during the cleanup process for each handle.

As an aside they’ll work using the Easy handle diretly.

Here’s the patch, enjoy!

Software , ,

  1. July 13th, 2008 at 22:11 | #1

    Oops it works, nevermind.

  2. gabe
    July 13th, 2008 at 22:09 | #2

    Nice. The patch link doesn’t seem to be working for me tho.

  3. taf2
    July 15th, 2008 at 18:58 | #3

    cool, i added my changes to github now since i’ve been making more changes

  1. No trackbacks yet.
CommentLuv Enabled

Comments links could be nofollow free.