diff options
Diffstat (limited to 'pn_node.c')
-rw-r--r-- | pn_node.c | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -2,6 +2,8 @@ #include <gio/gio.h> +#include "pn_log.h" + static void *parent_class; enum pn_node_status { @@ -15,6 +17,7 @@ struct pn_node_priv { int port; enum pn_node_status status; GSocketConnection *socket_conn; + GError *error; }; struct pn_node * @@ -45,6 +48,14 @@ pn_node_close(struct pn_node *node) PN_NODE_GET_CLASS(node)->close(node); } +void +pn_node_set_error(struct pn_node *node, + GError *error) +{ + node->priv->error = error; + pn_node_close(node); +} + /* pn_node stuff */ static void @@ -55,8 +66,9 @@ connect_cb(GObject *source, struct pn_node *node = user_data; struct pn_node_priv *priv = node->priv; GSocketConnection *socket_conn; + GError *error = NULL; - socket_conn = g_socket_client_connect_to_host_finish(G_SOCKET_CLIENT(source), res, NULL); + socket_conn = g_socket_client_connect_to_host_finish(G_SOCKET_CLIENT(source), res, &error); g_object_ref(node); @@ -69,7 +81,7 @@ connect_cb(GObject *source, g_signal_emit(G_OBJECT(node), class->open_sig, 0, node); } else { - pn_node_close(node); + pn_node_set_error(node, error); } g_object_unref(node); @@ -108,6 +120,17 @@ close_impl(struct pn_node *node) priv->status = PN_NODE_STATUS_CLOSED; + if (priv->error) { + struct pn_node_class *class; + class = g_type_class_peek(PN_NODE_TYPE); + g_signal_emit(G_OBJECT(node), class->error_sig, 0, &priv->error, node); + + if (priv->error) { + pn_warn(node, "unhandled error: %s", priv->error->message); + g_clear_error(&priv->error); + } + } + if (priv->socket_conn) { g_object_unref(priv->socket_conn); priv->socket_conn = NULL; @@ -146,6 +169,10 @@ class_init(void *g_class, G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + node_class->error_sig = g_signal_new("error", G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_FIRST, 0, NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); } static void |