# Patch for xerq of LDmud 3-2-dev472

diff -c /mud/src/driver/3-2-dev/src/util/xerq_orig/defs.h ./defs.h
*** /mud/src/driver/3-2-dev/src/util/xerq_orig/defs.h	Fri Oct 18 16:08:00 2002
--- ./defs.h	Fri Oct 18 16:35:43 2002
***************
*** 104,109 ****
--- 104,110 ----
      equeue_t *next;
      int       pos;    /* index of next byte in buf[] to write */
      int       len;    /* remaining length to write */
+     int32     handle; /* message handle for send-ok replys */
      char      buf[1]; /* allocated big enough to hold the data */
  };
  
***************
*** 218,225 ****
  extern void reply1keep(int32, const void *, int32);
  extern void replyn(int32, int, int, ...);
  extern void write1(void *, int);
! extern void add_to_queue(equeue_t **, char *, int);
! extern int flush_queue(equeue_t **, int);
  extern void add_retry(void (*func)(char *, int), char *mesg, int len, int t);
  
  extern void erq_rlookup(char *, int);
--- 219,226 ----
  extern void reply1keep(int32, const void *, int32);
  extern void replyn(int32, int, int, ...);
  extern void write1(void *, int);
! extern void add_to_queue(equeue_t **, char *, int, int32);
! extern int flush_queue(equeue_t **, int, int);
  extern void add_retry(void (*func)(char *, int), char *mesg, int len, int t);
  
  extern void erq_rlookup(char *, int);
diff -c /mud/src/driver/3-2-dev/src/util/xerq_orig/erq.c ./erq.c
*** /mud/src/driver/3-2-dev/src/util/xerq_orig/erq.c	Fri Oct 18 16:08:00 2002
--- ./erq.c	Fri Oct 18 16:44:33 2002
***************
*** 348,354 ****
          if (FD_ISSET(1, &write_fds))
          {
              XPRINTF((stderr, "%s stdout_queue ready for flush.\n", time_stamp()));
!             flush_queue(&stdout_queue, 1);
          }
  
          /* Check for retries */
--- 348,354 ----
          if (FD_ISSET(1, &write_fds))
          {
              XPRINTF((stderr, "%s stdout_queue ready for flush.\n", time_stamp()));
!             flush_queue(&stdout_queue, 1, 0);
          }
  
          /* Check for retries */
***************
*** 780,786 ****
          return 0;
  
      XPRINTF((stderr, "%s   Queuing data %p:%d\n", time_stamp(), mesg, len));
!     add_to_queue(qpp, mesg, len);
      return l;
  } /* writen() */
  
--- 780,786 ----
          return 0;
  
      XPRINTF((stderr, "%s   Queuing data %p:%d\n", time_stamp(), mesg, len));
!     add_to_queue(qpp, mesg, len, 0);
      return l;
  } /* writen() */
  
diff -c /mud/src/driver/3-2-dev/src/util/xerq_orig/socket.c ./socket.c
*** /mud/src/driver/3-2-dev/src/util/xerq_orig/socket.c	Fri Oct 18 16:08:00 2002
--- ./socket.c	Fri Oct 18 16:58:49 2002
***************
*** 80,86 ****
  
  /*-------------------------------------------------------------------------*/
  void
! add_to_queue (equeue_t **qpp, char *data, int len)
  
  /* Add the message <data> of <len> bytes to the end of queue <qpp>.
   */
--- 80,86 ----
  
  /*-------------------------------------------------------------------------*/
  void
! add_to_queue (equeue_t **qpp, char *data, int len, int32 hand)
  
  /* Add the message <data> of <len> bytes to the end of queue <qpp>.
   */
***************
*** 94,99 ****
--- 94,100 ----
      new->len = len;
      new->pos = 0;
      new->next = 0;
+     new->handle = hand;
      memcpy(&new->buf, data, len);
      while (*qpp)
          qpp = &(*qpp)->next;
***************
*** 102,108 ****
  
  /*-------------------------------------------------------------------------*/
  int
! flush_queue (equeue_t **qpp, int fd)
  
  /* Try to write all pending data from queue <qpp> to socket <fd>.
   * Return -1 if an error occured, and 0 if the queue could be emptied.
--- 103,109 ----
  
  /*-------------------------------------------------------------------------*/
  int
! flush_queue (equeue_t **qpp, int fd, int reply_handle)
  
  /* Try to write all pending data from queue <qpp> to socket <fd>.
   * Return -1 if an error occured, and 0 if the queue could be emptied.
***************
*** 131,136 ****
--- 132,141 ----
              break;
          }
          XPRINTF((stderr, "%s   Freeing queue entry %p.\n", time_stamp(), qp));
+         if (reply_handle) {
+             char r_ok[] = { ERQ_OK, 0 };
+             reply1(qp->handle, r_ok, sizeof(r_ok));
+         }
          next = qp->next;
          free(qp);
          qp = next;
***************
*** 252,258 ****
                     , time_stamp(), sp, sp->type, rw));
  
      if (sp->queue)
!         flush_queue(&sp->queue, sp->fd);
  
      switch(sp->type)
      {
--- 257,263 ----
                     , time_stamp(), sp, sp->type, rw));
  
      if (sp->queue)
!         flush_queue(&sp->queue, sp->fd, 1);
  
      switch(sp->type)
      {
***************
*** 516,532 ****
      {
          XPRINTF((stderr, "%s   Queue remaining data: %p:%d\n"
                         , time_stamp(), mesg+num, msglen-num));
!         add_to_queue(&sp->queue, mesg+num, msglen-num);
! /*
          num=htonl(num);
!         replyn(get_handle(mesg), 0, 2,
              (char[]) { ERQ_E_INCOMPLETE }, 1,
              (char *)&num, 4);
- */
          return;
      }
  
!     reply_errno(sp->handle);
      if (   errno != EWOULDBLOCK
  #if EWOULDBLOCK!=EAGAIN
          && errno != EAGAIN
--- 521,535 ----
      {
          XPRINTF((stderr, "%s   Queue remaining data: %p:%d\n"
                         , time_stamp(), mesg+num, msglen-num));
!         add_to_queue(&sp->queue, mesg+num, msglen-num, get_handle(mesg));
          num=htonl(num);
!         replyn(get_handle(mesg), 1, 2,
              (char[]) { ERQ_E_INCOMPLETE }, 1,
              (char *)&num, 4);
          return;
      }
  
!     reply_errno(get_handle(mesg));
      if (   errno != EWOULDBLOCK
  #if EWOULDBLOCK!=EAGAIN
          && errno != EAGAIN
