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


C++ FileInfo::AddChunkPath方法代码示例

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


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

示例1: _send_file_to_chunk


//.........这里部分代码省略.........
		if(!kvdata.GetValue(KEY_FILEDATA_RESULT, save_result.status)
			|| !kvdata.GetValue(KEY_FILEDATA_FID, save_result.fid)
			|| !kvdata.GetValue(KEY_FILEDATA_INDEX, save_result.index))
		{
			LOG_ERROR(logger, "file data rsp:get param failed.");
			fclose(fd);
			Socket::Close(chunk_fd);
			return false;
		}

		if(save_result.status==FileSaveResult::DATA_SAVE_FAILED || save_result.fid!=file_data.fid)
		{
			LOG_ERROR(logger, "save file data failed or fid invalid.cur fid="<<file_data.fid<<",recv fid="<<save_result.fid);
			fclose(fd);
			Socket::Close(chunk_fd);
			return false;
		}

		LOG_DEBUG(logger, "save file_data_seg succ. fid="<<file_data.fid<<",index="<<file_data.index);
		++file_data.index;
		file_data.offset += seg_size;
	}
	fclose(fd);

	file_data.flag = FileData::FLAG_END;
	kvdata.Clear();
	kvdata.SetValue(KEY_PROTOCOL_TYPE, PROTOCOL_FILE);
	kvdata.SetValue(KEY_FILEDATA_FLAG, file_data.flag);
	kvdata.SetValue(KEY_FILEDATA_FID, file_data.fid);
	kvdata.SetValue(KEY_FILEDATA_FILE_NAME, file_data.name);
	kvdata.SetValue(KEY_FILEDATA_FILE_SIZE, file_data.filesize);
	if(SendData(chunk_fd, kvdata) == false)
	{
		LOG_ERROR(logger, "send file data end to chunk failed.");
		Socket::Close(chunk_fd);
		return false;
	}

	//等待chunk回复file_info信息
	if(RecvData(chunk_fd, byte_buffer, kvdata) == false)
	{
		LOG_ERROR(logger, "recv file info from chunk failed.");
		fclose(fd);
		Socket::Close(chunk_fd);
		return false;
	}

	if(!kvdata.GetValue(KEY_PROTOCOL_TYPE, protocol_type) || protocol_type!=PROTOCOL_FILE_INFO)
	{
		LOG_ERROR(logger, "recv file info from chunk failed. invalid protocol_type");
		Socket::Close(chunk_fd);
		return false;
	}
	if(!kvdata.GetValue(KEY_FILEINFO_RSP_RESULT, fileinfo.result))
	{
		LOG_ERROR(logger, "recv file info from chunk failed. get result failed");
		Socket::Close(chunk_fd);
		return false;
	}
	if(!kvdata.GetValue(KEY_FILEINFO_RSP_FID, fileinfo.fid))
	{
		LOG_ERROR(logger, "recv file info from chunk failed. get fid failed");
		Socket::Close(chunk_fd);
		return false;
	}

	if(fileinfo.result == FileInfo::RESULT_SUCC || fileinfo.result==FileInfo::RESULT_CHUNK)
	{
		kvdata.GetValue(KEY_FILEINFO_RSP_FILE_NAME, fileinfo.name);
		kvdata.GetValue(KEY_FILEINFO_RSP_FILE_SIZE, fileinfo.size);

		uint32_t chunk_count;
		if(!kvdata.GetValue(KEY_FILEINFO_RSP_CHUNK_NUM, chunk_count) || chunk_count<=0)
		{
			Socket::Close(chunk_fd);
			return false;
		}
		for(int i=0; i<chunk_count; ++i)
		{
			KVData kv_chunkpath(true);
			if(!kvdata.GetValue(KEY_FILEINFO_RSP_CHUNK_PATH0, kv_chunkpath))
			{
				Socket::Close(chunk_fd);
				return false;
			}

			ChunkPath chunkpath;
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_ID, chunkpath.id);
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_IP, chunkpath.ip);
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_PORT, chunkpath.port);
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_INDEX, chunkpath.index);
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_OFFSET, chunkpath.offset);

			fileinfo.AddChunkPath(chunkpath);
		}
	}

	Socket::Close(chunk_fd);
	return true;
}
开发者ID:xmulyj,项目名称:SFDS,代码行数:101,代码来源:SFDSFile.cpp

示例2: _get_file_info

bool File::_get_file_info(string &fid, bool query_chunk, FileInfo &fileinfo)
{
	//连接master
	int master_fd = Socket::Connect(m_master_port, m_master_addr.c_str());
	if(master_fd == -1)
		return false;

	//协议数据
	FileInfoReq fileinfo_req;
	fileinfo_req.fid = fid;
	fileinfo_req.query_chunkpath = query_chunk?1:0;

	KVData kvdata(true);
	kvdata.SetValue(KEY_PROTOCOL_TYPE, PROTOCOL_FILE_INFO_REQ);
	kvdata.SetValue(KEY_FILEINFO_REQ_FID, fileinfo_req.fid);
	kvdata.SetValue(KEY_FILEINFO_REQ_CHUNKPATH, fileinfo_req.query_chunkpath);

	if(SendData(master_fd, kvdata) == false)
	{
		LOG_ERROR(logger, "send data to master failed.");
		Socket::Close(master_fd);
		return false;
	}

	ByteBuffer byte_buffer(10240);
	if(RecvData(master_fd, byte_buffer, kvdata) == false)
	{
		LOG_ERROR(logger, "recv data from master failed.");
		return false;
	}

	uint32_t protocol_type;
	if(!kvdata.GetValue(KEY_PROTOCOL_TYPE, protocol_type) || protocol_type!=PROTOCOL_FILE_INFO)
	{
		Socket::Close(master_fd);
		return false;
	}
	if(!kvdata.GetValue(KEY_FILEINFO_RSP_RESULT, fileinfo.result))
	{
		Socket::Close(master_fd);
		return false;
	}
	if(!kvdata.GetValue(KEY_FILEINFO_RSP_FID, fileinfo.fid))
	{
		Socket::Close(master_fd);
		return false;
	}

	if(fileinfo.result == FileInfo::RESULT_SUCC || fileinfo.result==FileInfo::RESULT_CHUNK)
	{
		kvdata.GetValue(KEY_FILEINFO_RSP_FILE_NAME, fileinfo.name);
		kvdata.GetValue(KEY_FILEINFO_RSP_FILE_SIZE, fileinfo.size);

		uint32_t chunk_count;
		if(!kvdata.GetValue(KEY_FILEINFO_RSP_CHUNK_NUM, chunk_count) || chunk_count<=0)
		{
			Socket::Close(master_fd);
			return false;
		}
		for(int i=0; i<chunk_count; ++i)
		{
			KVData kv_chunkpath(true);
			if(!kvdata.GetValue(KEY_FILEINFO_RSP_CHUNK_PATH0, kv_chunkpath))
			{
				Socket::Close(master_fd);
				return false;
			}

			ChunkPath chunkpath;
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_ID, chunkpath.id);
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_IP, chunkpath.ip);
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_PORT, chunkpath.port);
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_INDEX, chunkpath.index);
			kv_chunkpath.GetValue(KEY_FILEINFO_RSP_CHUNK_OFFSET, chunkpath.offset);

			fileinfo.AddChunkPath(chunkpath);
		}
	}

	Socket::Close(master_fd);
	return true;
}
开发者ID:xmulyj,项目名称:SFDS,代码行数:82,代码来源:SFDSFile.cpp


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