本文整理汇总了C++中Content::get_content_name_in_store方法的典型用法代码示例。如果您正苦于以下问题:C++ Content::get_content_name_in_store方法的具体用法?C++ Content::get_content_name_in_store怎么用?C++ Content::get_content_name_in_store使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Content
的用法示例。
在下文中一共展示了Content::get_content_name_in_store方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: host_receive_message
void Host::host_receive_message(int HID, int srcport, int dstport){
try{
//cout << "[HOST RECEIVE THREAD] From: " << srcport << "(" << (short)srcport << "). To: " << dstport << "(" << (short)dstport << ")\n";
//configure receiving port
const char* hname = "localhost";
Address * my_addr = new Address(hname, (short)dstport);
//LossyReceivingPort *my_port = new LossyReceivingPort(0);
ReceivingPort *my_port = new ReceivingPort();
my_port->setAddress(my_addr);
my_port->init();
Message *m = new Message();
Packet *p;
while (1)
{
p = my_port->receivePacket();
if(p!=NULL){
int type = m->get_packet_type(p);
//cout << "[H" << id_ << "] [Received] Type: " << type << "\n";
switch (type){
/*
* Message.TYPE_REQUEST
*/
case 0:{
/* make RESPONSE packet */
int CID = m->get_packet_CID(p);
int HID = m->get_packet_HID(p);
Content c;
string filename = c.get_content_name_in_host(id_,CID);
struct stat buffer;
if(stat(filename.c_str(), &buffer) != 0) break; /* if this file doesn't exist, do nothing... */
Packet *p = m->make_response_packet(CID, HID, filename.c_str());
/* queue the RESPONSE packet to the sending_queue */
{
boost::unique_lock<boost::timed_mutex> lock(* to_send_packets_mutex_ , boost::try_to_lock);
bool getLock = lock.owns_lock();
if(!getLock){
getLock = lock.timed_lock(boost::get_system_time() + boost::posix_time::milliseconds(500));
}
if(getLock){
to_send_packets_.push_back(p);
}
boost::timed_mutex *m = lock.release();
m->unlock();
}
break;
}
/*
* Message.TYPE_RESPONSE
*/
case 1:{
/* if this host is not waiting, discard */
if(!isWaiting){
break;
}
/* else, store the content to disk */
int size = p->getPayloadSize();
char *payload = p->getPayload();
int CID = m->get_packet_CID(p);
Content c;
ofstream outfile(c.get_content_name_in_store(id_, CID).c_str());
outfile.write(payload, size);
outfile.close();
isWaiting = false;
cout << "\n[H" << id_ << "]Content CID = " << CID << " has been delivered! \n" ;
break;
}
}
}
}
}
catch(const char *reason ){
cerr << "Exception:" << reason << endl;
exit(-1);
}
}