示例#1
0
	void CFile::FWRITE(const LWPR::Buffer& buf)
	{
		if(fwrite(buf.Inout(), buf.Size(), 1, m_fp) != 1)
		{
			throw IOException(EXCEPTION_TRACE, "fwrite error");
		}
	}
示例#2
0
	/**
	 * 处理收到的消息队列数据
	 */
	void DoReceiveMsqData(LWPR::Buffer& msg)
	{
		printf("Receiver::DoReceiveMsqData -------------------------------------------------------------\n");

		LWPR::INT32 nMsgType = 0;
		memcpy(&nMsgType, msg.Inout(), sizeof(nMsgType));
		printf("Receiver::DoReceiveMsqData Current thread id [%u] nMsgType [%d] nMsgLength [%d] [%s]\n",
		       LWPR::Thread::GetCurrentThreadId(),
		       nMsgType,
			   msg.Size(),
		       msg.Inout() + sizeof(LWPR::INT32));
	}
示例#3
0
	int DoChildWork(int argc, char** argv)
	{
		for(int i = 0; i < 10; i++)
		{
			LWPR::Buffer buf;
			buf.Size(128);

			LWPR::INT32 nMsgType = LWPR::Utility::GetPid();
			memcpy(buf.Inout(), &nMsgType, sizeof(nMsgType));

			strcpy(buf.Inout() + sizeof(LWPR::INT32), argv[3]);

			LWPR::IPCID_T nMsqId = atoi(argv[2]);

			LWPR::IPCMSQ_RET_TYPE_E nRet = LWPR::IPCMSQ::SendMsg(nMsqId, buf.Inout(), buf.Size());

			printf("LWPR::IPCMSQ::SendMsg %d\n", (int)nRet);

			sleep(1);
		}

		return 0;
	}
示例#4
0
bool View32Manager::AdjustStructData(const char* name,
                                     const void* indata,
                                     const STRUCT_INFO_T& remoteinfo,
                                     const bool inbigendian,
                                     LWPR::Buffer& outdata)
{
	assert(NULL != name);

	StructInfoMap::iterator it = m_Structs.find(name);
	if(m_Structs.end() != it)
	{
		STRUCT_INFO_T& localinfo = it->second;

		if(localinfo.items.size() != remoteinfo.items.size())
		{
			return false;
		}

		// 设置生成结构体的大小
		outdata.Size(localinfo.structSize);

		for(size_t i = 0; i < localinfo.items.size(); i++)
		{
			logger->debug(LTRACE, "%s %s local offset %d, remote offset %d"
			              , localinfo.structName.c_str()
			              , localinfo.items[i].cname.c_str()
			              , localinfo.items[i].offset
			              , remoteinfo.items[i].offset);

			switch(localinfo.items[i].type)
			{
			case STRUCT_DATA_TYPE_FLOAT:
			case STRUCT_DATA_TYPE_DOUBLE:
			case STRUCT_DATA_TYPE_STRING:
			case STRUCT_DATA_TYPE_CHAR:
				memcpy(outdata.Inout() + localinfo.items[i].offset,
				       (char *)indata + remoteinfo.items[i].offset,
				       remoteinfo.items[i].size * remoteinfo.items[i].count);
				break;
			case STRUCT_DATA_TYPE_SHORT:
				{
					for(LWPR::UINT32  k = 0; k < localinfo.items[i].count; k++)
					{
						short value = 0;
						memcpy(&value,
						       (char *)indata + remoteinfo.items[i].offset + k * remoteinfo.items[i].size ,
						       remoteinfo.items[i].size);

						// 字节序转化
						value = LWPR::Utility::IntegerToLocalByte16(value, inbigendian);


						memcpy((char *)outdata.Inout() + localinfo.items[i].offset + k * localinfo.items[i].size ,
						       &value,
						       localinfo.items[i].size);
					}
				}
				break;
			case STRUCT_DATA_TYPE_INT:
				{
					for(LWPR::UINT32  k = 0; k < localinfo.items[i].count; k++)
					{
						int value = 0;
						memcpy(&value,
						       (char *)indata + remoteinfo.items[i].offset + k * remoteinfo.items[i].size ,
						       remoteinfo.items[i].size);

						// 字节序转化
						value = LWPR::Utility::IntegerToLocalByte32(value, inbigendian);

						memcpy((char *)outdata.Inout() + localinfo.items[i].offset + k * localinfo.items[i].size ,
						       &value,
						       localinfo.items[i].size);
					}
				}
				break;
			case STRUCT_DATA_TYPE_LONG:
				{
					for(LWPR::UINT32  k = 0; k < localinfo.items[i].count; k++)
					{
						long value = 0;

						if(4 == remoteinfo.items[i].size)
						{
							LWPR::UINT32 value32 = 0;
							memcpy(&value32,
							       (char *)indata + remoteinfo.items[i].offset + k * remoteinfo.items[i].size ,
							       remoteinfo.items[i].size);

							// 字节序转化
							value = (long)LWPR::Utility::IntegerToLocalByte32(value32, inbigendian);
						}
						else if(8 == remoteinfo.items[i].size)
						{
							LWPR::UINT64 value64 = 0;
							memcpy(&value64,
							       (char *)indata + remoteinfo.items[i].offset + k * remoteinfo.items[i].size ,
							       remoteinfo.items[i].size);

							// 字节序转化
							value = (long)LWPR::Utility::IntegerToLocalByte64(value64, inbigendian);
						}

						memcpy((char *)outdata.Inout() + localinfo.items[i].offset + k * localinfo.items[i].size ,
						       &value,
						       localinfo.items[i].size);
					}
				}
				break;
			default:
				return false;
			}
		}

		return true;
	}

	return false;
}
示例#5
0
文件: Socket.cpp 项目: cbf621/tuxone
	LWPR::SOCKET_RET_TYPE_E Socket::ReadSocket(SOCKET_FD_T fd, LWPR::Buffer& buf, int length)
	{
		buf.Size(length);

		return ReadSocket(fd, buf.Inout(), length, INT_MAX);
	}