Esempio n. 1
0
bool NetSystem::Send(const UI32 nSocket, const IArchive & msg) {
    if (nSocket >= 65335) { //如何控制这个端口的范围
        LOG_ERROR("NetSystem::Send nSocket : %d", nSocket);
        Assert(false);
        return false;
    }

    LinkInfo * pLinkInfo = m_linkmanage.FindLinkBySocket(nSocket);
    if (NULL == pLinkInfo) {

        LOG_ERROR("NetSystem::Send LinkInfo is NULL");

        Assert(false);
        return false;
    }

    pLinkInfo->m_sendstream.WriteBuff(msg.GetStream(), msg.Length());

    struct epoll_event ev;
    ev.data.ptr = pLinkInfo;
    ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
    epoll_ctl(m_epfd, EPOLL_CTL_MOD, pLinkInfo->m_socket, &ev);

    return true;
}
Esempio n. 2
0
bool NetSystem::BroadCast(const char * pLinkType, const IArchive & msg,
        const IVarList & blacklist) {
    if (NULL == pLinkType || !m_linkmanage.IsExsitType(pLinkType) || 0 == msg.Length()) {
        LOG_ERROR("LinkType : %s, MsgLength : %d", pLinkType, msg.Length());
        Assert(false);
        return false;
    }

    const vector<LinkInfo *> * pVct = m_linkmanage.GetTypeOfLinks(pLinkType);
    vector<LinkInfo *>::const_iterator itor = pVct->begin();
    const vector<LinkInfo *>::const_iterator iend = pVct->end();
    UI32 nCount = blacklist.Count();
    while (itor != iend) {
        for (UI32 i = 0; i < nCount; i++) {
            if (blacklist.Type(i) != TYPE_INT) {
                LOG_ERROR("Error BlackList element type");
                Assert(false);
                continue;
            }

            if ((*itor)->m_socket == blacklist.GetInt(i)) {
                continue;
            }
        }

        (*itor)->m_sendstream.WriteBuff(msg.GetStream(), msg.Length());

        struct epoll_event ev;
        ev.data.ptr = *itor;
        ev.events = EPOLLOUT | EPOLLET;
        epoll_ctl(m_epfd, EPOLL_CTL_MOD, (*itor)->m_socket, &ev);

        itor++;
    }

    return true;
}