try to fix EOF on standard input problems
authorminima <minima>
Sun, 27 Jan 2002 15:35:33 +0000 (15:35 +0000)
committerminima <minima>
Sun, 27 Jan 2002 15:35:33 +0000 (15:35 +0000)
Changes
cmd/bye.pl
src/client.c
src/sel.c
src/sel.h

diff --git a/Changes b/Changes
index 5c25b363c452d459ebe97b33583fdebf4963a24f..e96fda535c8e3c9fe15d8b6b06b826fa0b28bc63 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 27Jan02=======================================================================
 1. make save work in cron context
+2. try to get the C client to handle closes on its standard input better
+handled.
 22Jan02=======================================================================
 1. limit spot dupe checking to first 12 characters
 13Jan02=======================================================================
index f38f93f8a0d72cdee32e66c23d1187ad47ceeb7c..653e939407a4067141f4da5bad97e11074af859a 100644 (file)
@@ -15,7 +15,7 @@ if ($self->is_user && -e "$main::data/logout") {
        sleep(1);
 }
 
-$self->send_now('Z', "");
+#$self->send_now('Z', "");
 
 $self->disconnect;
 
index 7b98f66129bb717914495cdbc7b38305667ae300..124ac56b8af921954e19f057e6d34a48f1817601 100644 (file)
@@ -375,12 +375,12 @@ int fcb_handler(sel_t *sp, int in, int out, int err)
                        default:
                                dbg(DBUF,"got errno %d in input", errno);
                                ending++;
-                               return 0;
+                               return 1;
                        }
                } else if (r == 0) {
                        dbg(DBUF, "ending normally");
                        ending++;
-                       return 0;
+                       return 1;
                }
 
                dbgdump(DBUF, "in ->", buf, r);
@@ -723,7 +723,8 @@ void process_node()
 void term_timeout(int i)
 {
        /* none of this is going to be reused so don't bother cleaning up properly */
-       tcflush(0, TCIOFLUSH);
+       if (isatty(0))
+               tcflush(0, TCIOFLUSH);
        kill(getpid(), 9);                      /* commit suicide */
 }
 
@@ -732,16 +733,23 @@ void terminate(int i)
        signal(SIGALRM, term_timeout);
        alarm(10);
        
-       while ((in && !is_chain_empty(in->outq)) ||
-                  (node && !is_chain_empty(node->outq))) {
+       if (node && node->sp->sort) {
+               sel_close(node->sp);
+               close(node->cnum);
+       }
+       while (in && in->sp->sort && !is_chain_empty(in->outq)) {
                sel_run();
        }
+       sel_run();
+       sel_run();
+       sel_run();
+       sel_run();
+       sel_run();
+       sel_run();
+       sel_run();
+       sel_run();
        if (in && in->t_set)
                tcsetattr(0, TCSADRAIN, &in->t);
-       if (node) {
-               shutdown(node->cnum, 3);
-               close(node->cnum);
-       }
        exit(i);
 }
 
@@ -749,10 +757,7 @@ void login_timeout(int i)
 {
        write(0, "Timed Out", 10);
        write(0, &nl, 1);
-       sel_run();                                      /* force a coordination */
-       if (in && in->t_set)
-               tcsetattr(0, TCSANOW, &in->t);
-       exit(i);
+       terminate(0);
 }
 
 /*
index 4856dda33e068f46479d10f2f3ec62c219594341..f476ed744784db6bd4d9394a4442f1c85d1c815a 100755 (executable)
--- a/src/sel.c
+++ b/src/sel.c
@@ -81,6 +81,16 @@ sel_t *sel_open(int cnum, void *fcb, char *name, int (*handler)(), int sort, int
        return sp;
 }
 
+/* 
+ * post a close handler for this connection, to do special things
+ * in the event of this cnum closing, the default is just to close
+ */
+
+void sel_closehandler(sel_t *sp, void (*handler)())
+{
+       sp->closehandler = handler;
+}
+
 /*
  * close (and thus clear down) a slot, it is assumed that you have done whatever
  * you need to do to close the actual device already
@@ -89,6 +99,11 @@ sel_t *sel_open(int cnum, void *fcb, char *name, int (*handler)(), int sort, int
 void sel_close(sel_t *sp)
 {
        if (sp->sort) {
+               if (sp->closehandler) {
+                       (sp->closehandler)(sp);
+               } else {
+                       close(sp->cnum);
+               }
                chain_flush(sp->msgbase);
                free(sp->msgbase);
                free(sp->name);
@@ -188,7 +203,10 @@ int sel_error(sel_t *sp, int err)
 
 /*
  * $Log$
- * Revision 1.4  2000-07-20 14:16:00  minima
+ * Revision 1.5  2002-01-27 15:35:33  minima
+ * try to fix EOF on standard input problems
+ *
+ * Revision 1.4  2000/07/20 14:16:00  minima
  * can use Sourceforge now!
  * added user->qra cleaning
  * added 4 digit qra to user broadcast dxspots if available
index dde95a42fd5374d1b2b595cb5cd2302e0a3a0fa5..4dad4168b0c36fa4415757501fa9ed82a485aeee 100755 (executable)
--- a/src/sel.h
+++ b/src/sel.h
@@ -8,7 +8,10 @@
  * $Header$
  * 
  * $Log$
- * Revision 1.3  2000-07-20 14:16:00  minima
+ * Revision 1.4  2002-01-27 15:35:33  minima
+ * try to fix EOF on standard input problems
+ *
+ * Revision 1.3  2000/07/20 14:16:00  minima
  * can use Sourceforge now!
  * added user->qra cleaning
  * added 4 digit qra to user broadcast dxspots if available
@@ -41,6 +44,7 @@ typedef struct {
        void *fcb;                                                 /* any fcb associated with this thing */
        reft *msgbase;                                     /* any messages for this port */
        int (*handler)();                                  /* the handler for this thingy */
+       int (*closehandler)();          /* special close handler */
 } sel_t;
 
 extern sel_t *sel;
@@ -58,6 +62,8 @@ extern struct timeval sel_tv;
 void sel_init(int, long, long);                                           /* initialise the select thing */
 void sel_run();                                                   /* run the select multiplexor */
 sel_t *sel_open(int, void *, char *, int (*)(), int, int);/*  initialise a slot */
+void sel_closehandler(sel_t *, void (*)());    /* post a closehandler for this cnum */
+
 void sel_close(sel_t *);
 int sel_error(sel_t *, int);              /* set/clear error flag */