• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ZPack类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: lookup_shared

string HTWorker::lookup_shared(const ZPack &zpack) {

	string result;

	if (zpack.key().empty())
		return Const::ZSC_REC_EMPTYKEY; //-1

	string key = zpack.key();
	string *ret = PMAP->get(key);

	if (ret == NULL) {

		printf("thread[%lu] DB Error: lookup found nothing\n", pthread_self());
		fflush(stdout);

		result = Const::ZSC_REC_NONEXISTKEY;
		result.append("Empty");
	} else {

		result = Const::ZSC_REC_SUCC;
		result.append(*ret);
	}

	return result;
}
开发者ID:fakeyee,项目名称:ZHT,代码行数:25,代码来源:HTWorker.cpp


示例2: remove_shared

string HTWorker::remove_shared(const ZPack &zpack) {

	string result;

	if (zpack.key().empty())
		return Const::ZSC_REC_EMPTYKEY; //-1

	string key = zpack.key();
	int ret = PMAP->remove(key);

	if (ret != 0) {

		printf("thread[%lu] DB Error: fail to remove, rcode = %d\n",
				pthread_self(), ret);
		fflush(stdout);

		result = Const::ZSC_REC_NONEXISTKEY; //-92
	} else {

		if (_instant_swap) {
			PMAP->writeFileFG();
		}

		result = Const::ZSC_REC_SUCC; //0, succeed.
	}

	return result;
}
开发者ID:fakeyee,项目名称:ZHT,代码行数:28,代码来源:HTWorker.cpp


示例3: append_shared

string HTWorker::append_shared(const ZPack &zpack) {

	string result;

	if (zpack.key().empty())
		return Const::ZSC_REC_EMPTYKEY; //-1

	string key = zpack.key();
	int ret = PMAP->append(key, zpack.SerializeAsString());

	if (ret != 0) {

		printf("thread[%lu] DB Error: fail to append, rcode = %d\n",
				pthread_self(), ret);
		fflush(stdout);

		result = Const::ZSC_REC_NONEXISTKEY; //-92
	} else {

		if (_instant_swap) {
			PMAP->writeFile();
			//PMAP->flushDbfile();
		}

		result = Const::ZSC_REC_SUCC; //0, succeed.
	}

	return result;
}
开发者ID:fkengun,项目名称:OHT,代码行数:29,代码来源:HTWorker.cpp


示例4: run

string HTWorker::run(const char *buf) {

	string result;

	ZPack zpack;
	string str(buf);
	zpack.ParseFromString(str);

	if (zpack.opcode() == Const::ZSC_OPC_LOOKUP) {

		result = lookup(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_INSERT) {

		result = insert(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_APPEND) {

		result = append(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_CMPSWP) {

		result = compare_swap(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_REMOVE) {

		result = remove(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_STCHGCB) {

		result = state_change_callback(zpack);
	} else {

		result = Const::ZSC_REC_UOPC;
	}

	return result;
}
开发者ID:fakeyee,项目名称:ZHT,代码行数:33,代码来源:HTWorker.cpp


示例5: printf

string HTWorker::state_change_callback_internal(const ZPack &zpack) {

	string result;

	if (zpack.key().empty())
		return Const::ZSC_REC_EMPTYKEY; //-1

	string key = zpack.key();
	string *ret = PMAP->get(key);

	if (ret == NULL) {

		printf("thread[%lu] DB Error: lookup found nothing\n", pthread_self());
		fflush(stdout);

		result = Const::ZSC_REC_NONEXISTKEY;
	} else {

		ZPack rltpack;
		rltpack.ParseFromString(*ret);

		if (zpack.val() == rltpack.val()) {

			result = Const::ZSC_REC_SUCC; //0, succeed.
		} else {

			result = Const::ZSC_REC_SCCBPOLLTRY;
		}
	}

	return result;
}
开发者ID:fakeyee,项目名称:ZHT,代码行数:32,代码来源:HTWorker.cpp


示例6: str_to_zpack

string ZHTClient::extract_value(const string &returnStr) {

	string val;

	//StrTokenizer strtok(returnStr, ":");
	//StrTokenizer strtok(returnStr, ";");
	/*
	 * hello,zht:hello,ZHT ==> zht:ZHT
	 * */

//	if (strtok.has_more_tokens()) {
//
//		while (strtok.has_more_tokens()) {
//
//			ZPack zpack;
//			zpack.ParseFromString(strtok.next_token());
//
//			if (zpack.valnull())
//				val.append("");
//			else
//				val.append(zpack.val());
//
//			val.append(":");
//		}
//
//		size_t found = val.find_last_of(":");
//		val = val.substr(0, found);
//
//	} else {

		ZPack zpack = str_to_zpack(returnStr);
		//zpack.ParseFromString(returnStr);
		if (zpack.valnull())
			val = "";
		else
			val = zpack.val();
	//}

	return val;
}
开发者ID:aalayach,项目名称:zebra,代码行数:40,代码来源:cpp_zhtclient.cpp


示例7: compare_swap

string HTWorker::compare_swap(const ZPack &zpack) {

	if (zpack.key().empty())
		return Const::ZSC_REC_EMPTYKEY; //-1

	string result = compare_swap_internal(zpack);

	string lkpresult = lookup_shared(zpack);

	result.append(erase_status_code(lkpresult));

#ifdef SCCB
	_stub->sendBack(_addr, result.data(), result.size());
	return "";
#else
	return result;
#endif
}
开发者ID:fakeyee,项目名称:ZHT,代码行数:18,代码来源:HTWorker.cpp


示例8: commonOpInternal

string ZHTClient::commonOpInternal(const string &opcode, const string &key,
		const string &val, const string &val2, string &result, int lease) {

	ZPack zpack;
	zpack.set_opcode(opcode); //"001": lookup, "002": remove, "003": insert, "004": append, "005", compare_swap
	zpack.set_replicanum(3);

	if (key.empty())
		return Const::ZSC_REC_EMPTYKEY; //-1, empty key not allowed.
	else
		zpack.set_key(key);

	if (val.empty()) {

		zpack.set_val("^"); //coup, to fix ridiculous bug of protobuf! //to debug
		zpack.set_valnull(true);
	} else {

		zpack.set_val(val);
		zpack.set_valnull(false);
	}

	if (val2.empty()) {

		zpack.set_newval("?"); //coup, to fix ridiculous bug of protobuf! //to debug
		zpack.set_newvalnull(true);
	} else {

		zpack.set_newval(val2);
		zpack.set_newvalnull(false);
	}

	zpack.set_lease(Const::toString(lease));

	string msg = zpack.SerializeAsString();

	/*ZPack tmp;
	 tmp.ParseFromString(msg);
	 printf("{%s}:{%s,%s}\n", tmp.key().c_str(), tmp.val().c_str(),
	 tmp.newval().c_str());*/

	char *buf = (char*) calloc(_msg_maxsize, sizeof(char));
	size_t msz = _msg_maxsize;

	/*send to and receive from*/
	_proxy->sendrecv(msg.c_str(), msg.size(), buf, msz);

	/*...parse status and result*/
	string sstatus;

	string srecv(buf);

	if (srecv.empty()) {

		sstatus = Const::ZSC_REC_SRVEXP;
	} else {

		result = srecv.substr(3); //the left, if any, is lookup result or second-try zpack
		sstatus = srecv.substr(0, 3); //status returned, the first three chars, like 001, -98...
	}

	free(buf);
	return sstatus;
}
开发者ID:Hellblazer,项目名称:ZHT,代码行数:64,代码来源:cpp_zhtclient.cpp


示例9: commonOpInternal

string ZHTClient::commonOpInternal(const string &opcode, const string &key,
		const string &val, const string &val2, string &result, int lease) {

	ZPack zpack;
	zpack.set_opcode(opcode); //"001": lookup, "002": remove, "003": insert, "004": append, "005", compare_swap
	zpack.set_replicanum(3);

        //cout<<"Op Code"<<opcode<<"Key"<<key<<endl;

	if (key.empty())
		return Const::ZSC_REC_EMPTYKEY; //-1, empty key not allowed.
	else
		zpack.set_key(key);

	if (val.empty()) {

		zpack.set_val("^"); //coup, to fix ridiculous bug of protobuf! //to debug
		zpack.set_valnull(true);
	} else {

		zpack.set_val(val);
		zpack.set_valnull(false);
	}

	if (val2.empty()) {

		zpack.set_newval("?"); //coup, to fix ridiculous bug of protobuf! //to debug
		zpack.set_newvalnull(true);
	} else {

		zpack.set_newval(val2);
		zpack.set_newvalnull(false);
	}

	zpack.set_lease(Const::toString(lease));
//cout<<"lease "<<lease<<endl;
	string msg = zpack.SerializeAsString();
//cout<<msg<<endl;
	/*ZPack tmp;
	 tmp.ParseFromString(msg);
	 printf("{%s}:{%s,%s}\n", tmp.key().c_str(), tmp.val().c_str(),
	 tmp.newval().c_str());*/
/*

	char *buf = (char*) calloc(_msg_maxsize, sizeof(char));
	size_t msz = _msg_maxsize;

*/
	/*send to and receive from*/
	// this is old making large msg problem
	//_proxy->sendrecv(msg.c_str(), msg.size(), buf, msz);

	TCPProxy tcp;
		ZHTUtil zu;
		HostEntity he = zu.getHostEntityByKey(msg);
		int sock = tcp.getSockCached(he.host, he.port);
		tcp.sendTo(sock, (void*) msg.c_str(), msg.size());
		string res;

		int recvcount = loopedrecv(sock, NULL, res);

	/*...parse status and result*/
	string sstatus;
	//  srecv is no longer used due to a large msg fix. now instead of sendrecv,
	//we are using sendto and loopedrecv methods
/*
	string srecv(buf);
cout<<"res value is "<<res<<endl;
	if (srecv.empty()) {
		cout<<"empty"<<endl;
		sstatus = Const::ZSC_REC_SRVEXP;
	} else {

		result = srecv.substr(3); //the left, if any, is lookup result or second-try zpack
		//cout<<"srecv string size="<<srecv.size()<<endl;
		if (srecv.size() == 36) {
			sstatus = srecv.substr(0, 36);
			//sstatus=Const::ZSC_REC_REMOVEMETADATAQUEUE;
		} else {
			sstatus = srecv.substr(0, 3); //status returned, the first three chars, like 001, -98...
		}

	}
*/
//cout<<"res value is "<<res<<endl;
	if (res.empty()) {
		//cout<<"empty"<<endl;
		sstatus = Const::ZSC_REC_SRVEXP;
	} else {

		result = res.substr(3); //the left, if any, is lookup result or second-try zpack
		//cout<<"srecv string size="<<srecv.size()<<endl;
		if (res.size() == 36) {
			sstatus = res.substr(0, 36);
			//sstatus=Const::ZSC_REC_REMOVEMETADATAQUEUE;
		} else {
			sstatus = res.substr(0, 3); //status returned, the first three chars, like 001, -98...
		}

	}
//.........这里部分代码省略.........
开发者ID:arihant15,项目名称:CloudKonPlus,代码行数:101,代码来源:cpp_zhtclient.cpp


示例10: if

string HTWorker::run(const char *buf) {

	string result;

	ZPack zpack;
	//string str(buf);
	string* str =(string*) buf;


	zpack.ParseFromString(*str);


	if(ZPack_Pack_type_BATCH_REQ  == zpack.pack_type()){//batch
		cout << "HTWrorker::run(): ZPack_Pack_type_BATCH_REQ received."<< endl;
		cout << "Batch contains "<< zpack.batch_item_size() << " items."<<endl;
		cout <<"zpack.key: "<< zpack.key() <<endl;
		cout <<"zpack.batch_item(i).val: "<<zpack.batch_item(0).val() << endl<< endl;
		result = Const::ZSC_REC_UOPC; // "OK";

	}else if(ZPack_Pack_type_SINGLE == zpack.pack_type()){//single

	if (zpack.opcode() == Const::ZSC_OPC_LOOKUP) {

		result = lookup(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_INSERT) {

		result = insert(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_APPEND) {

		result = append(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_CMPSWP) {

		result = compare_swap(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_REMOVE) {

		result = remove(zpack);
	} else if (zpack.opcode() == Const::ZSC_OPC_STCHGCB) {

		result = state_change_callback(zpack);
	} else {

		result = Const::ZSC_REC_UOPC;
	}
	}
	return result;
}
开发者ID:mierl,项目名称:zht-h,代码行数:46,代码来源:HTWorker.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ZRect类代码示例发布时间:2022-05-31
下一篇:
C++ ZObject类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap