Subject: bug#22493: 25.1.50; open-gnutls-stream doesn't respect :nowait, so the connections are synchronous

From: Lars Ingebrigtsen <[email-masked]>
Date: Sat, 30 Jan 2016 05:45:21 +0100

Looking at the code, and doing some experimentation, it looks like this
should be possible to implement.

First of all, gnutls-open-stream should call open-network-stream with
:nowait, and put a sentinel on the stream to see when it's opened, and
then it should call gnutls-negotiate from the sentinel.

The problem is, though, that the process isn't marked as a gnutls
process until gnutls_boot is called, so this needs to happen much
earlier.  Possibly by adding another keyword to make-network-process
that just sets

  XPROCESS (proc)->gnutls_p = 1;

The other problem is that reading/writing from these things will just
send plain text if the gnutls stuff hasn't been initialised:

#ifdef HAVE_GNUTLS
	      if (p->gnutls_p && p->gnutls_state)
		written = emacs_gnutls_write (p, cur_buf, cur_len);
	      else
#endif
		written = emacs_write_sig (outfd, cur_buf, cur_len);

I think that looks rather nonsensical.  If it's p->gnutls_p, then it
should never write to the process, no matter what the state is.  Rather
is should just skip writing until p->gnutls_state gets set (which
happens during gnutls_boot).

Or is there something subtle here I'm missing?  When would we ever want
to write plain text to something that's p->gnutls_p?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no