chiark / gitweb /
@@@ wip
[mLib] / test / tvec-remote.c
index e03297e16baeff6db27a0798a0442f6e7853039d..a00f04654409e2fe469bc3bb381d5b3dfe157765 100644 (file)
@@ -114,7 +114,7 @@ static int recv_all(struct tvec_state *tv, struct tvec_remote *r,
 #undef f_any
 }
 
-int tvec_send(struct tvec_state *tv, struct tvec_reomte *r)
+int tvec_send(struct tvec_state *tv, struct tvec_remote *r)
 {
   kludge64 k; unsigned char lenbuf[8];
   const char *p; size_t sz;
@@ -131,7 +131,7 @@ int tvec_send(struct tvec_state *tv, struct tvec_reomte *r)
   return (0);
 }
 
-int tvec_recv(struct tvec_state *tv, struct tvec_reomte *r, buf *b_out)
+int tvec_recv(struct tvec_state *tv, struct tvec_remote *r, buf *b_out)
 {
   kludge64 k, szmax; unsigned char lenbuf[8];
   unsigned char *p;
@@ -176,6 +176,7 @@ int tvec_recv(struct tvec_state *tv, struct tvec_reomte *r, buf *b_out)
 /*----- The output driver -------------------------------------------------*/
 
 #define SENDPK(ro, pk)                                                 \
+       if ((ro)->r.f&TVRF_BROKEN) /* do nothing */; else               \
        MC_BEFORE(setpk,                                                \
          { buf_reset(&(ro)->r.bout);                                   \
            buf_putu16l(&(ro)->r.bout.b, (pk)); })                      \
@@ -187,29 +188,26 @@ static int sendstr(struct tvec_output *o, unsigned pk,
 {
   struct remote_output *ro = (struct remote_output *)o;
 
-  if (ro->r.f&TVRF_BROKEN) return (-1);
-  dbuf_reset(&ro->r.bout);
-  buf_putu16l(&ro->r.bout.b, TVPK_ERROR);
-  buf_vputstrf16l(&ro->r.bout.b, msg, ap);
-  return (tvec_send(ro->_o.tv, &ro->r));
+  SENDPK(ro, pk) buf_vputstrf16l(&ro->r.bout.b, msg, ap);
+  return (ro->r.f&TVRF_BROKEN ? -1 : 0);
 }
 
-static void report(struct tvec_output *o, unsigned pk,
+static void report(struct tvec_output *o, unsigned pk, const char *what,
                   const char *msg, va_list *ap)
 {
   if (sendstr(o, pk, msg, ap)) {
-    fprintf(stderr, "%s: ", QUIS);
+    fprintf(stderr, "%s %s: ", QUIS, what);
     vfprintf(stderr, msg, *ap);
     fputc('\n', stderr);
   }
 }
 
 static void remote_error(struct tvec_output *o, const char *msg, va_list *ap)
-  { report(o, TVPK_ERROR, msg, ap); }
+  { report(o, TVPK_ERROR, "ERROR", msg, ap); }
 
 static void remote_notice(struct tvec_output *o,
                          const char *msg, va_list *ap)
-  { report(o, TVPK_NOTICE, msg, ap); }
+  { report(o, TVPK_NOTICE, "notice", msg, ap); }
 
 static void remote_setstatus(struct tvec_ouptut *o, int st)
 {