summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2014-01-30 18:20:00 +0100
committerMarc-André Lureau <marcandre.lureau@redhat.com>2014-02-21 12:22:03 +0100
commit68370795f08af3f834d5814ca8d71b82ca4a1396 (patch)
tree3595f77c968eada353b4637f71bb9282257c5eef
parent9cf9ca4348a58c99dc1bd849933687724be18748 (diff)
channel: talk to giostream instead of gsocket
-rw-r--r--gtk/spice-channel-priv.h2
-rw-r--r--gtk/spice-channel.c53
2 files changed, 41 insertions, 14 deletions
diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index 35704ea..f38156e 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -82,6 +82,8 @@ struct _SpiceChannelPrivate {
SpiceOpenSSLVerify *sslverify;
GSocket *sock;
GSocketConnection *conn;
+ GInputStream *in;
+ GOutputStream *out;
#if HAVE_SASL
sasl_conn_t *sasl_conn;
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index e729ffc..aff53ea 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -763,7 +763,8 @@ static void spice_channel_flush_wire(SpiceChannel *channel,
GIOCondition cond;
while (offset < datalen) {
- int ret;
+ gssize ret;
+ GError *error = NULL;
if (c->has_error) return;
@@ -779,9 +780,12 @@ static void spice_channel_flush_wire(SpiceChannel *channel,
ret = -1;
}
} else {
- GError *error = NULL;
- ret = g_socket_send(c->sock, ptr+offset, datalen-offset,
- NULL, &error);
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ ret = g_pollable_output_stream_write_nonblocking(G_POLLABLE_OUTPUT_STREAM(c->out),
+ ptr+offset, datalen-offset, NULL, &error);
+#else
+ ret = g_socket_send(c->sock, ptr+offset, datalen-offset, NULL, &error);
+#endif
if (ret < 0) {
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
cond = G_IO_OUT;
@@ -794,6 +798,7 @@ static void spice_channel_flush_wire(SpiceChannel *channel,
}
if (ret == -1) {
if (cond != 0) {
+ // TODO: should use g_pollable_input/output_stream_create_source() in 2.28 ?
g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
continue;
} else {
@@ -888,7 +893,7 @@ static void spice_channel_write_msg(SpiceChannel *channel, SpiceMsgOut *out)
static int spice_channel_read_wire(SpiceChannel *channel, void *data, size_t len)
{
SpiceChannelPrivate *c = channel->priv;
- int ret;
+ gssize ret;
GIOCondition cond;
reread:
@@ -908,7 +913,13 @@ reread:
}
} else {
GError *error = NULL;
- ret = g_socket_receive(c->sock, data, len, NULL, &error);
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ ret = g_pollable_input_stream_read_nonblocking(G_POLLABLE_INPUT_STREAM(c->in),
+ data, len, NULL, &error);
+#else
+ ret = g_socket_receive(c->sock,
+ data, len, NULL, &error);
+#endif
if (ret < 0) {
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
cond = G_IO_IN;
@@ -922,6 +933,7 @@ reread:
if (ret == -1) {
if (cond != 0) {
+ // TODO: should use g_pollable_input/output_stream_create_source() ?
g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
goto reread;
} else {
@@ -2061,9 +2073,12 @@ static void spice_channel_iterate_read(SpiceChannel *channel)
/* treat all incoming data (block on message completion) */
while (!c->has_error &&
c->state != SPICE_CHANNEL_STATE_MIGRATING &&
- g_socket_condition_check(c->sock, G_IO_IN) & G_IO_IN) {
-
- do
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_pollable_input_stream_is_readable(G_POLLABLE_INPUT_STREAM(c->in))
+#else
+ g_socket_condition_check(c->sock, G_IO_IN) & G_IO_IN
+#endif
+ ) { do
spice_channel_recv_msg(channel,
(handler_msg_in)SPICE_CHANNEL_GET_CLASS(channel)->handle_msg, NULL);
#if HAVE_SASL
@@ -2230,9 +2245,11 @@ static void *spice_channel_coroutine(void *data)
g_socket_set_blocking(c->sock, FALSE);
g_socket_set_keepalive(c->sock, TRUE);
+ c->conn = g_socket_connection_factory_create_connection(c->sock);
goto connected;
}
+
reconnect:
c->conn = spice_session_channel_open_host(c->session, channel, &c->tls);
if (c->conn == NULL) {
@@ -2293,7 +2310,11 @@ reconnect:
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ BIO *bio = bio_new_giostream(G_IO_STREAM(c->conn));
+#else
BIO *bio = bio_new_gsocket(c->sock);
+#endif
SSL_set_bio(c->ssl, bio, bio);
{
@@ -2324,6 +2345,9 @@ ssl_reconnect:
}
connected:
+ c->in = g_io_stream_get_input_stream(G_IO_STREAM(c->conn));
+ c->out = g_io_stream_get_output_stream(G_IO_STREAM(c->conn));
+
rc = setsockopt(g_socket_get_fd(c->sock), IPPROTO_TCP, TCP_NODELAY,
(const char*)&delay_val, sizeof(delay_val));
if ((rc != 0)
@@ -2497,10 +2521,9 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
g_object_unref(c->conn);
c->conn = NULL;
}
- if (c->sock) {
- g_object_unref(c->sock);
- c->sock = NULL;
- }
+
+ g_clear_object(&c->sock);
+
c->fd = -1;
free(c->peer_msg);
@@ -2726,8 +2749,10 @@ void spice_channel_swap(SpiceChannel *channel, SpiceChannel *swap, gboolean swap
/* TODO: split channel in 2 objects: a controller and a swappable
state object */
- SWAP(conn);
SWAP(sock);
+ SWAP(conn);
+ SWAP(in);
+ SWAP(out);
SWAP(ctx);
SWAP(ssl);
SWAP(sslverify);