From 9429905cb75e36107df9c0b44a3dd9293520f4f2 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Thu, 12 Mar 2015 22:55:04 -0500 Subject: an upgrade to link.c to allow keys in channels. segfault fixed to set tailf[i].to=0 in more cases so it can be tested. don't remember what changes were made to libirc.c --- libirc/libirc.c | 61 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 27 deletions(-) (limited to 'libirc/libirc.c') diff --git a/libirc/libirc.c b/libirc/libirc.c index fad958d..2394459 100644 --- a/libirc/libirc.c +++ b/libirc/libirc.c @@ -37,28 +37,35 @@ int serverConnect(char *serv,char *port) { return p?fd:0; } -//yeah. this is a copy of the previous function. -//with a bit of different stuff. didn't want to break anything yet. +int fdlen(int *fds) { + int i; + for(i=0;fds[i] != -1;i++); + return i+1; +} + int runem(int *fds,void (*line_handler)(),void (*extra_handler)()) { + int j; + int fdl=fdlen(fds); fd_set master; fd_set readfs; struct timeval timeout; int fdmax=0,n,s,i; int fd; - char *backlog=malloc(CHUNK+1); + char *backlogs[fdl]; char *t,*line=0; int blsize=CHUNK; int bllen=0; - char buffer[CHUNK];//THIS IS *NOT* NULL TERMINATED. - if(!backlog) return 252; + char buffers[fdl][CHUNK];//THIS IS *NOT* NULL TERMINATED. FD_ZERO(&master); FD_ZERO(&readfs); for(i=0;fds[i] != -1;i++) { + if(!backlogs[i]) return 252; FD_SET(fds[i],&master); + backlogs[i]=malloc(CHUNK+1); + memset(backlogs[i],0,CHUNK); + memset(buffers[i],0,CHUNK); fdmax=fds[i]>fdmax?fds[i]:fdmax; } - memset(backlog,0,CHUNK); - memset(buffer,0,CHUNK); int done=0; while(!done) { for(fd=0;fd<=fdmax;fd++) { @@ -74,14 +81,14 @@ int runem(int *fds,void (*line_handler)(),void (*extra_handler)()) { perror("select"); return 1; } - for(fd=0;fd<=fdmax;fd++) { - if(FD_ISSET(fd,&readfs)) { - if((n=recv(fd,buffer,CHUNK,0)) <= 0) {//read CHUNK bytes + for(i=0;fds[i] != -1;i++) { + if(FD_ISSET(fds[i],&readfs)) { + if((n=recv(fds[i],buffers[i],CHUNK,0)) <= 0) {//read CHUNK bytes fprintf(stderr,"recv: %d\n",n); perror("recv"); return 2; } else { - buffer[n]=0;//deff right. + buffers[i][n]=0;//deff right. if(bllen+n >= blsize) {//this is probably off... blsize+=n; t=malloc(blsize); @@ -90,30 +97,30 @@ int runem(int *fds,void (*line_handler)(),void (*extra_handler)()) { exit(253); } memset(t,0,blsize);//optional? - memcpy(t,backlog,blsize-n+1);//??? - free(backlog); - backlog=t; + memcpy(t,backlogs[i],blsize-n+1);//??? + free(backlogs[i]); + backlogs[i]=t; } - memcpy(backlog+bllen,buffer,n); + memcpy(backlogs[i]+bllen,buffers[i],n); bllen+=n; - for(i=0,s=0;i bllen) { //if the ending position is after the size of the backlog... bllen=0;//fuck shifting. :P } else { - for(i=s;i<=bllen;i++) {//should work. - backlog[i-s]=backlog[i]; + for(j=s;j<=bllen;j++) {//should work. + backlogs[i][j-s]=backlogs[i][j]; } bllen-=s; } @@ -147,7 +154,7 @@ int runit(int fd,void (*line_handler)(),void (*extra_handler)()) { int fds[2]; fds[0]=fd; fds[1]=-1; - runem(fds,line_handler,extra_handler); + return runem(fds,line_handler,extra_handler); } //not needed? -- cgit v1.2.3