Commit fd794a95 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos Committed by Carlos Garcia Campos

WebSockets: closed signal not emitted when io stream is SoupIOStream

That's the case of connections created by SoupSession. In that case, if
the server hasn't closed its end of the connection, we fail to shutdown
the client end, because shutdown_wr_io_stream() does nothing when the io
stream is not a GSocketConnection. So, for SoupIOStream we need to get
the base io stream which is a GSocketConnection.
parent 23762ad4
Pipeline #90855 passed with stage
in 46 seconds
......@@ -217,3 +217,11 @@ soup_io_stream_new (GIOStream *base_iostream,
"close-on-dispose", close_on_dispose,
NULL);
}
GIOStream *
soup_io_stream_get_base_iostream (SoupIOStream *stream)
{
g_return_val_if_fail (SOUP_IS_IO_STREAM (stream), NULL);
return stream->priv->base_iostream;
}
......@@ -35,6 +35,8 @@ GType soup_io_stream_get_type (void);
GIOStream *soup_io_stream_new (GIOStream *base_iostream,
gboolean close_on_dispose);
GIOStream *soup_io_stream_get_base_iostream (SoupIOStream *stream);
G_END_DECLS
#endif /* __SOUP_IO_STREAM_H__ */
......@@ -24,6 +24,7 @@
#include "soup-websocket-connection.h"
#include "soup-enum-types.h"
#include "soup-io-stream.h"
#include "soup-uri.h"
/*
......@@ -281,12 +282,17 @@ shutdown_wr_io_stream (SoupWebsocketConnection *self)
{
SoupWebsocketConnectionPrivate *pv = self->pv;
GSocket *socket;
GIOStream *base_iostream;
GError *error = NULL;
stop_output (self);
if (G_IS_SOCKET_CONNECTION (pv->io_stream)) {
socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (pv->io_stream));
base_iostream = SOUP_IS_IO_STREAM (pv->io_stream) ?
soup_io_stream_get_base_iostream (SOUP_IO_STREAM (pv->io_stream)) :
pv->io_stream;
if (G_IS_SOCKET_CONNECTION (base_iostream)) {
socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (base_iostream));
g_socket_shutdown (socket, FALSE, TRUE, &error);
if (error != NULL) {
g_debug ("error shutting down io stream: %s", error->message);
......
......@@ -498,9 +498,11 @@ test_send_bad_data (Test *test,
GIOStream *io;
gsize written;
const char *frame;
gboolean close_event = FALSE;
g_signal_handlers_disconnect_by_func (test->server, on_error_not_reached, NULL);
g_signal_connect (test->server, "error", G_CALLBACK (on_error_copy), &error);
g_signal_connect (test->client, "closed", G_CALLBACK (on_close_set_flag), &close_event);
io = soup_websocket_connection_get_io_stream (test->client);
......@@ -516,6 +518,7 @@ test_send_bad_data (Test *test,
g_clear_error (&error);
WAIT_UNTIL (soup_websocket_connection_get_state (test->client) == SOUP_WEBSOCKET_STATE_CLOSED);
g_assert (close_event);
g_assert_cmpuint (soup_websocket_connection_get_close_code (test->client), ==, SOUP_WEBSOCKET_CLOSE_BAD_DATA);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment