diff options
author | Søren Sandmann <sandmann@redhat.com> | 2007-07-31 22:35:44 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2007-07-31 22:35:44 -0400 |
commit | b46ded3d0cd47571c3dadf8bf1f65fafacdffd98 (patch) | |
tree | 4b97a91a6661f5f127ad9f8630cd5f9c42475d2f | |
parent | bf34e6c6d5dc932edbde10a86031ba64da325ab5 (diff) |
Some cleanups
-rw-r--r-- | src/lac.h | 34 | ||||
-rw-r--r-- | src/lacconnection.c | 2 | ||||
-rw-r--r-- | src/lacinternals.h | 11 | ||||
-rw-r--r-- | src/lactcpconnection.c | 28 | ||||
-rw-r--r-- | src/lactlsconnection.c | 67 |
5 files changed, 32 insertions, 110 deletions
@@ -210,37 +210,6 @@ void lac_byte_queue_delete_head (LacByteQueue *queue, void lac_byte_queue_delete_tail (LacByteQueue *queue, gsize size); - -/* TLS */ -typedef struct LacTLS LacTLS; - -typedef int (* LacTLSSendFunc) (LacTLS *tls, - const guint8 *data, - gsize len, - GError **err); -typedef int (* LacTLSRecvFunc) (LacTLS *tls, - guint8 *data, - gsize buf_size, - GError **err); -LacTLS *lac_tls_new (int fd); -LacTLS *lac_tls_new2 (LacTLSSendFunc send_func, - LacTLSRecvFunc recv_func, - gpointer data); -gpointer lac_tls_get_data (LacTLS *tls); -gboolean lac_tls_handshake (LacTLS *tls, - GError **err); -gint lac_tls_recv (LacTLS *tls, - gchar *buf, - guint len, - GError **err); -gint lac_tls_send (LacTLS *tls, - gchar *buf, - guint len, - GError **err); -gboolean lac_tls_needs_write (LacTLS *tls); -void lac_tls_free (LacTLS *tls); - - /* * Watching file descriptors */ @@ -305,9 +274,6 @@ union _LacConnectionEvent { LacConnectionErrorEvent error; }; -/* - * LacConnection - */ typedef struct _LacConnection LacConnection; typedef void (* LacConnectionFunc) (LacConnection *connection, diff --git a/src/lacconnection.c b/src/lacconnection.c index f461e27..054f84a 100644 --- a/src/lacconnection.c +++ b/src/lacconnection.c @@ -102,7 +102,7 @@ lac_connection_destroy (LacConnection *connection) if (connection->is_tcp) lac_tcp_connection_unref (connection->u.tcp); else - lac_tls_connection_unref (connection->u.tls); + lac_tls_connection_free (connection->u.tls); lac_address_free (connection->address); diff --git a/src/lacinternals.h b/src/lacinternals.h index c4fa2ec..d26fe07 100644 --- a/src/lacinternals.h +++ b/src/lacinternals.h @@ -67,10 +67,7 @@ gpointer lac_tcp_connection_get_data (LacTcpConnection void lac_tcp_connection_write (LacTcpConnection *connection, const gchar *data, guint len); -void lac_tcp_connection_write_cstr (LacTcpConnection *connection, - const gchar *data); -void lac_tcp_connection_shutdown_write (LacTcpConnection *connection); -LacTcpConnection * lac_tcp_connection_ref (LacTcpConnection *connection); +LacTcpConnection * lac_tcp_connection_ref (LacTcpConnection *connection); void lac_tcp_connection_unref (LacTcpConnection *connection); void lac_tcp_connection_close (LacTcpConnection *connection); gboolean lac_tcp_connection_is_connected (LacTcpConnection *connection); @@ -92,11 +89,7 @@ gpointer lac_tls_connection_get_data (LacTlsConnection void lac_tls_connection_write (LacTlsConnection *connection, const gchar *data, guint len); -void lac_tls_connection_write_cstr (LacTlsConnection *connection, - const gchar *data); -void lac_tls_connection_shutdown_write (LacTlsConnection *connection); -LacTlsConnection * lac_tls_connection_ref (LacTlsConnection *connection); -void lac_tls_connection_unref (LacTlsConnection *connection); +void lac_tls_connection_free (LacTlsConnection *connection); void lac_tls_connection_close (LacTlsConnection *connection); gboolean lac_tls_connection_is_connected (LacTlsConnection *connection); void lac_tls_connection_flush (LacTlsConnection *connection); diff --git a/src/lactcpconnection.c b/src/lactcpconnection.c index 258ff78..31c9e7d 100644 --- a/src/lactcpconnection.c +++ b/src/lactcpconnection.c @@ -412,9 +412,16 @@ lac_tcp_connection_get_data (LacTcpConnection *connection) } void -lac_tcp_connection_write (LacTcpConnection *connection, - const gchar *data, - guint len) +lac_tcp_connection_write_queue (LacTcpConnection *connection, + LacByteQueue *queue) +{ + lac_byte_queue_transfer_data (connection->unwritten, queue); +} + +void +lac_tcp_connection_write (LacTcpConnection *connection, + const gchar *data, + guint len) { gboolean do_writes; @@ -437,21 +444,6 @@ lac_tcp_connection_write (LacTcpConnection *connection, } void -lac_tcp_connection_write_cstr (LacTcpConnection *connection, - const gchar *data) -{ - guint len; - - g_return_if_fail (connection != NULL); - g_return_if_fail (data != NULL); - - len = strlen (data); - - if (len > 0) - lac_tcp_connection_write (connection, data, len); -} - -void lac_tcp_connection_close (LacTcpConnection *connection) { g_return_if_fail (connection != NULL); diff --git a/src/lactlsconnection.c b/src/lactlsconnection.c index f78fc4e..0181f28 100644 --- a/src/lactlsconnection.c +++ b/src/lactlsconnection.c @@ -38,8 +38,6 @@ struct _LacTlsConnection gnutls_session_t session; gboolean need_handshake; - - int ref_count; }; static void @@ -142,17 +140,17 @@ do_writes (LacTlsConnection *connection) { n_written = gnutls_record_send (connection->session, buffer, n_available); - } - - if (n_written < 0) - { - if (n_written != GNUTLS_E_INTERRUPTED && - n_written != GNUTLS_E_AGAIN) + + if (n_written < 0) { - err = (GError *)0x01; /* FIXME - make a new error */ + if (n_written != GNUTLS_E_INTERRUPTED && + n_written != GNUTLS_E_AGAIN) + { + err = (GError *)0x01; /* FIXME - make a new error */ + } + + n_written = 0; } - - n_written = 0; } lac_byte_queue_delete_head (connection->unwritten, n_written); @@ -312,7 +310,6 @@ lac_tls_connection_new (const LacAddress *address, tls->data = data; tls->buffer = lac_byte_queue_new (); tls->unwritten = lac_byte_queue_new (); - tls->ref_count = 1; gnutls_global_init (); @@ -337,29 +334,18 @@ lac_tls_connection_new (const LacAddress *address, return tls; } -LacTlsConnection * -lac_tls_connection_ref (LacTlsConnection *connection) -{ - connection->ref_count++; - - return connection; -} - void -lac_tls_connection_unref (LacTlsConnection *connection) +lac_tls_connection_free (LacTlsConnection *connection) { - if (--connection->ref_count == 0) - { - lac_connection_unref (connection->tcp_connection); - - lac_byte_queue_free (connection->buffer, TRUE); - lac_byte_queue_free (connection->unwritten, TRUE); - gnutls_deinit (connection->session); - - gnutls_certificate_free_credentials (connection->xcred); - - g_free (connection); - } + lac_connection_unref (connection->tcp_connection); + + lac_byte_queue_free (connection->buffer, TRUE); + lac_byte_queue_free (connection->unwritten, TRUE); + gnutls_deinit (connection->session); + + gnutls_certificate_free_credentials (connection->xcred); + + g_free (connection); } void @@ -373,21 +359,6 @@ lac_tls_connection_write (LacTlsConnection *tls, } void -lac_tls_connection_write_cstr (LacTlsConnection *connection, - const gchar *data) -{ - guint len; - - g_return_if_fail (connection != NULL); - g_return_if_fail (data != NULL); - - len = strlen (data); - - if (len > 0) - lac_tls_connection_write (connection, data, len); -} - -void lac_tls_connection_close (LacTlsConnection *connection) { lac_connection_close (connection->tcp_connection); |