From 70d7f4c32ad5b334840bd986315b58f04e9cd102 Mon Sep 17 00:00:00 2001 From: ftrvxmtrx Date: Wed, 23 Apr 2014 21:20:11 +0200 Subject: [PATCH] nusb/rndis: avoid allocation on each transmission The slack space for outgoing packets set to 44+16 bytes. --- sys/src/cmd/nusb/ether/ether.c | 4 ++-- sys/src/cmd/nusb/ether/rndis.c | 18 +++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/sys/src/cmd/nusb/ether/ether.c b/sys/src/cmd/nusb/ether/ether.c index 4b8b61845..cc3116911 100644 --- a/sys/src/cmd/nusb/ether/ether.c +++ b/sys/src/cmd/nusb/ether/ether.c @@ -290,12 +290,12 @@ writeconndata(Req *r) n = 60; /* slack space for header and trailers */ - n += 2*16; + n += 44+16; b = allocb(n); /* header space */ - b->wp += 16; + b->wp += 44; b->rp = b->wp; /* copy in the ethernet packet */ diff --git a/sys/src/cmd/nusb/ether/rndis.c b/sys/src/cmd/nusb/ether/rndis.c index 88e91a725..bc688d9b7 100644 --- a/sys/src/cmd/nusb/ether/rndis.c +++ b/sys/src/cmd/nusb/ether/rndis.c @@ -95,19 +95,15 @@ static void rndistransmit(Dev *ep, Block *b) { int n; - uchar *req; n = BLEN(b); - if((req = malloc(44 + n)) != nil){ - PUT4(req, 1); /* type = 1 (packet) */ - PUT4(req+4, 44+n); /* len */ - PUT4(req+8, 44-8); /* data offset */ - PUT4(req+12, n); /* data length */ - memset(req+16, 0, 7*4); - memcpy(req+44, b->rp, n); - write(ep->dfd, req, 44+n); - free(req); - } + b->rp -= 44; + PUT4(b->rp, 1); /* type = 1 (packet) */ + PUT4(b->rp+4, 44+n); /* len */ + PUT4(b->rp+8, 44-8); /* data offset */ + PUT4(b->rp+12, n); /* data length */ + memset(b->rp+16, 0, 7*4); + write(ep->dfd, b->rp, 44+n); freeb(b); }