Exemplo n.º 1
0
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;
}
Exemplo n.º 2
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;
	/* --- */
}
Exemplo n.º 3
0
static
void pscom_psm_init(void)
{
	pspsm_debug = pscom.env.debug;
	pspsm_debug_stream = pscom_debug_stream();

	/* see comment in pspsm_init() */
	pscom_env_get_uint(&pscom.env.psm_uniq_id, ENV_PSM_UNIQ_ID);
	if (!pscom.env.psm_uniq_id) {
		pscom_env_get_uint(&pscom.env.psm_uniq_id, ENV_PMI_ID);
	}

	INIT_LIST_HEAD(&pspsm_poll.poll.next);
	pspsm_poll.poll.do_read = pscom_psm_make_progress;

	// Preinitialize pspsm. Ignore errors. pscom_psm_connect will see the error again.
	pspsm_init();
}
Exemplo n.º 4
0
static
int pscom_psm_con_init(pscom_con_t *con)
{
	return pspsm_init();
}