plan 9 kernel history: overview | file list | diff list

1990/0930/port/stream.c (diff list | history)

1990/0914/sys/src/9/port/stream.c:127,1331990/0930/sys/src/9/port/stream.c:127,133 (short | long | prev | next)
1990/0227    
		; 
 
	/* 
	 *  look for a free block, garbage collect if there are none 
1990/0930    
	 *  look for a free block 
1990/0227    
	 */ 
	lock(bcp); 
	while(bcp->first == 0){ 
1990/0914/sys/src/9/port/stream.c:878,8891990/0930/sys/src/9/port/stream.c:878,914
1990/0227    
} 
 
/* 
1990/0930    
 *  return the stream id 
 */ 
long 
streamctlread(Chan *c, void *vbuf, long n) 
{ 
	uchar *buf = vbuf; 
	char num[32]; 
	Stream *s; 
 
	s = c->stream; 
	if(STREAMTYPE(c->qid) == Sctlqid){ 
		sprint(num, "%d", s->id); 
		return stringread(c, buf, n, num); 
	} else { 
		if(CHDIR & c->qid) 
			return devdirread(c, vbuf, n, 0, 0, streamgen); 
		else 
			panic("streamctlread"); 
	} 
} 
 
/* 
1990/0227    
 *  return true if there is an output buffer available 
 */ 
static int 
isinput(void *x) 
{ 
	return ((Queue *)x)->first != 0; 
1990/0930    
	Queue *q; 
 
	q = (Queue *)x; 
	return (q->flag&QHUNGUP) || q->first!=0; 
1990/0227    
} 
 
/* 
1990/0914/sys/src/9/port/stream.c:895,9221990/0930/sys/src/9/port/stream.c:920,935
1990/0227    
	Block *bp; 
	Stream *s; 
	Queue *q; 
	long rv = 0; 
	int left, i, x; 
1990/0930    
	int left, i; 
1990/0227    
	uchar *buf = vbuf; 
	char num[32]; 
 
	s = c->stream; 
	switch(STREAMTYPE(c->qid)){ 
	case Sdataqid: 
		break; 
	case Sctlqid: 
		sprint(num, "%d", s->id); 
		return stringread(c, buf, n, num); 
	default: 
		if(CHDIR & c->qid) 
			return devdirread(c, vbuf, n, 0, 0, streamgen); 
		else 
			panic("streamread"); 
	} 
1990/0930    
	if(STREAMTYPE(c->qid) != Sdataqid) 
		return streamctlread(c, vbuf, n); 
1990/0227    
 
	/* 
	 *  one reader at a time 
	 */ 
1990/0930    
	s = c->stream; 
1990/0227    
	qlock(&s->rdlock); 
	if(waserror()){ 
		qunlock(&s->rdlock); 
1990/0914/sys/src/9/port/stream.c:974,9841990/0930/sys/src/9/port/stream.c:987,1002
1990/0227    
 *  This routing is entrered with s->wrlock'ed and must unlock. 
 */ 
static long 
streamctlwrite(Stream *s, void *a, long n) 
1990/0930    
streamctlwrite(Chan *c, void *a, long n) 
1990/0227    
{ 
	Qinfo *qi; 
	Block *bp; 
1990/0930    
	Stream *s; 
1990/0227    
 
1990/0930    
	if(STREAMTYPE(c->qid) != Sctlqid) 
		panic("streamctlwrite %lux", c->qid); 
	s = c->stream; 
 
1990/0227    
	/* 
	 *  package 
	 */ 
1990/0914/sys/src/9/port/stream.c:1038,10631990/0930/sys/src/9/port/stream.c:1056,1065
1990/0911    
	s = c->stream; 
 
1990/0227    
	/* 
	 *  one writer at a time 
	qlock(&s->wrlock); 
	if(waserror()){ 
		qunlock(&s->wrlock); 
		nexterror(); 
	} 
1990/0911    
	 */ 
1990/0227    
                 
	/* 
	 *  decode the qid 
	 */ 
	switch(STREAMTYPE(c->qid)){ 
	case Sdataqid: 
		break; 
	case Sctlqid: 
		n = streamctlwrite(s, a, n); 
1990/0911    
		goto out; 
1990/0227    
	default: 
		panic("bad stream qid\n"); 
	} 
1990/0930    
	if(STREAMTYPE(c->qid) != Sdataqid) 
		return streamctlwrite(c, a, n); 
1990/0227    
 
	/* 
	 *  No writes allowed on hungup channels 
1990/0914/sys/src/9/port/stream.c:1066,10721990/0930/sys/src/9/port/stream.c:1068,1074
1990/0227    
	if(q->other->flag & QHUNGUP) 
		error(0, Ehungup); 
 
1990/0312    
	if((GLOBAL(a) && !docopy) || n==0){ 
1990/0930    
	if(!docopy && GLOBAL(a)){ 
1990/0227    
		/* 
		 *  `a' is global to the whole system, just create a 
		 *  pointer to it and pass it on. 
1990/0914/sys/src/9/port/stream.c:1103,11111990/0930/sys/src/9/port/stream.c:1105,1110
1990/0227    
			} 
		} 
	} 
1990/0911    
out: 
/*	qunlock(&s->wrlock); 
	poperror(); /**/ 
1990/0227    
	return n; 
1990/0312    
} 
 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)