merge changes for 0.6 rc2

git-svn-id: https://svn.apache.org/repos/asf/thrift/branches/0.6.x@1065464 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/csharp/src/Transport/TFramedTransport.cs b/lib/csharp/src/Transport/TFramedTransport.cs
index b7ad5f2..e259f5a 100644
--- a/lib/csharp/src/Transport/TFramedTransport.cs
+++ b/lib/csharp/src/Transport/TFramedTransport.cs
@@ -24,9 +24,12 @@
 	public class TFramedTransport : TTransport
 	{
 		protected TTransport transport = null;
-		protected MemoryStream writeBuffer = new MemoryStream(1024);
+		protected MemoryStream writeBuffer;
 		protected MemoryStream readBuffer = null;
 
+		private const int header_size = 4;
+		private static byte[] header_dummy = new byte[header_size]; // used as header placeholder while initilizing new write buffer
+
 		public class Factory : TTransportFactory
 		{
 			public override TTransport GetTransport(TTransport trans)
@@ -35,7 +38,12 @@
 			}
 		}
 
-		public TFramedTransport(TTransport transport)
+		public TFramedTransport()
+		{
+			InitWriteBuffer();
+		}
+
+		public TFramedTransport(TTransport transport) : this()
 		{
 			this.transport = transport;
 		}
@@ -77,8 +85,8 @@
 
 		private void ReadFrame()
 		{
-			byte[] i32rd = new byte[4];
-			transport.ReadAll(i32rd, 0, 4);
+			byte[] i32rd = new byte[header_size];
+			transport.ReadAll(i32rd, 0, header_size);
 			int size =
 				((i32rd[0] & 0xff) << 24) |
 				((i32rd[1] & 0xff) << 16) |
@@ -99,16 +107,31 @@
 		{
 			byte[] buf = writeBuffer.GetBuffer();
 			int len = (int)writeBuffer.Length;
-			writeBuffer = new MemoryStream(writeBuffer.Capacity);
+			int data_len = len - header_size;
+			if ( data_len < 0 )
+				throw new System.InvalidOperationException (); // logic error actually
 
-			byte[] i32out = new byte[4];
-			i32out[0] = (byte)(0xff & (len >> 24));
-			i32out[1] = (byte)(0xff & (len >> 16));
-			i32out[2] = (byte)(0xff & (len >> 8));
-			i32out[3] = (byte)(0xff & (len));
-			transport.Write(i32out, 0, 4);
+			InitWriteBuffer();
+
+			// Inject message header into the reserved buffer space
+			buf[0] = (byte)(0xff & (data_len >> 24));
+			buf[1] = (byte)(0xff & (data_len >> 16));
+			buf[2] = (byte)(0xff & (data_len >> 8));
+			buf[3] = (byte)(0xff & (data_len));
+
+			// Send the entire message at once
 			transport.Write(buf, 0, len);
+
 			transport.Flush();
 		}
+
+		private void InitWriteBuffer ()
+		{
+			// Create new buffer instance
+			writeBuffer = new MemoryStream(1024);
+
+			// Reserve space for message header to be put right before sending it out
+			writeBuffer.Write ( header_dummy, 0, header_size );
+		}
 	}
 }
diff --git a/lib/java/src/org/apache/thrift/async/TAsyncClientManager.java b/lib/java/src/org/apache/thrift/async/TAsyncClientManager.java
index b28c312..98f7194 100644
--- a/lib/java/src/org/apache/thrift/async/TAsyncClientManager.java
+++ b/lib/java/src/org/apache/thrift/async/TAsyncClientManager.java
@@ -183,7 +183,6 @@
 
   /** Comparator used in TreeSet */
   private static class TAsyncMethodCallTimeoutComparator implements Comparator<TAsyncMethodCall> {
-    @Override
     public int compare(TAsyncMethodCall left, TAsyncMethodCall right) {
       if (left.getTimeoutTimestamp() == right.getTimeoutTimestamp()) {
         return (int)(left.getSequenceId() - right.getSequenceId());
diff --git a/lib/js/thrift.js b/lib/js/thrift.js
index 9b92658..c06e27a 100644
--- a/lib/js/thrift.js
+++ b/lib/js/thrift.js
@@ -713,5 +713,20 @@
    
 }
 
+Thrift.objectLength = function(obj) {
+  var length = 0;
+  for (k in obj) {
+    if (obj.hasOwnProperty(k)) {
+      length++;
+    }
+  }
+  return length;
+}
 
-
+Thirft.inherits = function(constructor, superConstructor) {
+  // Prototypal Inheritance
+  // http://javascript.crockford.com/prototypal.html
+  function F() {}
+  F.prototype = superConstructor.prototype;
+  constructor.prototype = new F();
+}
diff --git a/lib/nodejs/lib/thrift/thrift.js b/lib/nodejs/lib/thrift/thrift.js
index 73f772b..53ca106 100644
--- a/lib/nodejs/lib/thrift/thrift.js
+++ b/lib/nodejs/lib/thrift/thrift.js
@@ -85,7 +85,7 @@
           case 1:
               if( ret.ftype == Type.STRING ){
                   ret = input.readString()
-                  this.message = ret.value
+                  this.message = ret
               } else {
                   ret = input.skip(ret.ftype)
               }
@@ -94,7 +94,7 @@
           case 2:
               if( ret.ftype == Type.I32 ){
                   ret = input.readI32()
-                  this.type = ret.value
+                  this.type = ret
               } else {
                   ret   = input.skip(ret.ftype)
               }
@@ -128,3 +128,11 @@
   output.writeFieldStop()
   output.writeStructEnd()
 }
+
+exports.objectLength = function(obj) {
+  return Object.keys(obj).length;
+}
+
+exports.inherits = function(constructor, superConstructor) {
+  sys.inherits(constructor, superConstructor);
+}