1616#include " template.h"
1717#include " mining.h"
1818#include " getopt.h"
19-
19+ # include " log.h "
2020
2121std::atomic<uint32_t > found_solutions{0 };
2222
@@ -51,8 +51,7 @@ void on_write_end(uv_write_t *req, int status)
5151{
5252 if (status < 0 )
5353 {
54- fprintf (stderr, " error on_write_end %d" , status);
55- exit (1 );
54+ LOGERR (" error on_write_end %d\n " , status);
5655 }
5756 free (req);
5857}
@@ -85,7 +84,7 @@ void mine(mining_worker_t *worker)
8584 int32_t to_mine_index = next_chain_to_mine ();
8685 if (to_mine_index == -1 )
8786 {
88- printf (" waiting for new tasks\n " );
87+ LOG (" waiting for new tasks\n " );
8988 worker->timer .data = worker;
9089 uv_timer_start (&worker->timer , mine_with_timer, 500 , 0 );
9190 } else {
@@ -95,7 +94,7 @@ void mine(mining_worker_t *worker)
9594 start_worker_mining (worker);
9695
9796 duration_t elapsed = Time::now () - start;
98- // printf ("=== mining time: %fs\n", elapsed.count());
97+ // LOG ("=== mining time: %fs\n", elapsed.count());
9998 }
10099}
101100
@@ -191,12 +190,12 @@ void log_hashrate(uv_timer_t *timer)
191190 if (current_time > start_time)
192191 {
193192 duration_t eplased = current_time - start_time;
194- printf (" hashrate: %.0f MH/s " , total_mining_count.load () / eplased.count () / 1000000 );
193+ LOG (" hashrate: %.0f MH/s " , total_mining_count.load () / eplased.count () / 1000000 );
195194 for (int i = 0 ; i < gpu_count; i++)
196195 {
197- printf (" gpu%d: %.0f MH/s " , i, device_mining_count[i].load () / eplased.count () / 1000000 );
196+ LOG_WITHOUT_TS (" gpu%d: %.0f MH/s " , i, device_mining_count[i].load () / eplased.count () / 1000000 );
198197 }
199- printf (" solutions: %u\n " , found_solutions.load (std::memory_order_relaxed));
198+ LOG_WITHOUT_TS (" solutions: %u\n " , found_solutions.load (std::memory_order_relaxed));
200199 }
201200}
202201
@@ -250,7 +249,7 @@ void on_read(uv_stream_t *server, ssize_t nread, const uv_buf_t *buf)
250249{
251250 if (nread < 0 )
252251 {
253- fprintf (stderr, " error on_read %ld: might be that the full node is not synced, or miner wallets are not setup, try to reconnect\n " , nread);
252+ LOGERR ( " error on_read %ld: might be that the full node is not synced, or miner wallets are not setup, try to reconnect\n " , nread);
254253 uv_timer_start (&reconnect_timer, try_to_reconnect, 5000 , 0 );
255254 return ;
256255 }
@@ -274,7 +273,7 @@ void on_read(uv_stream_t *server, ssize_t nread, const uv_buf_t *buf)
274273 break ;
275274
276275 case SUBMIT_RESULT:
277- printf (" submitted: %d -> %d: %d \n " , message->submit_result ->from_group , message->submit_result ->to_group , message->submit_result ->status );
276+ LOG (" submitted: %d -> %d: %d \n " , message->submit_result ->from_group , message->submit_result ->to_group , message->submit_result ->status );
278277 break ;
279278 }
280279 free_server_message_except_jobs (message);
@@ -288,11 +287,11 @@ void on_connect(uv_connect_t *req, int status)
288287{
289288 if (status < 0 )
290289 {
291- fprintf (stderr, " connection error %d: might be that the full node is not reachable, try to reconnect\n " , status);
290+ LOGERR ( " connection error %d: might be that the full node is not reachable, try to reconnect\n " , status);
292291 uv_timer_start (&reconnect_timer, try_to_reconnect, 5000 , 0 );
293292 return ;
294293 }
295- printf (" the server is connected %d %p\n " , status, req);
294+ LOG (" the server is connected %d %p\n " , status, req);
296295
297296 tcp = req->handle ;
298297 uv_read_start (req->handle , alloc_buffer, on_read);
@@ -325,7 +324,7 @@ int hostname_to_ip(char *ip_address, char *hostname)
325324 int res = getaddrinfo (hostname, NULL , &hints, &servinfo);
326325 if (res != 0 )
327326 {
328- fprintf (stderr, " getaddrinfo: %s\n " , gai_strerror (res));
327+ LOGERR ( " getaddrinfo: %s\n " , gai_strerror (res));
329328 return 1 ;
330329 }
331330
@@ -349,19 +348,19 @@ int main(int argc, char **argv)
349348 int rc = WSAStartup (MAKEWORD (2 , 2 ), &wsa);
350349 if (rc != 0 )
351350 {
352- printf (" Initialize winsock failed: %d" , rc);
351+ LOGERR (" Initialize winsock failed: %d\n " , rc);
353352 exit (1 );
354353 }
355354 #endif
356355
357- printf (" Running gpu-miner version : %s\n " , MINER_VERSION);
356+ LOG (" Running gpu-miner version : %s\n " , MINER_VERSION);
358357
359358 int gpu_count = 0 ;
360359 cudaGetDeviceCount (&gpu_count);
361- printf (" GPU count: %d\n " , gpu_count);
360+ LOG (" GPU count: %d\n " , gpu_count);
362361 for (int i = 0 ; i < gpu_count; i++)
363362 {
364- printf (" GPU #%d has #%d cores\n " , i, get_device_cores (i));
363+ LOG (" GPU #%d has #%d cores\n " , i, get_device_cores (i));
365364 use_device[i] = true ;
366365 }
367366
@@ -396,18 +395,22 @@ int main(int argc, char **argv)
396395 {
397396 int device = atoi (argv[optind]);
398397 if (device < 0 || device >= gpu_count) {
399- printf (" Invalid gpu index %d\n " , device);
398+ LOGERR (" Invalid gpu index %d\n " , device);
400399 exit (1 );
401400 }
402401 use_device[device] = true ;
403402 }
404403 break ;
405404 default :
406- printf (" Invalid command %c\n " , command);
405+ LOGERR (" Invalid command %c\n " , command);
407406 exit (1 );
408407 }
409408 }
410- printf (" will connect to broker @%s:%d\n " , broker_ip, port);
409+ LOG (" will connect to broker @%s:%d\n " , broker_ip, port);
410+
411+ #ifdef __linux__
412+ signal (SIGPIPE, SIG_IGN);
413+ #endif
411414
412415 mining_workers_init (gpu_count);
413416 setup_gpu_worker_count (gpu_count, gpu_count * parallel_mining_works_per_gpu);
0 commit comments