From 34b0e1a8adf19f695a85280ebb69b062d71b48f7 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 11 Oct 2017 19:12:14 +0200 Subject: Second --- server/data_stream.c | 18 +++++++++++++++--- server/main.c | 9 +++++++++ server/zbuffer.c | 3 +++ 3 files changed, 27 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/data_stream.c b/server/data_stream.c index e86114e..3d25104 100644 --- a/server/data_stream.c +++ b/server/data_stream.c @@ -33,6 +33,7 @@ static void write_data_fd(u8 *data,i64 len,void *fdp){ } cursor+=nwr; } + fprintf(stderr,"write_data_fd(len=%" PRIi64 ")\n",len); } static void bufappend(u8 **buf,i64 *cursor,i64 *cap,u8 *data,i64 datalen){ @@ -103,15 +104,21 @@ int data_stream_frame(struct data_stream *s){ s->pids=realloc(s->pids,s->pidbufsize,pid_t); numpids=proc_listallpids(s->pids,s->pidbufsize*sizeof(pid_t)); } - serialise8(buf8,numpids); + + // correct value will be written later + i64 numpids_buf_cursor=s->cursor; bufappend(&s->writebuf,&s->cursor,&s->writebufsize,buf8,8); + i64 nfailed=0; for(i64 index=0;indexpids[index]; struct proc_taskinfo info; int result=proc_pidinfo(pid,PROC_PIDTASKINFO,0,&info,sizeof(info)); - if(result!=sizeof info)continue; + if(result!=sizeof info){ + nfailed++; + continue; + } serialise4(buf8,pid); bufappend(&s->writebuf,&s->cursor,&s->writebufsize,buf8,4); @@ -126,7 +133,7 @@ int data_stream_frame(struct data_stream *s){ s->namebuf[0]='\0'; } - fprintf(stderr,"index=%" PRIi64 " pid=%d namelen=%zu\n",index,pid,namelen); + // fprintf(stderr,"pi=%" PRIi64 " pid=%d namelen=%zu\n",index-nfailed,pid,namelen); serialise8(buf8,namelen); bufappend(&s->writebuf,&s->cursor,&s->writebufsize,buf8,8); bufappend(&s->writebuf,&s->cursor,&s->writebufsize,s->namebuf,namelen); @@ -141,7 +148,12 @@ int data_stream_frame(struct data_stream *s){ // fprintf(stderr,"PID %u (%s): %llu %llu %llu\n",pid,namebuf,info.pti_total_user,info.pti_total_system,info.pti_resident_size); } + numpids-=nfailed; + serialise8(buf8,numpids); + memcpy(s->writebuf+numpids_buf_cursor,buf8,8); + zbuffer_write(s->z,s->writebuf,s->cursor); + // fprintf(stderr,"zbuffer_write(cursor=%" PRIi64 ")\n",s->cursor); s->cursor=0; if(callback_error)return -1; diff --git a/server/main.c b/server/main.c index 3cf1ffd..ffa16cd 100644 --- a/server/main.c +++ b/server/main.c @@ -69,6 +69,7 @@ static void connection_handler(int sock){ break; } if(ret==0||!FD_ISSET(sock,&inset)){ // timeout + before=make_timestamp(); if(do_send_frames){ if(data_stream_frame(stream)<0){ printf("Error sending data\n"); @@ -77,6 +78,14 @@ static void connection_handler(int sock){ printf("."); fflush(stdout); } timeleft=polldelay; + + i64 after=make_timestamp(); + if(after #include #include #include "zbuffer.h" @@ -48,6 +49,7 @@ void zbuffer_write(struct zbuffer *z,u8 *data,i64 len){ z->strm.avail_out=BUFSZ_ZOUT; z->strm.next_out=z->out; } + // fprintf(stderr,"zbuffer_write: avail_out = %d\n",z->strm.avail_out); assert(z->strm.avail_in==0); } @@ -74,6 +76,7 @@ void zbuffer_finish_destroy(struct zbuffer *z){ z->strm.avail_out=BUFSZ_ZOUT; z->strm.next_out=z->out; } + deflateEnd(&z->strm); free(z->out); free(z); } -- cgit v1.2.3-70-g09d2