URI: 
       tFix 15-year-old sam protocol bug. - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 78439d25f8b2f6f2289e9f4e4400e0f7cdb5fa70
   DIR parent ad2922ef28f026b8bbd0aee30d92f703613c1486
  HTML Author: rsc <devnull@localhost>
       Date:   Fri, 12 Jan 2007 15:57:34 +0000
       
       Fix 15-year-old sam protocol bug.
       
       Diffstat:
         M src/cmd/sam/file.c                  |      27 +++------------------------
         M src/cmd/sam/mesg.c                  |      21 +++++++++++++--------
         M src/cmd/sam/rasp.c                  |      17 ++++++++++++++++-
         M src/cmd/sam/sam.h                   |       3 ++-
       
       4 files changed, 34 insertions(+), 34 deletions(-)
       ---
   DIR diff --git a/src/cmd/sam/file.c b/src/cmd/sam/file.c
       t@@ -266,18 +266,6 @@ filedeltext(File *f, Text *t)
        #endif
        
        void
       -fileinsert(File *f, uint p0, Rune *s, uint ns)
       -{
       -        if(p0 > f->b.nc)
       -                panic("internal error: fileinsert");
       -        if(f->seq > 0)
       -                fileuninsert(f, &f->delta, p0, ns);
       -        bufinsert(&f->b, p0, s, ns);
       -        if(ns)
       -                f->mod = TRUE;
       -}
       -
       -void
        fileuninsert(File *f, Buffer *delta, uint p0, uint ns)
        {
                Undo u;
       t@@ -292,18 +280,6 @@ fileuninsert(File *f, Buffer *delta, uint p0, uint ns)
        }
        
        void
       -filedelete(File *f, uint p0, uint p1)
       -{
       -        if(!(p0<=p1 && p0<=f->b.nc && p1<=f->b.nc))
       -                panic("internal error: filedelete");
       -        if(f->seq > 0)
       -                fileundelete(f, &f->delta, p0, p1);
       -        bufdelete(&f->b, p0, p1);
       -        if(p1 > p0)
       -                f->mod = TRUE;
       -}
       -
       -void
        fileundelete(File *f, Buffer *delta, uint p0, uint p1)
        {
                Undo u;
       t@@ -499,6 +475,9 @@ fileundo(File *f, int isundo, int canredo, uint *q0p, uint *q1p, int flag)
        
                raspstart(f);
                while(delta->nc > 0){
       +                /* rasp and buffer are in sync; sync with wire if needed */
       +                if(needoutflush())
       +                        raspflush(f);
                        up = delta->nc-Undosize;
                        bufread(delta, up, (Rune*)&u, Undosize);
                        if(isundo){
   DIR diff --git a/src/cmd/sam/mesg.c b/src/cmd/sam/mesg.c
       t@@ -1,5 +1,5 @@
        #include "sam.h"
       -
       +#define DEBUG
        Header        h;
        uchar        indata[DATASIZE];
        uchar        outdata[2*DATASIZE+3];        /* room for overflow message */
       t@@ -10,7 +10,7 @@ Posn        cmdpt;
        Posn        cmdptadv;
        Buffer        snarfbuf;
        int        waitack;
       -int        noflush;
       +int        outbuffered;
        int        tversion;
        
        int        inshort(void);
       t@@ -807,21 +807,26 @@ outsend(void)
        {
                int outcount;
        
       +        if(outp >= outdata+nelem(outdata))
       +                panic("outsend");
                outcount = outp-outmsg;
                outcount -= 3;
                outmsg[1] = outcount;
                outmsg[2] = outcount>>8;
                outmsg = outp;
       -        if(!noflush){
       +        if(!outbuffered){
                        outcount = outmsg-outdata;
                        if (write(1, (char*) outdata, outcount) != outcount)
                                rescue();
                        outmsg = outdata;
                        return;
                }
       -        if(outmsg < outdata+DATASIZE)
       -                return;
       -        outflush();
       +}
       +
       +int
       +needoutflush(void)
       +{
       +        return 1;
        }
        
        void
       t@@ -829,7 +834,7 @@ outflush(void)
        {
                if(outmsg == outdata)
                        return;
       -        noflush = 0;
       +        outbuffered = 0;
                outT0(Hack);
                waitack = 1;
                do
       t@@ -839,5 +844,5 @@ outflush(void)
                        }
                while(waitack);
                outmsg = outdata;
       -        noflush = 1;
       +        outbuffered = 1;
        }
   DIR diff --git a/src/cmd/sam/rasp.c b/src/cmd/sam/rasp.c
       t@@ -3,7 +3,7 @@
         * GROWDATASIZE must be big enough that all errors go out as Hgrowdata's,
         * so they will be scrolled into visibility in the ~~sam~~ window (yuck!).
         */
       -#define        GROWDATASIZE        50        /* if size is > this, send data with grow */
       +#define        GROWDATASIZE        50        /* if size is <= this, send data with grow */
        
        void        rcut(List*, Posn, Posn);
        int        rterm(List*, Posn);
       t@@ -80,6 +80,20 @@ raspdone(File *f, int toterm)
        }
        
        void
       +raspflush(File *f)
       +{
       +        if(grown){
       +                outTsll(Hgrow, f->tag, growpos, grown);
       +                grown = 0;
       +        }
       +        else if(shrunk){
       +                outTsll(Hcut, f->tag, shrinkpos, shrunk);
       +                shrunk = 0;
       +        }
       +        outflush();
       +}
       +
       +void
        raspdelete(File *f, uint p1, uint p2, int toterm)
        {
                long n;
       t@@ -323,3 +337,4 @@ rdata(List *r, Posn p1, Posn n)
                }
                return rg;
        }
       +
   DIR diff --git a/src/cmd/sam/sam.h b/src/cmd/sam/sam.h
       t@@ -218,6 +218,7 @@ void                raspstart(File*);
        void                raspdelete(File*, uint, uint, int);
        void                raspinsert(File*, uint, Rune*, uint, int);
        void                raspdone(File*, int);
       +void                raspflush(File*);
        
        /*
         * acme fns
       t@@ -404,4 +405,4 @@ void        outTsll(Hmesg, int, long, long);
        void        outTsl(Hmesg, int, long);
        void        outTsv(Hmesg, int, vlong);
        void        outflush(void);
       -
       +int needoutflush(void);