aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--events.c45
-rw-r--r--uzbl-core.c39
-rw-r--r--uzbl-core.h4
3 files changed, 68 insertions, 20 deletions
diff --git a/events.c b/events.c
index abd794b..32816a1 100644
--- a/events.c
+++ b/events.c
@@ -52,20 +52,19 @@ void
send_event_socket(GString *msg) {
GError *error = NULL;
GString *tmp;
+ GIOChannel *gio = NULL;
GIOStatus ret = 0;
gsize len;
- guint i=0;
-
- if(uzbl.comm.socket_path &&
- uzbl.comm.clientchan &&
- uzbl.comm.clientchan->is_writeable) {
+ 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(i < uzbl.state.event_buffer->len) {
- tmp = g_ptr_array_index(uzbl.state.event_buffer, i++);
- ret = g_io_channel_write_chars (uzbl.comm.clientchan,
+ 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? */
@@ -73,15 +72,16 @@ send_event_socket(GString *msg) {
if (ret == G_IO_STATUS_ERROR) {
g_warning ("Error sending event to socket: %s", error->message);
}
- g_io_channel_flush(uzbl.comm.clientchan, &error);
+ g_io_channel_flush(uzbl.comm.connect_chan, &error);
}
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.clientchan,
+ ret == G_IO_STATUS_AGAIN) {
+ ret = g_io_channel_write_chars (uzbl.comm.connect_chan,
msg->str, msg->len,
&len, &error);
}
@@ -89,17 +89,36 @@ send_event_socket(GString *msg) {
if (ret == G_IO_STATUS_ERROR) {
g_warning ("Error sending event to socket: %s", error->message);
}
- g_io_channel_flush(uzbl.comm.clientchan, &error);
+ g_io_channel_flush(uzbl.comm.connect_chan, &error);
}
}
/* buffer events until a socket is set and connected
- * or a timeout is encountered
+ * or a timeout is encountered
*/
else {
if(!uzbl.state.event_buffer)
uzbl.state.event_buffer = g_ptr_array_new();
g_ptr_array_add(uzbl.state.event_buffer, (gpointer)g_string_new(msg->str));
}
+
+ if(msg && uzbl.comm.client_chan) {
+ while(i < uzbl.comm.client_chan->len) {
+ gio = g_ptr_array_index(uzbl.comm.client_chan, i++);
+ ret = 0;
+
+ if(gio && gio->is_writeable && 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);
+ }
+ }
+ }
}
void
diff --git a/uzbl-core.c b/uzbl-core.c
index a9f5326..ad224e8 100644
--- a/uzbl-core.c
+++ b/uzbl-core.c
@@ -51,6 +51,8 @@ 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,
+ "Socket Name", "CSOCKET" },
{ "geometry", 'g', 0, G_OPTION_ARG_STRING, &uzbl.gui.geometry,
"Set window geometry (format: WIDTHxHEIGHT+-X+-Y)", "GEOMETRY" },
{ "version", 'V', 0, G_OPTION_ARG_NONE, &uzbl.behave.print_version,
@@ -1517,20 +1519,42 @@ gboolean
control_socket(GIOChannel *chan) {
struct sockaddr_un remote;
unsigned int t = sizeof(remote);
+ GIOChannel *iochan;
int clientsock;
clientsock = accept (g_io_channel_unix_get_fd(chan),
(struct sockaddr *) &remote, &t);
- if ((uzbl.comm.clientchan = g_io_channel_unix_new(clientsock))) {
- g_io_channel_set_encoding(uzbl.comm.clientchan, NULL, NULL);
- g_io_add_watch(uzbl.comm.clientchan, G_IO_IN|G_IO_HUP,
- (GIOFunc) control_client_socket, uzbl.comm.clientchan);
+ if(!uzbl.comm.client_chan)
+ uzbl.comm.client_chan = g_ptr_array_new();
+
+ if ((iochan = g_io_channel_unix_new(clientsock))) {
+ g_io_channel_set_encoding(iochan, NULL, NULL);
+ g_io_add_watch(iochan, G_IO_IN|G_IO_HUP,
+ (GIOFunc) control_client_socket, iochan);
+ g_ptr_array_add(uzbl.comm.client_chan, (gpointer)iochan);
+ }
+ return TRUE;
+}
+
+void
+init_connect_socket(gchar *name) {
+ int sockfd;
+ 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);
+ }
}
-
- return TRUE;
}
gboolean
@@ -1912,6 +1936,9 @@ settings_init () {
printf ("No configuration file loaded.\n");
}
+ if(s->connect_socket_name)
+ init_connect_socket(s->connect_socket_name);
+
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 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;