Don't put output on stdin, instead do it on http connection

This commit is contained in:
Alexander Larsson 2010-11-18 22:21:16 +01:00
parent 8a0429b42d
commit f11a7d2fde
7 changed files with 155 additions and 62 deletions

View File

@ -670,6 +670,7 @@ broadway_client_write_header (BroadwayClient *client)
char *header;
header =
"HTTP/1.1 200 OK\r\n"
"Content-type: multipart/x-mixed-replace;boundary=x\r\n"
"Content-Encoding: gzip\r\n"
"\r\n";

View File

@ -280,7 +280,7 @@ function handleLoad(event)
}
}
function connect(app)
function connect()
{
var xhr = createXHR();
if (xhr) {
@ -290,13 +290,8 @@ function connect(app)
}
xhr.multipart = true;
xhr.open("GET", "/cgi-bin/" + app, true);
xhr.open("GET", "/output", true);
xhr.onload = handleLoad;
xhr.send(null);
}
}
function startClient(app)
{
connect(app);
}

View File

@ -6,6 +6,6 @@
<script type="text/javascript" src="broadway.js"></script>
</head>
<body onload="startClient('broadway')">
<body onload="connect()">
</body>
</html>

View File

@ -138,6 +138,44 @@ http_request_free (HttpRequest *request)
g_free (request);
}
#include <unistd.h>
#include <fcntl.h>
static void
set_fd_blocking (int fd)
{
glong arg;
if ((arg = fcntl (fd, F_GETFL, NULL)) < 0)
arg = 0;
arg = arg & ~O_NONBLOCK;
fcntl (fd, F_SETFL, arg);
}
static void
start_output (HttpRequest *request)
{
GSocket *socket;
GdkDisplayBroadway *display_broadway;
int fd;
g_print ("start_output\n");
socket = g_socket_connection_get_socket (request->connection);
display_broadway = GDK_DISPLAY_BROADWAY (request->display);
fd = g_socket_get_fd (socket);
set_fd_blocking (fd);
display_broadway->output = broadway_client_new (fd);
_gdk_broadway_resync_windows ();
/* TODO: This leaks the connection since we just keep the fd,
we want to avoid using the fd at all here */
g_object_ref (request->connection);
http_request_free (request);
}
static void
send_error (HttpRequest *request,
int error_code,
@ -216,6 +254,8 @@ got_request (HttpRequest *request)
send_data (request, "text/html", client_html, G_N_ELEMENTS(client_html) - 1);
else if (strcmp (escaped, "/broadway.js") == 0)
send_data (request, "text/javascript", broadway_js, G_N_ELEMENTS(broadway_js) - 1);
else if (strcmp (escaped, "/output") == 0)
start_output (request);
else
send_error (request, 404, "File not found");
}
@ -269,6 +309,7 @@ handle_incoming_connection (GSocketService *service,
in = g_io_stream_get_input_stream (G_IO_STREAM (connection));
request->data = g_data_input_stream_new (in);
g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (request->data), FALSE);
/* Be tolerant of input */
g_data_input_stream_set_newline_type (request->data, G_DATA_STREAM_NEWLINE_TYPE_ANY);
@ -283,16 +324,12 @@ gdk_display_open (const gchar *display_name)
GdkDisplay *display;
GdkDisplayBroadway *display_broadway;
const char *sm_client_id;
int fd;
GError *error;
fd = dup(STDOUT_FILENO);
dup2(STDERR_FILENO, STDOUT_FILENO);
display = g_object_new (GDK_TYPE_DISPLAY_BROADWAY, NULL);
display_broadway = GDK_DISPLAY_BROADWAY (display);
display_broadway->connection = broadway_client_new (fd);
display_broadway->output = NULL;
/* initialize the display's screens */
display_broadway->screens = g_new (GdkScreen *, 1);

View File

@ -75,7 +75,7 @@ struct _GdkDisplayBroadway
GdkWindow *active_offscreen_window;
GSocketService *service;
BroadwayClient *connection;
BroadwayClient *output;
};
struct _GdkDisplayBroadwayClass

View File

@ -40,6 +40,8 @@
typedef struct _GdkCursorPrivate GdkCursorPrivate;
void _gdk_broadway_resync_windows (void);
struct _GdkCursorPrivate
{
GdkCursor cursor;

View File

@ -121,28 +121,12 @@ diff_surfaces (cairo_surface_t *surface,
static guint dirty_flush_id = 0;
static gboolean
dirty_flush_idle (gpointer data)
static void
window_data_send (BroadwayClient *client, GdkWindowImplBroadway *impl)
{
GList *l;
GdkDisplayBroadway *display;
BroadwayClient *client;
display = GDK_DISPLAY_BROADWAY (gdk_display_get_default ());
client = display->connection;
dirty_flush_id = 0;
for (l = all_windows; l != NULL; l = l->next)
{
GdkWindowImplBroadway *impl = l->data;
GdkDrawableImplBroadway *drawable_impl = GDK_DRAWABLE_IMPL_BROADWAY (impl);
cairo_t *cr;
if (impl->dirty)
{
impl->dirty = FALSE;
if (impl->last_synced)
{
diff_surfaces (drawable_impl->surface,
@ -168,20 +152,86 @@ dirty_flush_idle (gpointer data)
cairo_paint (cr);
cairo_destroy (cr);
}
static gboolean
dirty_flush_idle (gpointer data)
{
GList *l;
GdkDisplayBroadway *display;
BroadwayClient *client;
dirty_flush_id = 0;
display = GDK_DISPLAY_BROADWAY (gdk_display_get_default ());
client = display->output;
if (client == NULL)
return FALSE;
for (l = all_windows; l != NULL; l = l->next)
{
GdkWindowImplBroadway *impl = l->data;
if (impl->dirty)
{
impl->dirty = FALSE;
window_data_send (display->output, impl);
}
}
broadway_client_flush (display->connection);
broadway_client_flush (client);
return FALSE;
}
static void
queue_dirty_flush (void)
queue_dirty_flush (GdkDisplayBroadway *display)
{
if (dirty_flush_id == 0)
if (dirty_flush_id == 0 && display->output != NULL)
dirty_flush_id = gdk_threads_add_idle (dirty_flush_idle, NULL);
}
void
_gdk_broadway_resync_windows (void)
{
GdkDisplayBroadway *display;
GList *l;
dirty_flush_id = 0;
display = GDK_DISPLAY_BROADWAY (gdk_display_get_default ());
for (l = all_windows; l != NULL; l = l->next)
{
GdkWindowImplBroadway *impl = l->data;
GdkWindowObject *private;
private = (GdkWindowObject*) GDK_DRAWABLE_IMPL_BROADWAY (impl)->wrapper;
impl->dirty = FALSE;
impl->last_synced = FALSE;
g_print ("creating new window %d at %d,%d %dx%d\n",
impl->id,
private->x,
private->y,
private->width,
private->height);
broadway_client_new_surface (display->output,
impl->id,
private->x,
private->y,
private->width,
private->height);
if (GDK_WINDOW_IS_MAPPED (private))
{
g_print ("showing window\n");
broadway_client_show_surface (display->output, impl->id);
g_print ("sending window data\n");
window_data_send (display->output, impl);
}
}
broadway_client_flush (display->output);
}
static void
gdk_window_impl_broadway_init (GdkWindowImplBroadway *impl)
@ -294,7 +344,8 @@ _gdk_window_impl_new (GdkWindow *window,
private->window_type == GDK_WINDOW_TEMP);
g_assert (GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT);
broadway_client_new_surface (display_broadway->connection,
if (display_broadway->output)
broadway_client_new_surface (display_broadway->output,
impl->id,
private->x,
private->y,
@ -341,7 +392,8 @@ _gdk_broadway_window_destroy (GdkWindow *window,
_gdk_broadway_drawable_finish (private->impl);
display_broadway = GDK_DISPLAY_BROADWAY (gdk_window_get_display (window));
broadway_client_destroy_surface (display_broadway->connection,
if (display_broadway->output)
broadway_client_destroy_surface (display_broadway->output,
impl->id);
}
@ -399,8 +451,11 @@ gdk_window_broadway_show (GdkWindow *window, gboolean already_mapped)
_gdk_make_event (GDK_WINDOW (private), GDK_MAP, NULL, FALSE);
display_broadway = GDK_DISPLAY_BROADWAY (gdk_window_get_display (window));
broadway_client_show_surface (display_broadway->connection, impl->id);
queue_dirty_flush ();
if (display_broadway->output)
{
broadway_client_show_surface (display_broadway->output, impl->id);
queue_dirty_flush (display_broadway);
}
}
static void
@ -420,8 +475,11 @@ gdk_window_broadway_hide (GdkWindow *window)
_gdk_make_event (GDK_WINDOW (private), GDK_UNMAP, NULL, FALSE);
display_broadway = GDK_DISPLAY_BROADWAY (gdk_window_get_display (window));
broadway_client_hide_surface (display_broadway->connection, impl->id);
queue_dirty_flush ();
if (display_broadway->output)
{
broadway_client_hide_surface (display_broadway->output, impl->id);
queue_dirty_flush (display_broadway);
}
_gdk_window_clear_update_area (window);
}
@ -1134,7 +1192,7 @@ _gdk_windowing_window_process_updates_recurse (GdkWindow *window,
private = (GdkWindowObject *)window;
impl = GDK_WINDOW_IMPL_BROADWAY (private->impl);
impl->dirty = TRUE;
queue_dirty_flush ();
queue_dirty_flush (GDK_DISPLAY_BROADWAY (gdk_window_get_display (window)));
}
void
@ -1216,10 +1274,10 @@ _gdk_broadway_window_translate (GdkWindow *window,
rects[i].height = rect.height;
}
display_broadway = GDK_DISPLAY_BROADWAY (gdk_window_get_display (window));
broadway_client_copy_rectangles (display_broadway->connection,
broadway_client_copy_rectangles (display_broadway->output,
GDK_WINDOW_IMPL_BROADWAY (impl)->id,
rects, n_rects, dx, dy);
queue_dirty_flush ();
queue_dirty_flush (display_broadway);
g_free (rects);
}
}