why fail to ngx_http_output_filter after a timer????

supergui nginx-forum at nginx.us
Thu Jul 30 11:50:33 MSD 2009


below codes are main illustration to my meaning, that is i set a timer(just 1000ms) to output body , but this doesn't work?  
is this something do with the return value or i need to do more things?



////////////////////////////////////////////////////////////////////////////////

char* out_buf[1024]={0}

static ngx_int_t
ngx_http_gdrive_handler(ngx_http_request_t *r)
{
     //set my context
     gdrive_module_ctx* gmc=(gdrive_module_ctx *)ngx_palloc(r->pool, sizeof(gdrive_module_ctx));
    ngx_http_set_ctx(r, gmc, ngx_http_gdrive_module);

      r->headers_out.status = NGX_HTTP_OK;
       r->headers_out.content_length_n = sizeof(out_buf);

       rc = ngx_http_send_header(r);
      
      gmc->try_trunk_eve.handler=write_trunk;
      gmc->try_trunk_eve->data=r;
      gmc->try_trunk_eve->log=r->connectoin->log;
      ngx_add_timer(&gmc->try_trunk_eve, 1000);        //write 1000ms later

      return NGX_AGAIN;
}

static void write_trunk(ngx_event_t *wev)
{
    ngx_http_request_t         *r = wev->data;
    gdrive_module_ctx* gmc=ngx_http_get_module_ctx(r, ngx_http_gdrive_module);

    ngx_buf_t    *b;
    ngx_chain_t   out;


    b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));


     out.buf = b;
    out.next = NULL;

    b->memory = 1;
    b->flush = 1;
    b->last_buf=1;


    b->pos=(u_char*)out_buf;
    b->last=b->pos+sizeof(out_buf);
    
     /*
     *           just can't output here?? the r->connection->fd has been change to an negative value?? but the connection has not been close yet,      why?
      */
     ngx_http_output_filter(r, &out);
}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,4601,4601#msg-4601






More information about the nginx mailing list