summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pn_node.c31
-rw-r--r--pn_node.h3
2 files changed, 32 insertions, 2 deletions
diff --git a/pn_node.c b/pn_node.c
index 6d7f7ac..61c0050 100644
--- a/pn_node.c
+++ b/pn_node.c
@@ -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
diff --git a/pn_node.h b/pn_node.h
index 10c88ef..c243fd9 100644
--- a/pn_node.h
+++ b/pn_node.h
@@ -18,6 +18,7 @@ struct pn_node_class {
void (*close) (struct pn_node *node);
guint open_sig;
+ guint error_sig;
};
#define PN_NODE_TYPE (pn_node_get_type())
@@ -30,6 +31,8 @@ void pn_node_free(struct pn_node *node);
void pn_node_connect(struct pn_node *node, const char *hostname, int port);
void pn_node_close(struct pn_node *node);
+void pn_node_set_error(struct pn_node *node, GError *error);
+
GType pn_node_get_type(void);
#endif /* PN_NODE_H */