X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=queue.c;h=4e1a05165220963b82d47d65b0bc792085972842;hb=6ccc7b22a020d9dde824656655e4e6a920e6abc3;hp=29c2b65ca7b5fed55f9f8a507a49a29f918d2a5f;hpb=5139a081952de0c231f53bc4876655e0fcecd994;p=ir-tcl-moved-to-github.git diff --git a/queue.c b/queue.c index 29c2b65..4e1a051 100644 --- a/queue.c +++ b/queue.c @@ -6,7 +6,21 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: queue.c,v $ - * Revision 1.1 1995-07-28 10:28:39 adam + * Revision 1.5 1995-11-28 13:53:40 quinn + * Windows port. + * + * Revision 1.4 1995/10/17 12:18:59 adam + * Bug fix: when target connection closed, the connection was not + * properly reestablished. + * + * Revision 1.3 1995/08/04 11:32:40 adam + * More work on output queue. Memory related routines moved + * to mem.c + * + * Revision 1.2 1995/08/03 13:23:01 adam + * Request queue. + * + * Revision 1.1 1995/07/28 10:28:39 adam * First work on request queue. * */ @@ -18,61 +32,84 @@ #include "ir-tclp.h" -void *ir_tcl_malloc (size_t size) -{ - void *p = malloc (size); - if (!p) - { - logf (LOG_FATAL, "Out of memory. %d bytes requested", size); - exit (1); - } - return p; -} - -int ir_tcl_send (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu, - const char *msg) +int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu, + const char *msg, const char *object_name) { IrTcl_Request **rp; - int empty; if (!z_APDU (p->odr_out, &apdu, 0)) { - Tcl_AppendResult (interp, odr_errlist [odr_geterror (p->odr_out)], + Tcl_AppendResult (interp, odr_errmsg (odr_geterror (p->odr_out)), NULL); odr_reset (p->odr_out); return TCL_ERROR; } rp = &p->request_queue; - empty = *rp ? 0 : 1; while (*rp) rp = &(*rp)->next; *rp = ir_tcl_malloc (sizeof(**rp)); (*rp)->next = NULL; - (*rp)->state = IR_TCL_R_Queue; + + if (ir_tcl_strdup (interp, &(*rp)->object_name, object_name) == TCL_ERROR) + return TCL_ERROR; + if (ir_tcl_strdup (interp, &(*rp)->callback, p->callback) == TCL_ERROR) + return TCL_ERROR; + (*rp)->buf_out = odr_getbuf (p->odr_out, &(*rp)->len_out, NULL); + odr_setbuf (p->odr_out, NULL, 0, 1); odr_reset (p->odr_out); - if (empty) + if (p->state == IR_TCL_R_Idle) { - int r; - - r = cs_put (p->cs_link, (*rp)->buf_out, (*rp)->len_out); - if (r < 0) + logf (LOG_DEBUG, "send_apdu. Sending %s", msg); + if (ir_tcl_send_q (p, p->request_queue, msg) == TCL_ERROR) { sprintf (interp->result, "cs_put failed in %s", msg); return TCL_ERROR; } - else if (r == 1) - { - ir_select_add_write (cs_fileno (p->cs_link), p); - logf (LOG_DEBUG, "Send part of %s", msg); - (*rp)->state = IR_TCL_R_Writing; - } - else - { - logf (LOG_DEBUG, "Send %s (%d bytes)", msg, (*rp)->len_out); - (*rp)->state = IR_TCL_R_Waiting; - } + } + else + logf (LOG_DEBUG, "send_apdu. Not idle (%s)", msg); + return TCL_OK; +} + +int ir_tcl_send_q (IrTcl_Obj *p, IrTcl_Request *rp, const char *msg) +{ + int r; + + assert (rp); + r = cs_put (p->cs_link, rp->buf_out, rp->len_out); + if (r < 0) + return TCL_ERROR; + else if (r == 1) + { + ir_select_add_write (cs_fileno (p->cs_link), p); + logf (LOG_DEBUG, "Send part of %s", msg); + p->state = IR_TCL_R_Writing; + } + else + { + logf (LOG_DEBUG, "Send %s (%d bytes)", msg, rp->len_out); + p->state = IR_TCL_R_Waiting; + free (rp->buf_out); + rp->buf_out = NULL; } return TCL_OK; } +void ir_tcl_del_q (IrTcl_Obj *p) +{ + IrTcl_Request *rp, *rp1; + + for (rp = p->request_queue; rp; rp = rp1) + { + free (rp->object_name); + free (rp->callback); + free (rp->buf_out); + rp1 = rp->next; + free (rp); + } + p->request_queue = NULL; +} + + +