7 typedef struct EQueue EQueue;
17 static EQueue *equeue;
22 partial(int id, Event *e, uchar *b, int n)
28 for(eq = equeue; eq != nil; eq = eq->next)
34 /* partial message exists for this id */
35 eq->buf = realloc(eq->buf, eq->nbuf+n);
37 drawerror(display, "eplumb: cannot allocate buffer");
38 memmove(eq->buf+eq->nbuf, b, n);
40 e->v = plumbunpackpartial((char*)eq->buf, eq->nbuf, &nmore);
41 if(nmore == 0){ /* no more to read in this message */
46 for(p = equeue; p!=nil && p->next!=eq; p = p->next)
49 drawerror(display, "eplumb: bad event queue");
61 addpartial(int id, char *b, int n)
65 eq = malloc(sizeof(EQueue));
75 memmove(eq->buf, b, n);
84 plumbevent(int id, Event *e, uchar *b, int n)
88 if(partial(id, e, b, n) == 0){
89 /* no partial message already waiting for this id */
90 e->v = plumbunpackpartial((char*)b, n, &nmore);
91 if(nmore > 0) /* incomplete message */
92 addpartial(id, (char*)b, n);
100 eplumb(int key, char *port)
104 fd = plumbopen(port, OREAD|OCEXEC);
107 return estartfn(key, fd, 8192, plumbevent);