static void pscom_psm_con_cleanup(pscom_con_t *con) { pspsm_con_info_t *ci = con->arch.psm.ci; if (!ci) return; pspsm_con_cleanup(ci); pspsm_con_free(ci); con->arch.psm.ci = NULL; }
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_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; /* --- */ }