Example #1
0
File: bench.c Project: hnkien/river
/**
 * pthread entry point, running the reader event base.
 */
void *
comet_run_readers(void *ptr) {

	struct reader_thread *rt = ptr;
	int i, j;
	rt->base = event_base_new();

	for(i = 0; i < rt->channel_count; ++i) {
		char *chan = rt->channels[i];
		char *url = calloc(strlen(chan) + 17, 1);
		sprintf(url, "/subscribe?name=%s", chan);

		for(j = 0; j < rt->reader_per_chan; ++j) {

			struct evhttp_connection *evcon = evhttp_connection_new(rt->hi->host, rt->hi->port);
			struct evhttp_request *evreq = evhttp_request_new(on_end_of_subscribe, rt);

			evhttp_connection_set_base(evcon, rt->base);
			evhttp_request_set_chunked_cb(evreq, on_http_message_chunk);
			evhttp_make_request(evcon, evreq, EVHTTP_REQ_GET, url);
			/* printf("[SUBSCRIBE: http://127.0.0.1:1234%s]\n", url); */
		}
	}
	event_base_dispatch(rt->base);
	return NULL;
}
Example #2
0
int
pubsub_to_pubsub_main_path(char *source_address, int source_port, char *target_address, int target_port, int (*cb)(char *data, struct evbuffer *evb, char **target_path, void *arg), void *cbarg, char *target_path)
{

    event_init();

    struct evhttp_connection *evhttp_source_connection = NULL;
    struct evhttp_connection *evhttp_target_connection = NULL;
    struct evhttp_request *evhttp_source_request = NULL;
    
    fprintf(stdout, "connecting to http://%s:%d/sub\n", source_address, source_port);
    evhttp_source_connection = evhttp_connection_new(source_address, source_port);
    if (evhttp_source_connection == NULL) {
        fprintf(stdout, "FAILED CONNECT TO SOURCE %s:%d\n", source_address, source_port);
        exit(1);
    }

    fprintf(stdout, "connecting to http://%s:%d/pub\n", target_address, target_port);
    evhttp_target_connection = evhttp_connection_new(target_address, target_port);
    if (evhttp_target_connection == NULL) {
        fprintf(stdout, "FAILED CONNECT TO TARGET %s:%d\n", target_address, target_port);
        exit(1);
    }

    struct global_data *data;
    data = calloc(1, sizeof(*data));
    data->evhttp_target_connection = evhttp_target_connection;
    data->target_address = target_address;
    data->target_path = calloc(4096, sizeof(char *));
    strcpy(data->target_path, target_path);
    data->cb = cb;
    data->cbarg = cbarg;

    evhttp_source_request = evhttp_request_new(http_chunked_request_done, data);
    evhttp_add_header(evhttp_source_request->output_headers, "Host", source_address);
    evhttp_request_set_chunked_cb(evhttp_source_request, source_callback);

    if (evhttp_make_request(evhttp_source_connection, evhttp_source_request, EVHTTP_REQ_GET, "/sub") == -1) {
        fprintf(stdout, "FAILED make_request to source\n");
        exit(1);
    }

    event_dispatch();
    evhttp_connection_free(evhttp_source_connection);
    evhttp_connection_free(evhttp_target_connection);
    fprintf(stdout, "EXITING\n");

    return 0;
}