Fix asynchrounous GnuTLS socket handling on some versions of the GnuTLS library.
[bpt/emacs.git] / src / process.c
index 9b15e4c..02eb112 100644 (file)
@@ -1414,7 +1414,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)  */)
          val = XCDR (Vdefault_process_coding_system);
       }
     XPROCESS (proc)->encode_coding_system = val;
-    /* Note: At this momemnt, the above coding system may leave
+    /* Note: At this moment, the above coding system may leave
        text-conversion or eol-conversion unspecified.  They will be
        decided after we read output from the process and decode it by
        some coding system, or just before we actually send a text to
@@ -3120,7 +3120,7 @@ usage: (make-network-process &rest ARGS)  */)
     {
       struct hostent *host_info_ptr;
 
-      /* gethostbyname may fail with TRY_AGAIN, but we don't honour that,
+      /* gethostbyname may fail with TRY_AGAIN, but we don't honor that,
         as it may `hang' Emacs for a very long time.  */
       immediate_quit = 1;
       QUIT;
@@ -4620,15 +4620,39 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
              some data in the TCP buffers so that select works, but
              with custom pull/push functions we need to check if some
              data is available in the buffers manually.  */
-          if (nfds == 0 &&
-              wait_proc && wait_proc->gnutls_p /* Check for valid process.  */
-              /* Do we have pending data?  */
-              && emacs_gnutls_record_check_pending (wait_proc->gnutls_state) > 0)
-          {
-              nfds = 1;
-              /* Set to Available.  */
-              FD_SET (wait_proc->infd, &Available);
-          }
+          if (nfds == 0)
+           {
+             if (! wait_proc)
+               {
+                 /* We're not waiting on a specific process, so loop
+                    through all the channels and check for data. */
+                 struct Lisp_Process *proc;
+                 for (channel = 0; channel < MAXDESC; ++channel)
+                   {
+                     if (! NILP (chan_process[channel]) &&
+                         (proc = XPROCESS (chan_process[channel])) != NULL &&
+                         proc->gnutls_p &&
+                         proc->infd &&
+                         emacs_gnutls_record_check_pending (proc->gnutls_state) > 0)
+                       {
+                         nfds++;
+                         FD_SET (proc->infd, &Available);
+                       }
+                   }
+               }
+             else
+               {
+                 /* Check this specific channel. */
+                 if (wait_proc->gnutls_p && /* Check for valid process.  */
+                     /* Do we have pending data?  */
+                     emacs_gnutls_record_check_pending (wait_proc->gnutls_state) > 0)
+                   {
+                     nfds = 1;
+                     /* Set to Available.  */
+                     FD_SET (wait_proc->infd, &Available);
+                   }
+               }
+           }
 #endif
        }