int benchmark_packet_handler(CONN *conn, CB_DATA *packet) { char *p = NULL, *end = NULL, *s = NULL; int respcode = -1; long long int len = 0; if(conn) { conn->over_timeout(conn); p = packet->data;end = packet->data + packet->ndata; //check response code if((s = strstr(p, "HTTP/"))) { s += 5; while(*s != 0x20 && s < end)++s; while(*s == 0x20)++s; if(*s >= '0' && *s <= '9') respcode = atoi(s); } conn->s_id = respcode; if(respcode != 200 && respcode != 204) nerrors++; /* if(respcode != 200) { //fprintf(stdout, "HTTP:%s\n", p); conn->over_timeout(conn); return http_over(conn, respcode); } */ //check Content-Length if((s = strcasestr(p, "Content-Length"))) { s += 14; while(s < end) { if(*s >= '0' && *s <= '9')break; else ++s; } if(*s >= '0' && *s <= '9' && (len = atoll(s)) > 0) { conn->recv_chunk(conn, len); } else { return http_check_over(conn); } } else { return http_check_over(conn); } } return -1; }
int benchmark_packet_handler(CONN *conn, CB_DATA *packet) { char *p = NULL, *end = NULL, *s = NULL; int respcode = -1; long long int len = 0; if(conn) { p = packet->data; end = packet->data + packet->ndata; //check response code if((s = strstr(p, "HTTP/"))) { s += 5; while(*s != 0x20 && s < end)++s; while(*s == 0x20)++s; if(*s >= '0' && *s <= '9') respcode = atoi(s); } conn->s_id = respcode; //check Content-Length if((s = strstr(p, "Content-Length")) || (s = strstr(p, "content-length"))) { s += 14; while(s < end) { if(*s >= '0' && *s <= '9')break; else++s; } if(*s >= '0' && *s <= '9' && (len = atoll(s)) > 0) return conn->recv_chunk(conn, len); } return http_check_over(conn); } return -1; }
int benchmark_data_handler(CONN *conn, CB_DATA *packet, CB_DATA *cache, CB_DATA *chunk) { if(conn) { return http_check_over(conn); } return 0; }
/* error handler */ int benchmark_error_handler(CONN *conn, CB_DATA *packet, CB_DATA *cache, CB_DATA *chunk) { if(conn) { //fprintf(stdout, "%s::%d error on conn[%s:%d] c_state:%d s_state:%d via %d\n", __FILE__, __LINE__, conn->local_ip, conn->local_port, conn->c_state, conn->s_state, conn->fd); return http_check_over(conn); } return -1; }
/* timeout handler*/ int benchmark_timeout_handler(CONN *conn, CB_DATA *packet, CB_DATA *cache, CB_DATA *chunk) { if(conn) { if(cache && cache->data) { ACCESS_LOGGER(logger, "timeout on conn[%s:%d] uri[%s] via %d status:%d", conn->local_ip, conn->local_port, cache->data, conn->fd, conn->status); } else { ACCESS_LOGGER(logger, "timeout on conn[%s:%d] via %d status:%d", conn->local_ip, conn->local_port, conn->fd, conn->status); } ntimeout++; return http_check_over(conn); } return -1; }