12 typedef struct VtSconn VtSconn;
27 char adir[NETPATHLEN];
28 Queue *q; /* Queue(VtReq*) */
31 static void listenproc(void*);
32 static void connproc(void*);
34 char *VtServerLog = "libventi/server";
62 s = vtmallocz(sizeof(VtSrv));
63 s->afd = announce(addr, s->adir);
69 proccreate(listenproc, s, STACK);
83 ctl = listen(srv->adir, dir);
88 sc = vtmallocz(sizeof(VtSconn));
93 proccreate(connproc, sc, STACK);
109 if(first && chattyventi){
111 fmtinstall('F', vtfcallfmt);
116 if(0) fprint(2, "new call %s on %d\n", sc->dir, sc->ctl);
117 fd = accept(sc->ctl, sc->dir);
120 fprint(2, "accept %s: %r\n", sc->dir);
126 if(vtversion(c) < 0){
127 fprint(2, "vtversion %s: %r\n", sc->dir);
130 if(vtsrvhello(c) < 0){
131 fprint(2, "vtsrvhello %s: %r\n", sc->dir);
135 if(0) fprint(2, "new proc %s\n", sc->dir);
136 proccreate(vtsendproc, c, STACK);
142 while((p = vtrecv(c)) != nil){
143 r = vtmallocz(sizeof(VtReq));
144 if(vtfcallunpack(&r->tx, p) < 0){
145 vtlog(VtServerLog, "<font size=-1>%T %s:</font> recv bad packet %p: %r<br>\n", c->addr, p);
146 fprint(2, "bad packet on %s: %r\n", sc->dir);
150 vtlog(VtServerLog, "<font size=-1>%T %s:</font> recv packet %p (%F)<br>\n", c->addr, p, &r->tx);
152 fprint(2, "%s <- %F\n", argv0, &r->tx);
154 if(r->tx.msgtype == VtTgoodbye)
156 r->rx.tag = r->tx.tag;
159 if(_vtqsend(sc->srv->q, r) < 0){
161 fprint(2, "hungup queue\n");
167 if(0) fprint(2, "eof on %s\n", sc->dir);
171 vtfcallclear(&r->tx);
174 if(0) fprint(2, "freed %s\n", sc->dir);
184 r = _vtqrecv(srv->q);
185 vtlog(VtServerLog, "<font size=-1>%T %s:</font> vtgetreq %F<br>\n", ((VtSconn*)r->sc)->c->addr, &r->tx);
196 if(r->rx.tag != r->tx.tag)
198 if(r->rx.msgtype != r->tx.msgtype+1 && r->rx.msgtype != VtRerror)
201 fprint(2, "%s -> %F\n", argv0, &r->rx);
202 if((p = vtfcallpack(&r->rx)) == nil){
203 vtlog(VtServerLog, "%s: vtfcallpack %F: %r<br>\n", sc->c->addr, &r->rx);
204 fprint(2, "fcallpack on %s: %r\n", sc->dir);
206 vtfcallclear(&r->rx);
209 vtlog(VtServerLog, "<font size=-1>%T %s:</font> send packet %p (%F)<br>\n", sc->c->addr, p, &r->rx);
210 if(vtsend(sc->c, p) < 0)
211 fprint(2, "vtsend %F: %r\n", &r->rx);
213 vtfcallclear(&r->tx);
214 vtfcallclear(&r->rx);