Ejemplo n.º 1
0
int LcReplGroup::connGroupLstnrs()
{
    Addr2ClntConnMap_t::iterator itr;
    Addr2ClntConnMap_t &lstrMap = m_pSockConnMgr->getClntConnMap();
    const char* sockAddr;
    ClientConn * pConn;
    for (itr = lstrMap.begin(); itr != lstrMap.end(); itr = lstrMap.next ( itr ))
    {
        sockAddr = itr.first();
        pConn = itr.second();
        LS_DBG_M("LcReplGroup::connAllListenSvr addr:%s", sockAddr);
        if (!pConn->isActive() )
        {
            LS_DBG_M("LcReplGroup::connAllListenSvr is not active,  pMultiplexer:%p", getMultiplexer());
            pConn->closeConnection();
            pConn->SetMultiplexer(getMultiplexer() );

            GSockAddr serverAddr;
            serverAddr.set(sockAddr, AF_INET );
            if (pConn->connectTo (&serverAddr) != -1)
            {
                LS_INFO ("node[%s] addr=%p, is connecting to master[%s]"
                    ,pConn->getLocalAddr(), pConn, sockAddr);

                LcReplSender::getInstance().clientJoinListenSvrReq(pConn);
            }
            else
                LS_INFO ("failed to connect to master %d", pConn->isActive());
        }
    }
  return LS_OK;
}
Ejemplo n.º 2
0
int CoreSocket::listen(const char *pURL, int backlog, int *fd, int sndBuf,
                       int rcvBuf)
{
    int ret;
    GSockAddr server;
    ret = server.set(pURL, 0);
    if (ret != 0)
        return LS_FAIL;
    return listen(server, backlog, fd, sndBuf, rcvBuf);
}
Ejemplo n.º 3
0
int  CoreSocket::connect(const char *pURL, int iFLTag, int *fd,
                         int dnslookup,
                         int nodelay)
{
    int ret;
    GSockAddr server;
    *fd = -1;
    int tag = NO_ANY;
    if (dnslookup)
        tag |= DO_NSLOOKUP;
    ret = server.set(pURL, tag);
    if (ret != 0)
        return LS_FAIL;
    return connect(server, iFLTag, fd, nodelay);
}
Ejemplo n.º 4
0
int HttpListener::start()
{
    GSockAddr addr;
    if ( addr.set( getAddrStr(), 0 ) )
        return errno;
    int fd;
    int ret = CoreSocket::listen( addr,
            SmartSettings::getSockBacklog(), &fd,
            m_iSockSendBufSize, m_iSockRecvBufSize );
    if ( ret != 0 )
    {
        return ret;
    }
    return setSockAttr( fd, addr );
}
Ejemplo n.º 5
0
bool LcReplConf::parse(const char *szFile)
{
    char pSockAddr[64];
    const char* pAddr;    
    StringList lbAddrs;
    AutoStr str;
    if (!m_confParser.loadConfig(szFile, "="))
    {
        initLogger("stderr", "DBG");
        LS_ERROR (  "LcReplConf unable to load config %s, error:%s"
            , szFile, m_confParser.getErrorMessage());
        return false;               
    }
    initLogger(getLogFile(), getLogLevel());

    const char *pEntry = m_confParser.getConfig("REPL.LBADDRS");
    setLBAddrs(pEntry);
    
    GSockAddr sockAddr;
    //LISTENSVRADDR
    pAddr = m_confParser.getConfig("REPL.LISTENSVRADDR");
    if (!setLisenSvrAddr(pAddr))
    {
        LS_ERROR ( "LcReplConf fails to load Repl ListenSvrAddr %s", pAddr);
        return false;        
    }
    m_lsntnrSvrIp = getIpOfAddr(pAddr, str);
    
    if ( !isAllowedIP(getLocalLsntnrIp() ))
    {
        LS_ERROR ( "Repl ListenSvrIp %s is not in LB Addrs"
            , getLocalLsntnrIp());
        return false;
    }
    //MEMCACHEDADDR
    pAddr = m_confParser.getConfig("CACHED.ADDR");
    if (pAddr == NULL || sockAddr.set(pAddr, 0))
    {
        LS_ERROR (  "LcReplConf fails to load Repl MemCached SvrAddr %s", pAddr);
        return false;
    }
    sockAddr.toString(pSockAddr, 64);
    m_cachedAddr = pSockAddr;
    
    //GzipStream
    const char *ptr = m_confParser.getConfig("REPL.GZIPSTREAM");
    if(ptr != NULL && !strcasecmp(ptr, "YES"))
        m_bGzipStream = true;
    
    //SubFileNum
    int v;
    ptr = m_confParser.getConfig("CACHED.SLICES");
    if ((ptr != NULL) && ((v = atoi(ptr)) > 0))
        m_iSubFileNum = v;
    
    if ( m_confParser.getConfig("CACHED.SHMDIR")) 
        m_shmDir = m_confParser.getConfig("CACHED.SHMDIR");
    if ( m_confParser.getConfig("CACHED.SHMNAME"))
        m_shmName = m_confParser.getConfig("CACHED.SHMNAME");
    if (m_confParser.getConfig("CACHED.SHMHASHNAME"))
        m_shmHashName = m_confParser.getConfig("CACHED.SHMHASHNAME");

    ptr = m_confParser.getConfig("REPL.MAXTIDPACKET");
    m_maxTidPacket = ptr ? atoi(ptr) : DEF_MAXTIDPACKET;

    ptr = m_confParser.getConfig("REPL.VALMAXSZ");
    m_valMaxSz = ptr ? atoi(ptr) : DEF_VALMAXSZ;
    
    ptr = m_confParser.getConfig("REPL.MEMMAXSZ");
    m_memMaxSz = ptr ? atoi(ptr) : DEF_MEMMAXSZ;

    if ( (ptr = m_confParser.getConfig("CACHED.USECAS")) != NULL)
    {
        m_useCas = strcmp(ptr, "TRUE") ? false : true;
    }
    
    if ((ptr = m_confParser.getConfig("CACHED.USESASL")) != NULL )
    {
        if ( !strcmp(ptr, "TRUE"))
            m_useSasl = true;        
    }
    
    if ((ptr = m_confParser.getConfig("CACHED.NOMEMFAIL")) != NULL )
    {
        if ( !strcmp(ptr, "TRUE"))
            m_noMemFail = true;        
    }
    
    char pBuf[1024], pBuf2[1024];
    uint16_t num  = getSubFileNum();
    m_pPriorities = new int[num];
    m_pShmFiles = new char *[num];
    for (int i=0; i < num; ++i)
    {   //Cached.Slice.
        snprintf(pBuf, sizeof(pBuf), "CACHED.SLICE.PRIORITY.%d", i);
        const char *ptr = m_confParser.getConfig(pBuf);
        if ((ptr != NULL) && ((v = atoi(ptr)) >= 0))
        {
            LS_DBG_M (  "%s=%d", pBuf, v);
            m_pPriorities[i] = v;
        }
        snprintf(pBuf, sizeof(pBuf), "CACHED.SHMFILEPATH.%d", i);
        ptr = m_confParser.getConfig(pBuf);
        if (ptr != NULL)
        {
            snprintf(pBuf2, sizeof(pBuf2), "%s/%s", m_shmDir.c_str(), ptr);
            m_confParser.setConfig(pBuf, pBuf2);
            m_pShmFiles[i] = (char*)m_confParser.getConfig(pBuf);
            LS_DBG_M("%s=%s", pBuf, pBuf2);
        }
        else
        {
            LS_ERROR ( 
                "[ERROR] [Configure]: LcReplConf config file, missing required: %s\n", pBuf);
            return false;               
        }
    }
    
    return true;
}