static int pscom_psm_connect(pscom_con_t *con, int con_fd) { int arch = PSCOM_ARCH_PSM; pspsm_con_info_t *ci = pspsm_con_create(); pspsm_info_msg_t msg; pspsm_info_msg_t my_msg; if (pspsm_init() || !ci) goto dont_use; if (pspsm_con_init(ci)) goto dont_use; ci->con = con; /* We want talk psm */ pscom_writeall(con_fd, &arch, sizeof(arch)); /* step 1 */ if ((pscom_readall(con_fd, &arch, sizeof(arch)) != sizeof(arch)) || (arch != PSCOM_ARCH_PSM)) { goto err_remote; } /* step 2 : recv connection id's */ if ((pscom_readall(con_fd, &msg, sizeof(msg)) != sizeof(msg))) { goto err_remote; } /* step 3: send my connection id's */ pspsm_con_get_info_msg(ci, &my_msg); pscom_writeall(con_fd, &my_msg, sizeof(my_msg)); /* Connect */ if (pspsm_con_connect(ci, &msg)) { /* ToDo: bad! How to inform the peer about the error? */ DPRINT(0, "Psm pspsm_con_connect() failed!"); goto err_local; } pscom_psm_con_init(con, con_fd, ci); return 1; /* --- */ err_local: err_remote: dont_use: if (ci) { pspsm_con_cleanup(ci); pspsm_con_free(ci); } return 0; }
static int pscom_extoll_accept(pscom_con_t *con, int con_fd) { int arch = PSCOM_ARCH_EXTOLL; psex_con_info_t *ci = psex_con_create(); psex_info_msg_t msg; if (!ci) goto err_no_ci; if (psex_init()) goto out_noextoll; if (psex_con_init(ci, NULL, con)) goto dont_use; /* Initialize connection */ /* step 1: Yes, we talk extoll. */ pscom_writeall(con_fd, &arch, sizeof(arch)); /* step 2: Send Connection id's */ psex_con_get_info_msg(ci, &msg); pscom_writeall(con_fd, &msg, sizeof(msg)); /* step 3 : recv connection id's */ if ((pscom_readall(con_fd, &msg, sizeof(msg)) != sizeof(msg))) goto err_remote; /* Connect */ if (psex_con_connect(ci, &msg)) { /* ToDo: bad! How to inform the peer about the error? */ DPRINT(0, "Extoll psex_con_connect() failed!"); goto err_local; } pscom_extoll_con_init(con, con_fd, ci); return 1; /* --- */ err_local: err_remote: if (ci) psex_con_cleanup(ci); if (ci) psex_con_free(ci); return 0; /* --- */ dont_use: out_noextoll: psex_con_free(ci); err_no_ci: arch = PSCOM_ARCH_ERROR; pscom_writeall(con_fd, &arch, sizeof(arch)); return 0; /* Dont use extoll */ /* --- */ }
static int pscom_shm_connect(pscom_con_t *con, int con_fd) { int arch = PSCOM_ARCH_SHM; shm_conn_t shm; shm_info_msg_t msg; int err; if (!shm_is_local(con)) return 0; /* Dont use sharedmem */ /* talk shm? */ pscom_writeall(con_fd, &arch, sizeof(arch)); /* step 1 */ if ((pscom_readall(con_fd, &arch, sizeof(arch)) != sizeof(arch)) || (arch != PSCOM_ARCH_SHM)) goto err_remote; /* step 2 : recv shm_id */ if ((pscom_readall(con_fd, &msg, sizeof(msg)) != sizeof(msg)) || (msg.shm_id == -1)) goto err_remote; shm.local_com = NULL; shm.remote_com = NULL; err = shm_initrecv(&shm) || shm_initsend(&shm, msg.shm_id); /* step 3 : send shm_id or error */ msg.shm_id = err ? -1 : shm.local_id; pscom_writeall(con_fd, &msg, sizeof(msg)); if (err) goto err_local; /* step 4: Shared mem initialized. Recv final ACK. */ if ((pscom_readall(con_fd, &msg, sizeof(msg)) != sizeof(msg)) || (msg.shm_id == -1)) goto err_ack; shm_init_con(con, con_fd, &shm); return 1; /* --- */ err_ack: err_local: if (shm.local_com) shmdt(shm.local_com); if (shm.remote_com) shmdt(shm.remote_com); err_remote: return 0; }
static int pscom_psm_accept(pscom_con_t *con, int con_fd) { int arch = PSCOM_ARCH_PSM; pspsm_con_info_t *ci = pspsm_con_create(); pspsm_info_msg_t msg; if (pspsm_init() || !ci) goto out_nopsm; if (pspsm_con_init(ci)) goto dont_use; /* step 1: Yes, we talk psm. */ pscom_writeall(con_fd, &arch, sizeof(arch)); /* step 2: Send Connection id's */ pspsm_con_get_info_msg(ci, &msg); pscom_writeall(con_fd, &msg, sizeof(msg)); /* step 3 : recv connection id's */ if ((pscom_readall(con_fd, &msg, sizeof(msg)) != sizeof(msg))) { goto err_remote; } /* Connect */ if (pspsm_con_connect(ci, &msg)) { /* ToDo: bad! How to inform the peer about the error? */ DPRINT(0, "Psm pspsm_con_connect() failed!"); goto err_local; } pscom_psm_con_init(con, con_fd, ci); return 1; /* --- */ err_local: err_remote: if (ci) pspsm_con_cleanup(ci); dont_use: if (ci) pspsm_con_free(ci); return 0; /* --- */ out_nopsm: arch = PSCOM_ARCH_ERROR; pscom_writeall(con_fd, &arch, sizeof(arch)); return 0; /* --- */ }
static int pscom_elan_connect(pscom_con_t *con, int con_fd) { int arch = PSCOM_ARCH_ELAN; pselan_con_info_t *ci = pselan_con_create(); pselan_info_msg_t msg; pselan_info_msg_t my_msg; if (!ci) goto dont_use; /* Dont use elan */ /* We want talk elan */ pscom_writeall(con_fd, &arch, sizeof(arch)); /* step 1 */ if ((pscom_readall(con_fd, &arch, sizeof(arch)) != sizeof(arch)) || (arch != PSCOM_ARCH_ELAN)) goto err_remote; /* step 2 : recv connection id's */ if ((pscom_readall(con_fd, &msg, sizeof(msg)) != sizeof(msg))) goto err_remote; /* step 3: send my connection id's */ my_msg.destvp = pselan_get_myvp(); my_msg.remote_ptr = pselan_get_r_ptr(ci); pscom_writeall(con_fd, &my_msg, sizeof(my_msg)); /* Connect */ pselan_connect(ci, msg.destvp, msg.remote_ptr); pscom_elan_con_init(con, con_fd, ci); return 1; /* --- */ err_remote: dont_use: if (ci) { pselan_con_destroy(ci); } return 0; }
static int pscom_shm_accept(pscom_con_t *con, int con_fd) { int arch = PSCOM_ARCH_SHM; shm_conn_t shm; shm_info_msg_t msg; if ((!shm_is_local(con)) || shm_initrecv(&shm)) { arch = PSCOM_ARCH_ERROR; pscom_writeall(con_fd, &arch, sizeof(arch)); return 0; /* Dont use sharedmem */ } /* step 1: Yes, we talk shm. */ pscom_writeall(con_fd, &arch, sizeof(arch)); /* step 2: Send shm_id. */ msg.shm_id = shm.local_id; pscom_writeall(con_fd, &msg, sizeof(msg)); /* step 3: Recv shm_id. */ if ((pscom_readall(con_fd, &msg, sizeof(msg)) != sizeof(msg)) || msg.shm_id == -1) goto err_remote; if (shm_initsend(&shm, msg.shm_id)) goto err_local; /* step 4: Shared mem initialized. Send final ACK. */ msg.shm_id = 0; pscom_writeall(con_fd, &msg, sizeof(msg)); shm_init_con(con, con_fd, &shm); return 1; /* --- */ err_local: msg.shm_id = -1; /* send error */ pscom_writeall(con_fd, &msg, sizeof(msg)); err_remote: shmdt(shm.local_com); return 0; /* shm failed */ }
static int pscom_elan_accept(pscom_con_t *con, int con_fd) { int arch = PSCOM_ARCH_ELAN; pselan_con_info_t *ci = pselan_con_create(); pselan_info_msg_t msg; if (!ci) goto out_noelan; /* step 1: Yes, we talk elan. */ pscom_writeall(con_fd, &arch, sizeof(arch)); /* step 2: Send Connection id's */ msg.destvp = pselan_get_myvp(); msg.remote_ptr = pselan_get_r_ptr(ci); pscom_writeall(con_fd, &msg, sizeof(msg)); /* step 3 : recv connection id's */ if ((pscom_readall(con_fd, &msg, sizeof(msg)) != sizeof(msg))) goto err_remote; /* Connect */ pselan_connect(ci, msg.destvp, msg.remote_ptr); pscom_elan_con_init(con, con_fd, ci); return 1; /* --- */ err_remote: if (ci) { pselan_con_destroy(ci); } out_noelan: arch = PSCOM_ARCH_ERROR; pscom_writeall(con_fd, &arch, sizeof(arch)); return 0; /* Dont use elan */ /* --- */ }