From 0a7671a6080605cc2de4bcd5a9338cfe9f407868 Mon Sep 17 00:00:00 2001 From: bogdanadnan Date: Mon, 20 Aug 2018 21:16:25 +0300 Subject: [PATCH] Added revision version. Set current revision to 2. Full version: v0.1.2 --- http/http.cpp | 61 +++++++++++++++++++++++++++++-------------------- miner/miner.cpp | 19 +++++++++------ 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/http/http.cpp b/http/http.cpp index 76b483d..b1115a6 100755 --- a/http/http.cpp +++ b/http/http.cpp @@ -163,16 +163,20 @@ string http::__get_response(const string &url, const string &post_data) { char *buff = (char *)request.c_str(); int sz = request.size(); + int n = 0; + while(sz > 0) { - int n = send(sockfd, buff, sz, 0); - if(n < 0) { - close(sockfd); - return ""; - } + n = send(sockfd, buff, sz, 0); + if(n < 0) break; buff+=n; sz-=n; } + if(n < 0) { + close(sockfd); + continue; + } + http_parser_settings settings; memset(&settings, 0, sizeof(settings)); settings.on_body = http_callback; @@ -181,28 +185,35 @@ string http::__get_response(const string &url, const string &post_data) { http_parser_init(&parser, HTTP_RESPONSE); parser.data = (void *)&reply; - fd_set fds ; - timeval tv ; - int n; - - FD_ZERO(&fds) ; - FD_SET(sockfd, &fds) ; - - tv.tv_sec = 10; - tv.tv_usec = 0; - - n = select(sockfd+1, &fds, NULL, NULL, &tv); - if (n <= 0) { - close(sockfd); - return ""; + fd_set fds; + timeval tv; + + time_t timestamp = time(NULL); + while(time(NULL) - timestamp < 10) { + FD_ZERO(&fds); + FD_SET(sockfd, &fds); + + tv.tv_sec = 0; + tv.tv_usec = 100000; + + n = select(sockfd + 1, &fds, NULL, NULL, &tv); + if(n == 0) + continue; + else if(n < 0) + break; + else { + char buffer[2048]; + n = recv(sockfd, buffer, 2048, 0); + if (n > 0) + http_parser_execute(&parser, &settings, buffer, n); + else if(n <= 0) + break; + + if (reply != "") + break; + } } - char buffer[2048]; - n = recv(sockfd, buffer, 2048, 0); - - if(n > 0) - http_parser_execute(&parser, &settings, buffer, n); - close(sockfd); if(reply != "") diff --git a/miner/miner.cpp b/miner/miner.cpp index 744ef8f..0fc6bde 100755 --- a/miner/miner.cpp +++ b/miner/miner.cpp @@ -205,7 +205,7 @@ void miner::__display_report() { time_t total_time = time(NULL) - __begin_time; - if(!__args.is_verbose() || hashers.size() == 1) { + if(!__args.is_verbose()) { for (vector::iterator it = hashers.begin(); it != hashers.end(); ++it) { hash_rate += (*it)->get_current_hash_rate(); avg_hash_rate_cblocks += (*it)->get_avg_hash_rate_cblocks(); @@ -240,13 +240,18 @@ void miner::__display_report() { "Hash rate: " << setw(6)<< (*it)->get_current_hash_rate() << " H/s " << "Avg. (Cblocks): " << setw(6) << (*it)->get_avg_hash_rate_cblocks() << " H/s " << "Avg. (Gblocks): " << setw(6) << (*it)->get_avg_hash_rate_gblocks() << " " << - "Count: " << setw(4) << ((*it)->get_hash_count_cblocks() + (*it)->get_hash_count_gblocks()) << endl; + "Count: " << setw(4) << ((*it)->get_hash_count_cblocks() + (*it)->get_hash_count_gblocks()); + + if(hashers.size() > 1) + ss << endl; + } + if(hashers.size() > 1) { + ss << fixed << setprecision(2) << "--> ALL " << + "Hash rate: " << setw(6) << hash_rate << " H/s " << + "Avg. (Cblocks): " << setw(6) << avg_hash_rate_cblocks << " H/s " << + "Avg. (Gblocks): " << setw(6) << avg_hash_rate_gblocks << " " << + "Count: " << setw(4) << (hash_count_cblocks + hash_count_gblocks); } - ss << fixed << setprecision(2) << "--> ALL " << - "Hash rate: " << setw(6) << hash_rate << " H/s " << - "Avg. (Cblocks): " << setw(6) << avg_hash_rate_cblocks << " H/s " << - "Avg. (Gblocks): " << setw(6) << avg_hash_rate_gblocks << " " << - "Count: " << setw(4) << (hash_count_cblocks + hash_count_gblocks); } LOG(ss.str());