g_tls_connection_base_real_pop_io (GTlsConnectionBase  *tls,
                                   GIOCondition         direction,
                                   gboolean             success,
                                   GError             **error)
{
  GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
  GError *my_error = NULL;

  /* This function MAY or MAY NOT set error when it fails! */

  if (direction & G_IO_IN)
    {
      priv->read_cancellable = NULL;
      if (!success)
        {
          my_error = priv->read_error;
          priv->read_error = NULL;
        }
      else
        g_clear_error (&priv->read_error);
    }

  if (direction & G_IO_OUT)
    {
      priv->write_cancellable = NULL;
      if (!success && !my_error)
        {
          my_error = priv->write_error;
          priv->write_error = NULL;
        }
      else
        g_clear_error (&priv->write_error);
    }

  if (success)
    return G_TLS_CONNECTION_BASE_OK;

  if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
    {
      g_propagate_error (error, my_error);
      return G_TLS_CONNECTION_BASE_WOULD_BLOCK;
    }

  if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT))
    {
      g_propagate_error (error, my_error);
      return G_TLS_CONNECTION_BASE_TIMED_OUT;
    }

  if (priv->missing_requested_client_certificate &&
      !priv->successful_posthandshake_op)
    {
      g_assert (G_IS_TLS_CLIENT_CONNECTION (tls));

      /* Probably the server requires a client certificate, but we failed to
       * provide one. With TLS 1.3 the server is no longer able to tell us
       * this, so we just have to guess. If there is an error from the TLS
       * interaction (request for user certificate), we provide that. Otherwise,
       * guess that G_TLS_ERROR_CERTIFICATE_REQUIRED is probably appropriate.
       * This could be wrong, but only applies to the small minority of
       * connections where a client cert is requested but not provided, and then
       * then only if the client has never successfully read or written.
       */
      if (priv->interaction_error)
        {
          g_propagate_error (error, priv->interaction_error);
          priv->interaction_error = NULL;
        }
      else
        {
          g_clear_error (error);
          g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_CERTIFICATE_REQUIRED,
                               _("Server required TLS certificate"));
        }
      g_clear_error (&my_error);
    }
  else if (my_error)
    {
      g_propagate_error (error, my_error);
    }

  return G_TLS_CONNECTION_BASE_ERROR;
}
g_tls_connection_base_real_pop_io (GTlsConnectionBase  *tls,
                                   GIOCondition         direction,
                                   gboolean             success,
                                   GError             **error)
{
  GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
  GError *my_error = NULL;

   

  if (direction & G_IO_IN)
    {
      priv->read_cancellable = NULL;
      if (!success)
        {
          my_error = priv->read_error;
          priv->read_error = NULL;
        }
      else
        g_clear_error (&priv->read_error);
    }

  if (direction & G_IO_OUT)
    {
      priv->write_cancellable = NULL;
      if (!success && !my_error)
        {
          my_error = priv->write_error;
          priv->write_error = NULL;
        }
      else
        g_clear_error (&priv->write_error);
    }

  if (success)
    return G_TLS_CONNECTION_BASE_OK;

  if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
    {
      g_propagate_error (error, my_error);
      return G_TLS_CONNECTION_BASE_WOULD_BLOCK;
    }

  if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT))
    {
      g_propagate_error (error, my_error);
      return G_TLS_CONNECTION_BASE_TIMED_OUT;
    }

  if (priv->missing_requested_client_certificate &&
      !priv->successful_posthandshake_op)
    {
      g_assert (G_IS_TLS_CLIENT_CONNECTION (tls));

       
      if (priv->interaction_error)
        {
          g_propagate_error (error, priv->interaction_error);
          priv->interaction_error = NULL;
        }
      else
        {
          g_clear_error (error);
          g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_CERTIFICATE_REQUIRED,
                               _("Server required TLS certificate"));
        }
      g_clear_error (&my_error);
    }
  else if (my_error)
    {
      g_propagate_error (error, my_error);
    }

  return G_TLS_CONNECTION_BASE_ERROR;
}