The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

wip: property getter, check for incoming socket data

initial-version
Gergely Polonkai 4 years ago
parent 80178d5406
commit 51a7ea4d3e
  1. 87
      ssb-gtk/sbot.c

@ -326,6 +326,61 @@ initialise(SsbScuttler *scuttler, const gchar *ssb_dir)
emit_initialised(scuttler, TRUE);
}
typedef struct {
SsbScuttler *scuttler;
gpointer read_buffer;
} DataReadType;
static gboolean check_incoming_data(SsbScuttler *scuttler);
static void
data_read(GObject *source, GAsyncResult *result, gpointer user_data)
{
gssize bytes_read;
/* SsbScuttler *scuttler = ((DataReadType *)user_data)->scuttler; */
/* gpointer read_buffer = ((DataReadType *)user_data)->read_buffer; */
GError *err = NULL;
g_debug("g_input_stream_read_async() finished");
// We no longer need this struct, just the pointers within which are saved few lines above
g_slice_free(DataReadType, user_data);
if ((bytes_read = g_input_stream_read_finish(G_INPUT_STREAM(source), result, &err)) == -1) {
g_error("Error while reading from socket: %s", err->message);
return;
}
g_debug("Read %ld bytes", bytes_read);
// Re-add the idle handler
g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
G_SOURCE_FUNC(check_incoming_data),
g_object_ref(singleton),
g_object_unref);
}
static gboolean
check_incoming_data(SsbScuttler *scuttler)
{
DataReadType *data = g_slice_new(DataReadType);
GInputStream *stream = g_io_stream_get_input_stream(G_IO_STREAM(scuttler->connection));
g_debug("Checking for incoming data");
data->scuttler = scuttler;
data->read_buffer = g_malloc(MAX_MESSAGE_SIZE);
g_input_stream_read_async(stream,
data->read_buffer, MAX_MESSAGE_SIZE,
G_PRIORITY_DEFAULT,
NULL,
data_read, data);
return FALSE;
}
/**
* ssb_scuttler_ensure():
* @ssb_dir: (nullable): the SSB directory
@ -349,6 +404,11 @@ ssb_scuttler_ensure(const gchar *ssb_dir)
initialise(singleton, ssb_dir);
}
g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
G_SOURCE_FUNC(check_incoming_data),
g_object_ref(singleton),
g_object_unref);
return TRUE;
}
@ -882,6 +942,32 @@ ssb_scuttler_finalize(GObject *gobject)
}
static void
ssb_scuttler_get_property(GObject *gobject,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
SsbScuttler *scuttler = SSB_SCUTTLER(gobject);
switch (property_id) {
case PROP_INITIALISED:
g_value_set_boolean(value, scuttler->initialised);
break;
case PROP_CONNECTED:
g_value_set_boolean(value, scuttler->connection != NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
break;
}
}
static void
ssb_scuttler_class_init(SsbScuttlerClass *klass)
{
@ -895,6 +981,7 @@ ssb_scuttler_class_init(SsbScuttlerClass *klass)
gobject_class->dispose = ssb_scuttler_dispose;
gobject_class->finalize = ssb_scuttler_finalize;
gobject_class->get_property = ssb_scuttler_get_property;
/**
* SsbScuttler::initialised:

Loading…
Cancel
Save