[broadway] Handle errors in input nicer

Also, fix a leak
This commit is contained in:
Alexander Larsson 2010-11-25 13:25:36 +01:00
parent 9cc073803f
commit a4fc901c07

View File

@ -184,10 +184,11 @@ got_input (GInputStream *stream,
message = g_data_input_stream_read_upto_finish (G_DATA_INPUT_STREAM (stream), result, &len, &error); message = g_data_input_stream_read_upto_finish (G_DATA_INPUT_STREAM (stream), result, &len, &error);
if (message == NULL) if (message == NULL)
{ {
g_print (error->message); GDK_DISPLAY_BROADWAY (request->display)->input = NULL;
g_error_free (error); http_request_free (request);
exit (1); return;
} }
g_assert (message[0] == 0); g_assert (message[0] == 0);
_gdk_events_got_input (request->display, message + 1); _gdk_events_got_input (request->display, message + 1);
@ -285,11 +286,11 @@ start_input (HttpRequest *request)
} }
} }
if (num_key1 != 1 || num_key2 != 1 || origin == NULL || host == NULL) if (num_key1 != 1 || num_key2 != 1 || origin == NULL || host == NULL)
{ {
g_print ("error"); g_strfreev (lines);
exit (1); send_error (request, 400, "Bad websocket request");
return;
} }
challenge[0] = (key1 >> 24) & 0xff; challenge[0] = (key1 >> 24) & 0xff;
@ -303,8 +304,9 @@ start_input (HttpRequest *request)
if (!g_input_stream_read_all (G_INPUT_STREAM (request->data), challenge+8, 8, NULL, NULL, NULL)) if (!g_input_stream_read_all (G_INPUT_STREAM (request->data), challenge+8, 8, NULL, NULL, NULL))
{ {
g_print ("error"); g_strfreev (lines);
exit (1); send_error (request, 400, "Bad websocket request");
return;
} }
checksum = g_checksum_new (G_CHECKSUM_MD5); checksum = g_checksum_new (G_CHECKSUM_MD5);
@ -333,6 +335,8 @@ start_input (HttpRequest *request)
g_data_input_stream_read_upto_async (request->data, "\xff", 1, 0, NULL, g_data_input_stream_read_upto_async (request->data, "\xff", 1, 0, NULL,
(GAsyncReadyCallback)got_input, request); (GAsyncReadyCallback)got_input, request);
g_strfreev (lines);
} }
static void static void