static void gfarm_paraccess_connect_finish(void *closure) { struct gfarm_access *a = closure; gfarm_error_t e; struct gfs_connection *gfs_server; e = gfs_client_connect_result_multiplexed(a->protocol_state, &gfs_server); if (e != GFARM_ERR_NO_ERROR) { gfarm_paraccess_callback(a->pa, a, &a->load, NULL, e); return; } gfarm_paraccess_callback(a->pa, a, &a->load, gfs_server, e); gfs_client_disconnect(gfs_server); }
static void gfarm_paraccess_load_finish(void *closure) { struct gfarm_access *a = closure; gfarm_error_t e; e = gfs_client_get_load_result_multiplexed(a->protocol_state, &a->load); gfarm_paraccess_callback(a->pa, a, e == GFARM_ERR_NO_ERROR ? &a->load : NULL, NULL, e); }
static void gfarm_paraccess_connect_request(void *closure) { struct gfarm_access *a = closure; gfarm_error_t e; struct gfs_client_connect_state *cs; e = gfs_client_get_load_result_multiplexed(a->protocol_state, &a->load); if (e != GFARM_ERR_NO_ERROR) { gfarm_paraccess_callback(a->pa, a, NULL, NULL, e); return; } e = gfs_client_connect_request_multiplexed(a->pa->q, a->canonical_hostname, &a->peer_addr, gfarm_paraccess_connect_finish, a, &cs); if (e != GFARM_ERR_NO_ERROR) { gfarm_paraccess_callback(a->pa, a, &a->load, NULL, e); return; } a->protocol_state = cs; }
gfarm_error_t gfarm_paraccess_request(struct gfarm_paraccess *pa, void *closure, char *canonical_hostname, int port, struct sockaddr *peer_addr) { int rv; gfarm_error_t e; struct gfarm_access *a; struct gfs_client_get_load_state *gls; /* * Wait until at least one slot becomes available. * We limit concurrency here. */ while (pa->free_list == NULL) { rv = gfarm_eventqueue_turn(pa->q, NULL); if (rv == EAGAIN || rv == EINTR) { continue; /* not really an error */ } else if (rv != 0) { return (gfarm_errno_to_error(rv)); } } /* acquire free slot */ a = pa->free_list; pa->free_list = a->next; --pa->nfree; a->closure = closure; a->canonical_hostname = canonical_hostname; a->port = port; a->peer_addr = *peer_addr; e = gfs_client_get_load_request_multiplexed(pa->q, &a->peer_addr, pa->try_auth ? gfarm_paraccess_connect_request : gfarm_paraccess_load_finish, a, &gls, 1); if (e != GFARM_ERR_NO_ERROR) { gfarm_paraccess_callback(pa, a, NULL, NULL, e); return (e); } a->protocol_state = gls; a->pa = pa; return (GFARM_ERR_NO_ERROR); }