X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=www%2Fwirtcl.c;h=a94baf6d157b9b36dee6a0c582348bd0e271c668;hb=949f8c4efedfe6d191264853690c84f527e1790b;hp=f05500f9cf4c4e69e37dcebf645114a7dd1802b8;hpb=c1c09b4242df9a16cd11477deea2e35f8ff57fec;p=egate.git diff --git a/www/wirtcl.c b/www/wirtcl.c index f05500f..a94baf6 100644 --- a/www/wirtcl.c +++ b/www/wirtcl.c @@ -41,7 +41,21 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * * $Log: wirtcl.c,v $ - * Revision 1.2 1995/10/27 17:30:16 adam + * Revision 1.6 1995/11/01 16:15:47 adam + * Better presentation of records. Query/set number persistent. + * + * Revision 1.5 1995/10/31 16:56:24 adam + * Record presentation. + * + * Revision 1.4 1995/10/31 10:03:53 adam + * Work on queries. + * New command implemented - aborts script. + * + * Revision 1.3 1995/10/30 17:35:18 adam + * New function zwait that waits for a variable change - due to i/o events + * that invoke callback routines. + * + * Revision 1.2 1995/10/27 17:30:16 adam * First search request/response that works. * * Revision 1.1 1995/10/27 15:12:08 adam @@ -63,6 +77,7 @@ #include #include +#include #include "wtcl.h" #include "wirtcl.h" @@ -87,6 +102,21 @@ struct tcl_info { }; +static int events (struct tcl_info *p, char *waitVar); + +static int proc_zwait_invoke (ClientData clientData, Tcl_Interp *interp, + int argc, char **argv) +{ + struct tcl_info *p = (struct tcl_info*) clientData; + + if (argc < 2) + return TCL_OK; + events (p, argv[1]); + return TCL_OK; +} + + + /* select(2) callbacks */ struct callback { void (*r_handle)(ClientData); @@ -121,7 +151,9 @@ static void *do_create (WCLIENT wcl, void *args) gw_log (GW_LOG_FATAL, mod, "Cannot make Irtcl_Interp"); exit (1); } + log_init(LOG_ALL, "irtcl", "/usr/local/etc/httpd/logs/irtcl_log"); /* initialize irtcl */ + Tcl_CreateCommand (p->interp, "zwait", proc_zwait_invoke, p, NULL); for (i=0; iw_interp, fname, parms))) + return r; + return 0; +} + + +static int events (struct tcl_info *p, char *waitVar) +{ + int r, i; + char *cp; + char *waitVarVal; static fd_set fdset_tcl_r; static fd_set fdset_tcl_w; static fd_set fdset_tcl_x; + int fifo_in = p->wcl->linein; + if (fifo_in > max_fd) + max_fd = fifo_in; - if ((r = w_interp_exec (p->w_interp, fname, parms))) - return r; + assert (waitVar); + if ((cp = Tcl_GetVar (p->interp, waitVar, 0))) + { + waitVarVal = malloc (strlen(cp)+1); + strcpy (waitVarVal, cp); + } + else + { + char msg[128]; + + sprintf (msg, "Variable %s doesn't exist", waitVar); + gw_log (GW_LOG_WARN, mod, "%s", msg); + Tcl_AppendResult (p->interp, msg, NULL); + return TCL_ERROR; + } + gw_log (GW_LOG_DEBUG, mod, "Waiting %s=%s", waitVar, waitVarVal); while (1) { + if (!(cp = Tcl_GetVar (p->interp, waitVar, 0)) || + strcmp (cp, waitVarVal)) + { + gw_log (GW_LOG_DEBUG, mod, "Changed to %s", cp); + Tcl_AppendResult (p->interp, cp, NULL); + free (waitVarVal); + return TCL_OK; + } FD_ZERO (&fdset_tcl_r); FD_ZERO (&fdset_tcl_w); FD_ZERO (&fdset_tcl_x); - - if ((cp=Tcl_GetVar (p->interp, "sessionWait", 0)) && !strcmp (cp, "0")) - return 0; - for (r=0, i=min_fd; i<=max_fd; i++) + + for (r=0, i=0; i<=max_fd; i++) { if (callback_table[i].w_handle) { @@ -170,16 +235,26 @@ static int do_exec (const char *fname, char *parms, void *mydata) } } if (!r) - return 0; + break; + gw_log (GW_LOG_DEBUG, mod, "fifo select %d", fifo_in); + FD_SET (fifo_in, &fdset_tcl_r); if ((r = select(max_fd+1, &fdset_tcl_r, &fdset_tcl_w, - &fdset_tcl_x, 0)) < 0) + &fdset_tcl_x, 300)) < 0) { - perror("select"); + gw_log (GW_LOG_ERRNO|GW_LOG_FATAL, mod, "select"); exit(1); } if (!r) - continue; - for (i=min_fd; i<=max_fd; i++) + { + gw_log (GW_LOG_DEBUG, mod, "timeout"); + break; + } + if (FD_ISSET (fifo_in, &fdset_tcl_r)) + { + gw_log (GW_LOG_DEBUG, mod, "FIFO closed"); + break; + } + for (i=0; i<=max_fd; i++) { if (FD_ISSET (i, &fdset_tcl_r)) { @@ -198,7 +273,8 @@ static int do_exec (const char *fname, char *parms, void *mydata) } } } - return 0; + free (waitVarVal); + return TCL_OK; } void ir_select_add (int fd, void *obj)