static gboolean read_cb (GIOChannel *source, GIOCondition condition, gpointer data) { PnNode *conn; gchar buf[PN_BUF_LEN + 1]; gsize bytes_read; pn_log ("begin"); conn = PN_NODE (data); pn_debug ("conn=%p,name=%s", conn, conn->name); g_object_ref (conn); { GIOStatus status = G_IO_STATUS_NORMAL; status = pn_node_read (conn, buf, PN_BUF_LEN, &bytes_read, NULL); if (status == G_IO_STATUS_AGAIN) { g_object_unref (conn); return TRUE; } if (status == G_IO_STATUS_EOF) { conn->error = g_error_new (PN_NODE_ERROR, PN_NODE_ERROR_OPEN, "End of stream"); } if (conn->error) { pn_node_error (conn); g_object_unref (conn); return FALSE; } } pn_node_parse (conn, buf, bytes_read); g_object_unref (conn); pn_log ("end"); return TRUE; }
static void read_cb (GObject *source, GAsyncResult *result, gpointer user_data) { PnNode *conn; gssize size; GError *error = NULL; conn = PN_NODE(user_data); size = g_input_stream_read_finish (G_INPUT_STREAM (source), result, &error); conn = PN_NODE(user_data); if (G_UNLIKELY (size == 0)) error = g_error_new_literal(PN_NODE_ERROR, PN_NODE_ERROR_OPEN, "End of stream"); if (error) goto nok; pn_node_parse (conn, (char *) conn->input_buffer, size); if (conn->status == PN_NODE_STATUS_OPEN) g_input_stream_read_async (G_INPUT_STREAM (source), conn->input_buffer, PN_BUF_LEN, G_PRIORITY_DEFAULT, NULL, read_cb, conn); else g_object_unref (conn); return; nok: conn->error = error; pn_node_error (conn); g_object_unref (conn); }
static gboolean read_cb (GIOChannel *source, GIOCondition condition, gpointer data) { PnNode *conn; gchar buf[PN_BUF_LEN + 1]; gsize bytes_read; pn_log ("begin"); conn = PN_NODE (data); pn_debug ("conn=%p,source=%p", conn, source); g_object_ref (conn); { GIOStatus status = G_IO_STATUS_NORMAL; status = pn_node_read (conn, buf, PN_BUF_LEN, &bytes_read, &conn->error); if (status == G_IO_STATUS_AGAIN) { g_object_unref (conn); return TRUE; } if (conn->error) { pn_node_error (conn); g_object_unref (conn); return FALSE; } if (status != G_IO_STATUS_NORMAL) { pn_warning ("not normal, status=%d", status); g_object_unref (conn); return TRUE; } } if (!conn->error) { PnHttpServer *http_conn; http_conn = PN_HTTP_SERVER (conn); if (http_conn->cur) { /* make sure the server is not sending the same buffer again */ /** @todo find out why this happens */ if (!(http_conn->old_buffer && strncmp (buf, http_conn->old_buffer, bytes_read) == 0)) { pn_node_parse (http_conn->cur, buf, bytes_read); g_free (http_conn->old_buffer); http_conn->old_buffer = g_strndup (buf, bytes_read); } } if (conn->error) { pn_node_error (conn); g_object_unref (conn); return FALSE; } } g_object_unref (conn); pn_log ("end"); return TRUE; }