You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2013/01/11 11:43:25 UTC

[5/6] THRIFT-1826 update c_glib source header paths Patch: Simon South

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.c b/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.c
new file mode 100644
index 0000000..bef4087
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.c
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
+
+G_DEFINE_ABSTRACT_TYPE(ThriftProtocolFactory, thrift_protocol_factory, G_TYPE_OBJECT)
+
+ThriftProtocol *
+thrift_protocol_factory_get_protocol(ThriftProtocolFactory *factory,
+                                     ThriftTransport *transport)
+{
+  return THRIFT_PROTOCOL_FACTORY_GET_CLASS (factory)->get_protocol (factory,
+                                                                    transport);
+}
+
+static void
+thrift_protocol_factory_init (ThriftProtocolFactory *factory)
+{
+  THRIFT_UNUSED_VAR (factory);
+}
+
+static void
+thrift_protocol_factory_class_init (ThriftProtocolFactoryClass *cls)
+{
+  cls->get_protocol = thrift_protocol_factory_get_protocol;
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.h b/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.h
new file mode 100644
index 0000000..a9cd5f5
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/protocol/thrift_protocol_factory.h
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_PROTOCOL_FACTORY_H
+#define _THRIFT_PROTOCOL_FACTORY_H
+
+#include <glib-object.h>
+
+#include <thrift/c_glib/transport/thrift_transport.h>
+#include <thrift/c_glib/protocol/thrift_protocol.h>
+
+G_BEGIN_DECLS
+
+/*! \file thrift_protocol_factory.h
+ *  \brief Abstract class for Thrift protocol factory implementations.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_PROTOCOL_FACTORY (thrift_protocol_factory_get_type ())
+#define THRIFT_PROTOCOL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_PROTOCOL_FACTORY, ThriftProtocolFactory))
+#define THRIFT_IS_PROTOCOL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_PROTOCOL_FACTORY))
+#define THRIFT_PROTOCOL_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_PROTOCOL_FACTORY, ThriftProtocolFactoryClass))
+#define THRIFT_IS_PROTOCOL_FACTORY_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_PROTOCOL_FACTORY))
+#define THRIFT_PROTOCOL_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_PROTOCOL_FACTORY, ThriftProtocolFactoryClass))
+
+/*!
+ * Thrift Protocol Factory object
+ */
+struct _ThriftProtocolFactory
+{
+  GObject parent;
+};
+typedef struct _ThriftProtocolFactory ThriftProtocolFactory;
+
+/*!
+ * Thrift Protocol Factory class
+ */
+struct _ThriftProtocolFactoryClass
+{
+  GObjectClass parent;
+
+  ThriftProtocol *(*get_protocol) (ThriftProtocolFactory *factory,
+                                   ThriftTransport *transport);
+};
+typedef struct _ThriftProtocolFactoryClass ThriftProtocolFactoryClass;
+
+/* used by THRIFT_TYPE_PROTOCOL_FACTORY */
+GType thrift_protocol_factory_get_type (void);
+
+/* virtual public methods */
+ThriftProtocol *thrift_protocol_factory_get_protocol(ThriftProtocolFactory *factory, ThriftTransport *transport);
+
+G_END_DECLS
+
+#endif /* _THRIFT_PROTOCOL_FACTORY_H */

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/server/thrift_server.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/server/thrift_server.c b/lib/c_glib/src/thrift/c_glib/server/thrift_server.c
new file mode 100644
index 0000000..0171cee
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/server/thrift_server.c
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <thrift/c_glib/thrift.h>
+#include "thrift_server.h"
+
+/* object properties */
+enum _ThriftServerProperties
+{
+  PROP_0,
+  PROP_THRIFT_SERVER_PROCESSOR,
+  PROP_THRIFT_SERVER_SERVER_TRANSPORT,
+  PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY,
+  PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY,
+  PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY,
+  PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY
+};
+
+G_DEFINE_ABSTRACT_TYPE(ThriftServer, thrift_server, G_TYPE_OBJECT)
+
+void
+thrift_server_get_property (GObject *object, guint property_id,
+                            GValue *value, GParamSpec *pspec)
+{
+  ThriftServer *server = THRIFT_SERVER (object);
+
+  THRIFT_UNUSED_VAR (pspec);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_SERVER_PROCESSOR:
+      g_value_set_object (value, server->processor);
+      break;
+    case PROP_THRIFT_SERVER_SERVER_TRANSPORT:
+      g_value_set_object (value, server->server_transport);
+      break;
+    case PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY:
+      g_value_set_object (value, server->input_transport_factory);
+      break;
+    case PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY:
+      g_value_set_object (value, server->output_transport_factory);
+      break;
+    case PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY:
+      g_value_set_object (value, server->input_protocol_factory);
+      break;
+    case PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY:
+      g_value_set_object (value, server->output_protocol_factory);
+      break;
+  }
+}
+
+void
+thrift_server_set_property (GObject *object, guint property_id,
+                            const GValue *value, GParamSpec *pspec)
+{
+  ThriftServer *server = THRIFT_SERVER (object);
+
+  THRIFT_UNUSED_VAR (pspec);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_SERVER_PROCESSOR:
+      server->processor = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_SERVER_SERVER_TRANSPORT:
+      server->server_transport = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY:
+      server->input_transport_factory = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY:
+      server->output_transport_factory = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY:
+      server->input_protocol_factory = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY:
+      server->output_protocol_factory = g_value_get_object (value);
+      break;
+  }
+}
+
+void
+thrift_server_serve (ThriftServer *server)
+{
+  THRIFT_SERVER_GET_CLASS (server)->serve (server);
+}
+
+void
+thrift_server_stop (ThriftServer *server)
+{
+  THRIFT_SERVER_GET_CLASS (server)->stop (server);
+}
+
+/* instance initializer for Thrift Server */
+static void
+thrift_server_init (ThriftServer *server)
+{
+  server->processor = NULL;
+  server->server_transport = NULL;
+  server->input_transport_factory = NULL;
+  server->output_transport_factory = NULL;
+  server->input_protocol_factory = NULL;
+  server->output_protocol_factory = NULL;
+}
+
+/* class initializer for ThriftServer
+ * TODO: implement ServerEventHandler as a GClosure
+ */
+static void
+thrift_server_class_init (ThriftServerClass *cls)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+
+  gobject_class->get_property = thrift_server_get_property;
+  gobject_class->set_property = thrift_server_set_property;
+
+  g_object_class_install_property (gobject_class,
+      PROP_THRIFT_SERVER_PROCESSOR,
+      g_param_spec_object ("processor", "Processor", "Thrift Processor",
+                           THRIFT_TYPE_PROCESSOR,
+                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (gobject_class,
+      PROP_THRIFT_SERVER_SERVER_TRANSPORT,
+      g_param_spec_object ("server_transport", "Server Transport",
+                           "Thrift Server Transport",
+                           THRIFT_TYPE_SERVER_TRANSPORT,
+                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (gobject_class,
+      PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY,
+      g_param_spec_object ("input_transport_factory", "Input Transport Factory",
+                           "Thrift Server Input Transport Factory",
+                           THRIFT_TYPE_TRANSPORT_FACTORY,
+                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (gobject_class,
+      PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY,
+      g_param_spec_object ("output_transport_factory",
+                           "Output Transport Factory",
+                           "Thrift Server Output Transport Factory",
+                           THRIFT_TYPE_TRANSPORT_FACTORY,
+                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (gobject_class,
+      PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY,
+      g_param_spec_object ("input_protocol_factory", "Input Protocol Factory",
+                           "Thrift Server Input Protocol Factory",
+                           THRIFT_TYPE_PROTOCOL_FACTORY,
+                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (gobject_class,
+      PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY,
+      g_param_spec_object ("output_protocol_factory", "Output Protocol Factory",
+                           "Thrift Server Output Protocol Factory",
+                           THRIFT_TYPE_PROTOCOL_FACTORY,
+                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+  /* set these as virtual methods to be implemented by a subclass */
+  cls->serve = thrift_server_serve;
+  cls->stop = thrift_server_stop;
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/server/thrift_server.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/server/thrift_server.h b/lib/c_glib/src/thrift/c_glib/server/thrift_server.h
new file mode 100644
index 0000000..a3aa94e
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/server/thrift_server.h
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_SERVER_H
+#define _THRIFT_SERVER_H
+
+#include <glib-object.h>
+
+#include <thrift/c_glib/processor/thrift_processor.h>
+#include <thrift/c_glib/transport/thrift_server_transport.h>
+#include <thrift/c_glib/transport/thrift_transport_factory.h>
+#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
+
+G_BEGIN_DECLS
+
+/*! \file thrift_server.h
+ *  \brief Abstract class for Thrift servers.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_SERVER (thrift_server_get_type ())
+#define THRIFT_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SERVER, ThriftServer))
+#define THRIFT_IS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SERVER))
+#define THRIFT_SERVER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_SERVER, ThriftServerClass))
+#define THRIFT_IS_SERVER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SERVER))
+#define THRIFT_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SERVER, ThriftServerClass))
+
+/*!
+ * Thrift Server object
+ */
+struct _ThriftServer
+{
+  GObject parent;
+
+  /* protected */
+  ThriftProcessor *processor;
+  ThriftServerTransport *server_transport;
+  ThriftTransportFactory *input_transport_factory;
+  ThriftTransportFactory *output_transport_factory;
+  ThriftProtocolFactory *input_protocol_factory;
+  ThriftProtocolFactory *output_protocol_factory;
+};
+typedef struct _ThriftServer ThriftServer;
+
+/*!
+ * Thrift Server class
+ */
+struct _ThriftServerClass
+{
+  GObjectClass parent;
+
+  /* vtable */
+  void (*serve) (ThriftServer *server);
+  void (*stop) (ThriftServer *server);
+};
+typedef struct _ThriftServerClass ThriftServerClass;
+
+/* used by THRIFT_TYPE_SERVER */
+GType thrift_server_get_type (void);
+
+/*!
+ * Processes the request.
+ * \public \memberof ThriftServerClass
+ */
+void thrift_server_serve (ThriftServer *server);
+
+/*!
+ * Stop handling requests.
+ */
+void thrift_server_stop (ThriftServer *server);
+
+G_END_DECLS
+
+#endif /* _THRIFT_SERVER_H */
+

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.c b/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.c
new file mode 100644
index 0000000..7a39bc2
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.c
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <thrift/c_glib/server/thrift_simple_server.h>
+#include <thrift/c_glib/transport/thrift_transport_factory.h>
+#include <thrift/c_glib/protocol/thrift_protocol_factory.h>
+#include <thrift/c_glib/protocol/thrift_binary_protocol_factory.h>
+
+G_DEFINE_TYPE(ThriftSimpleServer, thrift_simple_server, THRIFT_TYPE_SERVER)
+
+void
+thrift_simple_server_serve (ThriftServer *server)
+{
+  g_return_if_fail (THRIFT_IS_SIMPLE_SERVER (server));
+
+  ThriftTransport *t = NULL;
+  ThriftTransport *input_transport = NULL, *output_transport = NULL;
+  ThriftProtocol *input_protocol = NULL, *output_protocol = NULL;
+  ThriftSimpleServer *tss = THRIFT_SIMPLE_SERVER(server);
+
+  THRIFT_SERVER_TRANSPORT_GET_CLASS (server->server_transport)
+      ->listen (server->server_transport, NULL);
+
+  tss->running = TRUE;
+  while (tss->running == TRUE)
+  {
+    t = thrift_server_transport_accept (server->server_transport, NULL);
+    input_transport =
+        THRIFT_TRANSPORT_FACTORY_GET_CLASS (server->input_transport_factory)
+            ->get_transport (server->input_transport_factory, t);
+    output_transport = 
+        THRIFT_TRANSPORT_FACTORY_GET_CLASS (server->output_transport_factory)
+            ->get_transport (server->output_transport_factory, t);
+    input_protocol =
+        THRIFT_PROTOCOL_FACTORY_GET_CLASS (server->input_protocol_factory)
+            ->get_protocol (server->input_protocol_factory, t);
+    output_protocol =
+        THRIFT_PROTOCOL_FACTORY_GET_CLASS (server->output_protocol_factory)
+            ->get_protocol (server->output_protocol_factory, t);
+
+    while (THRIFT_PROCESSOR_GET_CLASS (server->processor)
+               ->process (server->processor, input_protocol, output_protocol))
+    {
+      // TODO: implement transport peek ()
+    }
+
+    // TODO: handle exceptions
+    THRIFT_TRANSPORT_GET_CLASS (input_transport)->close (input_transport, NULL);
+    THRIFT_TRANSPORT_GET_CLASS (output_transport)->close (output_transport,
+                                                          NULL);
+  } 
+
+  // attempt to shutdown
+  THRIFT_SERVER_TRANSPORT_GET_CLASS (server->server_transport)
+      ->close (server->server_transport, NULL); 
+}
+
+void
+thrift_simple_server_stop (ThriftServer *server)
+{
+  g_return_if_fail (THRIFT_IS_SIMPLE_SERVER (server));
+  (THRIFT_SIMPLE_SERVER (server))->running = FALSE;
+}
+
+static void
+thrift_simple_server_init (ThriftSimpleServer *tss)
+{
+  tss->running = FALSE;
+
+  ThriftServer *server = THRIFT_SERVER(tss);
+
+  if (server->input_transport_factory == NULL)
+  {
+    server->input_transport_factory =
+        g_object_new (THRIFT_TYPE_TRANSPORT_FACTORY, NULL);
+  }
+  if (server->output_transport_factory == NULL)
+  {
+    server->output_transport_factory =
+        g_object_new (THRIFT_TYPE_TRANSPORT_FACTORY, NULL);
+  }
+  if (server->input_protocol_factory == NULL)
+  {
+    server->input_protocol_factory =
+        g_object_new (THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, NULL);
+  }
+  if (server->output_protocol_factory == NULL)
+  {
+    server->output_protocol_factory =
+        g_object_new (THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, NULL);
+  }
+}
+
+/* initialize the class */
+static void
+thrift_simple_server_class_init (ThriftSimpleServerClass *class)
+{
+  ThriftServerClass *cls = THRIFT_SERVER_CLASS(class);
+
+  cls->serve = thrift_simple_server_serve;
+  cls->stop = thrift_simple_server_stop;
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.h b/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.h
new file mode 100644
index 0000000..d45dc21
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/server/thrift_simple_server.h
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_SIMPLE_SERVER_H
+#define _THRIFT_SIMPLE_SERVER_H
+
+#include <glib-object.h>
+
+#include <thrift/c_glib/server/thrift_server.h>
+
+G_BEGIN_DECLS
+
+/*! \file thrift_simple_server.h
+ *  \brief A simple Thrift server, single-threaded.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_SIMPLE_SERVER (thrift_simple_server_get_type ())
+#define THRIFT_SIMPLE_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_SIMPLE_SERVER, ThriftSimpleServer))
+#define THRIFT_IS_SIMPLE_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_SIMPLE_SERVER))
+#define THRIFT_SIMPLE_SERVER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c) THRIFT_TYPE_SIMPLE_SERVER, ThriftSimpleServerClass))
+#define THRIFT_IS_SIMPLE_SERVER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_SIMPLE_SERVER))
+#define THRIFT_SIMPLE_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_SIMPLE_SERVER, ThriftSimpleServerClass))
+
+/**
+ * Thrift Simple Server instance.
+ */
+struct _ThriftSimpleServer
+{
+  ThriftServer parent;
+
+  /* private */
+  volatile gboolean running;
+};
+typedef struct _ThriftSimpleServer ThriftSimpleServer;
+
+/**
+ * Thrift Simple Server class.
+ */
+struct _ThriftSimpleServerClass
+{
+  ThriftServerClass parent;
+};
+typedef struct _ThriftSimpleServerClass ThriftSimpleServerClass;
+
+/* used by THRIFT_TYPE_SIMPLE_SERVER */
+GType thrift_simple_server_get_type (void);
+
+G_END_DECLS
+
+#endif /* _THRIFT_SIMPLE_SERVER_H */
+

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/thrift.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/thrift.c b/lib/c_glib/src/thrift/c_glib/thrift.c
new file mode 100644
index 0000000..0051df0
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/thrift.c
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <thrift/c_glib/thrift.h>
+
+/**
+ * GHashTable callback to add keys to a GList.
+ */
+void
+thrift_hash_table_get_keys (gpointer key, gpointer value, gpointer user_data)
+{
+  THRIFT_UNUSED_VAR (value);
+  GList **list = (GList **) user_data;
+  *list = g_list_append (*list, key);
+}
+

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/thrift.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/thrift.h b/lib/c_glib/src/thrift/c_glib/thrift.h
new file mode 100644
index 0000000..0636a2f
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/thrift.h
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_H
+#define _THRIFT_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+
+/* this macro is called to satisfy -Wall hardcore compilation */
+#ifndef THRIFT_UNUSED_VAR
+# define THRIFT_UNUSED_VAR(x) ((void) x)
+#endif
+
+void thrift_hash_table_get_keys (gpointer key, gpointer value,
+                                 gpointer user_data);
+
+#endif // #ifndef _THRIFT_THRIFT_H

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/thrift_application_exception.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/thrift_application_exception.c b/lib/c_glib/src/thrift/c_glib/thrift_application_exception.c
new file mode 100644
index 0000000..2b8b395
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/thrift_application_exception.c
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "thrift_application_exception.h"
+#include <thrift/c_glib/protocol/thrift_protocol.h>
+
+G_DEFINE_TYPE(ThriftApplicationException, thrift_application_exception, THRIFT_TYPE_STRUCT)
+
+gint32
+thrift_application_exception_read (ThriftStruct *object,
+                                   ThriftProtocol *protocol, GError **error)
+{
+  gint32 ret;
+  gint32 xfer = 0;
+  gchar *name;
+  ThriftType ftype;
+  gint16 fid;
+  ThriftApplicationException *this = THRIFT_APPLICATION_EXCEPTION (object);
+
+  /* read the struct begin marker */
+  if ((ret = thrift_protocol_read_struct_begin (protocol, &name, error)) < 0)
+  {
+    if (name) g_free (name);
+    return -1;
+  }
+  xfer += ret;
+  if (name) g_free (name);
+
+  while (1)
+  {
+    if ((ret = thrift_protocol_read_field_begin (protocol, &name, &ftype,
+                                                 &fid, error)) < 0)
+    {
+      if (name) g_free (name);
+      return -1;
+    }
+    xfer += ret;
+    if (name) g_free (name);
+
+    /* break if we get a STOP field */
+    if (ftype == T_STOP)
+    {
+      break;
+    }
+
+    switch (fid)
+    {
+      case 1:
+        if (ftype == T_STRING)
+        {
+          if ((ret = thrift_protocol_read_string (protocol, &this->message,
+                                                  error)) < 0)
+            return -1;
+          xfer += ret;
+          this->__isset_message = TRUE;
+        } else {
+          if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
+            return -1;
+          xfer += ret;
+        }
+        break;
+      case 2:
+        if (ftype == T_I32)
+        {
+          if ((ret = thrift_protocol_read_i32 (protocol, &this->type,
+                                               error)) < 0)
+            return -1;
+          xfer += ret;
+          this->__isset_type = TRUE;
+        } else {
+          if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
+            return -1;
+          xfer += ret;
+        }
+        break;
+      default:
+        if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
+          return -1;
+        xfer += ret;
+        break;
+    }
+    if ((ret = thrift_protocol_read_field_end (protocol, error)) < 0)
+      return -1;
+    xfer += ret;
+  }
+
+  if ((ret = thrift_protocol_read_struct_end (protocol, error)) < 0)
+    return -1;
+  xfer += ret;
+
+  return xfer;
+}
+
+gint32
+thrift_application_exception_write (ThriftStruct *object,
+                                    ThriftProtocol *protocol, GError **error)
+{
+  gint32 ret;
+  gint32 xfer = 0;
+
+  ThriftApplicationException *this = THRIFT_APPLICATION_EXCEPTION (object);
+
+  if ((ret = thrift_protocol_write_struct_begin (protocol,
+                                                 "TApplicationException",
+                                                 error)) < 0)
+    return -1;
+  xfer += ret;
+  if ((ret = thrift_protocol_write_field_begin (protocol, "message",
+                                                T_STRING, 1, error)) < 0)
+    return -1;
+  xfer += ret;
+  if ((ret = thrift_protocol_write_string (protocol, this->message, error)) < 0)
+    return -1;
+  xfer += ret;
+  if ((ret = thrift_protocol_write_field_end (protocol, error)) < 0)
+    return -1;
+  xfer += ret;
+  if ((ret = thrift_protocol_write_field_begin (protocol, "type",
+                                                T_I32, 2, error)) < 0)
+    return -1;
+  xfer += ret;
+  if ((ret = thrift_protocol_write_i32 (protocol, this->type, error)) < 0)
+    return -1;
+  xfer += ret;
+  if ((ret = thrift_protocol_write_field_end (protocol, error)) < 0)
+    return -1;
+  xfer += ret;
+  if ((ret = thrift_protocol_write_field_stop (protocol, error)) < 0)
+    return -1;
+  xfer += ret;
+  if ((ret = thrift_protocol_write_struct_end (protocol, error)) < 0)
+    return -1;
+  xfer += ret;
+
+  return xfer;
+}
+
+
+/* GError domain */
+#define THRIFT_APPLICATION_EXCEPTION_ERROR_DOMAIN "thrift-application-exception-error-quark"
+
+GQuark
+thrift_application_exception_error_quark (void)
+{
+  return g_quark_from_static_string (THRIFT_APPLICATION_EXCEPTION_ERROR_DOMAIN);
+}
+
+void
+thrift_application_exception_init (ThriftApplicationException *object)
+{
+  object->type = 0;
+  object->__isset_type = FALSE;
+  object->message = NULL;
+  object->__isset_message = FALSE;
+}
+
+void
+thrift_application_exception_class_init (ThriftApplicationExceptionClass *class)
+{
+  ThriftStructClass *cls = THRIFT_STRUCT_CLASS(class);
+  cls->read = thrift_application_exception_read;
+  cls->write = thrift_application_exception_write;
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/thrift_application_exception.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/thrift_application_exception.h b/lib/c_glib/src/thrift/c_glib/thrift_application_exception.h
new file mode 100644
index 0000000..580f4fc
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/thrift_application_exception.h
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_APPLICATION_EXCEPTION_H
+#define _THRIFT_APPLICATION_EXCEPTION_H
+
+#include <glib-object.h>
+#include "thrift_struct.h"
+
+G_BEGIN_DECLS
+
+/*! \file thrift_application_exception.h
+ *  \brief C Implementation of a TApplicationException.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_APPLICATION_EXCEPTION (thrift_application_exception_get_type ())
+#define THRIFT_APPLICATION_EXCEPTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_APPLICATION_EXCEPTION, ThriftApplicationException))
+#define THRIFT_IS_APPLICATION_EXCEPTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_APPLICATION_EXCEPTION))
+#define THRIFT_APPLICATION_EXCEPTION_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_APPLICATION_EXCEPTION, ThriftApplicationExceptionClass))
+#define THRIFT_IS_APPLICATION_EXCEPTION_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_APPLICATION_EXCEPTION))
+#define THRIFT_APPLICATION_EXCEPTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_APPLICATION_EXCEPTION, ThriftApplicationExceptionClass))
+
+struct _ThriftApplicationException
+{
+  ThriftStruct parent;
+
+  /* public */
+  gint32 type;
+  gboolean __isset_type;
+  gchar *message;
+  gboolean __isset_message;
+};
+typedef struct _ThriftApplicationException ThriftApplicationException;
+
+struct _ThriftApplicationExceptionClass
+{
+  ThriftStructClass parent;
+};
+typedef struct _ThriftApplicationExceptionClass ThriftApplicationExceptionClass;
+
+GType thrift_application_exception_get_type (void);
+
+/* gerror codes */
+typedef enum
+{
+  THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN_METHOD,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_MESSAGE_TYPE,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_WRONG_METHOD_NAME,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_BAD_SEQUENCE_ID,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_MISSING_RESULT,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_INTERNAL_ERROR,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_PROTOCOL_ERROR,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_TRANSFORM,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_PROTOCOL,
+  THRIFT_APPLICATION_EXCEPTION_ERROR_UNSUPPORTED_CLIENT_TYPE
+} ThriftApplicationExceptionError;
+
+/* define error domain for GError */
+GQuark thrift_application_exception_error_quark (void);
+#define THRIFT_APPLICATION_EXCEPTION_ERROR (thrift_application_exception_error_quark ())
+
+G_END_DECLS
+
+#endif /* _THRIFT_APPLICATION_EXCEPTION_H */

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/thrift_struct.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/thrift_struct.c b/lib/c_glib/src/thrift/c_glib/thrift_struct.c
new file mode 100644
index 0000000..f24f2a1
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/thrift_struct.c
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <thrift/c_glib/thrift.h>
+#include "thrift_struct.h"
+
+G_DEFINE_ABSTRACT_TYPE(ThriftStruct, thrift_struct, G_TYPE_OBJECT)
+
+gint32
+thrift_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
+                    GError **error)
+{
+  g_return_val_if_fail (THRIFT_IS_STRUCT (object), -1);
+  return THRIFT_STRUCT_GET_CLASS (object)->read (object, protocol, error);
+}
+
+gint32
+thrift_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
+                     GError **error)
+{
+  g_return_val_if_fail (THRIFT_IS_STRUCT (object), -1);
+  return THRIFT_STRUCT_GET_CLASS (object)->write (object, protocol, error);
+}
+
+static void
+thrift_struct_class_init (ThriftStructClass *cls)
+{
+  cls->read = thrift_struct_read;
+  cls->write = thrift_struct_write;
+}
+
+static void
+thrift_struct_init (ThriftStruct *structure)
+{
+  THRIFT_UNUSED_VAR (structure);
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/thrift_struct.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/thrift_struct.h b/lib/c_glib/src/thrift/c_glib/thrift_struct.h
new file mode 100644
index 0000000..656cb54
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/thrift_struct.h
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef THRIFT_STRUCT_H
+#define THRIFT_STRUCT_H
+
+#include <glib-object.h>
+
+#include <thrift/c_glib/protocol/thrift_protocol.h>
+
+G_BEGIN_DECLS
+
+#define THRIFT_TYPE_STRUCT (thrift_struct_get_type ())
+#define THRIFT_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_STRUCT, ThriftStruct))
+#define THRIFT_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_STRUCT, ThriftStructClass))
+#define THRIFT_IS_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_STRUCT))
+#define THRIFT_IS_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_STRUCT))
+#define THRIFT_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_STRUCT, ThriftStructClass))
+
+/* struct */
+struct _ThriftStruct
+{
+  GObject parent;
+
+  /* private */
+};
+typedef struct _ThriftStruct ThriftStruct;
+
+struct _ThriftStructClass
+{
+  GObjectClass parent;
+
+  /* public */
+  gint32 (*read) (ThriftStruct *object, ThriftProtocol *protocol,
+                  GError **error);
+  gint32 (*write) (ThriftStruct *object, ThriftProtocol *protocol,
+                   GError **error);
+};
+typedef struct _ThriftStructClass ThriftStructClass;
+
+GType thrift_struct_get_type (void);
+
+gint32 thrift_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
+                           GError **error);
+
+gint32 thrift_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
+                            GError **error);
+G_END_DECLS
+
+#endif

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.c b/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.c
new file mode 100644
index 0000000..a32e5ad
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.c
@@ -0,0 +1,368 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/transport/thrift_transport.h>
+#include <thrift/c_glib/transport/thrift_buffered_transport.h>
+
+/* object properties */
+enum _ThriftBufferedTransportProperties
+{
+  PROP_0,
+  PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT,
+  PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE,
+  PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE
+};
+
+G_DEFINE_TYPE(ThriftBufferedTransport, thrift_buffered_transport, THRIFT_TYPE_TRANSPORT)
+
+/* implements thrift_transport_is_open */
+gboolean
+thrift_buffered_transport_is_open (ThriftTransport *transport)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+  return THRIFT_TRANSPORT_GET_CLASS (t->transport)->is_open (t->transport);
+}
+
+/* implements thrift_transport_open */
+gboolean
+thrift_buffered_transport_open (ThriftTransport *transport, GError **error)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+  return THRIFT_TRANSPORT_GET_CLASS (t->transport)->open (t->transport, error);
+}
+
+/* implements thrift_transport_close */
+gboolean
+thrift_buffered_transport_close (ThriftTransport *transport, GError **error)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+  return THRIFT_TRANSPORT_GET_CLASS (t->transport)->close (t->transport, error);
+}
+
+/* the actual read is "slow" because it calls the underlying transport */
+gint32
+thrift_buffered_transport_read_slow (ThriftTransport *transport, gpointer buf,
+                                     guint32 len, GError **error)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+  guint32 want = len;
+  guint32 got = 0;
+  guchar tmpdata[len];
+  guint32 have = t->r_buf->len;
+
+  // we shouldn't hit this unless the buffer doesn't have enough to read
+  assert (t->r_buf->len < want);
+
+  // first copy what we have in our buffer.
+  if (have > 0)
+  {
+    memcpy (buf, t->r_buf, t->r_buf->len);
+    want -= t->r_buf->len;
+    t->r_buf = g_byte_array_remove_range (t->r_buf, 0, t->r_buf->len);
+  }
+
+  // if the buffer is still smaller than what we want to read, then just
+  // read it directly.  otherwise, fill the buffer and then give out
+  // enough to satisfy the read.
+  if (t->r_buf_size < want)
+  {
+    got += THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
+                                                            tmpdata,
+                                                            want,
+                                                            error);
+
+    // copy the data starting from where we left off
+    memcpy (buf + have, tmpdata, got);
+    return got + have; 
+  } else {
+    got += THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
+                                                            tmpdata,
+                                                            want,
+                                                            error);
+    t->r_buf = g_byte_array_append (t->r_buf, tmpdata, got);
+    
+    // hand over what we have up to what the caller wants
+    guint32 give = want < t->r_buf->len ? want : t->r_buf->len;
+
+
+    memcpy (buf + len - want, t->r_buf->data, give);
+    t->r_buf = g_byte_array_remove_range (t->r_buf, 0, give);
+    want -= give;
+
+    return (len - want);
+  }
+}
+
+/* implements thrift_transport_read */
+gint32
+thrift_buffered_transport_read (ThriftTransport *transport, gpointer buf,
+                                guint32 len, GError **error)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+
+  /* if we have enough buffer data to fulfill the read, just use
+   * a memcpy */
+  if (len <= t->r_buf->len)
+  {
+    memcpy (buf, t->r_buf->data, len);
+    g_byte_array_remove_range (t->r_buf, 0, len);
+    return len;
+  }
+
+  return thrift_buffered_transport_read_slow (transport, buf, len, error);
+}
+
+/* implements thrift_transport_read_end
+ * called when write is complete.  nothing to do on our end. */
+gboolean
+thrift_buffered_transport_read_end (ThriftTransport *transport, GError **error)
+{
+  /* satisfy -Wall */
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+gboolean
+thrift_buffered_transport_write_slow (ThriftTransport *transport, gpointer buf,
+                                      guint32 len, GError **error)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+  guint32 have_bytes = t->w_buf->len;
+  guint32 space = t->w_buf_size - t->w_buf->len;
+
+  // we need two syscalls because the buffered data plus the buffer itself
+  // is too big.
+  if ((have_bytes + len >= 2*t->w_buf->len) || (have_bytes == 0))
+  {
+    if (have_bytes > 0)
+    {
+      THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
+                                                        t->w_buf->data,
+                                                        have_bytes,
+                                                        error);
+    }
+    THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
+                                                      buf, len, error);
+    if (t->w_buf->len > 0)
+    {
+      t->w_buf = g_byte_array_remove_range (t->w_buf, 0, t->w_buf->len);
+    }
+
+    return TRUE;
+  }
+
+  t->w_buf = g_byte_array_append (t->w_buf, buf, space);
+  THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
+                                                    t->w_buf->data,
+                                                    t->w_buf->len,
+                                                    error);
+
+  t->w_buf = g_byte_array_remove_range (t->w_buf, 0, t->w_buf->len);
+  t->w_buf = g_byte_array_append (t->w_buf, buf+space, len-space);
+
+  return TRUE;
+}
+
+/* implements thrift_transport_write */
+gboolean
+thrift_buffered_transport_write (ThriftTransport *transport,
+                                 const gpointer buf,
+                                 const guint32 len, GError **error)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+
+  /* the length of the current buffer plus the length of the data being read */
+  if (t->w_buf->len + len <= t->w_buf_size)
+  {
+    t->w_buf = g_byte_array_append (t->w_buf, buf, len);
+    return len;
+  }
+
+  return thrift_buffered_transport_write_slow (transport, buf, len, error);
+}
+
+/* implements thrift_transport_write_end
+ * called when write is complete.  nothing to do on our end. */
+gboolean
+thrift_buffered_transport_write_end (ThriftTransport *transport, GError **error)
+{
+  /* satisfy -Wall */
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+/* implements thrift_transport_flush */
+gboolean
+thrift_buffered_transport_flush (ThriftTransport *transport, GError **error)
+{
+  ThriftBufferedTransport *t = THRIFT_BUFFERED_TRANSPORT (transport);
+
+  if (t->w_buf != NULL && t->w_buf->len > 0)
+  {
+    // write the buffer and then empty it
+    THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
+                                                      t->w_buf->data,
+                                                      t->w_buf->len,
+                                                      error);
+    t->w_buf = g_byte_array_remove_range (t->w_buf, 0, t->w_buf->len);
+  }
+  THRIFT_TRANSPORT_GET_CLASS (t->transport)->flush (t->transport,
+                                                    error);
+
+  return TRUE;
+}
+
+/* initializes the instance */
+static void
+thrift_buffered_transport_init (ThriftBufferedTransport *transport)
+{
+  transport->transport = NULL;
+  transport->r_buf = g_byte_array_new ();
+  transport->w_buf = g_byte_array_new ();
+}
+
+/* destructor */
+static void
+thrift_buffered_transport_finalize (GObject *object)
+{
+  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
+
+  if (transport->r_buf != NULL)
+  {
+    g_byte_array_free (transport->r_buf, TRUE);
+  }
+  transport->r_buf = NULL;
+
+  if (transport->w_buf != NULL)
+  {
+    g_byte_array_free (transport->w_buf, TRUE);
+  }
+  transport->w_buf = NULL;
+}
+
+/* property accessor */
+void
+thrift_buffered_transport_get_property (GObject *object, guint property_id,
+                                        GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT:
+      g_value_set_object (value, transport->transport);
+      break;
+    case PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE:
+      g_value_set_uint (value, transport->r_buf_size);
+      break;
+    case PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE:
+      g_value_set_uint (value, transport->w_buf_size);
+      break;
+  }
+}
+
+/* property mutator */
+void
+thrift_buffered_transport_set_property (GObject *object, guint property_id,
+                                        const GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftBufferedTransport *transport = THRIFT_BUFFERED_TRANSPORT (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT:
+      transport->transport = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE:
+      transport->r_buf_size = g_value_get_uint (value);
+      break;
+    case PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE:
+      transport->w_buf_size = g_value_get_uint (value);
+      break;
+  }
+}
+
+/* initializes the class */
+static void
+thrift_buffered_transport_class_init (ThriftBufferedTransportClass *cls)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+  GParamSpec *param_spec = NULL;
+
+  /* setup accessors and mutators */
+  gobject_class->get_property = thrift_buffered_transport_get_property;
+  gobject_class->set_property = thrift_buffered_transport_set_property;
+
+  param_spec = g_param_spec_object ("transport", "transport (construct)",
+                                    "Thrift transport",
+                                    THRIFT_TYPE_TRANSPORT,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_BUFFERED_TRANSPORT_TRANSPORT,
+                                   param_spec);
+
+  param_spec = g_param_spec_uint ("r_buf_size",
+                                  "read buffer size (construct)",
+                                  "Set the read buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_BUFFERED_TRANSPORT_READ_BUFFER_SIZE,
+                                   param_spec);
+
+  param_spec = g_param_spec_uint ("w_buf_size",
+                                  "write buffer size (construct)",
+                                  "Set the write buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_BUFFERED_TRANSPORT_WRITE_BUFFER_SIZE,
+                                   param_spec);
+
+
+  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
+
+  gobject_class->finalize = thrift_buffered_transport_finalize;
+  ttc->is_open = thrift_buffered_transport_is_open;
+  ttc->open = thrift_buffered_transport_open;
+  ttc->close = thrift_buffered_transport_close;
+  ttc->read = thrift_buffered_transport_read;
+  ttc->read_end = thrift_buffered_transport_read_end;
+  ttc->write = thrift_buffered_transport_write;
+  ttc->write_end = thrift_buffered_transport_write_end;
+  ttc->flush = thrift_buffered_transport_flush;
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.h b/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.h
new file mode 100644
index 0000000..6abe10e
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_buffered_transport.h
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_BUFFERED_TRANSPORT_H
+#define _THRIFT_BUFFERED_TRANSPORT_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <thrift/c_glib/transport/thrift_transport.h>
+
+G_BEGIN_DECLS
+
+/*! \file thrift_buffered_transport.h
+ *  \brief Implementation of a Thrift buffered transport.  Subclasses
+ *         the ThriftTransport class.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_BUFFERED_TRANSPORT (thrift_buffered_transport_get_type ())
+#define THRIFT_BUFFERED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransport))
+#define THRIFT_IS_BUFFERED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT))
+#define THRIFT_BUFFERED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransportClass))
+#define THRIFT_IS_BUFFERED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_BUFFERED_TRANSPORT)
+#define THRIFT_BUFFERED_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_BUFFERED_TRANSPORT, ThriftBufferedTransportClass))
+
+/*!
+ * ThriftBufferedTransport  instance.
+ */
+struct _ThriftBufferedTransport
+{
+  ThriftTransport parent;
+
+  /* protected */
+  ThriftTransport *transport;
+
+  /* private */
+  GByteArray *r_buf;
+  GByteArray *w_buf;
+  guint32 r_buf_size;
+  guint32 w_buf_size;
+};
+typedef struct _ThriftBufferedTransport ThriftBufferedTransport;
+
+/*!
+ * ThriftBufferedTransport class.
+ */
+struct _ThriftBufferedTransportClass
+{
+  ThriftTransportClass parent;
+};
+typedef struct _ThriftBufferedTransportClass ThriftBufferedTransportClass;
+
+/* used by THRIFT_TYPE_BUFFERED_TRANSPORT */
+GType thrift_buffered_transport_get_type (void);
+
+G_END_DECLS
+
+#endif

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.c b/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.c
new file mode 100644
index 0000000..a58b875
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.c
@@ -0,0 +1,360 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/transport/thrift_transport.h>
+#include <thrift/c_glib/transport/thrift_framed_transport.h>
+
+/* object properties */
+enum _ThriftFramedTransportProperties
+{
+  PROP_0,
+  PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT,
+  PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE,
+  PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE
+};
+
+G_DEFINE_TYPE(ThriftFramedTransport, thrift_framed_transport, THRIFT_TYPE_TRANSPORT)
+
+/* implements thrift_transport_is_open */
+gboolean
+thrift_framed_transport_is_open (ThriftTransport *transport)
+{
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+  return THRIFT_TRANSPORT_GET_CLASS (t->transport)->is_open (t->transport);
+}
+
+/* implements thrift_transport_open */
+gboolean
+thrift_framed_transport_open (ThriftTransport *transport, GError **error)
+{
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+  return THRIFT_TRANSPORT_GET_CLASS (t->transport)->open (t->transport, error);
+}
+
+/* implements thrift_transport_close */
+gboolean
+thrift_framed_transport_close (ThriftTransport *transport, GError **error)
+{
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+  return THRIFT_TRANSPORT_GET_CLASS (t->transport)->close (t->transport, error);
+}
+
+/* reads a frame and puts it into the buffer */
+gboolean
+thrift_framed_transport_read_frame (ThriftTransport *transport,
+                                    GError **error)
+{
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+  gint32 sz, bytes;
+
+  /* read the size */
+  THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
+                                                   (guint32 *) &sz,
+                                                   sizeof (sz), error);
+  sz = ntohl (sz);
+
+  /* create a buffer to hold the data and read that much data */
+  guchar tmpdata[sz];
+  bytes = THRIFT_TRANSPORT_GET_CLASS (t->transport)->read (t->transport,
+                                                           tmpdata,
+                                                           sz,
+                                                           error);
+
+  /* add the data to the buffer */
+  g_byte_array_append (t->r_buf, tmpdata, bytes);
+
+  return TRUE;
+}
+
+/* the actual read is "slow" because it calls the underlying transport */
+gint32
+thrift_framed_transport_read_slow (ThriftTransport *transport, gpointer buf,
+                                   guint32 len, GError **error)
+{
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+  guint32 want = len;
+  guint32 have = t->r_buf->len;
+
+  // we shouldn't hit this unless the buffer doesn't have enough to read
+  assert (t->r_buf->len < want);
+
+  // first copy what we have in our buffer, if there is anything left
+  if (have > 0)
+  {
+    memcpy (buf, t->r_buf, t->r_buf->len);
+    want -= t->r_buf->len;
+    t->r_buf = g_byte_array_remove_range (t->r_buf, 0, t->r_buf->len);
+  }
+
+  // read a frame of input and buffer it
+  thrift_framed_transport_read_frame (transport, error);
+
+  // hand over what we have up to what the caller wants
+  guint32 give = want < t->r_buf->len ? want : t->r_buf->len;
+
+  // copy the data into the buffer
+  memcpy (buf + len - want, t->r_buf->data, give);
+  t->r_buf = g_byte_array_remove_range (t->r_buf, 0, give);
+  want -= give;
+
+  return (len - want);
+}
+
+/* implements thrift_transport_read */
+gint32
+thrift_framed_transport_read (ThriftTransport *transport, gpointer buf,
+                              guint32 len, GError **error)
+{
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+
+  /* if we have enough buffer data to fulfill the read, just use
+   * a memcpy from the buffer */
+  if (len <= t->r_buf->len)
+  {
+    memcpy (buf, t->r_buf->data, len);
+    g_byte_array_remove_range (t->r_buf, 0, len);
+    return len;
+  }
+
+  return thrift_framed_transport_read_slow (transport, buf, len, error);
+}
+
+/* implements thrift_transport_read_end
+ * called when read is complete.  nothing to do on our end. */
+gboolean
+thrift_framed_transport_read_end (ThriftTransport *transport, GError **error)
+{
+  /* satisfy -Wall */
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+gboolean
+thrift_framed_transport_write_slow (ThriftTransport *transport, gpointer buf,
+                                    guint32 len, GError **error)
+{
+  THRIFT_UNUSED_VAR (error);
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+
+  // append the data to the buffer and we're done
+  g_byte_array_append (t->w_buf, buf, len);
+
+  return TRUE;
+}
+
+/* implements thrift_transport_write */
+gboolean
+thrift_framed_transport_write (ThriftTransport *transport,
+                               const gpointer buf,     
+                               const guint32 len, GError **error)
+{
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+
+  /* the length of the current buffer plus the length of the data being read */
+  if (t->w_buf->len + len <= t->w_buf_size)
+  {
+    t->w_buf = g_byte_array_append (t->w_buf, buf, len);
+    return TRUE;
+  }
+
+  return thrift_framed_transport_write_slow (transport, buf, len, error);
+}
+
+/* implements thrift_transport_write_end
+ * called when write is complete.  nothing to do on our end. */
+gboolean
+thrift_framed_transport_write_end (ThriftTransport *transport, GError **error)
+{
+  /* satisfy -Wall */
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+/* implements thrift_transport_flush */
+gboolean
+thrift_framed_transport_flush (ThriftTransport *transport, GError **error)
+{
+  ThriftFramedTransport *t = THRIFT_FRAMED_TRANSPORT (transport);
+  gint32 sz_hbo, sz_nbo;
+
+  // get the size of the frame in host and network byte order
+  sz_hbo = t->w_buf->len + sizeof(sz_nbo);
+  sz_nbo = (gint32) htonl ((guint32) t->w_buf->len);
+
+  // copy the size of the frame and then the frame itself
+  guchar tmpdata[sz_hbo];
+  memcpy (tmpdata, (guint8 *) &sz_nbo, sizeof (sz_nbo));
+
+  if (t->w_buf->len > 0)
+  {
+    memcpy (tmpdata + sizeof (sz_nbo), t->w_buf->data, t->w_buf->len);
+    t->w_buf = g_byte_array_remove_range (t->w_buf, 0, t->w_buf->len);
+  }
+    
+  // write the buffer and then empty it
+  THRIFT_TRANSPORT_GET_CLASS (t->transport)->write (t->transport,
+                                                    tmpdata, sz_hbo,
+                                                    error);
+
+  THRIFT_TRANSPORT_GET_CLASS (t->transport)->flush (t->transport,
+                                                    error);
+
+  return TRUE;
+}
+
+/* initializes the instance */
+static void
+thrift_framed_transport_init (ThriftFramedTransport *transport)
+{
+  transport->transport = NULL;
+  transport->r_buf = g_byte_array_new ();
+  transport->w_buf = g_byte_array_new ();
+}
+
+/* destructor */
+static void
+thrift_framed_transport_finalize (GObject *object)
+{
+  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
+
+  if (transport->r_buf != NULL)
+  {
+    g_byte_array_free (transport->r_buf, TRUE);
+  }
+  transport->r_buf = NULL;
+
+  if (transport->w_buf != NULL)
+  {
+    g_byte_array_free (transport->w_buf, TRUE);
+  }
+  transport->w_buf = NULL;
+}
+
+/* property accessor */
+void
+thrift_framed_transport_get_property (GObject *object, guint property_id,
+                                      GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT:
+      g_value_set_object (value, transport->transport);
+      break;
+    case PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE:
+      g_value_set_uint (value, transport->r_buf_size);
+      break;
+    case PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE:
+      g_value_set_uint (value, transport->w_buf_size);
+      break;
+  }
+}
+
+/* property mutator */
+void
+thrift_framed_transport_set_property (GObject *object, guint property_id,
+                                      const GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftFramedTransport *transport = THRIFT_FRAMED_TRANSPORT (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT:
+      transport->transport = g_value_get_object (value);
+      break;
+    case PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE:
+      transport->r_buf_size = g_value_get_uint (value);
+      break;
+    case PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE:
+      transport->w_buf_size = g_value_get_uint (value);
+      break;
+  }
+}
+
+/* initializes the class */
+static void
+thrift_framed_transport_class_init (ThriftFramedTransportClass *cls)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+  GParamSpec *param_spec = NULL;
+
+  /* setup accessors and mutators */
+  gobject_class->get_property = thrift_framed_transport_get_property;
+  gobject_class->set_property = thrift_framed_transport_set_property;
+
+  param_spec = g_param_spec_object ("transport", "transport (construct)",
+                                    "Thrift transport",
+                                    THRIFT_TYPE_TRANSPORT,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_FRAMED_TRANSPORT_TRANSPORT,
+                                   param_spec);
+
+  param_spec = g_param_spec_uint ("r_buf_size",
+                                  "read buffer size (construct)",
+                                  "Set the read buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_FRAMED_TRANSPORT_READ_BUFFER_SIZE,
+                                   param_spec);
+
+  param_spec = g_param_spec_uint ("w_buf_size",
+                                  "write buffer size (construct)",
+                                  "Set the write buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_FRAMED_TRANSPORT_WRITE_BUFFER_SIZE,
+                                   param_spec);
+
+
+  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
+
+  gobject_class->finalize = thrift_framed_transport_finalize;
+  ttc->is_open = thrift_framed_transport_is_open;
+  ttc->open = thrift_framed_transport_open;
+  ttc->close = thrift_framed_transport_close;
+  ttc->read = thrift_framed_transport_read;
+  ttc->read_end = thrift_framed_transport_read_end;
+  ttc->write = thrift_framed_transport_write;
+  ttc->write_end = thrift_framed_transport_write_end;
+  ttc->flush = thrift_framed_transport_flush;
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.h b/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.h
new file mode 100644
index 0000000..055f4f0
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_framed_transport.h
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_FRAMED_TRANSPORT_H
+#define _THRIFT_FRAMED_TRANSPORT_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <thrift/c_glib/transport/thrift_transport.h>
+
+G_BEGIN_DECLS
+
+/*! \file thrift_framed_transport.h
+ *  \brief Implementation of a Thrift framed transport.  Subclasses
+ *         the ThriftTransport class.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_FRAMED_TRANSPORT (thrift_framed_transport_get_type ())
+#define THRIFT_FRAMED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransport))
+#define THRIFT_IS_FRAMED_TRANSPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_FRAMED_TRANSPORT))
+#define THRIFT_FRAMED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransportClass))
+#define THRIFT_IS_FRAMED_TRANSPORT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_FRAMED_TRANSPORT)
+#define THRIFT_FRAMED_TRANSPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_FRAMED_TRANSPORT, ThriftFramedTransportClass))
+
+/*!
+ * ThriftFramedTransport instance.
+ */
+struct _ThriftFramedTransport
+{
+  ThriftTransport parent;
+
+  /* protected */
+  ThriftTransport *transport;
+
+  /* private */
+  GByteArray *r_buf;
+  GByteArray *w_buf;
+  guint32 r_buf_size;
+  guint32 w_buf_size;
+};
+typedef struct _ThriftFramedTransport ThriftFramedTransport;
+
+/*!
+ * ThriftFramedTransport class.
+ */
+struct _ThriftFramedTransportClass
+{
+  ThriftTransportClass parent;
+};
+typedef struct _ThriftFramedTransportClass ThriftFramedTransportClass;
+
+/* used by THRIFT_TYPE_FRAMED_TRANSPORT */
+GType thrift_framed_transport_get_type (void);
+
+G_END_DECLS
+
+#endif

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.c
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.c b/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.c
new file mode 100644
index 0000000..aa05e96
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.c
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/transport/thrift_transport.h>
+#include <thrift/c_glib/transport/thrift_memory_buffer.h>
+
+/* object properties */
+enum _ThriftMemoryBufferProperties
+{
+  PROP_0,
+  PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE,
+};
+
+G_DEFINE_TYPE(ThriftMemoryBuffer, thrift_memory_buffer, THRIFT_TYPE_TRANSPORT)
+
+/* implements thrift_transport_is_open */
+gboolean
+thrift_memory_buffer_is_open (ThriftTransport *transport)
+{
+  THRIFT_UNUSED_VAR (transport);
+  return TRUE;
+}
+
+/* implements thrift_transport_open */
+gboolean
+thrift_memory_buffer_open (ThriftTransport *transport, GError **error)
+{
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+/* implements thrift_transport_close */
+gboolean
+thrift_memory_buffer_close (ThriftTransport *transport, GError **error)
+{
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+/* implements thrift_transport_read */
+gint32
+thrift_memory_buffer_read (ThriftTransport *transport, gpointer buf,
+                           guint32 len, GError **error)
+{
+  THRIFT_UNUSED_VAR (error);
+  ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (transport);
+  guint32 give = len; 
+
+  /* if the requested bytes are more than what we have available,
+   * just give all that we have the buffer */
+  if (t->buf->len < len)
+  {
+    give = t->buf->len;
+  }
+
+  memcpy (buf, t->buf->data, give);
+  g_byte_array_remove_range (t->buf, 0, give);
+
+  return give;
+}
+
+/* implements thrift_transport_read_end
+ * called when read is complete.  nothing to do on our end. */
+gboolean
+thrift_memory_buffer_read_end (ThriftTransport *transport, GError **error)
+{
+  /* satisfy -Wall */
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+/* implements thrift_transport_write */
+gboolean
+thrift_memory_buffer_write (ThriftTransport *transport,
+                            const gpointer buf,     
+                            const guint32 len, GError **error)
+{
+  THRIFT_UNUSED_VAR (error);
+
+  ThriftMemoryBuffer *t = THRIFT_MEMORY_BUFFER (transport);
+
+  /* return an exception if the buffer doesn't have enough space. */
+  if (len > t->buf_size - t->buf->len)
+  {
+    g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_SEND,
+                 "unable to write %d bytes to buffer of length %d",
+                 len, t->buf_size);
+    return FALSE;
+  } else {
+    t->buf = g_byte_array_append (t->buf, buf, len);
+    return TRUE;
+  }
+}
+
+/* implements thrift_transport_write_end
+ * called when write is complete.  nothing to do on our end. */
+gboolean
+thrift_memory_buffer_write_end (ThriftTransport *transport, GError **error)
+{
+  /* satisfy -Wall */
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+  return TRUE;
+}
+
+/* implements thrift_transport_flush */
+gboolean
+thrift_memory_buffer_flush (ThriftTransport *transport, GError **error)
+{
+  THRIFT_UNUSED_VAR (transport);
+  THRIFT_UNUSED_VAR (error);
+
+  return TRUE;
+}
+
+/* initializes the instance */
+static void
+thrift_memory_buffer_init (ThriftMemoryBuffer *transport)
+{
+  transport->buf = g_byte_array_new ();
+}
+
+/* destructor */
+static void
+thrift_memory_buffer_finalize (GObject *object)
+{
+  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
+
+  if (transport->buf != NULL)
+  {
+    g_byte_array_free (transport->buf, TRUE);
+  }
+  transport->buf = NULL;
+}
+
+/* property accessor */
+void
+thrift_memory_buffer_get_property (GObject *object, guint property_id,
+                                   GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
+      g_value_set_uint (value, transport->buf_size);
+      break;
+  }
+}
+
+/* property mutator */
+void
+thrift_memory_buffer_set_property (GObject *object, guint property_id,
+                                   const GValue *value, GParamSpec *pspec)
+{
+  THRIFT_UNUSED_VAR (pspec);
+  ThriftMemoryBuffer *transport = THRIFT_MEMORY_BUFFER (object);
+
+  switch (property_id)
+  {
+    case PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE:
+      transport->buf_size = g_value_get_uint (value);
+      break;
+  }
+}
+
+/* initializes the class */
+static void
+thrift_memory_buffer_class_init (ThriftMemoryBufferClass *cls)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+  GParamSpec *param_spec = NULL;
+
+  /* setup accessors and mutators */
+  gobject_class->get_property = thrift_memory_buffer_get_property;
+  gobject_class->set_property = thrift_memory_buffer_set_property;
+
+  param_spec = g_param_spec_uint ("buf_size",
+                                  "buffer size (construct)",
+                                  "Set the read buffer size",
+                                  0, /* min */
+                                  1048576, /* max, 1024*1024 */
+                                  512, /* default value */
+                                  G_PARAM_CONSTRUCT_ONLY |
+                                  G_PARAM_READWRITE);
+  g_object_class_install_property (gobject_class,
+                                   PROP_THRIFT_MEMORY_BUFFER_BUFFER_SIZE,
+                                   param_spec);
+
+  ThriftTransportClass *ttc = THRIFT_TRANSPORT_CLASS (cls);
+
+  gobject_class->finalize = thrift_memory_buffer_finalize;
+  ttc->is_open = thrift_memory_buffer_is_open;
+  ttc->open = thrift_memory_buffer_open;
+  ttc->close = thrift_memory_buffer_close;
+  ttc->read = thrift_memory_buffer_read;
+  ttc->read_end = thrift_memory_buffer_read_end;
+  ttc->write = thrift_memory_buffer_write;
+  ttc->write_end = thrift_memory_buffer_write_end;
+  ttc->flush = thrift_memory_buffer_flush;
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e3da7683/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.h
----------------------------------------------------------------------
diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.h b/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.h
new file mode 100644
index 0000000..7214d30
--- /dev/null
+++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_memory_buffer.h
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_MEMORY_BUFFER_H
+#define _THRIFT_MEMORY_BUFFER_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <thrift/c_glib/transport/thrift_transport.h>
+
+G_BEGIN_DECLS
+
+/*! \file thrift_memory_buffer.h
+ *  \brief Implementation of a Thrift memory buffer transport.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_MEMORY_BUFFER (thrift_memory_buffer_get_type ())
+#define THRIFT_MEMORY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBuffer))
+#define THRIFT_IS_MEMORY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_MEMORY_BUFFER))
+#define THRIFT_MEMORY_BUFFER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBufferClass))
+#define THRIFT_IS_MEMORY_BUFFER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_MEMORY_BUFFER)
+#define THRIFT_MEMORY_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_MEMORY_BUFFER, ThriftMemoryBufferClass))
+
+/*!
+ * ThriftMemoryBuffer instance.
+ */
+struct _ThriftMemoryBuffer
+{
+  ThriftTransport parent;
+
+  /* private */
+  GByteArray *buf;
+  guint32 buf_size;
+};
+typedef struct _ThriftMemoryBuffer ThriftMemoryBuffer;
+
+/*!
+ * ThriftMemoryBuffer class.
+ */
+struct _ThriftMemoryBufferClass
+{
+  ThriftTransportClass parent;
+};
+typedef struct _ThriftMemoryBufferClass ThriftMemoryBufferClass;
+
+/* used by THRIFT_TYPE_MEMORY_BUFFER */
+GType thrift_memory_buffer_get_type (void);
+
+G_END_DECLS
+
+#endif