struct asfd *champ_chooser_connect(struct async *as, struct sdirs *sdirs, struct conf *conf) { int champsock=-1; char *champname=NULL; struct asfd *chfd=NULL; // Connect to champ chooser now. // This may start up a new champ chooser. On a machine with multiple // cores, it may be faster to do now, way before it is actually needed // in phase2. if((champsock=connect_to_champ_chooser(sdirs, conf))<0) { logp("could not connect to champ chooser\n"); goto error; } if(!(chfd=asfd_alloc()) || chfd->init(chfd, "champ chooser socket", as, champsock, NULL /* no SSL */, ASFD_STREAM_STANDARD, conf)) goto error; as->asfd_add(as, chfd); if(!(champname=prepend("cname", conf->cname, strlen(conf->cname), ":"))) goto error; if(chfd->write_str(chfd, CMD_GEN, champname) || chfd->read_expect(chfd, CMD_GEN, "cname ok")) goto error; free(champname); return chfd; error: free(champname); as->asfd_remove(as, chfd); asfd_free(&chfd); close_fd(&champsock); return NULL; }
struct asfd *champ_chooser_connect(struct async *as, struct sdirs *sdirs, struct conf **confs) { int champsock=-1; char *champname=NULL; struct asfd *chfd=NULL; const char *cname=NULL; // Connect to champ chooser now. // This may start up a new champ chooser. On a machine with multiple // cores, it may be faster to do now, way before it is actually needed // in phase2. if((champsock=connect_to_champ_chooser(sdirs, confs))<0) { logp("could not connect to champ chooser\n"); goto error; } if(!(chfd=setup_asfd(as, "champ chooser socket", &champsock, NULL, ASFD_STREAM_STANDARD, ASFD_FD_SERVER_TO_CHAMP_CHOOSER, -1, confs))) goto error; cname=get_string(confs[OPT_CNAME]); if(!(champname=prepend_n("cname", cname, strlen(cname), ":"))) goto error; if(chfd->write_str(chfd, CMD_GEN, champname) || chfd->read_expect(chfd, CMD_GEN, "cname ok")) goto error; free(champname); return chfd; error: free(champname); as->asfd_remove(as, chfd); asfd_free(&chfd); close_fd(&champsock); return NULL; }