Exemplo n.º 1
0
static void add_default_headers()
{
    struct headers *header;
    for (header = default_headers; header->header != NULL; header++) {
        struct headers *h = malloc(sizeof(*h));
        RING_INIT(h);
        h->header = header->header;
        h->value = header->value;
        RING_APPEND(config_opts.headers, header);
    }
}
Exemplo n.º 2
0
static void
init_thread(thread_pool_t *tp, thread_t *t)
{
    ASSERT(tp && t, "init empty thread pool");
	pthread_mutex_init(&t->task_list_lock, NULL);
    pthread_cond_init(&t->task_list_aval_cond, NULL);
	t->manager = tp;
	t->state = IDLE;
	RING_INIT(&t->tasks, task, link);
	t->mem_pool = mem_pool_create(sizeof(task_t), TASK_POOL_SIZE, false);
}
Exemplo n.º 3
0
static struct headers *parse_header_param(const char *optarg)
{
    struct headers *header;
    char *hp;
    char *h = optarg ? strdup(optarg) : NULL;
    if (h == NULL)
        return NULL;

    header = malloc(sizeof(*header));
    RING_INIT(header);
    memset(header, 0, sizeof(*header));

    if ((hp = strstr(h, ":")) == NULL) {
        header->header = h; // only the header was found
        return header;
    } else {
        *hp++ = '\0';
        while (*h == ' ') h++; /* consume whitespace */
        header->header = h;
        while (*hp == ' ') hp++; /* consume whitespace */
        header->value = hp;
        return header;
    }
}
Exemplo n.º 4
0
void parse_args(int argc, char *argv[])
{
    long l;
    int i;
    const char *progname = argv[0];
    struct headers *header;

    initialize_params();

    while ((i = getopt(argc, argv, opts)) > 0) {
        switch (i) {
        case 'H':
            header = parse_header_param(optarg);
            if (header == NULL) {
                fprintf(stderr, "error parsing -H parameter\n");
                print_help(stderr, progname);
                exit(-1);
            } else {
                overwrite_header(&config_opts.headers, header);
            }
            break;
        case 'C':
        {
            /* split on : if present
             * first part is config_opts.connect
             * second part is config_opts.connect_port
             */
            char *portstr;
            config_opts.connect = strdup(optarg);
            portstr = strchr(config_opts.connect, ':');
            if (portstr)
                *portstr++ = '\0'; /* terminate the host part */
            if (portstr && *portstr) {
                errno = 0;
                l = strtol(portstr, (char **)NULL, 10);
                if (errno) {
                    perror("invalid connect port (-C) value");
                    print_help(stderr, progname);
                    exit(-1);
                } else if (l < 0 || l >= USHRT_MAX) {
                    fprintf(stderr, "invalid connect port (-C): %ld\n",
                            l);
                    print_help(stderr, progname);
                    exit(-1);
                }
                config_opts.connect_port = (unsigned short)l;
            }
        }
        break;
        case 'c':
            errno = 0;
            l = strtol(optarg, (char **)NULL, 10);
            if (errno) {
                perror("invalid concurrency (-c) value");
                print_help(stderr, progname);
                exit(-1);
            } else if (l <= 0 || l == LONG_MAX) {
                fprintf(stderr, "invalid concurrency (-c): %ld\n", l);
                print_help(stderr, progname);
                exit(-1);
            }
            config_opts.concurrency = (int)l;
            break;
        case 'n':
            errno = 0;
            l = strtol(optarg, (char **)NULL, 10);
            if (errno) {
                perror("invalid request count (-n) value");
                print_help(stderr, progname);
                exit(-1);
            } else if (l <= 0 || l == LONG_MAX) {
                fprintf(stderr, "invalid request count (-n): %ld\n", l);
                print_help(stderr, progname);
                exit(-1);
            }
            config_opts.count = (int)l;
            break;
        case 'o':
            config_opts.halfopen = 1;
            break;
        case 'v':
            config_opts.verbose++;
            break;
        default:
            fprintf(stderr, "Unknown option: %o\n", i);
        case 'h':
            print_help(stderr, progname);
            exit(-1);
            break;
        }
    }
    argc -= optind;
    argv += optind;
    if (argc == 0) {
        fprintf(stderr, "At least one URL required...");
        print_help(stderr, progname);
        exit(-1);
    } else for (i = 0; i < argc; i++) {
            struct urls *url = malloc(sizeof(*url));
            RING_INIT(url);
            url->url = strdup(argv[i]);
            RING_APPEND(config_opts.urls, url);
        }
}