ApacheBench

 view release on metacpan or  search on metacpan

src/apachebench/socket_io.c  view on Meta::CPAN


#ifdef AB_DEBUG
    printf("AB_DEBUG: close_connection() - stage 2\n");
#endif

    /* finish if last response has been received */
    if (++registry->done >= registry->need_to_be_done)
        return;

#ifdef AB_DEBUG
    printf("AB_DEBUG: close_connection() - stage 3\n");
#endif

    /* else continue with requests in run queues */
    if (schedule_next_request(registry, c))
        start_connect(registry, c);
}


/* --------------------------------------------------------- */

/* write out request to a connection - assumes we can write
   (small) request out in one go into our new socket buffer  */

static void
write_request(struct global * registry, struct connection * c) {

#ifndef NO_WRITEV
    struct iovec out[2];
    int outcnt = 1;
#endif
    int bytes_sent;
    STRLEN len;
    SV *res;
    char *post_body;

#ifdef AB_DEBUG
    printf("AB_DEBUG: write_request() - stage 1, registry->done = %d\n", registry->done);
#endif
    gettimeofday(&c->before_postdata_time, 0);

    /* the url in this run has dynamicly-generated postdata */
    if (registry->posting[c->url] == 2) {
        res = call_perl_function__one_arg(registry->postsubs[c->url],
                                          newSVpv(c->url > 0 ? registry->stats[c->url - 1][c->thread].response : "", 0));

        if (SvPOK(res)) {
            post_body = SvPV(res, len);
#ifdef AB_DEBUG
            printf("AB_DEBUG: write_request() - stage 1-postsub.2, postsub res %s, length %d\n", post_body, (int)len);
#endif
            registry->postdata[c->url] = post_body;
            registry->postlen[c->url] = (int) len;
        } else {
            registry->postdata[c->url] = "";
            registry->postlen[c->url] = 0;
            registry->posting[c->url] = 0; // change back to a GET request
        }
    }

    gettimeofday(&c->connect_time, 0); // start timer

    reset_request(registry, c); // this generates the request headers; must call the above first to determine POST content

#ifdef AB_DEBUG
    printf("AB_DEBUG: write_request() - stage 2, registry->done = %d\n", registry->done);
#endif

#ifndef NO_WRITEV
    out[0].iov_base = c->request;
    out[0].iov_len = c->reqlen;

#ifdef AB_DEBUG
    printf("AB_DEBUG: write_request() - stage 2a.1, registry->done = %d, postdata[%d] = %s\n", registry->done, c->url, registry->postdata[c->url]);
#endif
    if (registry->posting[c->url] > 0) {
        out[1].iov_base = registry->postdata[c->url];
        out[1].iov_len = registry->postlen[c->url];
        outcnt = 2;
        registry->totalposted[c->url] = (c->reqlen + registry->postlen[c->url]);
    }
#ifdef AB_DEBUG
    printf("AB_DEBUG: write_request() - stage 2a.2, registry->done = %d\n", registry->done);
#endif
    bytes_sent = writev(c->fd, out, outcnt);

#else /* NO_WRITEV */

#ifdef AB_DEBUG
    printf("AB_DEBUG: write_request() - stage 2b.1, registry->done = %d, postdata[%d] = %s\n", registry->done, c->url, registry->postdata[c->url]);
#endif
    ab_write(c->fd, c->request, c->reqlen);
    if (registry->posting[c->url] > 0)
        bytes_sent = ab_write(c->fd, registry->postdata[c->url], registry->postlen[c->url]);
#endif /* NO_WRITEV */

#ifdef AB_DEBUG
    printf("AB_DEBUG: write_request() - stage 3, registry->done = %d, postdata[%d] = %s\n", registry->done, c->url, registry->postdata[c->url]);
#endif

    FD_SET(c->fd, &registry->readbits);
    FD_CLR(c->fd, &registry->writebits);
    gettimeofday(&c->sent_request_time, 0);

    if (registry->memory[c->run] >= 3)
        c->response = calloc(1, registry->buffersize[c->run]);
}

/* --------------------------------------------------------- */

/* setup or reset request */
static int
reset_request(struct global * registry, struct connection * c) {
    int i = c->url;

    char * ctype = calloc(40, sizeof(char));
    strcpy(ctype, "application/x-www-form-urlencoded");

#ifdef AB_DEBUG
    printf("AB_DEBUG: reset_request() - stage 0.1\n");
#endif



( run in 2.495 seconds using v1.01-cache-2.11-cpan-02777c243ea )