gnutls: handle simultaneous ops, do handshaking in a thread
Keep separate internal read/write states so that you can do
simultaneous reads/writes (either simultaneous async ops in the same
thread, or simultaneous sync ops in different threads). Add
locking/blocking so that this works correctly even in the presence of
rehandshakes (and add test cases for this).
As part of this, change handshaking so that the I/O part of it always
happens in a separate thread, which has three advantages:
1. It simplifies GTlsConnectionGnutlsSource by making it not have to
worry about flipping back and forth between read and write.
2. (Future) It will let the caller asynchronously handle
certificate-related functionality that is implemented via
synchronous callbacks in gnutls.
3. (Future) We can use g_task_set_return_on_cancel() to allow
cancellation even during uncancellable PKCS#11 operations.
https://bugzilla.gnome.org/show_bug.cgi?id=656343
https://bugzilla.gnome.org/show_bug.cgi?id=660252