ext/revdispatch/revdispatch.cc in evdispatch-0.2.1 vs ext/revdispatch/revdispatch.cc in evdispatch-0.2.2

- old
+ new

@@ -89,18 +89,24 @@ req->set_opt(name, RSTRING_PTR(obj));\ }\ } static -VALUE Loop_request( VALUE self, VALUE url, VALUE options ) +VALUE Loop_request( int argc, VALUE *argv, VALUE self ) { EVD::Dispatch *d; const int VALUE_BUFFER_SIZE = 1024; char VALUE_BUFFER[VALUE_BUFFER_SIZE]; Data_Get_Struct( self, EVD::Dispatch, d ); + VALUE url, options; + // required 1 argument the 'url' and 1 optional the hash of options + if( rb_scan_args( argc, argv, "11", &url, &options ) == 1 ) { + options = rb_hash_new(); + } + EVD::HttpRequest *req = new EVD::HttpRequest( *d, RSTRING_PTR(url) ); // check for some specific options SET_LONG_VAL("port"); SET_STR_VAL("autoreferer"); @@ -120,11 +126,11 @@ EVD::Queue<EVD::Response>::POP_STATE rstate; EVD::request_t rid = FIX2LONG(id); Data_Get_Struct( self, EVD::Dispatch, d ); - rstate = d->wait_for_response_by_id( rid, EVD::Timer(FIX2LONG(timeout_seconds), FIX2LONG(timeout_mseconds)) ); + rstate = d->wait_for_response_by_id( rid, EVD::Timer(FIX2LONG(timeout_seconds), (FIX2LONG(timeout_mseconds)*1000*1000)) ); return rb_int_new(rstate); } static @@ -135,11 +141,11 @@ EVD::HttpResponse *res = NULL; EVD::request_t rid = FIX2LONG(id); res = (EVD::HttpResponse*)d->response_for( rid ); - if( res ){ + if( res ) { VALUE result = rb_hash_new(); rb_hash_aset( result, ID2SYM(rb_intern("name")), rb_str_new( res->name.c_str(), res->name.length() ) ); rb_hash_aset( result, ID2SYM(rb_intern("body")), rb_str_new( res->body.c_str(), res->body.length() ) ); @@ -153,10 +159,20 @@ } return Qnil; } static +VALUE Loop_flush( VALUE self ) +{ + EVD::Dispatch *d; + Data_Get_Struct( self, EVD::Dispatch, d ); + + d->flush(); + return Qnil; +} + +static VALUE Loop_stop( VALUE self ) { EVD::Dispatch *d; Data_Get_Struct( self, EVD::Dispatch, d ); @@ -189,10 +205,11 @@ // setup the Loop object rb_define_alloc_func( rb_Loop, Loop_alloc ); rb_define_method( rb_Loop, "start", (VALUE (*)(...))Loop_start, 0 ); rb_define_method( rb_Loop, "request_http", (VALUE (*)(...))Loop_request_http, 1 ); - rb_define_method( rb_Loop, "request", (VALUE (*)(...))Loop_request, 2 ); + rb_define_method( rb_Loop, "request", (VALUE (*)(...))Loop_request, -1 ); + rb_define_method( rb_Loop, "flush", (VALUE (*)(...))Loop_flush, 0 ); rb_define_method( rb_Loop, "response_for", (VALUE (*)(...))Loop_response_for, 1 ); rb_define_method( rb_Loop, "wait_for_response", (VALUE (*)(...))Loop_wait_for_response, 3 ); rb_define_method( rb_Loop, "stop", (VALUE (*)(...))Loop_stop, 0 ); }