static void nc_ai_cb(void *arg, int error, struct addrinfo *ai) { struct nameconn *nc = arg; if (error == 0) { nc->ai_cur = nc->ai_res = ai; nc->state = NC_CONN; nc_connect(nc); } else nc_done(nc, error); }
static void nc_write_cb(int sd, short type, void *arg) { struct nameconn *nc = arg; int error; socklen_t errsiz = sizeof(int); if (getsockopt(nc->sd, SOL_SOCKET, SO_ERROR, &error, &errsiz) < 0) btpd_err("getsockopt error (%s).\r\n", strerror(errno)); if (error == 0) { btpd_ev_del(&nc->write_ev); nc_done(nc, 0); } else { btpd_ev_del(&nc->write_ev); closesocket(nc->sd); nc->ai_cur = nc->ai_cur->ai_next; nc_connect(nc); } }
int sc_start() { sc = (store_client_t *)malloc(sizeof(store_client_t)); nc_arg_t nc_arg; int rv = init_nc_arg(&nc_arg); if(rv < 0) return -1; printf("sc ip:%s,port:%d\n",nc_arg.ip,nc_arg.port); rv = nc_connect(&sc->nc,&nc_arg); if(rv < 0) return -1; sc->stop_daemon = 0; //start the main loop thread pthread_attr_t attr; pthread_attr_init(&attr); pthread_create(&sc->thread_id, &attr, thread_entry, sc); pthread_attr_destroy(&attr); return 0; }
int nc_connect_entry(struct CP_ENTRY *cpe) { int s = nc_socket(cpe); if(s==-1) return -1; return nc_connect(s, cpe) ? -1 : s; }