summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/data_stream.c18
-rw-r--r--server/main.c9
-rw-r--r--server/zbuffer.c3
3 files changed, 27 insertions, 3 deletions
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;index<numpids;index++) {
pid_t pid=s->pids[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<before){
+ printf("Time ran backwards?\n");
+ after=before;
+ }
+ timeleft-=after-before;
+ if(timeleft<0)timeleft=0;
continue;
}
diff --git a/server/zbuffer.c b/server/zbuffer.c
index af37f74..d65c7cc 100644
--- a/server/zbuffer.c
+++ b/server/zbuffer.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include <assert.h>
#include <zlib.h>
#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);
}