当前位置: 首页>>代码示例>>C++>>正文


C++ TCPSocket::getIP方法代码示例

本文整理汇总了C++中TCPSocket::getIP方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::getIP方法的具体用法?C++ TCPSocket::getIP怎么用?C++ TCPSocket::getIP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCPSocket的用法示例。


在下文中一共展示了TCPSocket::getIP方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run

void* Network::run()
{
	if (m_listening == false)
		return NULL;

	m_running = true;

	int maxfd;
	fd_set checkfds;
	struct timeval timeout;

	FD_ZERO(&checkfds);
	FD_SET(m_notify.notifyFD(), &checkfds);
	FD_SET(m_Server->getFD(), &checkfds);

	(m_notify.notifyFD() > m_Server->getFD()) ?
		(maxfd = m_notify.notifyFD()) : (maxfd = m_Server->getFD());

	for (;;) {
		fd_set readfds;
		int ret;

		// set select timeout 1 secs
		timeout.tv_sec = 1;
		timeout.tv_usec = 0;

		// set readfds to inital checkfds
		readfds = checkfds;

		ret = select(maxfd + 1, &readfds, NULL, NULL, &timeout);
		if (ret == 0) {
			cleanConnections();
			continue;
		}

		// new data from notify
		if (FD_ISSET(m_notify.notifyFD(), &readfds)) {
			m_running = false;
			break;
		}

		// new data from socket
		if (FD_ISSET(m_Server->getFD(), &readfds)) {
			TCPSocket* socket = m_Server->newSocket();
			if (socket == NULL)
				continue;

			Connection* connection = new Connection(socket, m_queue);
			if (connection == NULL)
				continue;

			connection->start("netConnection");
			m_connections.push_back(connection);
			L.log(net, trace, "[%08x] connection opened %s", connection->getID(), socket->getIP().c_str());
		}

	}

	return NULL;
}
开发者ID:BeeRed,项目名称:ebusd,代码行数:60,代码来源:network.cpp

示例2: run


//.........这里部分代码省略.........
    tdiff.tv_sec = 1;
    tdiff.tv_nsec = 0;
#ifdef HAVE_PPOLL
    int socketCount = m_httpServer ? 2 : 1;
    int nfds = 1+socketCount;
    struct pollfd fds[nfds];

    memset(fds, 0, sizeof(fds));

    fds[0].fd = m_notify.notifyFD();
    fds[0].events = POLLIN;

    fds[1].fd = m_tcpServer->getFD();
    fds[1].events = POLLIN;

    if (m_httpServer) {
        fds[2].fd = m_httpServer->getFD();
        fds[2].events = POLLIN;
    }
#else
#ifdef HAVE_PSELECT
    int maxfd;
    fd_set checkfds;

    FD_ZERO(&checkfds);
    FD_SET(m_notify.notifyFD(), &checkfds);
    FD_SET(m_tcpServer->getFD(), &checkfds);
    if (m_httpServer) {
        FD_SET(m_httpServer->getFD(), &checkfds);
    }

    maxfd = (m_notify.notifyFD() > m_tcpServer->getFD()) ?
            m_notify.notifyFD() : m_tcpServer->getFD();
    if (m_httpServer && m_httpServer->getFD()>maxfd) {
        maxfd = m_httpServer->getFD();
    }
#endif
#endif

    while (true) {

#ifdef HAVE_PPOLL
        // wait for new fd event
        ret = ppoll(fds, nfds, &tdiff, NULL);
#else
#ifdef HAVE_PSELECT
        // set readfds to inital checkfds
        fd_set readfds = checkfds;
        // wait for new fd event
        ret = pselect(maxfd + 1, &readfds, NULL, NULL, &tdiff, NULL);
#endif
#endif

        if (ret == 0) {
            cleanConnections();
            continue;
        }
        bool newData = false, isHttp = false;
#ifdef HAVE_PPOLL
        // new data from notify
        if (fds[0].revents & POLLIN) {
            return;
        }

        // new data from socket
        if (fds[1].revents & POLLIN) {
            newData = true;
        } else if (m_httpServer && fds[2].revents & POLLIN) {
            newData = isHttp = true;
        }
#else
#ifdef HAVE_PSELECT
        // new data from notify
        if (FD_ISSET(m_notify.notifyFD(), &readfds)) {
            return;
        }

        // new data from socket
        if (FD_ISSET(m_tcpServer->getFD(), &readfds)) {
            newData = true;
        } else if (m_httpServer && FD_ISSET(m_httpServer->getFD(), &readfds)) {
            newData = isHttp = true;
        }
#endif
#endif
        if (newData) {
            TCPSocket* socket = (isHttp ? m_httpServer : m_tcpServer)->newSocket();
            if (socket == NULL)
                continue;

            Connection* connection = new Connection(socket, isHttp, m_netQueue);
            if (connection == NULL)
                continue;

            connection->start("connection");
            m_connections.push_back(connection);
            logInfo(lf_network, "[%05d] %s connection opened %s", connection->getID(), isHttp ? "HTTP" : "client", socket->getIP().c_str());
        }
    }
}
开发者ID:Giermann,项目名称:ebusd,代码行数:101,代码来源:network.cpp


注:本文中的TCPSocket::getIP方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。