static void prepare_mock_test(io_poller *poller, const char *name) { switch(name[0]) { case 'c': // client io_mock_set_events(poller, &client_events); // the test script uses two outgoing connections initiate_connection(poller, "127.0.0.1:6543"); initiate_connection(poller, "127.0.0.1:6543"); break; case 's': // server io_mock_set_events(poller, &server_events); create_listener(poller, "127.0.0.1:6543"); break; case 'e': // error io_mock_set_events(poller, &error_events); create_listener(poller, "127.0.0.1:6543"); create_listener(poller, "127.0.0.1:6544"); initiate_connection(poller, "127.0.0.1:6500"); break; default: fprintf(stderr, "Specify either 'client' or 'server', not '%s'.\n", optarg); exit(1); } }
int main(int argc, char *argv[]) { char * temp=malloc(strlen(argv[argc-1]+1)); strcpy(temp,argv[argc-1]); umask(0); printf("Reply potato: %d\nRequest potato: %d\n",SIZEOF_REPLY_POTATO,SIZEOF_REQUEST_POTATO); initiate_connection(temp); return fuse_main(argc-1, argv, &xmp_oper, NULL); }
static void process_args(io_poller *poller, int argc, char **argv) { char buf[256], *cp; int optidx, i, c; optidx = 0; static struct option longopts[] = { // name, has_arg (1=reqd,2=opt), flag, val {"mock", 1, 0, 'm'}, {"client", 1, 0, 'c'}, {"server", 1, 0, 's'}, {0, 0, 0, 0}, }; // dynamically create the option string from the long // options. Why oh why doesn't glibc do this for us??? cp = buf; for(i=0; longopts[i].name; i++) { if(!longopts[i].flag) { *cp++ = longopts[i].val; if(longopts[i].has_arg > 0) *cp++ = ':'; if(longopts[i].has_arg > 1) *cp++ = ':'; } } *cp++ = '\0'; for(;;) { c = getopt_long(argc, argv, buf, longopts, &optidx); if(c == -1) break; switch(c) { case 'c': init_poller(poller, IO_POLLER_ANY); initiate_connection(poller, optarg); break; case 'm': init_poller(poller, IO_POLLER_MOCK); prepare_mock_test(poller, optarg); break; case 's': init_poller(poller, IO_POLLER_ANY); create_listener(poller, optarg); break; case '?': // getopt_long already printed the error message exit(1); } } }
void restart_connections_by_peer(struct connection *c) { struct connection *d; if (c->host_pair == NULL) return; d = c->host_pair->connections; for (; d != NULL; d = d->hp_next) { if ( #ifdef DYNAMICDNS (c->dnshostname && d->dnshostname && (strcmp(c->dnshostname, d->dnshostname) == 0)) || (c->dnshostname == NULL && d->dnshostname == NULL && #endif /* DYNAMICDNS */ sameaddr(&d->spd.that.host_addr, &c->spd.that.host_addr) #ifdef DYNAMICDNS ) #endif /* DYNAMICDNS */ ) terminate_connection(d->name); } #ifdef DYNAMICDNS update_host_pairs(c); #endif /* DYNAMICDNS */ if (c->host_pair == NULL) return; d = c->host_pair->connections; for (; d != NULL; d = d->hp_next) { if ( #ifdef DYNAMICDNS (c->dnshostname && d->dnshostname && (strcmp(c->dnshostname, d->dnshostname) == 0)) || (c->dnshostname == NULL && d->dnshostname == NULL && #endif /* DYNAMICDNS */ sameaddr(&d->spd.that.host_addr, &c->spd.that.host_addr) #ifdef DYNAMICDNS ) #endif /* DYNAMICDNS */ ) initiate_connection(d->name, NULL_FD, 0, pcim_demand_crypto); } }
/* Get resource denoted by the |uri|. The debug and error messages are printed in stderr, while the response body is printed in stdout. */ static void run(const char *uri) { struct http_parser_url u; char *host; uint16_t port; int rv; SSL_CTX *ssl_ctx; struct event_base *evbase; http2_session_data *session_data; /* Parse the |uri| and stores its components in |u| */ rv = http_parser_parse_url(uri, strlen(uri), 0, &u); if(rv != 0) { errx(1, "Could not parse URI %s", uri); } host = strndup(&uri[u.field_data[UF_HOST].off], u.field_data[UF_HOST].len); if(!(u.field_set & (1 << UF_PORT))) { port = 443; } else { port = u.port; } ssl_ctx = create_ssl_ctx(); evbase = event_base_new(); session_data = create_http2_session_data(evbase); session_data->stream_data = create_http2_stream_data(uri, &u); initiate_connection(evbase, ssl_ctx, host, port, session_data); free(host); host = NULL; event_base_loop(evbase, 0); event_base_free(evbase); SSL_CTX_free(ssl_ctx); }