Ejemplo n.º 1
0
static void
close_conn(client_t *cli, picoev_loop* loop)
{
  if(!cli->keep_alive){
    picoev_del(loop, cli->fd);
    clean_cli(cli);
    close(cli->fd);
#ifdef DEBUG
    printf("close fd %d \n", cli->fd);
#endif
    ruby_xfree(cli);
  }else{
    clean_cli(cli);
    disable_cork(cli);
    cli->keep_alive = 1;
    cli->environ = Qnil;
    cli->http_status = Qnil;
    cli->headers = Qnil;
    cli->header_done = 0;
    cli->body_type = BODY_TYPE_NONE;
    cli->status_code = 0;
    cli->response = Qnil;
    cli->content_length_set = 0;
    cli->content_length = 0;
    cli->write_bytes = 0;
    cli->response_closed = 0;
    cli->bad_request_code = 0;
    init_parser(cli, server_name, server_port);
  }
}
Ejemplo n.º 2
0
static inline void 
close_conn(client_t *cli, picoev_loop* loop)
{
    client_t *new_client;
    if(!cli->response_closed){
        close_response(cli);
    }

    picoev_del(loop, cli->fd);
    clean_cli(cli);

#ifdef DEBUG
    printf("start close client:%p fd:%d status_code %d \n", cli, cli->fd, cli->status_code);
    printf("picoev_del client:%p fd:%d \n", cli, cli->fd);
    printf("remain http pipeline size :%d \n", cli->request_queue->size);
#endif
    
    if(cli->request_queue->size > 0){
        if(check_status_code(cli) > 0){
            //process pipeline 
            prepare_call_wsgi(cli);
            call_wsgi_app(cli, loop);
        }
        return ;
    }

    if(cli->http != NULL){
        PyMem_Free(cli->http);
    }

    free_request_queue(cli->request_queue);
    if(!cli->keep_alive){
        close(cli->fd);
#ifdef DEBUG
        printf("close client:%p fd:%d status_code %d \n", cli, cli->fd, cli->status_code);
#endif
    }else{
        disable_cork(cli);
        new_client = new_client_t(cli->fd, cli->remote_addr, cli->remote_port);
        new_client->keep_alive = 1;
        init_parser(new_client, server_name, server_port);
        picoev_add(main_loop, new_client->fd, PICOEV_READ, keep_alive_timeout, r_callback, (void *)new_client);
    }
    //PyMem_Free(cli);
    dealloc_client(cli);
#ifdef DEBUG
    printf("********************\n\n");
#endif

}