本文整理汇总了C++中Stat::__set_uploaded方法的典型用法代码示例。如果您正苦于以下问题:C++ Stat::__set_uploaded方法的具体用法?C++ Stat::__set_uploaded怎么用?C++ Stat::__set_uploaded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stat
的用法示例。
在下文中一共展示了Stat::__set_uploaded方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect_server
static void connect_server(int thread_id, int repead_id, string host, int port)
{
char peerid[21], ip[16];
snprintf(peerid, 20, "%10d%10d", thread_id, repead_id);
peerid[20] = '\0';
snprintf(ip, 15, "%d.%d.%d.%d", thread_id & 0x000000ff, repead_id & 0x000000ff, port & 0x000000ff, host[0] & 0x000000ff);
ip[15] = '\0';
Peer peer;
peer.__set_ip(ip);
peer.__set_idc("tc");
peer.__set_port(host[1] & 0x000000ff);
peer.__set_peerid(peerid);
Stat stat;
stat.__set_downloaded(thread_id * repead_id);
stat.__set_left(thread_id + repead_id);
stat.__set_uploaded(thread_id);
stat.__set_status(static_cast<Status::type>(thread_id * repead_id % 5));
AnnounceRequest request;
request.__set_infohash("abcdefghijklmnopqrst");
request.__set_is_seed(thread_id * repead_id % 2);
request.__set_num_want(50);
request.__set_peer(peer);
request.__set_stat(stat);
//printf("%s:%d peerid: %s, infohash: %s, is_seed: %d, status: %d\n", ip, peer.port, peer.peerid.c_str(), request.infohash.c_str(), request.is_seed, stat.status);
AnnounceResponse response;
shared_ptr<TSocket> socket(new TSocket(host.c_str(), port));
socket->setConnTimeout(3000);
socket->setSendTimeout(3000);
socket->setRecvTimeout(5000);
shared_ptr<TTransport> transport(new TFramedTransport(socket));
shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport));
AnnounceClient client(protocol);
try {
transport->open();
client.announce(response, request);
transport->close();
//printf("success\n");
} catch (TException &tx) {
printf("ERROR: %s\n", tx.what());
return;
}
#if 0
printf("/*************************************************************/\n");
printf("%s:%d peerid: %s, infohash: %s, is_seed: %d, status: %d\n", ip, peer.port, peerid, request.infohash.c_str(), request.is_seed, stat.status);
printf("ret: %d, failure_reason: %s, min_interval: %d, have_seed: %d, peers_num: %ld\n"
, response.ret, response.failure_reason.c_str(), response.min_interval, response.have_seed, response.peers.size());
for (std::vector<Peer>::iterator it = response.peers.begin(); it != response.peers.end(); ++it) {
printf("%s:%d\n", it->ip.c_str(), it->port);
}
printf("/*************************************************************\n");
#endif
}