From 9e0401a22cc6d2413542216cafddb48decd00b8b Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Tue, 8 Dec 2020 11:37:54 +0000 Subject: [PATCH] fix some bug --- client.c | 2 +- p-server.c | 14 +++++++++++--- server.c | 21 +++++++++++++++------ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/client.c b/client.c index 993c0f0..8d69f66 100644 --- a/client.c +++ b/client.c @@ -384,7 +384,7 @@ static int parse_arg(int argc,const char *argv[]){ } else if(strcmp("-h",argv[cur]) == 0 || strcmp("--help",argv[cur]) == 0){ show_help_message(stdout,argv[0]); - return 0; + return -1; } else if(strcmp("-q",argv[cur]) == 0 || strcmp("--quiet",argv[cur]) == 0){ cmd_args.quiet_mode = true; diff --git a/p-server.c b/p-server.c index 2461db9..5173c92 100644 --- a/p-server.c +++ b/p-server.c @@ -58,8 +58,16 @@ static const int RESPONSE_REQUEST = DEFAULT_RESPONSE_REQUEST; #include "timerhelper.h" enum{ + #ifndef DEFAULT_TOP_TRACE_TIMER_ID Top_Trace_Timer_ID = CLOCK_REALTIME, + #else + Top_Trace_Timer_ID = DEFAULT_TOP_TRACE_TIMER_ID, + #endif + #ifndef DEFAULT_BOTTOM_TRACE_TIMER_ID Bottom_Trace_Timer_ID = CLOCK_THREAD_CPUTIME_ID + #else + Bottom_Trace_Timer_ID = DEFAULT_BOTTOM_TRACE_TIMER_ID + #endif }; static inline void report_resolution() @@ -311,7 +319,7 @@ int main(int argc, const char *argv[]){ #ifdef USE_TRACE clock_gettime(Top_Trace_Timer_ID,&ts_top_begin); #endif - fprintf(stderr,"Connected on : %s:%d\n",msg == NULL ? "(null)" : msg , ntohs(client_addr.sin_port)); + fprintf(stdout,"Connected on : %s:%d\n",msg == NULL ? "(null)" : msg , ntohs(client_addr.sin_port)); pid = fork(); if(pid == 0){ #ifdef USE_TRACE @@ -328,8 +336,8 @@ int main(int argc, const char *argv[]){ #ifdef USE_TRACE clock_gettime(Bottom_Trace_Timer_ID,&ts_bottom_end); struct timespec tophalf = timespec_sub(ts_top_end,ts_top_begin); - struct timespec bottomhelf = timespec_sub(ts_bottom_end,ts_bottom_end); - fprintf(stderr,"top: %ld ns, bottom: %ld ns\n",tophalf.tv_nsec,bottomhelf.tv_nsec); + struct timespec bottomhalf = timespec_sub(ts_bottom_end,ts_bottom_begin); + fprintf(stderr,"top: %ld ns, bottom: %ld ns\n",tophalf.tv_nsec,bottomhalf.tv_nsec); #endif free(buf); return retval; diff --git a/server.c b/server.c index 32f6c43..44ae211 100644 --- a/server.c +++ b/server.c @@ -68,8 +68,16 @@ static const int SLOW_SERVER_TIME = SLOW_SERVER; #ifdef USE_TRACE #include "timerhelper.h" enum{ + #ifndef DEFAULT_TOP_TRACE_TIMER_ID Top_Trace_Timer_ID = CLOCK_REALTIME, + #else + Top_Trace_Timer_ID = DEFAULT_TOP_TRACE_TIMER_ID, + #endif + #ifndef DEFAULT_BOTTOM_TRACE_TIMER_ID Bottom_Trace_Timer_ID = CLOCK_THREAD_CPUTIME_ID + #else + Bottom_Trace_Timer_ID = DEFAULT_BOTTOM_TRACE_TIMER_ID + #endif }; static inline void report_resolution() @@ -375,14 +383,15 @@ void * worker_proc(void * data){ } #ifdef USE_TRACE clock_gettime(Bottom_Trace_Timer_ID,&ts_bottom_end); - struct timespec tophalf = timespec_sub(ts_top_end,ts_top_end); - struct timespec bottomhelf = timespec_sub(ts_bottom_end,ts_bottom_begin); + struct timespec tophalf = timespec_sub(ts_top_end,ts_top_begin); + struct timespec bottomhalf = timespec_sub(ts_bottom_end,ts_bottom_begin); if(use_gui&&isatty_file(stderr)){ lock_scrolled(); add_scrolled_unlocked(1); - fprintf(stderr,"top : %ld ns, bottom : %ld ns\n",tophalf.tv_nsec,bottomhelf.tv_nsec); + fprintf(stderr,"top : %ld ns, bottom : %ld ns\n",tophalf.tv_nsec,bottomhalf.tv_nsec); unlock_scrolled(); } + else fprintf(stderr,"top : %ld ns, bottom : %ld ns\n",tophalf.tv_nsec,bottomhalf.tv_nsec); #endif if(close(csock) < 0) server_perror("csock close error"); @@ -409,14 +418,14 @@ void * worker_proc(void * data){ #ifdef USE_TRACE clock_gettime(Bottom_Trace_Timer_ID,&ts_bottom_end); struct timespec tophalf = timespec_sub(ts_top_end,ts_top_begin); - struct timespec bottomhelf = timespec_sub(ts_bottom_end,ts_bottom_begin); + struct timespec bottomhalf = timespec_sub(ts_bottom_end,ts_bottom_begin); if(use_gui&&isatty_file(stderr)){ lock_scrolled(); add_scrolled_unlocked(1); - fprintf(stderr,"top : %ld ns, bottom : %ld ns\n",tophalf.tv_nsec,bottomhelf.tv_nsec); + fprintf(stderr,"top : %ld ns, bottom : %ld ns\n",tophalf.tv_nsec,bottomhalf.tv_nsec); unlock_scrolled(); } - else fprintf(stderr,"top : %ld ns, bottom : %ld ns\n",tophalf.tv_nsec,bottomhelf.tv_nsec); + else fprintf(stderr,"top : %ld ns, bottom : %ld ns\n",tophalf.tv_nsec,bottomhalf.tv_nsec); #endif if(close(csock) < 0) server_perror("csock close error");