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


C++ Stat::__set_left方法代码示例

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


在下文中一共展示了Stat::__set_left方法的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
}
开发者ID:duanbing,项目名称:gingko,代码行数:55,代码来源:client_mock_s.cpp


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