aboutsummaryrefslogtreecommitdiff
path: root/src/libventi
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-02-14 19:33:42 +0000
committerrsc <devnull@localhost>2005-02-14 19:33:42 +0000
commit5ddc97fc3e63fb0bdf14ec3583afbec765f1a45d (patch)
tree02619869c53875b78dd9aafefe50c6d6f079811b /src/libventi
parent8ee6ad4d96bdb1f56cece8c11e75e5491ccc4020 (diff)
downloadplan9port-5ddc97fc3e63fb0bdf14ec3583afbec765f1a45d.tar.gz
plan9port-5ddc97fc3e63fb0bdf14ec3583afbec765f1a45d.tar.bz2
plan9port-5ddc97fc3e63fb0bdf14ec3583afbec765f1a45d.zip
disable logging
Diffstat (limited to 'src/libventi')
-rw-r--r--src/libventi/log.c40
-rw-r--r--src/libventi/rpc.c21
-rw-r--r--src/libventi/send.c13
-rw-r--r--src/libventi/server.c10
4 files changed, 58 insertions, 26 deletions
diff --git a/src/libventi/log.c b/src/libventi/log.c
index fdf6ceee..511a7f2a 100644
--- a/src/libventi/log.c
+++ b/src/libventi/log.c
@@ -2,8 +2,11 @@
#include <libc.h>
#include <venti.h>
+int ventilogging;
#define log not_the_log_library_call
+static char Eremoved[] = "[removed]";
+
enum
{ /* defaults */
LogChunkSize = 8192,
@@ -35,6 +38,9 @@ vtlogopen(char *name, uint size)
char *p;
VtLog *l, *last;
+ if(!ventilogging)
+ return nil;
+
h = hash(name)%nelem(vl.hash);
qlock(&vl.lk);
last = nil;
@@ -65,6 +71,7 @@ vtlogopen(char *name, uint size)
p = (char*)(l->chunk+nc);
for(i=0; i<nc; i++){
l->chunk[i].p = p;
+ l->chunk[i].wp = p;
p += LogChunkSize;
l->chunk[i].ep = p;
}
@@ -74,6 +81,7 @@ vtlogopen(char *name, uint size)
/* insert */
l->next = vl.hash[h];
vl.hash[h] = l;
+ l->ref++;
l->ref++;
qunlock(&vl.lk);
@@ -87,9 +95,11 @@ vtlogclose(VtLog *l)
return;
qlock(&vl.lk);
- if(--l->ref == 0)
+ if(--l->ref == 0){
+ /* must not be in hash table */
+ assert(l->name == Eremoved);
free(l);
- else
+ }else
assert(l->ref > 0);
qunlock(&vl.lk);
}
@@ -109,6 +119,8 @@ vtlogremove(char *name)
last->next = l->next;
else
vl.hash[h] = l->next;
+ l->name = Eremoved;
+ l->next = nil;
qunlock(&vl.lk);
vtlogclose(l);
return;
@@ -116,16 +128,35 @@ vtlogremove(char *name)
qunlock(&vl.lk);
}
+static int
+timefmt(Fmt *fmt)
+{
+ static uvlong t0;
+ uvlong t;
+
+ if(t0 == 0)
+ t0 = nsec();
+ t = nsec()-t0;
+ return fmtprint(fmt, "T+%d.%04d", (uint)(t/1000000000), (uint)(t%1000000000)/100000);
+}
+
void
vtlogvprint(VtLog *l, char *fmt, va_list arg)
{
int n;
char *p;
VtLogChunk *c;
+ static int first = 1;
if(l == nil)
return;
+ if(first){
+ fmtinstall('T', timefmt);
+ first = 0;
+ }
+
+
qlock(&l->lk);
c = l->w;
n = c->ep - c->wp;
@@ -160,8 +191,10 @@ vtlog(char *name, char *fmt, ...)
{
VtLog *l;
va_list arg;
-
+
l = vtlogopen(name, LogSize);
+ if(l == nil)
+ return;
va_start(arg, fmt);
vtlogvprint(l, fmt, arg);
va_end(arg);
@@ -183,6 +216,5 @@ vtlogdump(int fd, VtLog *l)
c = l->chunk;
write(fd, c->p, c->wp-c->p);
}
- vtlogclose(l);
}
diff --git a/src/libventi/rpc.c b/src/libventi/rpc.c
index a3914530..0cd9410a 100644
--- a/src/libventi/rpc.c
+++ b/src/libventi/rpc.c
@@ -36,7 +36,7 @@ vtrpc(VtConn *z, Packet *p)
{
int i;
uchar tag, buf[2], *top;
- Rwait *r;
+ Rwait *r, *rr;
/* must malloc because stack could be private */
r = vtmallocz(sizeof(Rwait));
@@ -86,16 +86,15 @@ vtrpc(VtConn *z, Packet *p)
muxrpc(z, p);
}
z->muxer = 0;
- /* if there is anyone else sleeping, wake them to mux */
- if(z->nsleep){
- for(i=0; i<256; i++)
- if(z->wait[i] != nil && ((Rwait*)z->wait[i])->sleeping)
- break;
- if(i==256)
- fprint(2, "libventi: nsleep botch\n");
- else
- rwakeup(&((Rwait*)z->wait[i])->r);
- }
+ /* if there is anyone else sleeping, wake first unfinished to mux */
+ if(z->nsleep)
+ for(i=0; i<256; i++){
+ rr = z->wait[i];
+ if(rr && rr->sleeping && !rr->done){
+ rwakeup(&rr->r);
+ break;
+ }
+ }
}
p = r->p;
diff --git a/src/libventi/send.c b/src/libventi/send.c
index 642d4de3..1d8477d5 100644
--- a/src/libventi/send.c
+++ b/src/libventi/send.c
@@ -10,10 +10,9 @@ static int
_vtsend(VtConn *z, Packet *p)
{
IOchunk ioc;
- int n;
+ int n, tot;
uchar buf[2];
-
if(z->state != VtStateConnected) {
werrstr("session not connected");
return -1;
@@ -32,18 +31,20 @@ _vtsend(VtConn *z, Packet *p)
ventisendbytes += n+2;
ventisendpackets++;
+ tot = 0;
for(;;){
n = packetfragments(p, &ioc, 1, 0);
if(n == 0)
break;
if(write(z->outfd, ioc.addr, ioc.len) < ioc.len){
- vtlog(VtServerLog, "%s: sending packet %p: %r", z->addr, p);
+ vtlog(VtServerLog, "<font size=-1>%T %s:</font> sending packet %p: %r<br>\n", z->addr, p);
packetfree(p);
return 0;
}
packetconsume(p, nil, ioc.len);
+ tot += ioc.len;
}
- vtlog(VtServerLog, "%s: sent packet %p", z->addr, p);
+ vtlog(VtServerLog, "<font size=-1>%T %s:</font> sent packet %p (%d bytes)<br>\n", z->addr, p, tot);
packetfree(p);
return 1;
}
@@ -108,10 +109,10 @@ _vtrecv(VtConn *z)
ventirecvbytes += len;
ventirecvpackets++;
p = packetsplit(p, len);
- vtlog(VtServerLog, "%s: read packet %p len %d", z->addr, p, len);
+ vtlog(VtServerLog, "<font size=-1>%T %s:</font> read packet %p len %d<br>\n", z->addr, p, len);
return p;
Err:
- vtlog(VtServerLog, "%s: error reading packet: %r", z->addr);
+ vtlog(VtServerLog, "<font size=-1>%T %s:</font> error reading packet: %r<br>\n", z->addr);
return nil;
}
diff --git a/src/libventi/server.c b/src/libventi/server.c
index ae64b327..ddaa97f8 100644
--- a/src/libventi/server.c
+++ b/src/libventi/server.c
@@ -142,12 +142,12 @@ if(first && chattyventi){
while((p = vtrecv(c)) != nil){
r = vtmallocz(sizeof(VtReq));
if(vtfcallunpack(&r->tx, p) < 0){
- vtlog(VtServerLog, "%s: recv bad packet %p: %r", c->addr, p);
+ vtlog(VtServerLog, "<font size=-1>%T %s:</font> recv bad packet %p: %r<br>\n", c->addr, p);
fprint(2, "bad packet on %s: %r\n", sc->dir);
packetfree(p);
continue;
}
- vtlog(VtServerLog, "%s: recv packet %p (%F)", c->addr, p, &r->tx);
+ vtlog(VtServerLog, "<font size=-1>%T %s:</font> recv packet %p (%F)<br>\n", c->addr, p, &r->tx);
if(chattyventi)
fprint(2, "%s <- %F\n", argv0, &r->tx);
packetfree(p);
@@ -182,7 +182,7 @@ vtgetreq(VtSrv *srv)
VtReq *r;
r = _vtqrecv(srv->q);
- vtlog(VtServerLog, "%s: vtgetreq %F\n", ((VtSconn*)r->sc)->c->addr, &r->tx);
+ vtlog(VtServerLog, "<font size=-1>%T %s:</font> vtgetreq %F<br>\n", ((VtSconn*)r->sc)->c->addr, &r->tx);
return r;
}
@@ -200,13 +200,13 @@ vtrespond(VtReq *r)
if(chattyventi)
fprint(2, "%s -> %F\n", argv0, &r->rx);
if((p = vtfcallpack(&r->rx)) == nil){
- vtlog(VtServerLog, "%s: vtfcallpack %F: %r", sc->c->addr, &r->rx);
+ vtlog(VtServerLog, "%s: vtfcallpack %F: %r<br>\n", sc->c->addr, &r->rx);
fprint(2, "fcallpack on %s: %r\n", sc->dir);
packetfree(p);
vtfcallclear(&r->rx);
return;
}
- vtlog(VtServerLog, "%s: send packet %p (%F)", sc->c->addr, p, &r->rx);
+ vtlog(VtServerLog, "<font size=-1>%T %s:</font> send packet %p (%F)<br>\n", sc->c->addr, p, &r->rx);
if(vtsend(sc->c, p) < 0)
fprint(2, "vtsend %F: %r\n", &r->rx);
scdecref(sc);