+(defun nntp-with-open-group-function (-group -server -connectionless -bodyfun)
+ "Protect against servers that don't like clients that keep idle connections opens.
+The problem being that these servers may either close a connection or
+simply ignore any further requests on a connection. Closed
+connections are not detected until `accept-process-output' has updated
+the `process-status'. Dropped connections are not detected until the
+connection timeouts (which may be several minutes) or
+`nntp-connection-timeout' has expired. When these occur
+`nntp-with-open-group', opens a new connection then re-issues the NNTP
+command whose response triggered the error."
+ (letf ((nntp-report-n (symbol-function 'nntp-report))
+ ((symbol-function 'nntp-report) (symbol-function 'nntp-report-1))
+ (nntp-with-open-group-internal nil))
+ (while (catch 'nntp-with-open-group-error
+ ;; Open the connection to the server
+ ;; NOTE: Existing connections are NOT tested.
+ (nntp-possibly-change-group -group -server -connectionless)
+
+ (let ((-timer
+ (and nntp-connection-timeout
+ (run-at-time
+ nntp-connection-timeout nil
+ (lambda ()
+ (let* ((-process (nntp-find-connection
+ nntp-server-buffer))
+ (-buffer (and -process
+ (process-buffer -process))))
+ ;; When I an able to identify the
+ ;; connection to the server AND I've
+ ;; received NO reponse for
+ ;; nntp-connection-timeout seconds.
+ (when (and -buffer (eq 0 (buffer-size -buffer)))
+ ;; Close the connection. Take no
+ ;; other action as the accept input
+ ;; code will handle the closed
+ ;; connection.
+ (nntp-kill-buffer -buffer))))))))
+ (unwind-protect
+ (setq nntp-with-open-group-internal
+ (condition-case nil
+ (funcall -bodyfun)
+ (quit
+ (unless debug-on-quit
+ (nntp-close-server))
+ (signal 'quit nil))))
+ (when -timer
+ (nnheader-cancel-timer -timer)))
+ nil))
+ (setf (symbol-function 'nntp-report) nntp-report-n))
+ nntp-with-open-group-internal))
+