/* http over */ int http_over(CONN *conn, int respcode) { int id = 0, n = 0, m = 0, nerror = 0, ntimeout = 0; if(conn) { MUTEX_LOCK(mutex); if(ncompleted < ntasks) { n = ++ncompleted; m = nrequests; nerror = nerrors; ntimeout = ntimeouts; } MUTEX_UNLOCK(mutex); //WARN_LOGGER(logger, "complete %d conn[%s:%d] via %d", n, conn->local_ip, conn->local_port, conn->fd); id = conn->c_id; if(n > 0 && n <= ntasks && (n%1000) == 0) { if(is_quiet) { REALLOG(logger, "requests:%d completed:%d error:%d timeout:%d concurrecy:%d", m, n, nerror, ntimeout, ncurrent); } else { fprintf(stdout, "requests:%d completed:%d error:%d timeout:%d concurrecy:%d\n", m, n, nerror, ntimeout, ncurrent); } } if(m < ntasks) { if(conn->d_state == 0 && is_keepalive && respcode == 200) { return http_request(conn); } else { if(is_keepalive) conn->close(conn); //if(respcode != 0 && respcode != 200)nerrors++; if(http_newconn(id, server_ip, server_port, server_is_ssl) == NULL) { if(ncurrent > 0)--ncurrent; } } } else { --ncurrent; conn->close(conn); } if(running_status && n == ntasks) { return http_show_state(n); } } return -1; }
static void benchmark_stop(int sig) { switch (sig) { case SIGINT: case SIGTERM: fprintf(stderr, "benchmark is interrupted by user.\n"); running_status = 0; http_show_state(ncompleted); if(sbase)sbase->stop(sbase); break; default: break; } }
/* http over */ int http_over(CONN *conn, int respcode) { int id = 0, n = 0; if(conn) { conn->over_cstate(conn); id = conn->c_id; if(ncompleted < ntasks) ++ncompleted; else return conn->over(conn); n = ncompleted; if(n > 0 && n <= ntasks && (n%1000) == 0) { if(is_quiet) { REALLOG(logger, "completed %d current:%d", n, ncurrent); } else fprintf(stdout, "completed %d current:%d\n", n, ncurrent); } if(ncompleted < ntasks) { if(conn->d_state == 0 && is_keepalive && respcode != 0) return http_request(conn); else { conn->close(conn); if(respcode != 0 && respcode != 200)nerrors++; if(http_newconn(id, server_ip, server_port, server_is_ssl) == NULL) { if(ncurrent > 0)--ncurrent; } } } else { conn->close(conn); if(n == ntasks) return http_show_state(n); } } return -1; }