M gnot/devhifi.c => gnot/devhifi.c +1 -1
@@ 99,7 99,7 @@ int hifidebug = 1;
void
hifireset(void)
{
- hifichan = ialloc(2*conf.nisdn*sizeof(Hifichan), 0);
+ hifichan = xalloc(2*conf.nisdn*sizeof(Hifichan));
hifichanN = &hifichan[2*conf.nisdn];
}
M gnot/devisdn.c => gnot/devisdn.c +1 -1
@@ 57,7 57,7 @@ int isdndebug;
void
isdnreset(void)
{
- isdndev = ialloc(conf.nisdn*sizeof(Isdn), 0);
+ isdndev = xalloc(conf.nisdn*sizeof(Isdn));
isdndevN = &isdndev[conf.nisdn];
}
M port/devbit.c => port/devbit.c +62 -62
@@ 352,7 352,7 @@ bitread(Chan *c, void *va, long n, ulong offset)
uchar *p, *q;
long miny, maxy, t, x, y;
ulong l, nw, ws, rv, gv, bv;
- int off, j, dn;
+ int off, j;
Fontchar *i;
GBitmap *src;
@@ 436,11 436,11 @@ bitread(Chan *c, void *va, long n, ulong offset)
* 'I' 1
* ldepth 1
* rectangle 16
- * if count great enough, also
+ * clip rectangle 16
* font info 3*12
* fontchars 6*(defont->n+1)
*/
- if(n < 18)
+ if(n < 34)
error(Ebadblt);
p[0] = 'I';
p[1] = gscreen.ldepth;
@@ 448,16 448,12 @@ bitread(Chan *c, void *va, long n, ulong offset)
PLONG(p+6, gscreen.r.min.y);
PLONG(p+10, gscreen.r.max.x);
PLONG(p+14, gscreen.r.max.y);
- dn = 18;
- if(bit.init=='j' && n>=18+16){
- PLONG(p+18, gscreen.clipr.min.x);
- PLONG(p+22, gscreen.clipr.min.y);
- PLONG(p+26, gscreen.clipr.max.x);
- PLONG(p+30, gscreen.clipr.max.y);
- dn += 16;
- }
- if(n >= dn+3*12+6*(defont->n+1)){
- p += dn;
+ PLONG(p+18, gscreen.clipr.min.x);
+ PLONG(p+22, gscreen.clipr.min.y);
+ PLONG(p+26, gscreen.clipr.max.x);
+ PLONG(p+30, gscreen.clipr.max.y);
+ if(n >= 34+3*12+6*(defont->n+1)){
+ p += 34;
sprint((char*)p, "%11d %11d %11d ", defont->n,
defont->height, defont->ascent);
p += 3*12;
@@ 468,9 464,9 @@ bitread(Chan *c, void *va, long n, ulong offset)
p[4] = i->left;
p[5] = i->width;
}
- n = dn+3*12+6*(defont->n+1);
+ n = 34+3*12+6*(defont->n+1);
}else
- n = dn;
+ n = 34;
bit.init = 0;
}else if(bit.lastid > 0){
/*
@@ 782,13 778,12 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
break;
case 'i':
- case 'j':
/*
* init
*
- * 'i','j' 1
+ * 'i' 1
*/
- bit.init = *p;
+ bit.init = 1;
m -= 1;
p += 1;
break;
@@ 905,12 900,14 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
* height 1
* ascent 1
* ldepth 2
+ * ncache 2
* next read returns allocated font id
*/
- if(m < 5)
+ if(m < 7)
error(Ebadblt);
v = GSHORT(p+3);
- if(v < 0)
+ t = GSHORT(p+5);
+ if(v<0 || t<0)
error(Ebadblt);
for(i=0; i<bit.nfont; i++)
if(bit.font[i] == 0)
@@ 922,6 919,8 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
bit.nfont += DMAP;
fontfound:
ff = smalloc(sizeof(GFont));
+ ff->ncache = t;
+ ff->cache = smalloc(t*sizeof(GCacheinfo));
bit.font[i] = ff;
ff = bit.font[i];
ff->height = p[1];
@@ 929,8 928,8 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
ff->ldepth = v;
ff->width = 0;
ff->b = 0;
- m -= 5;
- p += 5;
+ m -= 7;
+ p += 7;
bit.lastfid = i;
break;
@@ 1016,53 1015,16 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
m -= 11;
break;
- case 't':
- /*
- * texture
- * 't' 1
- * dst id 2
- * rect 16
- * src id 2
- * fcode 2
- */
- if(m < 23)
- error(Ebadblt);
- v = GSHORT(p+1);
- if(v<0 || v>=bit.nmap || (dst=bit.map[v])==0)
- error(Ebadbitmap);
- off = 0;
- fc = GSHORT(p+21) & 0xF;
- if(v == 0){
- if(flipping)
- fc = flipD[fc];
- off = 1;
- }
- rect.min.x = GLONG(p+3);
- rect.min.y = GLONG(p+7);
- rect.max.x = GLONG(p+11);
- rect.max.y = GLONG(p+15);
- v = GSHORT(p+19);
- if(v<0 || v>=bit.nmap || (src=bit.map[v])==0)
- error(Ebadbitmap);
- if(off && !isoff){
- cursoroff(1);
- isoff = 1;
- }
- gtexture(dst, rect, src, fc);
- m -= 23;
- p += 23;
- break;
-
- case 'u':
+ case 's':
/*
* string
- * 'u' 1
+ * 's' 1
* id 2
* pt 8
* font id 2
* code 2
* n 2
- * cache indexes 2*n (not null terminated)
+ * cache indices 2*n (not null terminated)
*/
if(m < 17)
error(Ebadblt);
@@ 1095,6 1057,43 @@ bitwrite(Chan *c, void *va, long n, ulong offset)
p += l;
break;
+ case 't':
+ /*
+ * texture
+ * 't' 1
+ * dst id 2
+ * rect 16
+ * src id 2
+ * fcode 2
+ */
+ if(m < 23)
+ error(Ebadblt);
+ v = GSHORT(p+1);
+ if(v<0 || v>=bit.nmap || (dst=bit.map[v])==0)
+ error(Ebadbitmap);
+ off = 0;
+ fc = GSHORT(p+21) & 0xF;
+ if(v == 0){
+ if(flipping)
+ fc = flipD[fc];
+ off = 1;
+ }
+ rect.min.x = GLONG(p+3);
+ rect.min.y = GLONG(p+7);
+ rect.max.x = GLONG(p+11);
+ rect.max.y = GLONG(p+15);
+ v = GSHORT(p+19);
+ if(v<0 || v>=bit.nmap || (src=bit.map[v])==0)
+ error(Ebadbitmap);
+ if(off && !isoff){
+ cursoroff(1);
+ isoff = 1;
+ }
+ gtexture(dst, rect, src, fc);
+ m -= 23;
+ p += 23;
+ break;
+
case 'v':
/*
* clear font cache and bitmap
@@ 1380,6 1379,7 @@ fontfree(GFont *f)
{
if(f->b)
bitfree(f->b);
+ free(f->cache);
free(f);
}
M port/devconc.c => port/devconc.c +1 -3
@@ 6,8 6,6 @@
#include "io.h"
#include "../port/error.h"
-#include "fcall.h"
-
#define concdebug 1
#define DPRINT if(concdebug)kprint
@@ 285,7 283,7 @@ concdevstclose(Queue *q)
q->ptr = 0;
q->other->ptr = 0;
dp->rq = 0;
- streamexit(cp->s);
+ streamexit(cp->s, 1);
qunlock(cp);
}
M port/devip.c => port/devip.c +51 -10
@@ 382,6 382,9 @@ ipwrite(Chan *c, char *a, long n, ulong offset)
backlog = 5;
cp->backlog = backlog;
}
+ else if(strcmp(field[0], "headers") == 0) {
+ cp->headers = 1; /* include addr/port in user packet */
+ }
else
return streamwrite(c, a, n, 0);
@@ 419,6 422,7 @@ udprcvmsg(Ipifc *ifc, Block *bp)
Port dport, sport;
ushort sum, len;
Ipaddr addr;
+ Block *nbp;
uh = (Udphdr *)(bp->rptr);
@@ 457,9 461,20 @@ udprcvmsg(Ipifc *ifc, Block *bp)
if(bp == 0)
return;
- /* Stuff the src address into the remote file */
- cp->dst = addr;
- cp->pdst = sport;
+ if(cp->headers){
+ /* pass the src address to the stream head */
+ nbp = allocb(Udphdrsize);
+ nbp->next = bp;
+ bp = nbp;
+ hnputl(bp->wptr, addr);
+ bp->wptr += 4;
+ hnputs(bp->wptr, sport);
+ bp->wptr += 2;
+ } else {
+ /* save the src address in the conversation struct */
+ cp->dst = addr;
+ cp->pdst = sport;
+ }
PUTNEXT(cp->readq, bp);
return;
}
@@ 471,18 486,19 @@ udprcvmsg(Ipifc *ifc, Block *bp)
void
udpstoput(Queue *q, Block *bp)
{
- Ipconv *ipc;
+ Ipconv *cp;
Udphdr *uh;
int dlen, ptcllen, newlen;
+ Ipaddr addr;
+ Port port;
if(bp->type == M_CTL) {
PUTNEXT(q, bp);
return;
}
- /* Prepend udp header to packet and pass on to ip layer */
- ipc = (Ipconv *)(q->ptr);
- if(ipc->psrc == 0)
+ cp = (Ipconv *)(q->ptr);
+ if(cp->psrc == 0)
error(Enoport);
if(bp->type != M_DATA) {
@@ 496,6 512,25 @@ udpstoput(Queue *q, Block *bp)
error(Emsgsize);
}
+ /*
+ * if we're in header mode, rip off the first 64 bytes as the
+ * destination. The destination is in ascii in the form
+ * %d.%d.%d.%d!%d
+ */
+ if(cp->headers){
+ /* get user specified addresses */
+ bp = pullup(bp, Udphdrsize);
+ if(bp == 0){
+ freeb(bp);
+ error(Emsgsize);
+ }
+ addr = nhgetl(bp->rptr);
+ bp->rptr += 4;
+ port = nhgets(bp->rptr);
+ bp->rptr += 2;
+ } else
+ addr = port = 0;
+
/* Round packet up to even number of bytes and check we can
* send it
*/
@@ 517,10 552,15 @@ udpstoput(Queue *q, Block *bp)
uh->frag[0] = 0;
uh->frag[1] = 0;
hnputs(uh->udpplen, ptcllen);
- hnputl(uh->udpdst, ipc->dst);
hnputl(uh->udpsrc, Myip[Myself]);
- hnputs(uh->udpsport, ipc->psrc);
- hnputs(uh->udpdport, ipc->pdst);
+ hnputs(uh->udpsport, cp->psrc);
+ if(cp->headers){
+ hnputl(uh->udpdst, addr);
+ hnputs(uh->udpdport, port);
+ } else {
+ hnputl(uh->udpdst, cp->dst);
+ hnputs(uh->udpdport, cp->pdst);
+ }
hnputs(uh->udplen, ptcllen);
uh->udpcksum[0] = 0;
uh->udpcksum[1] = 0;
@@ 536,6 576,7 @@ udpstclose(Queue *q)
ipc = (Ipconv *)(q->ptr);
+ ipc->headers = 0;
ipc->psrc = 0;
ipc->pdst = 0;
ipc->dst = 0;
M port/ipdat.h => port/ipdat.h +2 -0
@@ 291,6 291,7 @@ struct Ipconv
char *err; /* Async protocol error */
int backlog; /* Maximum number of waiting connections */
+ int headers; /* include header in packet */
int curlog; /* Number of waiting connections */
Ipconv *newcon; /* This is the start of a connection */
@@ 361,6 362,7 @@ enum /* Tcp connection states */
enum
{
Nipconv= 512, /* max conversations per interface */
+ Udphdrsize= 6, /* size if a to/from user Udp header */
};
/*
M port/stlapd.c => port/stlapd.c +8 -8
@@ 75,6 75,7 @@ struct Lapd
{
QLock; /* access, state change */
Rendez; /* waiting for state change */
+ int klocked;/* locked by kernel proc */
int state;
int flags;
Queue * rq;
@@ 723,12 724,14 @@ static void
lapdkproc(void *arg)
{
Lapd *lp = (Lapd *)arg;
- int locked = 0;
+
+ lp->klocked = 0;
lp->kstarted = 1;
if(waserror()){
- if (locked)
+ if(lp->klocked)
qunlock(lp);
+ lp->klocked = 0;
print("lapdkproc %d error\n", lp-lapd);
lp->kstarted = 0;
wakeup(lp);
@@ 739,12 742,10 @@ lapdkproc(void *arg)
if(!lp->t200 || NOW < lp->t200)
continue;
qlock(lp);
- locked = 1;
- USED(locked);
+ lp->klocked = 1;
if(lp->flags & Hungup){
qunlock(lp);
- locked = 0;
- USED(locked);
+ lp->klocked = 0;
break;
}
switch(lp->state){
@@ 762,8 763,7 @@ lapdkproc(void *arg)
break;
}
qunlock(lp);
- locked = 0;
- USED(locked);
+ lp->klocked = 0;
}
lp->kstarted = 0;
wakeup(lp);