~kris/9p

9hist

682e6360f0e544a28610690d823ac53ab5c10d47 — David du Colombier 25 years ago 840c8c3
Plan 9 from Bell Labs 2001-01-17
4 files changed, 123 insertions(+), 1 deletions(-)

M bitsy/sa1110uart.c
A ip/loopbackmedium.c
M ip/tcp.c
M port/portfns.h
M bitsy/sa1110uart.c => bitsy/sa1110uart.c +1 -0
@@ 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);

A ip/loopbackmedium.c => ip/loopbackmedium.c +119 -0
@@ 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);
}

M ip/tcp.c => ip/tcp.c +2 -1
@@ 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);
}


M port/portfns.h => port/portfns.h +1 -0
@@ 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*);