X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ffnet-adc.c;h=19141a21df5374cb0713193a8116c471eeccb7aa;hb=1d647d2580b5efd39c8c429ce849cc13e8a2a556;hp=2e920e653dea1288a5febfa1bbf3cc2ce6119c1d;hpb=33fede625f6a0eac733155b0276bf1b165068051;p=doldaconnect.git diff --git a/daemon/fnet-adc.c b/daemon/fnet-adc.c index 2e920e6..19141a2 100644 --- a/daemon/fnet-adc.c +++ b/daemon/fnet-adc.c @@ -58,6 +58,11 @@ struct qcmd { wchar_t **args; }; +struct qcmdqueue { + struct qcmd *f, *l; + int size; +}; + struct adchub { struct socket *sk; char *inbuf; @@ -69,7 +74,7 @@ struct adchub { iconv_t ich; int state; struct wcspair *hubinf; - struct qcmd *queue; + struct qcmdqueue queue; }; static wchar_t *eoc; @@ -163,26 +168,31 @@ static void sendadc(struct socket *sk, int sep, ...) va_end(args); } -static struct qcmd *newqcmd(struct qcmd **queue, wchar_t **args) +static struct qcmd *newqcmd(struct qcmdqueue *queue, wchar_t **args) { struct qcmd *new; - while(*queue != NULL) - queue = &((*queue)->next); new = smalloc(sizeof(*new)); new->next = NULL; new->args = args; - *queue = new; + if(queue->l == NULL) + queue->f = new; + else + queue->l->next = new; + queue->l = new; + queue->size++; return(new); } -static struct qcmd *ulqcmd(struct qcmd **queue) +static struct qcmd *ulqcmd(struct qcmdqueue *queue) { struct qcmd *ret; - if((ret = *queue) == NULL) + if((ret = queue->f) == NULL) return(NULL); - *queue = ret->next; + if((queue->f = ret->next) == NULL) + queue->l = NULL; + queue->size--; return(ret); } @@ -356,13 +366,13 @@ static void hubconnect(struct fnetnode *fn, struct socket *sk) { struct adchub *hub; - getsock(hub->sk = sk); sk->readcb = (void (*)(struct socket *, void *))hubread; sk->errcb = (void (*)(struct socket *, int, void *))huberr; sk->data = fn; hub = smalloc(sizeof(*hub)); memset(hub, 0, sizeof(*hub)); + getsock(hub->sk = sk); if((hub->ich = iconv_open("wchar_t", "utf-8")) == (iconv_t)-1) { flog(LOG_CRIT, "iconv cannot handle UTF-8: %s", strerror(errno)); killfnetnode(fn);