seed r424 - trunk/modules/Multiprocessing
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r424 - trunk/modules/Multiprocessing
- Date: Wed, 10 Dec 2008 00:37:27 +0000 (UTC)
Author: racarr
Date: Wed Dec 10 00:37:27 2008
New Revision: 424
URL: http://svn.gnome.org/viewvc/seed?rev=424&view=rev
Log:
Multiprocessing: Bidirectional pipes.
Added:
trunk/modules/Multiprocessing/bi.js (contents, props changed)
Modified:
trunk/modules/Multiprocessing/Makefile.am
trunk/modules/Multiprocessing/multi.c
Modified: trunk/modules/Multiprocessing/Makefile.am
==============================================================================
--- trunk/modules/Multiprocessing/Makefile.am (original)
+++ trunk/modules/Multiprocessing/Makefile.am Wed Dec 10 00:37:27 2008
@@ -13,7 +13,7 @@
`pkg-config --cflags glib-2.0` -g \
`pkg-config --cflags gobject-introspection-1.0`
-EXTRA_DIST = fork.js
+EXTRA_DIST = fork.js bi.js
libdir = ${exec_prefix}/lib/seed
Added: trunk/modules/Multiprocessing/bi.js
==============================================================================
--- (empty file)
+++ trunk/modules/Multiprocessing/bi.js Wed Dec 10 00:37:27 2008
@@ -0,0 +1,21 @@
+#!/usr/local/bin/seed
+Seed.import_namespace("Multiprocessing");
+Seed.import_namespace("Gtk");
+pipes = new Multiprocessing.Pipe();
+child_pid = Seed.fork();
+
+if (child_pid == 0)
+{
+ mine = pipes[0];
+ mine.add_watch(1,
+ function()
+ {
+ Seed.print("Child Got: " + mine.read());
+ mine.write("Pong");
+ return true;
+ });
+ Gtk.main();
+}
+mine = pipes[1];
+mine.write("Ping");
+Seed.print("Parent Got: " + mine.read());
\ No newline at end of file
Modified: trunk/modules/Multiprocessing/multi.c
==============================================================================
--- trunk/modules/Multiprocessing/multi.c (original)
+++ trunk/modules/Multiprocessing/multi.c Wed Dec 10 00:37:27 2008
@@ -6,28 +6,45 @@
SeedObject namespace_ref;
SeedClass pipe_class;
+typedef struct _pipe_priv
+{
+ GIOChannel * read;
+ GIOChannel * write;
+} pipe_priv;
+
SeedObject seed_construct_pipe(SeedContext ctx,
SeedObject constructor,
size_t argument_count,
const SeedValue arguments[],
SeedException * exception)
{
- GIOChannel *one, *two;
+ GIOChannel *oner, *onew, twor, twow;
SeedObject jsone, jstwo, jsret;
- int fd[2];
+ int fd1[2], fd2[2];
+ pipe_priv * priv_one, * priv_two;
- if (pipe(fd) < 0)
+ if (pipe(fd1) < 0)
+ {
+ perror("Pipe failed. Make me a javascript exception");
+ return seed_make_null(ctx);
+ }
+ if (pipe(fd2) < 0)
{
perror("Pipe failed. Make me a javascript exception");
return seed_make_null(ctx);
}
- one = g_io_channel_unix_new(fd[0]);
- two = g_io_channel_unix_new(fd[1]);
+ priv_one = g_new0(pipe_priv, 1);
+ priv_two = g_new0(pipe_priv, 1);
+
+ priv_one->read = g_io_channel_unix_new(fd1[0]);
+ priv_one->write = g_io_channel_unix_new(fd2[1]);
+ priv_two->read = g_io_channel_unix_new(fd2[0]);
+ priv_two->write = g_io_channel_unix_new(fd1[1]);
jsret = seed_make_object(ctx, 0, 0);
- jsone = seed_make_object(ctx, pipe_class, one);
- jstwo = seed_make_object(ctx, pipe_class, two);
+ jsone = seed_make_object(ctx, pipe_class, priv_one);
+ jstwo = seed_make_object(ctx, pipe_class, priv_two);
seed_object_set_property_at_index(ctx, jsret, 0, jsone, exception);
seed_object_set_property_at_index(ctx, jsret, 1, jstwo, exception);
@@ -35,7 +52,7 @@
return jsret;
}
-#define GET_CHANNEL GIOChannel * channel = \
+#define GET_CHANNEL pipe_priv * priv = \
seed_object_get_private(this_object)
@@ -50,7 +67,7 @@
gchar * read;
GET_CHANNEL;
- g_io_channel_read_line(channel, &read, 0, 0, 0);
+ g_io_channel_read_line(priv->read, &read, 0, 0, 0);
ret = seed_value_from_string(ctx, read, exception);
g_free(read);
@@ -83,6 +100,9 @@
bret = seed_value_to_boolean(ctx, ret, 0);
seed_context_unref(ctx);
+
+ if (!bret)
+ g_free(priv);
return bret;
}
@@ -100,9 +120,9 @@
GET_CHANNEL;
data = seed_value_to_string(ctx, arguments[0], exception);
- g_io_channel_write_chars(channel, data, -1, &written, 0);
- g_io_channel_write_chars(channel, &eol, 1, 0, 0);
- g_io_channel_flush(channel, 0);
+ g_io_channel_write_chars(priv->write, data, -1, &written, 0);
+ g_io_channel_write_chars(priv->write, &eol, 1, 0, 0);
+ g_io_channel_flush(priv->write, 0);
return seed_value_from_int(ctx, written, exception);
}
@@ -115,14 +135,14 @@
SeedException * exception)
{
GET_CHANNEL;
- marshal_privates * priv = g_malloc0(sizeof(marshal_privates));
+ marshal_privates * mpriv = g_malloc0(sizeof(marshal_privates));
glong condition = seed_value_to_long(ctx, arguments[0], exception);
- priv->function = arguments[1];
- priv->source = this_object;
- priv->user_data = argument_count == 3 ? arguments[2] : seed_make_null(ctx);
+ mpriv->function = arguments[1];
+ mpriv->source = this_object;
+ mpriv->user_data = argument_count == 3 ? arguments[2] : seed_make_null(ctx);
- g_io_add_watch(channel, condition, gio_marshal_func, priv);
+ g_io_add_watch(priv->read, condition, gio_marshal_func, mpriv);
return seed_value_from_boolean(ctx, TRUE, exception);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]