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


C++ NetStreamStorage::writePacket方法代码示例

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


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

示例1: length_storage

	bool
		NetStreamSocket::
		receiveExact( NetStreamStorage &msg )
		throw( NetStreamSocketException )
	{
		/* receive length of vector */
		unsigned char * const bufLength = new unsigned char[4];
		int bytesRead = 0;
		int readThisTime = 0;
		
		while (bytesRead<4)
		{
			readThisTime = recv( socket_, (char*)(bufLength + bytesRead), 4-bytesRead, 0 );

			if( readThisTime <= 0 )
			{
				// BailOnNetStreamSocketError definitely throws an exception so clear up heap
				delete[] bufLength;
				BailOnNetStreamSocketError( "NetStreamSocket::receive() @ recv" );
			}

			bytesRead += readThisTime;
		}
		NetStreamStorage length_storage(bufLength,4);
		int NN = length_storage.readInt() - 4;

		/* receive vector */
		unsigned char * const buf = new unsigned char[NN];
		bytesRead = 0;
		readThisTime = 0;
		
		while (bytesRead<NN)
		{
			readThisTime = recv( socket_, (char*)(buf + bytesRead), NN-bytesRead, 0 );

			if( readThisTime <= 0 )
			{
				// BailOnNetStreamSocketError definitely throws an exception so clear up heap
				delete[] bufLength;
				delete[] buf;
				BailOnNetStreamSocketError( "netstream::NetStreamSocket::receive() @ recv" );
			}

			bytesRead += readThisTime;
		}
		msg.reset();
		msg.writePacket(buf, NN);
		
		if (verbose_)
		{
			cerr << "Rcvd Storage with "  << 4 + NN <<  " bytes via netstream::NetStreamSocket: [";
			for (int i=0; i < 4; ++i)
			{
				cerr << " " << (int)bufLength[i] << " ";
			}
			for (int i=0; i < NN; ++i)
			{
				cerr << " " << (int)buf[i] << " ";
			}
			cerr << "]" << endl;
		}

		delete[] buf;
		delete[] bufLength;
		return true;
	}
开发者ID:OpenModelica,项目名称:OMCompiler-3rdParty,代码行数:66,代码来源:netstream-socket.cpp


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