PROP_0,
PROP_ADDRESS,
PROP_HOSTNAME,
- PROP_PORT
+ PROP_PORT,
+ PROP_INPUT_STREAM,
+ PROP_OUTPUT_STREAM
};
struct _GTcpClientPrivate
{
- GInetSocketAddress *address;
- gchar *hostname;
- gushort port;
- GSocket *socket;
+ GInetSocketAddress *address;
+ gchar *hostname;
+ gushort port;
+ GSocket *socket;
+ GNetworkInputStream *input;
+ GNetworkOutputStream *output;
};
static void
g_value_set_uint (value, client->priv->port);
break;
+ case PROP_INPUT_STREAM:
+ g_value_set_object (value, g_tcp_client_get_input_stream (client));
+ break;
+
+ case PROP_OUTPUT_STREAM:
+ g_value_set_object (value, g_tcp_client_get_output_stream (client));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
G_MAXUSHORT,
0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
+
+ g_object_class_install_property (gobject_class, PROP_INPUT_STREAM,
+ g_param_spec_object ("input-stream",
+ "input stream",
+ "the GNetworkInputStream for reading from this socket",
+ G_TYPE_NETWORK_INPUT_STREAM,
+ G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
+
+ g_object_class_install_property (gobject_class, PROP_OUTPUT_STREAM,
+ g_param_spec_object ("output-stream",
+ "output stream",
+ "the GNetworkOutputStream for writing to this socket",
+ G_TYPE_NETWORK_OUTPUT_STREAM,
+ G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
}
static void
client->priv->hostname = NULL;
client->priv->port = 0;
client->priv->socket = NULL;
+ client->priv->input = NULL;
+ client->priv->output = NULL;
}
GTcpClient *
if (!client->priv->socket)
return NULL;
- return _g_network_input_stream_new (client->priv->socket);
+ if (client->priv->input)
+ return client->priv->input;
+
+ // TODO: should we set g_object_notify here, or just create both these streams earlier?
+
+ return (client->priv->input = _g_network_input_stream_new (client->priv->socket));
}
GNetworkOutputStream *
if (!client->priv->socket)
return NULL;
- return _g_network_output_stream_new (client->priv->socket);
+ if (client->priv->output)
+ return client->priv->output;
+
+ // TODO: should we set g_object_notify here, or just create both these streams earlier?
+
+ return (client->priv->output = _g_network_output_stream_new (client->priv->socket));
}
gboolean