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


C++ UdpSocket::init方法代码示例

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


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

示例1:

	Program()
	{
		int r;
		r = socket1.init();
		socket1.setPort(10000);
		socket1.bind();
		socket1.setListener(this);
	}
开发者ID:KrystianD,项目名称:kdhome,代码行数:8,代码来源:main.cpp

示例2: tcpSktFl

ServiceManager::ServiceManager(uint32 _tcpAcptrSvcNum, uint32 _udpAcptrSvcNum, uint32 _sslAcptrSvcNum, 
							   uint32 _tcpSvcNum, uint32 _udpSvcNum, uint32 _sslSvcNum, 
							   uint32 _tcpAcptrThreadNum, uint32 _udpAcptrThreadNum, uint32 _sslAcptrThreadNum, uint32 _contextBase, 
							   uint32 _perClrTcpSktNum, uint32 _tcpSktClrNum, uint32 _perClrUdpSubSktNum, uint32 _udpSubSktClrNum, 
							   uint32 _perClrUdpSktNum, uint32 _udpSktClrNum, IFreeListShrPtr _packetFreeList, 
							   IPacketParserShrPtr _pktParser, bool _isIp4)
	: m_tcpAcptrSvcNum(_tcpAcptrSvcNum)
	, m_udpAcptrSvcNum(_udpAcptrSvcNum)
	, m_sslAcptrSvcNum(_sslAcptrSvcNum)
	, m_tcpSvcNum(_tcpSvcNum)
	, m_udpSvcNum(_udpSvcNum)
	, m_sslSvcNum(_sslSvcNum)
	, m_tcpAcptrThreadNum(_tcpAcptrThreadNum == 0 ? 1 : _tcpAcptrThreadNum)
	, m_udpAcptrThreadNum(_udpAcptrThreadNum == 0 ? 1 : _udpAcptrThreadNum)
	, m_sslAcptrThreadNum(_sslAcptrThreadNum == 0 ? 1 : _sslAcptrThreadNum)
	, m_perClrTcpSktNum(_perClrTcpSktNum == 0 ? 1 : _perClrTcpSktNum)
	, m_tcpSktClrNum(_tcpSktClrNum == 0 ? 1 : _tcpSktClrNum)
	, m_perClrUdpSubSktNum(_perClrUdpSubSktNum == 0 ? 1 : _perClrUdpSubSktNum)
	, m_udpSubSktClrNum(_udpSubSktClrNum == 0 ? 1 : _udpSubSktClrNum)
	, m_perClrUdpSktNum(_perClrUdpSktNum == 0 ? 1 : _perClrUdpSktNum)
	, m_udpSktClrNum(_udpSktClrNum == 0 ? 1 : _udpSktClrNum)

	, m_usingTcp(m_tcpAcptrSvcNum > 0 && m_tcpSvcNum > 0)
	, m_usingUdp(m_udpAcptrSvcNum > 0 && m_udpSvcNum > 0)
	, m_usingSSL(m_sslAcptrSvcNum > 0 && m_sslSvcNum > 0)

	, m_contexts(_contextBase)
	, m_netInfoMgr((m_tcpSvcNum+m_udpSvcNum+_contextBase)/3+1)

	, m_tcpAcptrSvcs(m_tcpAcptrSvcNum, NumChooser(0, (m_tcpAcptrSvcNum == 0 ? 1 : m_tcpAcptrSvcNum) - 1, 24249, false))
	, m_sslAcptrSvcs(m_sslAcptrSvcNum, NumChooser(0, (m_sslAcptrSvcNum == 0 ? 1 : m_sslAcptrSvcNum) - 1, 21139, false))
	, m_udpAcptrSvcs(m_udpAcptrSvcNum, NumChooser(0, (m_udpAcptrSvcNum == 0 ? 1 : m_udpAcptrSvcNum) - 1, 23449, false))
	, m_tcpSvcs(m_tcpSvcNum, NumChooser(0, (m_tcpSvcNum == 0 ? 1 : m_tcpSvcNum) - 1, 14249, false))
	, m_sslSvcs(m_sslSvcNum, NumChooser(0, (m_sslSvcNum == 0 ? 1 : m_sslSvcNum) - 1, 1222, false))
	, m_udpSvcs(m_udpSvcNum, NumChooser(0, (m_udpSvcNum == 0 ? 1 : m_udpSvcNum) - 1, 54249, false))
	, m_isIp4(_isIp4)
	, m_currMaxSnIndex(0)
{
	if (_pktParser)
	{
		m_pktParser = _pktParser;
	}
	else
	{
		m_pktParser = IPacketParserShrPtr(new PacketParser);
	}

	m_contexts.setHash();

	for (uint32 i=0; i<m_tcpAcptrSvcs.size(); ++i)
	{
		m_tcpAcptrSvcs[i] = new TcpAcceptorService(this, m_tcpAcptrThreadNum, m_isIp4);
	}
	for (uint32 i=0; i<m_sslAcptrSvcs.size(); ++i)
	{
		m_sslAcptrSvcs[i] = new SSLAcceptorService(this, m_sslAcptrThreadNum, m_isIp4);
	}
	for (uint32 i=0; i<m_udpAcptrSvcs.size(); ++i)
	{
		m_udpAcptrSvcs[i] = new UdpAcceptorService(this, m_udpAcptrThreadNum, m_isIp4);
	}
	for (uint32 i=0; i<m_tcpSvcs.size(); ++i)
	{
		m_tcpSvcs[i] = new TcpService(this, m_isIp4);
	}
	for (uint32 i=0; i<m_sslSvcs.size(); ++i)
	{
		m_sslSvcs[i] = new SSLService(this, m_isIp4);
	}
	for (uint32 i=0; i<m_udpSvcs.size(); ++i)
	{
		m_udpSvcs[i] = new UdpService(this, m_isIp4);
	}

	// create and init tcp socket free list
	IFreeListShrPtr tcpSktFl(new FreeList<TcpSocket>(m_tcpSktClrNum, m_perClrTcpSktNum));
	uint32 maxTcpNum = m_tcpSktClrNum*m_perClrTcpSktNum;
	for (uint32 ix=0, i=0; (i<maxTcpNum && m_usingTcp); ++i)
	{
		ix = (m_currMaxSnIndex+i) % m_tcpSvcs.size();
		TcpSocket* tcpSkt = (TcpSocket*)tcpSktFl->get(i);
		if (tcpSkt)
			tcpSkt->init(ISessionShrPtr(new Session(m_currMaxSnIndex+i, &m_netInfoMgr, m_currMaxSnIndex+i, 
													m_pktParser->create())), m_tcpSvcs[ix], this);
	}
	sTcpSktFList.set(tcpSktFl);
	if (m_usingTcp)
	{
		m_currMaxSnIndex += maxTcpNum;
	}

	// create and init udp sub socket free list
	IFreeListShrPtr udpSubSktFl(new FreeList<UdpSubSocket>(m_udpSubSktClrNum, m_perClrUdpSubSktNum));
	uint32 maxUdpSubNum = m_udpSubSktClrNum*m_perClrUdpSubSktNum;
	for (uint32 ix=0, i=0; (i<maxUdpSubNum && m_usingUdp); ++i)
	{
		ix = (m_currMaxSnIndex+i) % m_udpSvcs.size();
		UdpSubSocket* udpSubSkt = (UdpSubSocket*)udpSubSktFl->get(i);
		if (udpSubSkt)
			udpSubSkt->init(ISessionShrPtr(new Session(m_currMaxSnIndex+i, &m_netInfoMgr, m_currMaxSnIndex+i, 
//.........这里部分代码省略.........
开发者ID:utah2013zyd,项目名称:Game,代码行数:101,代码来源:ServiceManager.cpp


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