;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 123.24
;;; Reason:
;;;  A Chaos packet was being lost every time a SUPDUP connection was closed by remote end.
;;;  Caused by a combination of two problems:
;;;    ANY Chaos stream that receives a CLS or EOF loses that packet -- it is stored in instance
;;;      variable "input-packet" and never freed.  Cure: :before-close method frees input-packet.
;;;      Also requires that :discard-input-buffer clear "input-packet" in addition to freeing it.
;;;    Even if stream didn't lose a packet, SUPDUP wasn't closing the stream -- just the connection.
;;; Written 2-Oct-87 13:44:51 by pld at site LMI Cambridge
;;; while running on Jack Flanders from band 2
;;; with Experimental System 123.23, Experimental Local-File 73.0, Experimental FILE-Server 22.0, Experimental Unix-Interface 11.0, Experimental Tape 18.0, Experimental KERMIT 34.0, Experimental ZMail 71.0, Experimental Lambda-Diag 15.0, microcode 1754, SDU Boot Tape 3.12, SDU ROM 8.



; From modified file DJ: L.NETWORK.CHAOS; CHUSE.LISP#30 at 2-Oct-87 13:45:05
#10R CHAOS#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "CHAOS")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; CHAOS; CHUSE  "

;;; This is included in all chaosnet input streams, character and binary
(DEFFLAVOR INPUT-STREAM-MIXIN
	((INPUT-PACKET nil))
	()
  (:INCLUDED-FLAVORS SI:BASIC-BUFFERED-INPUT-STREAM))

(DEFMETHOD (INPUT-STREAM-MIXIN :DISCARD-INPUT-BUFFER) (IGNORE)
  (when input-packet
    (RETURN-PKT INPUT-PACKET)
    (setq input-packet nil)))

(defmethod (input-stream-mixin :before :close) (&rest ignore)
  (when input-packet
    (return-pkt input-packet)
    (setq input-packet nil)))

))

; From modified file DJ: L.NETWORK; SUPDUP.LISP#294 at 2-Oct-87 13:45:17
#8R SUPDUP#: #!:ZL
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "SUPDUP")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; SUPDUP  "

(DEFMETHOD (BASIC-NVT :DISCONNECT) ()
  (SEND TYPEIN-PROCESS ':FLUSH)
  (SEND TYPEOUT-PROCESS ':FLUSH)
  (WHEN CONNECTION
    (CHAOS:CLOSE-CONN CONNECTION)
    (CHAOS:REMOVE-CONN CONNECTION)
    (SETQ CONNECTION NIL)
    (close stream))
  (SEND TYPEIN-PROCESS ':RESET)
  (SEND TYPEOUT-PROCESS ':RESET))

))
