From 19806c1467b71d49881a9d76e28f3c656312e77b Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Tue, 13 Oct 2009 14:09:21 +0200 Subject: added multiple clients per socket support and --connect-socket argument --- uzbl-core.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'uzbl-core.h') diff --git a/uzbl-core.h b/uzbl-core.h index f0b60ab..12c1716 100644 --- a/uzbl-core.h +++ b/uzbl-core.h @@ -81,7 +81,8 @@ typedef struct { GHashTable *proto_var; gchar *sync_stdout; - GIOChannel *clientchan; + GIOChannel *connect_chan; + GPtrArray *client_chan; } Communication; @@ -98,6 +99,7 @@ typedef struct { gchar* searchtx; gboolean verbose; GPtrArray *event_buffer; + gchar* connect_socket_name; } State; -- cgit v1.2.3 From 5b1f6a5deed654e651e1de249a81b895d0073313 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Tue, 13 Oct 2009 15:53:19 +0200 Subject: handle multiple calls to --conect-socket --- events.c | 66 ++++++++++++++++++++++++++++++++++--------------------------- uzbl-core.c | 48 ++++++++++++++++++++++++++++---------------- uzbl-core.h | 7 +++++-- 3 files changed, 73 insertions(+), 48 deletions(-) (limited to 'uzbl-core.h') diff --git a/events.c b/events.c index 32816a1..6cb41f9 100644 --- a/events.c +++ b/events.c @@ -57,40 +57,47 @@ send_event_socket(GString *msg) { gsize len; guint i=0, j=0; - if(uzbl.comm.connect_chan && - uzbl.comm.connect_chan->is_writeable) { - if(uzbl.state.event_buffer) { - event_buffer_timeout(0); - - while(j < uzbl.state.event_buffer->len) { - tmp = g_ptr_array_index(uzbl.state.event_buffer, j++); - ret = g_io_channel_write_chars (uzbl.comm.connect_chan, - tmp->str, tmp->len, - &len, &error); - /* is g_ptr_array_free(uzbl.state.event_buffer, TRUE) enough? */ - //g_string_free(tmp, TRUE); - if (ret == G_IO_STATUS_ERROR) { - g_warning ("Error sending event to socket: %s", error->message); + if(uzbl.comm.connect_chan) { + while(i < uzbl.comm.connect_chan->len) { + gio = g_ptr_array_index(uzbl.comm.connect_chan, i++); + j=0; + + if(gio && gio->is_writeable) { + if(uzbl.state.event_buffer) { + event_buffer_timeout(0); + + while(j < uzbl.state.event_buffer->len) { + tmp = g_ptr_array_index(uzbl.state.event_buffer, j++); + ret = g_io_channel_write_chars (gio, + tmp->str, tmp->len, + &len, &error); + + if (ret == G_IO_STATUS_ERROR) { + g_warning ("Error sending event to socket: %s", error->message); + } + g_io_channel_flush(gio, &error); + } + } + + if(msg) { + while(!ret || + ret == G_IO_STATUS_AGAIN) { + ret = g_io_channel_write_chars (gio, + msg->str, msg->len, + &len, &error); + } + + if (ret == G_IO_STATUS_ERROR) { + g_warning ("Error sending event to socket: %s", error->message); + } + g_io_channel_flush(gio, &error); } - g_io_channel_flush(uzbl.comm.connect_chan, &error); } + } + if(uzbl.state.event_buffer) { g_ptr_array_free(uzbl.state.event_buffer, TRUE); uzbl.state.event_buffer = NULL; } - - if(msg) { - while(!ret || - ret == G_IO_STATUS_AGAIN) { - ret = g_io_channel_write_chars (uzbl.comm.connect_chan, - msg->str, msg->len, - &len, &error); - } - - if (ret == G_IO_STATUS_ERROR) { - g_warning ("Error sending event to socket: %s", error->message); - } - g_io_channel_flush(uzbl.comm.connect_chan, &error); - } } /* buffer events until a socket is set and connected * or a timeout is encountered @@ -101,6 +108,7 @@ send_event_socket(GString *msg) { g_ptr_array_add(uzbl.state.event_buffer, (gpointer)g_string_new(msg->str)); } + i=0; if(msg && uzbl.comm.client_chan) { while(i < uzbl.comm.client_chan->len) { gio = g_ptr_array_index(uzbl.comm.client_chan, i++); diff --git a/uzbl-core.c b/uzbl-core.c index ad224e8..e6f8edf 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -51,7 +51,7 @@ GOptionEntry entries[] = "Path to config file or '-' for stdin", "FILE" }, { "socket", 's', 0, G_OPTION_ARG_INT, &uzbl.state.socket_id, "Socket ID", "SOCKET" }, - { "connect-socket", 0, 0, G_OPTION_ARG_STRING, &uzbl.state.connect_socket_name, + { "connect-socket", 0, 0, G_OPTION_ARG_STRING_ARRAY, &uzbl.state.connect_socket_names, "Socket Name", "CSOCKET" }, { "geometry", 'g', 0, G_OPTION_ARG_STRING, &uzbl.gui.geometry, "Set window geometry (format: WIDTHxHEIGHT+-X+-Y)", "GEOMETRY" }, @@ -1538,23 +1538,37 @@ control_socket(GIOChannel *chan) { } void -init_connect_socket(gchar *name) { - int sockfd; +init_connect_socket() { + int sockfd, replay = 0; struct sockaddr_un local; - - sockfd = socket (AF_UNIX, SOCK_STREAM, 0); - local.sun_family = AF_UNIX; - strcpy (local.sun_path, name); - - if(!connect(sockfd, (struct sockaddr *) &local, sizeof(local))) { - if ((uzbl.comm.connect_chan = g_io_channel_unix_new(sockfd))) { - g_io_channel_set_encoding(uzbl.comm.connect_chan, NULL, NULL); - g_io_add_watch(uzbl.comm.connect_chan, G_IO_IN|G_IO_HUP, - (GIOFunc) control_client_socket, uzbl.comm.connect_chan); - /* replay buffered events */ - send_event_socket(NULL); + GIOChannel *chan; + gchar **name = NULL; + + if(!uzbl.comm.connect_chan) + uzbl.comm.connect_chan = g_ptr_array_new(); + + name = uzbl.state.connect_socket_names; + + while(name && *name) { + sockfd = socket (AF_UNIX, SOCK_STREAM, 0); + local.sun_family = AF_UNIX; + strcpy (local.sun_path, *name); + + if(!connect(sockfd, (struct sockaddr *) &local, sizeof(local))) { + if ((chan = g_io_channel_unix_new(sockfd))) { + g_io_channel_set_encoding(chan, NULL, NULL); + g_io_add_watch(chan, G_IO_IN|G_IO_HUP, + (GIOFunc) control_client_socket, chan); + g_ptr_array_add(uzbl.comm.connect_chan, (gpointer)chan); + replay++; + } } + name++; } + + /* replay buffered events */ + if(replay) + send_event_socket(NULL); } gboolean @@ -1936,8 +1950,8 @@ settings_init () { printf ("No configuration file loaded.\n"); } - if(s->connect_socket_name) - init_connect_socket(s->connect_socket_name); + if(s->connect_socket_names) + init_connect_socket(); g_signal_connect_after(n->soup_session, "request-started", G_CALLBACK(handle_cookies), NULL); } diff --git a/uzbl-core.h b/uzbl-core.h index 12c1716..32d92e3 100644 --- a/uzbl-core.h +++ b/uzbl-core.h @@ -81,7 +81,7 @@ typedef struct { GHashTable *proto_var; gchar *sync_stdout; - GIOChannel *connect_chan; + GPtrArray *connect_chan; GPtrArray *client_chan; } Communication; @@ -99,7 +99,7 @@ typedef struct { gchar* searchtx; gboolean verbose; GPtrArray *event_buffer; - gchar* connect_socket_name; + gchar** connect_socket_names; } State; @@ -424,6 +424,9 @@ update_gui(WebKitWebView *page, GArray *argv, GString *result); void event(WebKitWebView *page, GArray *argv, GString *result); +void +init_connect_socket(); + typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result); typedef struct { Command function; -- cgit v1.2.3