add TRACE p-server
This commit is contained in:
parent
50eeba56a4
commit
07aa3824a9
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -4,6 +4,7 @@
|
||||
],
|
||||
"files.associations": {
|
||||
"socket_wrapper.h": "c",
|
||||
"stdalign.h": "c"
|
||||
"stdalign.h": "c",
|
||||
"timerhelper.h": "c"
|
||||
}
|
||||
}
|
25
p-server.c
25
p-server.c
@ -13,6 +13,7 @@
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "socket_wrapper.h"
|
||||
|
||||
#ifndef DEFAULT_MAX_LISTEN_SOCKET
|
||||
@ -51,6 +52,15 @@ static const int RESPONSE_REQUEST = 3;
|
||||
static const int RESPONSE_REQUEST = DEFAULT_RESPONSE_REQUEST;
|
||||
#endif
|
||||
|
||||
#define USE_TRACE
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include "timerhelper.h"
|
||||
enum{
|
||||
Trace_Timer_ID = CLOCK_REALTIME
|
||||
};
|
||||
|
||||
/*========
|
||||
*Operation
|
||||
*========*/
|
||||
@ -276,15 +286,22 @@ int main(int argc, const char *argv[]){
|
||||
char ip_buf[INET_ADDRSTRLEN];
|
||||
const char * msg;
|
||||
int retval = 0;
|
||||
struct timespec ts,tsmiddle,tsend;
|
||||
if((csock = accept(sock, (struct sockaddr *)&client_addr,&client_addr_len)) < 0){
|
||||
free(buf);
|
||||
perror("accept error");
|
||||
return 1;
|
||||
}
|
||||
msg = inet_ntop(AF_INET,&client_addr.sin_addr,ip_buf,sizeof(ip_buf));
|
||||
#ifdef USE_TRACE
|
||||
clock_gettime(Trace_Timer_ID,&ts);
|
||||
#endif
|
||||
fprintf(stderr,"Connected on : %s:%d\n",msg == NULL ? "(null)" : msg , ntohs(client_addr.sin_port));
|
||||
pid = fork();
|
||||
if(pid == 0){
|
||||
#ifdef USE_TRACE
|
||||
clock_gettime(Trace_Timer_ID,&tsmiddle);
|
||||
#endif
|
||||
if((fd = read_request(csock,buf,bufsize)) > 0){
|
||||
retval = send_response(csock,fd,buf,bufsize);
|
||||
close(fd);
|
||||
@ -292,6 +309,14 @@ int main(int argc, const char *argv[]){
|
||||
else retval = fd;
|
||||
if(close(csock) < 0)
|
||||
perror("csock close error");
|
||||
#ifdef USE_TRACE
|
||||
clock_gettime(Trace_Timer_ID,&tsend);
|
||||
struct timespec tophalf = timespec_sub(tsmiddle,ts);
|
||||
struct timespec bottomhelf = timespec_sub(tsend,tsmiddle);
|
||||
struct timespec resolution;
|
||||
clock_getres(Trace_Timer_ID,&resolution);
|
||||
fprintf(stderr,"top: %ld ns, bottom: %ld ns, res: %ld\n",tophalf.tv_nsec,bottomhelf.tv_nsec,resolution.tv_nsec);
|
||||
#endif
|
||||
free(buf);
|
||||
return retval;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user