From 682e6360f0e544a28610690d823ac53ab5c10d47 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 17 Jan 2001 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2001-01-17 --- bitsy/sa1110uart.c | 1 + ip/loopbackmedium.c | 119 ++++++++++++++++++++++++++++++++++++++++++++ ip/tcp.c | 3 +- port/portfns.h | 1 + 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 ip/loopbackmedium.c diff --git a/bitsy/sa1110uart.c b/bitsy/sa1110uart.c index 68ecec5443f9769c65cf9ab855ee31da6bd18111..ed636e3f700774203329f4dd14d7c9e3da4a1be5 100644 --- a/bitsy/sa1110uart.c +++ b/bitsy/sa1110uart.c @@ -434,6 +434,7 @@ sa1100_uartsetup(int console) gpclkregs = mapspecial(GPCLKREGS, 64); gpclkregs->r0 = Gpclk_sus; /* set uart mode */ uart1regs = mapspecial(UART1REGS, 64); + p = uartsetup(&sa1100_uart, uart1regs, ClockFreq, "serialport1"); uartspecial(p, 115200, 0, 0, µcputc); intrenable(IRQ, IRQuart1b, sa1100_uartintr, p, p->name); diff --git a/ip/loopbackmedium.c b/ip/loopbackmedium.c new file mode 100644 index 0000000000000000000000000000000000000000..6bc98b9281999a76a3bfb7965afc6f971d16c333 --- /dev/null +++ b/ip/loopbackmedium.c @@ -0,0 +1,119 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "../port/error.h" + +#include "ip.h" + +enum +{ + Maxtu= 16*1024, +}; + +typedef struct LB LB; +struct LB +{ + Proc *readp; + Queue *q; + Fs *f; +}; + +static void loopbackread(void *a); + +static void +loopbackbind(Ipifc *ifc, int, char**) +{ + LB *lb; + + lb = smalloc(sizeof(*lb)); + lb->f = ifc->conv->p->f; + lb->q = qopen(128*1024, 1, nil, nil); + ifc->arg = lb; + + kproc("loopbackread", loopbackread, ifc); + +} + +static void +loopbackunbind(Ipifc *ifc) +{ + LB *lb = ifc->arg; + + if(lb->readp) + postnote(lb->readp, 1, "unbind", 0); + + /* wait for reader to die */ + while(lb->readp != 0) + tsleep(&up->sleep, return0, 0, 300); + + /* clean up */ + qfree(lb->q); + free(lb); +} + +static void +loopbackbwrite(Ipifc *ifc, Block *bp, int, uchar*) +{ + LB *lb; + + lb = ifc->arg; + if(qpass(lb->q, bp) < 0) + ifc->outerr++; + ifc->out++; +} + +static void +loopbackread(void *a) +{ + Ipifc *ifc; + Block *bp; + LB *lb; + + ifc = a; + lb = ifc->arg; + lb->readp = up; /* hide identity under a rock for unbind */ + if(waserror()){ + lb->readp = 0; + pexit("hangup", 1); + } + for(;;){ + bp = qbread(lb->q, Maxtu); + if(bp == nil) + continue; + ifc->in++; + if(!canrlock(ifc)){ + freeb(bp); + continue; + } + if(waserror()){ + runlock(ifc); + nexterror(); + } + if(ifc->lifc == nil) + freeb(bp); + else + ipiput(lb->f, ifc->lifc->local, bp); + runlock(ifc); + poperror(); + } +} + +Medium loopbackmedium = +{ +.hsize= 0, +.minmtu= 0, +.maxmtu= Maxtu, +.maclen= 0, +.name= "loopback", +.bind= loopbackbind, +.unbind= loopbackunbind, +.bwrite= loopbackbwrite, +}; + +void +loopbackmediumlink(void) +{ + addipmedium(&loopbackmedium); +} diff --git a/ip/tcp.c b/ip/tcp.c index 9d514994bcb8422255814ed6d6baad818c342548..bf9cf1c50c8941df700fa16bc93ee575e57256b3 100644 --- a/ip/tcp.c +++ b/ip/tcp.c @@ -333,8 +333,9 @@ tcpstate(Conv *c, char *state, int n) s = (Tcpctl*)(c->ptcl); return snprint(state, n, - "%s srtt %d mdev %d timer.start %d timer.count %d\n", + "%s srtt %d mdev %d cwin %d swin %d timer.start %d timer.count %d\n", tcpstates[s->state], s->srtt, s->mdev, + s->cwind, s->snd.wnd, s->timer.start, s->timer.count); } diff --git a/port/portfns.h b/port/portfns.h index 318155c5db51ebb1eeff7c4c65731619975ef157..f51001541a19f1241364282331c22238f0ba0706 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -235,6 +235,7 @@ int qconsume(Queue*, void*, int); Block* qcopy(Queue*, int, ulong); void qdiscard(Queue*, int); void qflush(Queue*); +void qfree(Queue*); int qfull(Queue*); Block* qget(Queue*); void qhangup(Queue*, char*);