Ejemplo n.º 1
0
proxyContext *proxyConnect( redisAddr *addrs, int count ) {
    proxyContext *p = proxyContextInit(count); 
    if( p == NULL )
        return NULL;

    p->count = 0;
    int cont = 0;
    for( int i = 0; i < count; i++ ) {
        redisContext *c = redisConnect(addrs[i].ip, addrs[i].port);
        if( c == NULL ) {
            printf("Connection Error: %s[%d]\n", addrs[i].ip, addrs[i].port);
        } 
        p->contexts[p->count++] = c;
        cont = createContinuum( p, &addrs[i], &(p->contexts[i]), cont);
    }

    sortContinuum( p, cont );

    if( p->count == 0 ){
        printf("No Connections\n");
        destroyProxyContext(p); 
    }

    return p;
}
Ejemplo n.º 2
0
static void	handle_continuum_start(LoadMibState *state, const char **atts)
{
	int		contnbr = 0;
	char		*contname = NULL;
	int		isNeighbor = 1;
	char		*desc = NULL;
	char		**att;
	char		*name;
	char		*value;
	int		idx;
	Continuum	*contin;

	if (noMibYet(state)) return;
	for (att = (char **) atts; *att; att++)
	{
		name = *att;
		att++;
		value = *att;
		if (strcmp(name, "nbr") == 0)
		{
			contnbr = atoi(value);
		}
		else if (strcmp(name, "name") == 0)
		{
			contname = value;
		}
		else if (strcmp(name, "neighbor") == 0)
		{
			isNeighbor = 1 - (0 == atoi(value));
		}
		else if (strcmp(name, "desc") == 0)
		{
			desc = value;
		}
		else return noteLoadError(state, "Unknown attribute.");
	}

	if (contname == NULL)
	{
		return noteLoadError(state, "Need name of continuum.");
	}

	idx = lookUpContinuum(contname);
	if (idx < 0)
	{
		contin = NULL;
	}
	else
	{
		if (contnbr == 0 || contnbr == idx)
		{
			contin = (_mib(NULL))->continua[idx];
		}
		else
		{
			return noteLoadError(state, "Continuum name/nbr \
mismatch.");
		}
	}

	switch (state->currentOperation)
	{
	case LoadAdding:
		if (contin == NULL)
		{
			contin = createContinuum(contnbr, contname, isNeighbor,
					desc);
			if (contin == NULL)
			{
				return putErrmsg("Couldn't add continuum.",
						contname);
			}
		}

		break;

	case LoadChanging:
		return noteLoadError(state, "'Change' not yet implemented.");

	case LoadDeleting:
		if (contin == NULL)
		{
			return noteLoadError(state, "No such continuum.");
		}

		return noteLoadError(state, "'Delete' not yet implemented.");

	default:
		return noteLoadError(state, "Not in an operation.");
	}
}