6 long ventisendbytes, ventisendpackets;
7 long ventirecvbytes, ventirecvpackets;
10 _vtsend(VtConn *z, Packet *p)
16 if(z->state != VtStateConnected) {
17 werrstr("session not connected");
24 werrstr("packet too large");
30 packetprefix(p, buf, 2);
31 ventisendbytes += n+2;
36 n = packetfragments(p, &ioc, 1, 0);
39 if(write(z->outfd, ioc.addr, ioc.len) < ioc.len){
40 vtlog(VtServerLog, "<font size=-1>%T %s:</font> sending packet %p: %r<br>\n", z->addr, p);
44 packetconsume(p, nil, ioc.len);
47 vtlog(VtServerLog, "<font size=-1>%T %s:</font> sent packet %p (%d bytes)<br>\n", z->addr, p, tot);
58 return strstr(e, "interrupted") != nil;
70 if(z->state != VtStateConnected) {
71 werrstr("session not connected");
76 /* get enough for head size */
79 b = packettrailer(p, 2);
81 if(0) fprint(2, "%d read hdr\n", getpid());
82 n = read(z->infd, b, 2);
83 if(0) fprint(2, "%d got %d (%r)\n", getpid(), n);
84 if(n==0 || (n<0 && !interrupted()))
87 packettrim(p, 0, size);
90 if(packetconsume(p, buf, 2) < 0)
92 len = (buf[0] << 8) | buf[1];
99 b = packettrailer(p, n);
100 if(0) fprint(2, "%d read body %d\n", getpid(), n);
101 n = read(z->infd, b, n);
102 if(0) fprint(2, "%d got %d (%r)\n", getpid(), n);
105 packettrim(p, 0, size);
106 if(n==0 || (n<0 && !interrupted()))
109 ventirecvbytes += len;
111 p = packetsplit(p, len);
112 vtlog(VtServerLog, "<font size=-1>%T %s:</font> read packet %p len %d<br>\n", z->addr, p, len);
115 vtlog(VtServerLog, "<font size=-1>%T %s:</font> error reading packet: %r<br>\n", z->addr);
120 * If you fork off two procs running vtrecvproc and vtsendproc,
121 * then vtrecv/vtsend (and thus vtrpc) will never block except on
122 * rendevouses, which is nice when it's running in one thread of many.
137 rwakeup(&z->rpcfork);
140 while((p = _vtrecv(z)) != nil)
141 if(_vtqsend(q, p) < 0){
148 while((p = _vtnbqrecv(q)) != nil)
152 rwakeup(&z->rpcfork);
170 rwakeup(&z->rpcfork);
173 while((p = _vtqrecv(q)) != nil)
174 if(_vtsend(z, p) < 0)
179 while((p = _vtnbqrecv(q)) != nil)
183 rwakeup(&z->rpcfork);
195 if(z->state != VtStateConnected){
196 werrstr("not connected");
201 q = _vtqincref(z->readq);
218 vtsend(VtConn *z, Packet *p)
223 if(z->state != VtStateConnected){
225 werrstr("not connected");
230 q = _vtqincref(z->writeq);
232 if(_vtqsend(q, p) < 0){
243 if(_vtsend(z, p) < 0){