static int tls_socket_write (CONNECTION* conn, const char* buf, size_t len)
{
  tlssockdata *data = conn->sockdata;
  int ret;
  size_t sent = 0;

  if (!data)
  {
    mutt_error (_("Error: no TLS socket open"));
    mutt_sleep (2);
    return -1;
  }

  do
  {
    do
    {
      ret = gnutls_record_send (data->state, buf + sent, len - sent);
    } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);

    if (ret < 0)
    {
      mutt_error ("tls_socket_write (%s)", gnutls_strerror (ret));
      mutt_sleep (4);
      return -1;
    }

    sent += ret;
  } while (sent < len);

  return sent;
}
static int tls_socket_write (CONNECTION* conn, const char* buf, size_t len)
{
  tlssockdata *data = conn->sockdata;
  int ret;
  size_t sent = 0;

  if (!data)
  {
    mutt_error (_("Error: no TLS socket open"));
    mutt_sleep (2);
    return -1;
  }

  do
  {
    do
    {
      ret = gnutls_record_send (data->state, buf + sent, len - sent);
    } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);

    if (ret < 0)
    {
      mutt_error ("tls_socket_write (%s)", gnutls_strerror (ret));
      mutt_sleep (4);
      return -1;
    }

    sent += ret;
  } while (sent < len);

  return sent;
}