예제 #1
0
/* Create a control connection to a slave */
static int
new_control_connection(group_t *g, char *host)
{
	protocol_t *p;

	if (host == NULL || host[0] == '\0') {
		uperf_error("remotehost not specified. Check profile\n");
		return (UPERF_FAILURE);
	}
	/* First check if we already have one */
	p = g->control;
	while (p) {
		if (strncasecmp(host, p->host, MAXHOSTNAME) == 0) {
			uperf_info("Resuing control connection for %s\n", host);
			return (UPERF_SUCCESS);
		}
		p = p->next;
	}
	/* Not found, create a new one */
	p = create_protocol(PROTOCOL_TCP, host, MASTER_PORT, MASTER);
	if (p != NULL) {
		/* Try connecting */
		if (p->connect(p, NULL) == 0) {
			p->next = g->control;
			if (g->control)
				g->control->prev = p;
			g->control = p;
			slaves[no_slaves++] = p;
			return (UPERF_SUCCESS);
		}
	}
	uperf_error("Error connecting to %s\n", host);
	return (UPERF_FAILURE);
}
ProtocolFacade* spark_protocol_instance(void)
{
	static ProtocolFacade* protocol = nullptr;

	if (!protocol) {
		bool udp = HAL_Feature_Get(FEATURE_CLOUD_UDP);
		DEBUG("UDP enabled %d", udp);
		protocol = create_protocol(udp ? PROTOCOL_DTLS : PROTOCOL_LIGHTSSL);
	}
	return protocol;
}