aboutsummaryrefslogtreecommitdiffhomepage
path: root/uzbl.c
diff options
context:
space:
mode:
authorGravatar Dequis <dx@dxzone.com.ar>2009-06-15 01:09:40 -0300
committerGravatar Dequis <dx@dxzone.com.ar>2009-06-15 01:09:40 -0300
commit50a2ba82d9a667b8e7ad700be399318a8349d338 (patch)
tree3e38e010f0138df5350c4bfcc24efca2a0c2219d /uzbl.c
parente230f5720de05c2d385b6047de1c8d7c422728d6 (diff)
Fix control_socket to use GIOChannel
Diffstat (limited to 'uzbl.c')
-rw-r--r--uzbl.c73
1 files changed, 28 insertions, 45 deletions
diff --git a/uzbl.c b/uzbl.c
index 1bb1e41..e953d3d 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -1791,65 +1791,48 @@ create_stdin () {
static gboolean
control_socket(GIOChannel *chan) {
- char *ctl_line;
- GString *result = g_string_new("");
-#if 1
struct sockaddr_un remote;
- char buffer[512];
- char temp[128];
- int sock, clientsock, n, done;
- unsigned int t;
-
- sock = g_io_channel_unix_get_fd(chan);
-
- memset (buffer, 0, sizeof (buffer));
-
- t = sizeof (remote);
- clientsock = accept (sock, (struct sockaddr *) &remote, &t);
-
- done = 0;
- do {
- memset (temp, 0, sizeof (temp));
- n = recv (clientsock, temp, 128, 0);
- if (n == 0) {
- buffer[strlen (buffer)] = '\0';
- done = 1;
- }
- if (!done)
- strcat (buffer, temp);
- } while (!done);
+ unsigned int t = sizeof(remote);
+ int clientsock;
+ GIOChannel *clientchan;
- if (strcmp (buffer, "\n") < 0) {
- buffer[strlen (buffer) - 1] = '\0';
- } else {
- buffer[strlen (buffer)] = '\0';
+ clientsock = accept (g_io_channel_unix_get_fd(chan),
+ (struct sockaddr *) &remote, &t);
+
+ if ((clientchan = g_io_channel_unix_new(clientsock))) {
+ g_io_add_watch(clientchan, G_IO_IN|G_IO_HUP,
+ (GIOFunc) control_client_socket, clientchan);
}
- ctl_line = g_strdup(buffer);
- parse_cmd_line (ctl_line, result);
-
- send (clientsock, result->str, result->len, 0);
-
- close (clientsock);
-#else
- /* TODO: we should be able to do it with this. but glib errors out with "Invalid argument" */
+ return TRUE;
+}
+
+static gboolean
+control_client_socket(GIOChannel *clientchan) {
+ char *ctl_line;
+ GString *result = g_string_new("");
GError *error = NULL;
- gsize len;
GIOStatus ret;
+ gsize len;
- ret = g_io_channel_read_line(chan, &ctl_line, &len, NULL, &error);
- if (ret == G_IO_STATUS_ERROR)
+ ret = g_io_channel_read_line(clientchan, &ctl_line, &len, NULL, &error);
+ if (ret == G_IO_STATUS_ERROR) {
g_error ("Error reading: %s\n", error->message);
+ return FALSE;
+ } else if (ret == G_IO_STATUS_EOF) {
+ /* socket closed, remove channel watch from main loop */
+ return FALSE;
+ }
- printf("Got line %s (%u bytes) \n",ctl_line, len);
if (ctl_line) {
parse_cmd_line (ctl_line, result);
- ret = g_io_channel_write_chars (chan, result->str, result->len, &len, &error);
+ ret = g_io_channel_write_chars (clientchan, result->str, result->len,
+ &len, &error);
if (ret == G_IO_STATUS_ERROR) {
- g_error ("Error writing: %s", error->message)
+ g_error ("Error writing: %s", error->message);
}
}
-#endif
+
g_string_free(result, TRUE);
g_free(ctl_line);
return TRUE;