X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=ir-tcl.c;h=d87d4d8513a27b43386ce8e40a942d7a21f477a9;hb=63352c7277aa5760cca113b9a97d09716ba4e7f8;hp=738394835b003e894e88bd00980e6cecd73441f0;hpb=ce0d0464e54cf6bed96cd32b7a99514beacd3989;p=ir-tcl-moved-to-github.git diff --git a/ir-tcl.c b/ir-tcl.c index 7383948..d87d4d8 100644 --- a/ir-tcl.c +++ b/ir-tcl.c @@ -5,7 +5,43 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: ir-tcl.c,v $ - * Revision 1.68 1996-01-04 11:05:22 adam + * Revision 1.78 1996-02-21 10:16:08 adam + * Simplified select handling. Only one function ir_tcl_select_set has + * to be externally defined. + * + * Revision 1.77 1996/02/20 17:52:58 adam + * Uses the YAZ oid system to name record syntax object identifiers. + * + * Revision 1.76 1996/02/20 16:09:51 adam + * Bug fix: didn't set element set names stamp correctly on result + * set records when element set names were set to the empty string. + * + * Revision 1.75 1996/02/19 15:41:53 adam + * Better log messages. + * Minor improvement of connect method. + * + * Revision 1.74 1996/02/05 17:58:03 adam + * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1. + * + * Revision 1.73 1996/01/29 11:35:19 adam + * Bug fix: cs_type member renamed to comstackType to avoid conflict with + * cs_type macro defined by YAZ. + * + * Revision 1.72 1996/01/19 17:45:34 quinn + * Added debugging output + * + * Revision 1.71 1996/01/19 16:22:38 adam + * New method: apduDump - returns information about last incoming APDU. + * + * Revision 1.70 1996/01/10 09:18:34 adam + * PDU specific callbacks implemented: initRespnse, searchResponse, + * presentResponse and scanResponse. + * Bug fix in the command line shell (tclmain.c) - discovered on OSF/1. + * + * Revision 1.69 1996/01/04 16:12:12 adam + * Setting PDUType renamed to eventType. + * + * Revision 1.68 1996/01/04 11:05:22 adam * New setting: PDUType - returns type of last PDU returned from the target. * Fixed a bug in configure/Makefile. * @@ -243,15 +279,14 @@ #include #include -#ifdef WINDOWS +#include #include -#else -#include -#endif #include #define CS_BLOCK 0 +#define IRTCL_GENERIC_FILES 0 + #include "ir-tclp.h" typedef struct { @@ -269,12 +304,36 @@ static void ir_deleteDiags (IrTcl_Diagnostic **dst_list, int *dst_num); static int do_disconnect (void *obj, Tcl_Interp *interp, int argc, char **argv); +static void ir_select_notify (ClientData clientData, int r, int w, int e); + +void ir_select_add (int fd, void *obj) +{ + ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0); +} + +void ir_select_add_write (int fd, void *obj) +{ + ir_tcl_select_set (ir_select_notify, fd, obj, 1, 1, 0); +} + +void ir_select_remove (int fd, void *obj) +{ + ir_tcl_select_set (NULL, fd, obj, 0, 0, 0); +} + +void ir_select_remove_write (int fd, void *obj) +{ + ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0); +} + static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj, int no, int which, const char *elements) { IrTcl_RecordList *rl; + if (elements && !*elements) + elements = NULL; for (rl = setobj->record_list; rl; rl = rl->next) { if (no == rl->no && (!rl->elements || !elements || @@ -307,30 +366,6 @@ static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj, return rl; } -static struct { - enum oid_value value; - const char *name; -} IrTcl_recordSyntaxTab[] = { -{ VAL_UNIMARC, "UNIMARC" }, -{ VAL_INTERMARC, "INTERMARC" }, -{ VAL_CCF, "CCF" }, -{ VAL_USMARC, "USMARC" }, -{ VAL_UKMARC, "UKMARC" }, -{ VAL_NORMARC, "NORMARC" }, -{ VAL_LIBRISMARC, "LIBRISMARC" }, -{ VAL_DANMARC, "DANMARC" }, -{ VAL_FINMARC, "FINMARC" }, -{ VAL_MAB, "MAB" }, -{ VAL_CANMARC, "CANMARC" }, -{ VAL_SBN, "SBN" }, -{ VAL_PICAMARC, "PICAMARC" }, -{ VAL_AUSMARC, "AUSMARC" }, -{ VAL_IBERMARC, "IBERMARC" }, -{ VAL_SUTRS, "SUTRS" }, -{ VAL_GRS1, "GRS1" }, -{ 0, NULL } -}; - /* * IrTcl_eval */ @@ -352,13 +387,21 @@ int IrTcl_eval (Tcl_Interp *interp, const char *command) /* * IrTcl_getRecordSyntaxStr: Return record syntax name of object id */ -static const char *IrTcl_getRecordSyntaxStr (enum oid_value value) +static char *IrTcl_getRecordSyntaxStr (enum oid_value value) { - int i; - for (i = 0; IrTcl_recordSyntaxTab[i].name; i++) - if (IrTcl_recordSyntaxTab[i].value == value) - return IrTcl_recordSyntaxTab[i].name; - return "USMARC"; + int *o; + struct oident ent, *entp; + + ent.proto = PROTO_Z3950; + ent.oclass = CLASS_RECSYN; + ent.value = value; + + o = oid_getoidbyent (&ent); + entp = oid_getentbyoid (o); + + if (!entp) + return ""; + return entp->desc; } /* @@ -366,11 +409,7 @@ static const char *IrTcl_getRecordSyntaxStr (enum oid_value value) */ static enum oid_value IrTcl_getRecordSyntaxVal (const char *name) { - int i; - for (i = 0; IrTcl_recordSyntaxTab[i].name; i++) - if (!strcmp (IrTcl_recordSyntaxTab[i].name, name)) - return IrTcl_recordSyntaxTab[i].value; - return 0; + return oid_getvalbyname (name); } static IrTcl_RecordList *find_IR_record (IrTcl_SetObj *setobj, int no) @@ -601,7 +640,7 @@ static int do_init_request (void *obj, Tcl_Interp *interp, req->implementationVersion = p->implementationVersion; req->userInformationField = 0; - return ir_tcl_send_APDU (interp, p, apdu, "init", argv[0]); + return ir_tcl_send_APDU (interp, p, apdu, "init", *argv); } /* @@ -676,6 +715,54 @@ static int do_options (void *obj, Tcl_Interp *interp, } /* + * do_apduInfo: Get APDU information + */ +static int do_apduInfo (void *obj, Tcl_Interp *interp, int argc, char **argv) +{ + char buf[16]; + FILE *apduf; + IrTcl_Obj *p = obj; + + if (argc <= 0) + return TCL_OK; + sprintf (buf, "%d", p->apduLen); + Tcl_AppendElement (interp, buf); + sprintf (buf, "%d", p->apduOffset); + Tcl_AppendElement (interp, buf); + if (!p->buf_in) + { + Tcl_AppendElement (interp, ""); + return TCL_OK; + } + apduf = fopen ("apdu.tmp", "w"); + if (!apduf) + { + Tcl_AppendElement (interp, ""); + return TCL_OK; + } + odr_dumpBER (apduf, p->buf_in, p->apduLen); + fclose (apduf); + if (!(apduf = fopen ("apdu.tmp", "r"))) + Tcl_AppendElement (interp, ""); + else + { + int c; + + Tcl_AppendResult (interp, " {", NULL); + while ((c = getc (apduf)) != EOF) + { + buf[0] = c; + buf[1] = '\0'; + Tcl_AppendResult (interp, buf, NULL); + } + fclose (apduf); + Tcl_AppendResult (interp, "}", NULL); + } + unlink ("apdu.tmp"); + return TCL_OK; +} + +/* * do_failInfo: Get fail information */ static int do_failInfo (void *obj, Tcl_Interp *interp, int argc, char **argv) @@ -956,9 +1043,7 @@ static int do_connect (void *obj, Tcl_Interp *interp, interp->result = "already connected"; return TCL_ERROR; } - if (ir_tcl_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR) - return TCL_ERROR; - if (!strcmp (p->cs_type, "tcpip")) + if (!strcmp (p->comstackType, "tcpip")) { p->cs_link = cs_create (tcpip_type, CS_BLOCK, p->protocol_type); addr = tcpip_strtoaddr (argv[2]); @@ -969,7 +1054,7 @@ static int do_connect (void *obj, Tcl_Interp *interp, } logf (LOG_DEBUG, "tcp/ip connect %s", argv[2]); } - else if (!strcmp (p->cs_type, "mosi")) + else if (!strcmp (p->comstackType, "mosi")) { #if MOSI p->cs_link = cs_create (mosi_type, CS_BLOCK, p->protocol_type); @@ -988,20 +1073,39 @@ static int do_connect (void *obj, Tcl_Interp *interp, else { Tcl_AppendResult (interp, "Bad comstack type: ", - p->cs_type, NULL); + p->comstackType, NULL); return TCL_ERROR; } + if (ir_tcl_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR) + return TCL_ERROR; +#if IRTCL_GENERIC_FILES +#ifdef WINDOWS + p->csFile = Tcl_GetFile (cs_fileno(p->cs_link), TCL_WIN_SOCKET); +#else + p->csFile = Tcl_GetFile (cs_fileno(p->cs_link), TCL_UNIX_FD); +#endif +#endif if ((r=cs_connect (p->cs_link, addr)) < 0) { interp->result = "connect fail"; do_disconnect (p, NULL, 2, NULL); return TCL_ERROR; } - p->pduType = "connect"; + logf(LOG_DEBUG, "cs_connect() returned %d fd=%d", r, + cs_fileno(p->cs_link)); + p->eventType = "connect"; +#if IRTCL_GENERIC_FILES + ir_select_add (p->csFile, p); +#else ir_select_add (cs_fileno (p->cs_link), p); +#endif if (r == 1) { +#if IRTCL_GENERIC_FILES + ir_select_add_write (p->csFile, p); +#else ir_select_add_write (cs_fileno (p->cs_link), p); +#endif p->state = IR_TCL_R_Connecting; } else @@ -1027,23 +1131,36 @@ static int do_disconnect (void *obj, Tcl_Interp *interp, if (argc == 0) { p->state = IR_TCL_R_Idle; - p->pduType = NULL; + p->eventType = NULL; p->hostname = NULL; p->cs_link = NULL; +#if IRTCL_GENERIC_FILES + p->csFile = 0; +#endif return TCL_OK; } if (p->hostname) { + logf(LOG_DEBUG, "Closing connection to %s", p->hostname); free (p->hostname); p->hostname = NULL; +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); + ir_select_remove (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); ir_select_remove (cs_fileno (p->cs_link), p); +#endif odr_reset (p->odr_in); assert (p->cs_link); cs_close (p->cs_link); p->cs_link = NULL; +#if IRTCL_GENERIC_FILES + Tcl_FreeFile (p->csFile); + p->csFile = NULL; +#endif ODR_MASK_ZERO (&p->options); ODR_MASK_SET (&p->options, 0); @@ -1070,16 +1187,16 @@ static int do_comstack (void *o, Tcl_Interp *interp, IrTcl_Obj *obj = o; if (argc == 0) - return ir_tcl_strdup (interp, &obj->cs_type, "tcpip"); + return ir_tcl_strdup (interp, &obj->comstackType, "tcpip"); else if (argc == -1) - return ir_tcl_strdel (interp, &obj->cs_type); + return ir_tcl_strdel (interp, &obj->comstackType); else if (argc == 3) { - free (obj->cs_type); - if (ir_tcl_strdup (interp, &obj->cs_type, argv[2]) == TCL_ERROR) + free (obj->comstackType); + if (ir_tcl_strdup (interp, &obj->comstackType, argv[2]) == TCL_ERROR) return TCL_ERROR; } - Tcl_AppendElement (interp, obj->cs_type); + Tcl_AppendElement (interp, obj->comstackType); return TCL_OK; } @@ -1102,19 +1219,19 @@ static int do_logLevel (void *o, Tcl_Interp *interp, /* - * do_pduType: Return type of last PDU received + * do_eventType: Return type of last event */ -static int do_pduType (void *obj, Tcl_Interp *interp, - int argc, char **argv) +static int do_eventType (void *obj, Tcl_Interp *interp, + int argc, char **argv) { IrTcl_Obj *p = obj; if (argc <= 0) { - p->pduType = NULL; + p->eventType = NULL; return TCL_OK; } - Tcl_AppendElement (interp, p->pduType ? p->pduType : ""); + Tcl_AppendElement (interp, p->eventType ? p->eventType : ""); return TCL_OK; } @@ -1178,6 +1295,34 @@ static int do_failback (void *obj, Tcl_Interp *interp, } /* + * do_initResponse: add init response handler + */ +static int do_initResponse (void *obj, Tcl_Interp *interp, + int argc, char **argv) +{ + IrTcl_Obj *p = obj; + + if (argc == 0) + { + p->initResponse = NULL; + return TCL_OK; + } + else if (argc == -1) + return ir_tcl_strdel (interp, &p->initResponse); + if (argc == 3) + { + free (p->initResponse); + if (argv[2][0]) + { + if (ir_tcl_strdup (interp, &p->initResponse, argv[2]) == TCL_ERROR) + return TCL_ERROR; + } + else + p->initResponse = NULL; + } + return TCL_OK; +} +/* * do_protocol: Set/get protocol method on IR object */ static int do_protocol (void *o, Tcl_Interp *interp, int argc, char **argv) @@ -1443,6 +1588,11 @@ static int do_preferredRecordSyntax (void *obj, Tcl_Interp *interp, ir_tcl_malloc (sizeof(*p->preferredRecordSyntax)))) *p->preferredRecordSyntax = IrTcl_getRecordSyntaxVal (argv[2]); } + else if (argc == 2) + { + Tcl_AppendElement (interp, IrTcl_getRecordSyntaxStr + (*p->preferredRecordSyntax)); + } return TCL_OK; } @@ -1529,9 +1679,10 @@ static IrTcl_Method ir_method_tab[] = { { 1, "protocol", do_protocol }, { 0, "failback", do_failback }, { 0, "failInfo", do_failInfo }, +{ 0, "apduInfo", do_apduInfo }, { 0, "logLevel", do_logLevel }, -{ 0, "PDUType", do_pduType }, +{ 0, "eventType", do_eventType }, { 1, "connect", do_connect }, { 0, "protocolVersion", do_protocolVersion }, { 1, "preferredMessageSize", do_preferredMessageSize }, @@ -1549,7 +1700,9 @@ static IrTcl_Method ir_method_tab[] = { { 0, "initResult", do_initResult }, { 0, "disconnect", do_disconnect }, { 0, "callback", do_callback }, +{ 0, "initResponse", do_initResponse }, { 0, "triggerResourceControl", do_triggerResourceControl }, +{ 0, "initResponse", do_initResponse }, { 0, NULL, NULL} }; @@ -1646,7 +1799,7 @@ static int ir_obj_mk (ClientData clientData, Tcl_Interp *interp, } #endif - logf (LOG_DEBUG, "ir object create"); + logf (LOG_DEBUG, "ir object create %s", argv[1]); obj->odr_in = odr_createmem (ODR_DECODE); obj->odr_out = odr_createmem (ODR_ENCODE); obj->odr_pr = odr_createmem (ODR_PRINT); @@ -1818,7 +1971,67 @@ static int do_search (void *o, Tcl_Interp *interp, int argc, char **argv) interp->result = "unknown query method"; return TCL_ERROR; } - return ir_tcl_send_APDU (interp, p, apdu, "search", argv[0]); + return ir_tcl_send_APDU (interp, p, apdu, "search", *argv); +} + +/* + * do_searchResponse: add search response handler + */ +static int do_searchResponse (void *o, Tcl_Interp *interp, + int argc, char **argv) +{ + IrTcl_SetObj *obj = o; + + if (argc == 0) + { + obj->searchResponse = NULL; + return TCL_OK; + } + else if (argc == -1) + return ir_tcl_strdel (interp, &obj->searchResponse); + if (argc == 3) + { + free (obj->searchResponse); + if (argv[2][0]) + { + if (ir_tcl_strdup (interp, &obj->searchResponse, argv[2]) + == TCL_ERROR) + return TCL_ERROR; + } + else + obj->searchResponse = NULL; + } + return TCL_OK; +} + +/* + * do_presentResponse: add present response handler + */ +static int do_presentResponse (void *o, Tcl_Interp *interp, + int argc, char **argv) +{ + IrTcl_SetObj *obj = o; + + if (argc == 0) + { + obj->presentResponse = NULL; + return TCL_OK; + } + else if (argc == -1) + return ir_tcl_strdel (interp, &obj->presentResponse); + if (argc == 3) + { + free (obj->presentResponse); + if (argv[2][0]) + { + if (ir_tcl_strdup (interp, &obj->presentResponse, argv[2]) + == TCL_ERROR) + return TCL_ERROR; + } + else + obj->presentResponse = NULL; + } + return TCL_OK; } /* @@ -1830,7 +2043,10 @@ static int do_resultCount (void *o, Tcl_Interp *interp, IrTcl_SetObj *obj = o; if (argc <= 0) + { + obj->resultCount = 0; return TCL_OK; + } return get_set_int (&obj->resultCount, interp, argc, argv); } @@ -2307,7 +2523,7 @@ static int do_present (void *o, Tcl_Interp *interp, int argc, char **argv) } else req->recordComposition = NULL; - return ir_tcl_send_APDU (interp, p, apdu, "present", argv[0]); + return ir_tcl_send_APDU (interp, p, apdu, "present", *argv); } /* @@ -2353,6 +2569,8 @@ static int do_loadFile (void *o, Tcl_Interp *interp, static IrTcl_Method ir_set_method_tab[] = { { 0, "search", do_search }, + { 0, "searchResponse", do_searchResponse }, + { 0, "presentResponse", do_presentResponse }, { 0, "searchStatus", do_searchStatus }, { 0, "presentStatus", do_presentStatus }, { 0, "nextResultSetPosition", do_nextResultSetPosition }, @@ -2581,7 +2799,37 @@ static int do_scan (void *o, Tcl_Interp *interp, int argc, char **argv) logf (LOG_DEBUG, "preferredPositionInResponse=%d", *req->preferredPositionInResponse); - return ir_tcl_send_APDU (interp, p, apdu, "scan", argv[0]); + return ir_tcl_send_APDU (interp, p, apdu, "scan", *argv); +} + +/* + * do_scanResponse: add scan response handler + */ +static int do_scanResponse (void *o, Tcl_Interp *interp, + int argc, char **argv) +{ + IrTcl_ScanObj *obj = o; + + if (argc == 0) + { + obj->scanResponse = NULL; + return TCL_OK; + } + else if (argc == -1) + return ir_tcl_strdel (interp, &obj->scanResponse); + if (argc == 3) + { + free (obj->scanResponse); + if (argv[2][0]) + { + if (ir_tcl_strdup (interp, &obj->scanResponse, argv[2]) + == TCL_ERROR) + return TCL_ERROR; + } + else + obj->scanResponse = NULL; + } + return TCL_OK; } /* @@ -2730,6 +2978,7 @@ static int do_scanLine (void *obj, Tcl_Interp *interp, int argc, char **argv) static IrTcl_Method ir_scan_method_tab[] = { { 0, "scan", do_scan }, + { 0, "scanResponse", do_scanResponse }, { 0, "stepSize", do_stepSize }, { 0, "numberOfTermsRequested", do_numberOfTermsRequested }, { 0, "preferredPositionInResponse", do_preferredPositionInResponse }, @@ -3146,7 +3395,7 @@ static void ir_scanResponse (void *o, Z_ScanResponse *scanrs, /* * ir_select_read: handle incoming packages */ -void ir_select_read (ClientData clientData) +static void ir_select_read (ClientData clientData) { IrTcl_Obj *p = clientData; Z_APDU *apdu; @@ -3154,9 +3403,12 @@ void ir_select_read (ClientData clientData) IrTcl_Request *rq; char *object_name; Tcl_CmdInfo cmd_info; + const char *apdu_call; + logf(LOG_DEBUG, "Read handler fd=%d", cs_fileno(p->cs_link)); if (p->state == IR_TCL_R_Connecting) { + logf(LOG_DEBUG, "Connect handler"); r = cs_rcvconnect (p->cs_link); if (r == 1) { @@ -3164,7 +3416,11 @@ void ir_select_read (ClientData clientData) return; } p->state = IR_TCL_R_Idle; +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); +#endif if (r < 0) { logf (LOG_DEBUG, "cs_rcvconnect error"); @@ -3194,7 +3450,11 @@ void ir_select_read (ClientData clientData) if ((r=cs_get (p->cs_link, &p->buf_in, &p->len_in)) <= 0) { logf (LOG_DEBUG, "cs_get failed, code %d", r); +#if IRTCL_GENERIC_FILES + ir_select_remove (p->csFile, p); +#else ir_select_remove (cs_fileno (p->cs_link), p); +#endif do_disconnect (p, NULL, 2, NULL); if (p->failback) { @@ -3206,23 +3466,31 @@ void ir_select_read (ClientData clientData) return; } if (r == 1) + { + logf(LOG_DEBUG, "PDU Fraction read"); return ; + } /* got complete APDU. Now decode */ + p->apduLen = r; + p->apduOffset = -1; odr_setbuf (p->odr_in, p->buf_in, r, 0); - logf (LOG_DEBUG, "cs_get ok, got %d", r); + logf (LOG_DEBUG, "cs_get ok, total size %d", r); if (!z_APDU (p->odr_in, &apdu, 0)) { - logf (LOG_DEBUG, "%s", odr_errmsg (odr_geterror (p->odr_in))); + logf (LOG_DEBUG, "cs_get failed: %s", + odr_errmsg (odr_geterror (p->odr_in))); do_disconnect (p, NULL, 2, NULL); if (p->failback) { p->failInfo = IR_TCL_FAIL_IN_APDU; + p->apduOffset = odr_offset (p->odr_in); IrTcl_eval (p->interp, p->failback); } /* release ir object now if failback deleted it */ ir_obj_delete (p); return; } + logf(LOG_DEBUG, "Decoded ok"); /* handle APDU and invoke callback */ rq = p->request_queue; if (!rq) @@ -3232,28 +3500,36 @@ void ir_select_read (ClientData clientData) } object_name = rq->object_name; logf (LOG_DEBUG, "getCommandInfo (%s)", object_name); + apdu_call = NULL; if (Tcl_GetCommandInfo (p->interp, object_name, &cmd_info)) { switch(apdu->which) { case Z_APDU_initResponse: - p->pduType = "init"; + p->eventType = "init"; ir_initResponse (p, apdu->u.initResponse); + apdu_call = p->initResponse; break; case Z_APDU_searchResponse: - p->pduType = "search"; + p->eventType = "search"; ir_searchResponse (p, apdu->u.searchResponse, (IrTcl_SetObj *) cmd_info.clientData); + apdu_call = ((IrTcl_SetObj *) + cmd_info.clientData)->searchResponse; break; case Z_APDU_presentResponse: - p->pduType = "present"; + p->eventType = "present"; ir_presentResponse (p, apdu->u.presentResponse, (IrTcl_SetObj *) cmd_info.clientData); + apdu_call = ((IrTcl_SetObj *) + cmd_info.clientData)->presentResponse; break; case Z_APDU_scanResponse: - p->pduType = "scan"; + p->eventType = "scan"; ir_scanResponse (p, apdu->u.scanResponse, (IrTcl_ScanObj *) cmd_info.clientData); + apdu_call = ((IrTcl_ScanObj *) + cmd_info.clientData)->scanResponse; break; default: logf (LOG_WARN, "Received unknown APDU type (%d)", @@ -3269,8 +3545,10 @@ void ir_select_read (ClientData clientData) } p->request_queue = rq->next; p->state = IR_TCL_R_Idle; - - if (rq->callback) + + if (apdu_call) + IrTcl_eval (p->interp, apdu_call); + else if (rq->callback) IrTcl_eval (p->interp, rq->callback); free (rq->buf_out); free (rq->callback); @@ -3291,15 +3569,16 @@ void ir_select_read (ClientData clientData) /* * ir_select_write: handle outgoing packages - not yet written. */ -void ir_select_write (ClientData clientData) +static void ir_select_write (ClientData clientData) { IrTcl_Obj *p = clientData; int r; IrTcl_Request *rq; - logf (LOG_DEBUG, "In write handler"); + logf (LOG_DEBUG, "Write handler fd=%d", cs_fileno(p->cs_link)); if (p->state == IR_TCL_R_Connecting) { + logf(LOG_DEBUG, "Connect handler"); r = cs_rcvconnect (p->cs_link); if (r == 1) return; @@ -3307,7 +3586,11 @@ void ir_select_write (ClientData clientData) if (r < 0) { logf (LOG_DEBUG, "cs_rcvconnect error"); +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); +#endif if (p->failback) { p->failInfo = IR_TCL_FAIL_CONNECT; @@ -3316,7 +3599,11 @@ void ir_select_write (ClientData clientData) do_disconnect (p, NULL, 2, NULL); return; } +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); +#endif if (p->callback) IrTcl_eval (p->interp, p->callback); return; @@ -3327,7 +3614,7 @@ void ir_select_write (ClientData clientData) assert (rq); if ((r=cs_put (p->cs_link, rq->buf_out, rq->len_out)) < 0) { - logf (LOG_DEBUG, "select write fail"); + logf (LOG_DEBUG, "cs_put write fail"); if (p->failback) { p->failInfo = IR_TCL_FAIL_WRITE; @@ -3339,13 +3626,26 @@ void ir_select_write (ClientData clientData) } else if (r == 0) /* remove select bit */ { + logf(LOG_DEBUG, "Write completed"); p->state = IR_TCL_R_Waiting; +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); +#endif free (rq->buf_out); rq->buf_out = NULL; } } +static void ir_select_notify (ClientData clientData, int r, int w, int e) +{ + if (r) + ir_select_read (clientData); + if (w) + ir_select_write (clientData); +} + /* ------------------------------------------------------- */ /*