Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25796
Modified Files: Tag: desiredata s_inter.c s_stuff.h Log Message: beginning multi-client support
Index: s_inter.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_inter.c,v retrieving revision 1.5.4.10.2.25.2.4 retrieving revision 1.5.4.10.2.25.2.5 diff -C2 -d -r1.5.4.10.2.25.2.4 -r1.5.4.10.2.25.2.5 *** s_inter.c 2 Dec 2006 03:12:12 -0000 1.5.4.10.2.25.2.4 --- s_inter.c 2 Dec 2006 05:13:10 -0000 1.5.4.10.2.25.2.5 *************** *** 427,431 **** x->udp = udp; x->fd = fd; ! x->outbuf = 0; x->next = 0; if (!(x->inbuf = (char *)malloc(INBUFSIZE))) bug("t_socketreceiver");; --- 427,431 ---- x->udp = udp; x->fd = fd; ! x->obuf = 0; x->next = 0; if (!(x->inbuf = (char *)malloc(INBUFSIZE))) bug("t_socketreceiver");; *************** *** 552,581 **** #define GUI_BYTESPERPING 1024 /* how much we send up per ping */
! static char *sys_guibuf; ! static int sys_guibufhead; ! static int sys_guibuftail; ! static int sys_guibufsize; ! static int sys_waitingforping; ! static int sys_bytessincelastping; ! ! static void sys_trytogetmoreguibuf(int newsize) { ! char *newbuf = (char *)realloc(sys_guibuf, newsize); ! sys_guibufsize = newsize; ! sys_guibuf = newbuf; }
void sys_vgui(char *fmt, ...) { ! // t_socketreceiver *self = sys_socketreceiver; int msglen; va_list ap; ! if (!sys_guibuf) { ! sys_guibuf = (char *)malloc(GUI_ALLOCCHUNK); ! sys_guibufsize = GUI_ALLOCCHUNK; ! sys_guibufhead = sys_guibuftail = 0; } ! if (sys_guibufhead > sys_guibufsize - (GUI_ALLOCCHUNK/2)) ! sys_trytogetmoreguibuf(sys_guibufsize + GUI_ALLOCCHUNK); va_start(ap, fmt); ! msglen = vsnprintf(sys_guibuf + sys_guibufhead, sys_guibufsize - sys_guibufhead, fmt, ap); va_end(ap); if(msglen < 0) { --- 552,575 ---- #define GUI_BYTESPERPING 1024 /* how much we send up per ping */
! static void sys_trytogetmoreguibuf(t_socketreceiver *self, int newsize) { ! self->osize = newsize; ! self->obuf = (char *)realloc(self->obuf, newsize); }
+ int max(int a, int b) { return ((a)>(b)?(a):(b)); } + void sys_vgui(char *fmt, ...) { ! t_socketreceiver *self = sys_socketreceiver; int msglen; va_list ap; ! if (!self->obuf) { ! self->obuf = (char *)malloc(GUI_ALLOCCHUNK); ! self->osize = GUI_ALLOCCHUNK; ! self->ohead = self->otail = 0; } ! if (self->ohead > self->osize - GUI_ALLOCCHUNK/2) ! sys_trytogetmoreguibuf(self,self->osize + GUI_ALLOCCHUNK); va_start(ap, fmt); ! msglen = vsnprintf(self->obuf+self->ohead, self->osize-self->ohead, fmt, ap); va_end(ap); if(msglen < 0) { *************** *** 583,599 **** return; } ! if (msglen >= sys_guibufsize - sys_guibufhead) { ! int msglen2, newsize = sys_guibufsize + 1 + (msglen > GUI_ALLOCCHUNK ? msglen : GUI_ALLOCCHUNK); ! sys_trytogetmoreguibuf(newsize); va_start(ap, fmt); ! msglen2 = vsnprintf(sys_guibuf + sys_guibufhead, ! sys_guibufsize - sys_guibufhead, fmt, ap); va_end(ap); if (msglen2 != msglen) bug("sys_vgui"); ! if (msglen >= sys_guibufsize - sys_guibufhead) msglen = sys_guibufsize - sys_guibufhead; } ! if (sys_debuglevel & DEBUG_MESSUP) fprintf(stderr, "%s", sys_guibuf + sys_guibufhead); ! sys_guibufhead += msglen; ! sys_bytessincelastping += msglen; }
--- 577,592 ---- return; } ! if (msglen >= self->osize - self->ohead) { ! int msglen2, newsize = self->osize+1+max(msglen,GUI_ALLOCCHUNK); ! sys_trytogetmoreguibuf(self,newsize); va_start(ap, fmt); ! msglen2 = vsnprintf(self->obuf+self->ohead, self->osize-self->ohead, fmt, ap); va_end(ap); if (msglen2 != msglen) bug("sys_vgui"); ! if (msglen >= self->osize-self->ohead) msglen = self->osize-self->ohead; } ! if (sys_debuglevel & DEBUG_MESSUP) fprintf(stderr, "%s", self->obuf+self->ohead); ! self->ohead += msglen; ! self->bytessincelastping += msglen; }
*************** *** 601,608 ****
static int sys_flushtogui(t_socketreceiver *self) { ! int writesize = sys_guibufhead - sys_guibuftail, nwrote = 0; if (!writesize) return 0; fprintf(stderr,"sys_flushtogui self=%p writesize=%d\n",self,writesize); ! nwrote = send(self->fd, sys_guibuf + sys_guibuftail, writesize, 0); if (nwrote < 0) { perror("pd-to-gui socket"); --- 594,601 ----
static int sys_flushtogui(t_socketreceiver *self) { ! int writesize = self->ohead-self->otail, nwrote = 0; if (!writesize) return 0; fprintf(stderr,"sys_flushtogui self=%p writesize=%d\n",self,writesize); ! nwrote = send(self->fd, self->obuf+self->otail, writesize, 0); if (nwrote < 0) { perror("pd-to-gui socket"); *************** *** 610,621 **** } else if (!nwrote) { return 0; ! } else if (nwrote >= sys_guibufhead - sys_guibuftail) { ! sys_guibufhead = sys_guibuftail = 0; } else if (nwrote) { ! sys_guibuftail += nwrote; ! if (sys_guibuftail > (sys_guibufsize >> 2)) { ! memmove(sys_guibuf, sys_guibuf + sys_guibuftail, sys_guibufhead - sys_guibuftail); ! sys_guibufhead = sys_guibufhead - sys_guibuftail; ! sys_guibuftail = 0; } } --- 603,614 ---- } else if (!nwrote) { return 0; ! } else if (nwrote >= self->ohead-self->otail) { ! self->ohead = self->otail = 0; } else if (nwrote) { ! self->otail += nwrote; ! if (self->otail > self->osize>>2) { ! memmove(self->obuf, self->obuf+self->otail, self->ohead-self->otail); ! self->ohead -= self->otail; ! self->otail = 0; } } *************** *** 623,627 **** }
! void glob_ping(t_pd *dummy) {sys_waitingforping = 0;}
int sys_pollgui(void) { --- 616,620 ---- }
! void glob_ping(t_pd *dummy) {t_socketreceiver *self = sys_socketreceiver; self->waitingforping = 0;}
int sys_pollgui(void) { *************** *** 686,690 **** sys_netreceive = netreceive_new(&s_,sys_guisetportnumber,0); fprintf(stderr,"sys_netreceive=%p\n",sys_netreceive); ! if (!sys_netreceive) return; printer0 = (t_text *)pd_new3("print left"); printer1 = (t_text *)pd_new3("print right"); --- 679,683 ---- sys_netreceive = netreceive_new(&s_,sys_guisetportnumber,0); fprintf(stderr,"sys_netreceive=%p\n",sys_netreceive); ! if (!sys_netreceive) return 0; printer0 = (t_text *)pd_new3("print left"); printer1 = (t_text *)pd_new3("print right");
Index: s_stuff.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_stuff.h,v retrieving revision 1.5.4.10.2.8.2.1 retrieving revision 1.5.4.10.2.8.2.2 diff -C2 -d -r1.5.4.10.2.8.2.1 -r1.5.4.10.2.8.2.2 *** s_stuff.h 2 Dec 2006 03:12:13 -0000 1.5.4.10.2.8.2.1 --- s_stuff.h 2 Dec 2006 05:13:10 -0000 1.5.4.10.2.8.2.2 *************** *** 182,187 **** /* for sending only: */ int fd; - char *outbuf; struct _socketreceiver *next; } t_socketreceiver;
--- 182,190 ---- /* for sending only: */ int fd; struct _socketreceiver *next; + char *obuf; + int ohead, otail, osize; + int waitingforping; + int bytessincelastping; } t_socketreceiver;