thrift-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bryanduxb...@apache.org
Subject svn commit: r761849 [1/2] - in /incubator/thrift/trunk: compiler/cpp/src/generate/ lib/rb/ lib/rb/benchmark/ lib/rb/ext/ lib/rb/lib/ lib/rb/lib/thrift/ lib/rb/lib/thrift/protocol/ lib/rb/lib/thrift/serializer/ lib/rb/lib/thrift/server/ lib/rb/lib/thrif...
Date Sat, 04 Apr 2009 00:58:05 GMT
Author: bryanduxbury
Date: Sat Apr  4 00:58:03 2009
New Revision: 761849

URL: http://svn.apache.org/viewvc?rev=761849&view=rev
Log:
THRIFT-276. rb: Ruby libraries should have one class per file

This monster of a patch moves all the classes into their own files and specs as appropriate. Additionally, it concentrates all the requires into thrift.rb, removing the need to require any other file. (Changes were made to the compiler to reflect this reduced requirement.)

Added:
    incubator/thrift/trunk/lib/rb/lib/thrift/protocol/base_protocol.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/serializer/
    incubator/thrift/trunk/lib/rb/lib/thrift/serializer/deserializer.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/serializer/serializer.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server/base_server.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server/mongrel_http_server.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblocking_server.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server/simple_server.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server/thread_pool_server.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server/threaded_server.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_server_transport.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_transport.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/buffered_transport.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/framed_transport.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/io_stream_transport.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/server_socket.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_server_socket.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_socket.rb
    incubator/thrift/trunk/lib/rb/spec/base_protocol_spec.rb
    incubator/thrift/trunk/lib/rb/spec/base_transport_spec.rb
    incubator/thrift/trunk/lib/rb/spec/binary_protocol_accelerated_spec.rb
    incubator/thrift/trunk/lib/rb/spec/binary_protocol_spec.rb
    incubator/thrift/trunk/lib/rb/spec/binary_protocol_spec_shared.rb
    incubator/thrift/trunk/lib/rb/spec/http_client_spec.rb
    incubator/thrift/trunk/lib/rb/spec/mongrel_http_server_spec.rb
    incubator/thrift/trunk/lib/rb/spec/nonblocking_server_spec.rb
    incubator/thrift/trunk/lib/rb/spec/server_socket_spec.rb
    incubator/thrift/trunk/lib/rb/spec/unix_socket_spec.rb
Removed:
    incubator/thrift/trunk/lib/rb/lib/thrift/protocol.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binaryprotocol.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binaryprotocolaccelerated.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/serializer.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server/httpserver.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblockingserver.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/httpclient.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/unixsocket.rb
    incubator/thrift/trunk/lib/rb/spec/binaryprotocol_spec.rb
    incubator/thrift/trunk/lib/rb/spec/binaryprotocol_spec_shared.rb
    incubator/thrift/trunk/lib/rb/spec/binaryprotocolaccelerated_spec.rb
    incubator/thrift/trunk/lib/rb/spec/httpclient_spec.rb
    incubator/thrift/trunk/lib/rb/spec/httpserver_spec.rb
    incubator/thrift/trunk/lib/rb/spec/nonblockingserver_spec.rb
    incubator/thrift/trunk/lib/rb/spec/protocol_spec.rb
    incubator/thrift/trunk/lib/rb/spec/transport_spec.rb
    incubator/thrift/trunk/lib/rb/spec/unixsocket_spec.rb
Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc
    incubator/thrift/trunk/lib/rb/Manifest
    incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb
    incubator/thrift/trunk/lib/rb/benchmark/client.rb
    incubator/thrift/trunk/lib/rb/benchmark/server.rb
    incubator/thrift/trunk/lib/rb/benchmark/thin_server.rb
    incubator/thrift/trunk/lib/rb/ext/memory_buffer.c
    incubator/thrift/trunk/lib/rb/ext/protocol.c
    incubator/thrift/trunk/lib/rb/lib/thrift.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/protocol/compact_protocol.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb
    incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb
    incubator/thrift/trunk/lib/rb/script/proto_benchmark.rb
    incubator/thrift/trunk/lib/rb/script/read_struct.rb
    incubator/thrift/trunk/lib/rb/script/write_struct.rb
    incubator/thrift/trunk/lib/rb/spec/compact_protocol_spec.rb
    incubator/thrift/trunk/lib/rb/spec/serializer_spec.rb
    incubator/thrift/trunk/lib/rb/spec/server_spec.rb
    incubator/thrift/trunk/lib/rb/spec/socket_spec.rb
    incubator/thrift/trunk/lib/rb/spec/spec_helper.rb
    incubator/thrift/trunk/lib/rb/spec/struct_spec.rb

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc Sat Apr  4 00:58:03 2009
@@ -155,7 +155,6 @@
    */
 
   std::string rb_autogen_comment();
-  std::string rb_imports();
   std::string render_includes();
   std::string declare_field(t_field* tfield);
   std::string type_name(t_type* ttype);
@@ -214,13 +213,11 @@
   // Print header
   f_types_ <<
     rb_autogen_comment() << endl <<
-    rb_imports() << endl <<
     render_includes() << endl;
     begin_namespace(f_types_, ruby_modules(program_));
 
   f_consts_ <<
     rb_autogen_comment() << endl <<
-    rb_imports() << endl <<
     "require File.dirname(__FILE__) + '/" << program_name_ << "_types'" << endl <<
     endl;
     begin_namespace(f_consts_, ruby_modules(program_));
@@ -255,14 +252,6 @@
 }
 
 /**
- * Prints standard thrift imports
- */
-string t_rb_generator::rb_imports() {
-  return
-    string("require 'thrift/protocol'");
-}
-
-/**
  * Closes the type files
  */
 void t_rb_generator::close_generator() {
@@ -638,8 +627,7 @@
 
   f_service_ <<
     rb_autogen_comment() << endl <<
-    "require 'thrift'" << endl <<
-    rb_imports() << endl;
+    "require 'thrift'" << endl;
 
   if (tservice->get_extends() != NULL) {
     f_service_ <<

Modified: incubator/thrift/trunk/lib/rb/Manifest
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/Manifest?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/Manifest (original)
+++ incubator/thrift/trunk/lib/rb/Manifest Sat Apr  4 00:58:03 2009
@@ -1,9 +1,6 @@
 benchmark/benchmark.rb
 benchmark/Benchmark.thrift
 benchmark/client.rb
-benchmark/gen-rb/Benchmark_constants.rb
-benchmark/gen-rb/Benchmark_types.rb
-benchmark/gen-rb/BenchmarkService.rb
 benchmark/server.rb
 benchmark/thin_server.rb
 CHANGELOG
@@ -26,36 +23,45 @@
 lib/thrift/core_ext.rb
 lib/thrift/exceptions.rb
 lib/thrift/processor.rb
-lib/thrift/protocol/binaryprotocol.rb
-lib/thrift/protocol/binaryprotocolaccelerated.rb
+lib/thrift/protocol/binary_protocol_accelerated.rb
+lib/thrift/protocol/binary_protocol.rb
 lib/thrift/protocol/compact_protocol.rb
 lib/thrift/protocol.rb
-lib/thrift/serializer.rb
-lib/thrift/server/httpserver.rb
-lib/thrift/server/nonblockingserver.rb
+lib/thrift/serializer/serializer.rb
+lib/thrift/serializer/deserializer.rb
+lib/thrift/server/mongrel_http_server.rb
+lib/thrift/server/nonblocking_server.rb
 lib/thrift/server.rb
 lib/thrift/struct.rb
 lib/thrift/thrift_native.rb
-lib/thrift/transport/httpclient.rb
-lib/thrift/transport/socket.rb
-lib/thrift/transport/unixsocket.rb
+lib/thrift/transport/buffered_transport.rb
+lib/thrift/transport/framed_transport.rb
+lib/thrift/transport/http_client_transport.rb
+lib/thrift/transport/io_stream_transport.rb
+lib/thrift/transport/memory_buffer_transport.rb
 lib/thrift/transport.rb
 lib/thrift/types.rb
 lib/thrift.rb
 Manifest
+Rakefile
 README
-spec/binaryprotocol_spec.rb
-spec/binaryprotocol_spec_shared.rb
-spec/binaryprotocolaccelerated_spec.rb
+script/proto_benchmark.rb
+script/read_struct.rb
+script/write_struct.rb
+setup.rb
+spec/binary_protocol_accelerated_spec.rb
+spec/binary_protocol_spec.rb
+spec/binary_protocol_spec_shared.rb
 spec/client_spec.rb
 spec/compact_protocol_spec.rb
 spec/exception_spec.rb
-spec/httpclient_spec.rb
-spec/httpserver_spec.rb
-spec/nonblockingserver_spec.rb
+spec/http_client_spec.rb
+spec/mongrel_http_server_spec.rb
+spec/nonblocking_server_spec.rb
 spec/processor_spec.rb
 spec/protocol_spec.rb
 spec/serializer_spec.rb
+spec/server_socket_spec.rb
 spec/server_spec.rb
 spec/socket_spec.rb
 spec/socket_spec_shared.rb
@@ -64,4 +70,4 @@
 spec/ThriftSpec.thrift
 spec/transport_spec.rb
 spec/types_spec.rb
-spec/unixsocket_spec.rb
+spec/unix_socket_spec.rb

Modified: incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/benchmark.rb Sat Apr  4 00:58:03 2009
@@ -20,8 +20,6 @@
 require 'rubygems'
 $:.unshift File.dirname(__FILE__) + '/../lib'
 require 'thrift'
-require 'thrift/server/nonblockingserver'
-require 'thrift/transport/unixsocket'
 require 'stringio'
 
 HOST = '127.0.0.1'

Modified: incubator/thrift/trunk/lib/rb/benchmark/client.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/client.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/client.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/client.rb Sat Apr  4 00:58:03 2009
@@ -19,7 +19,6 @@
 
 $:.unshift File.dirname(__FILE__) + '/../lib'
 require 'thrift'
-require 'thrift/server/nonblockingserver'
 $:.unshift File.dirname(__FILE__) + "/gen-rb"
 require 'BenchmarkService'
 

Modified: incubator/thrift/trunk/lib/rb/benchmark/server.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/server.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/server.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/server.rb Sat Apr  4 00:58:03 2009
@@ -19,7 +19,6 @@
 
 $:.unshift File.dirname(__FILE__) + '/../lib'
 require 'thrift'
-require 'thrift/server/nonblockingserver'
 $:.unshift File.dirname(__FILE__) + "/gen-rb"
 require 'BenchmarkService'
 
@@ -41,8 +40,8 @@
     handler = BenchmarkHandler.new
     processor = ThriftBenchmark::BenchmarkService::Processor.new(handler)
     transport = ServerSocket.new(host, port)
-    transportFactory = FramedTransportFactory.new
-    args = [processor, transport, transportFactory, nil, 20]
+    transport_factory = FramedTransportFactory.new
+    args = [processor, transport, transport_factory, nil, 20]
     if serverClass == NonblockingServer
       logger = Logger.new(STDERR)
       logger.level = Logger::WARN

Modified: incubator/thrift/trunk/lib/rb/benchmark/thin_server.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/benchmark/thin_server.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/benchmark/thin_server.rb (original)
+++ incubator/thrift/trunk/lib/rb/benchmark/thin_server.rb Sat Apr  4 00:58:03 2009
@@ -19,7 +19,6 @@
 
 $:.unshift File.dirname(__FILE__) + '/../lib'
 require 'thrift'
-require 'thrift/server/nonblockingserver'
 $:.unshift File.dirname(__FILE__) + "/gen-rb"
 require 'BenchmarkService'
 HOST = 'localhost'
@@ -39,7 +38,7 @@
 handler = BenchmarkHandler.new
 processor = ThriftBenchmark::BenchmarkService::Processor.new(handler)
 transport = Thrift::ServerSocket.new(HOST, PORT)
-transportFactory = Thrift::FramedTransportFactory.new
+transport_factory = Thrift::FramedTransportFactory.new
 logger = Logger.new(STDERR)
 logger.level = Logger::WARN
-Thrift::NonblockingServer.new(processor, transport, transportFactory, nil, 20, logger).serve
+Thrift::NonblockingServer.new(processor, transport, transport_factory, nil, 20, logger).serve

Modified: incubator/thrift/trunk/lib/rb/ext/memory_buffer.c
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/ext/memory_buffer.c?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/ext/memory_buffer.c (original)
+++ incubator/thrift/trunk/lib/rb/ext/memory_buffer.c Sat Apr  4 00:58:03 2009
@@ -59,7 +59,7 @@
 }
 
 void Init_memory_buffer() {
-  VALUE thrift_memory_buffer_class = rb_const_get(thrift_module, rb_intern("MemoryBuffer"));
+  VALUE thrift_memory_buffer_class = rb_const_get(thrift_module, rb_intern("MemoryBufferTransport"));
   rb_define_method(thrift_memory_buffer_class, "write", rb_thrift_memory_buffer_write, 1);
   rb_define_method(thrift_memory_buffer_class, "read", rb_thrift_memory_buffer_read, 1);
   

Modified: incubator/thrift/trunk/lib/rb/ext/protocol.c
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/ext/protocol.c?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/ext/protocol.c (original)
+++ incubator/thrift/trunk/lib/rb/ext/protocol.c Sat Apr  4 00:58:03 2009
@@ -144,7 +144,7 @@
 }
 
 void Init_protocol() {
-  VALUE c_protocol = rb_const_get(thrift_module, rb_intern("Protocol"));
+  VALUE c_protocol = rb_const_get(thrift_module, rb_intern("BaseProtocol"));
   
   rb_define_method(c_protocol, "skip", rb_thrift_protocol_skip, 1);
   rb_define_method(c_protocol, "write_message_end", rb_thrift_write_message_end, 0);

Modified: incubator/thrift/trunk/lib/rb/lib/thrift.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift.rb Sat Apr  4 00:58:03 2009
@@ -25,10 +25,35 @@
 require 'thrift/processor'
 require 'thrift/client'
 require 'thrift/struct'
-require 'thrift/protocol'
-require 'thrift/protocol/binaryprotocol'
+
+# serializer
+require 'thrift/serializer/serializer'
+require 'thrift/serializer/deserializer'
+
+# protocol
+require 'thrift/protocol/base_protocol'
+require 'thrift/protocol/binary_protocol'
+require 'thrift/protocol/binary_protocol_accelerated'
 require 'thrift/protocol/compact_protocol'
-require 'thrift/transport'
+
+# transport
+require 'thrift/transport/base_transport'
+require 'thrift/transport/base_server_transport'
 require 'thrift/transport/socket'
-require 'thrift/server'
-require "thrift/thrift_native"
\ No newline at end of file
+require 'thrift/transport/server_socket'
+require 'thrift/transport/unix_socket'
+require 'thrift/transport/unix_server_socket'
+require 'thrift/transport/buffered_transport'
+require 'thrift/transport/framed_transport'
+require 'thrift/transport/http_client_transport'
+require 'thrift/transport/io_stream_transport'
+require 'thrift/transport/memory_buffer_transport'
+
+# server
+require 'thrift/server/base_server'
+require 'thrift/server/nonblocking_server'
+require 'thrift/server/simple_server'
+require 'thrift/server/threaded_server'
+require 'thrift/server/thread_pool_server'
+
+require 'thrift/thrift_native'
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/protocol/base_protocol.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/protocol/base_protocol.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/protocol/base_protocol.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/protocol/base_protocol.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,290 @@
+# 
+# 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.
+# 
+
+# this require is to make generated struct definitions happy
+require 'set'
+
+module Thrift
+  class ProtocolException < Exception
+
+    UNKNOWN = 0
+    INVALID_DATA = 1
+    NEGATIVE_SIZE = 2
+    SIZE_LIMIT = 3
+    BAD_VERSION = 4
+
+    attr_reader :type
+
+    def initialize(type=UNKNOWN, message=nil)
+      super(message)
+      @type = type
+    end
+  end
+
+  class BaseProtocol
+
+    attr_reader :trans
+
+    def initialize(trans)
+      @trans = trans
+    end
+
+    def native?
+      puts "wrong method is being called!"
+      false
+    end
+
+    def write_message_begin(name, type, seqid)
+      raise NotImplementedError
+    end
+
+    def write_message_end; nil; end
+
+    def write_struct_begin(name)
+      raise NotImplementedError
+    end
+
+    def write_struct_end; nil; end
+
+    def write_field_begin(name, type, id)
+      raise NotImplementedError
+    end
+
+    def write_field_end; nil; end
+
+    def write_field_stop
+      raise NotImplementedError
+    end
+
+    def write_map_begin(ktype, vtype, size)
+      raise NotImplementedError
+    end
+
+    def write_map_end; nil; end
+
+    def write_list_begin(etype, size)
+      raise NotImplementedError
+    end
+
+    def write_list_end; nil; end
+
+    def write_set_begin(etype, size)
+      raise NotImplementedError
+    end
+
+    def write_set_end; nil; end
+
+    def write_bool(bool)
+      raise NotImplementedError
+    end
+
+    def write_byte(byte)
+      raise NotImplementedError
+    end
+
+    def write_i16(i16)
+      raise NotImplementedError
+    end
+
+    def write_i32(i32)
+      raise NotImplementedError
+    end
+
+    def write_i64(i64)
+      raise NotImplementedError
+    end
+
+    def write_double(dub)
+      raise NotImplementedError
+    end
+
+    def write_string(str)
+      raise NotImplementedError
+    end
+
+    def read_message_begin
+      raise NotImplementedError
+    end
+
+    def read_message_end; nil; end
+
+    def read_struct_begin
+      raise NotImplementedError
+    end
+
+    def read_struct_end; nil; end
+
+    def read_field_begin
+      raise NotImplementedError
+    end
+
+    def read_field_end; nil; end
+
+    def read_map_begin
+      raise NotImplementedError
+    end
+
+    def read_map_end; nil; end
+
+    def read_list_begin
+      raise NotImplementedError
+    end
+
+    def read_list_end; nil; end
+
+    def read_set_begin
+      raise NotImplementedError
+    end
+
+    def read_set_end; nil; end
+
+    def read_bool
+      raise NotImplementedError
+    end
+
+    def read_byte
+      raise NotImplementedError
+    end
+
+    def read_i16
+      raise NotImplementedError
+    end
+
+    def read_i32
+      raise NotImplementedError
+    end
+
+    def read_i64
+      raise NotImplementedError
+    end
+
+    def read_double
+      raise NotImplementedError
+    end
+
+    def read_string
+      raise NotImplementedError
+    end
+
+    def write_field(name, type, fid, value)
+      write_field_begin(name, type, fid)
+      write_type(type, value)
+      write_field_end
+    end
+
+    def write_type(type, value)
+      case type
+      when Types::BOOL
+        write_bool(value)
+      when Types::BYTE
+        write_byte(value)
+      when Types::DOUBLE
+        write_double(value)
+      when Types::I16
+        write_i16(value)
+      when Types::I32
+        write_i32(value)
+      when Types::I64
+        write_i64(value)
+      when Types::STRING
+        write_string(value)
+      when Types::STRUCT
+        value.write(self)
+      else
+        raise NotImplementedError
+      end
+    end
+
+    def read_type(type)
+      case type
+      when Types::BOOL
+        read_bool
+      when Types::BYTE
+        read_byte
+      when Types::DOUBLE
+        read_double
+      when Types::I16
+        read_i16
+      when Types::I32
+        read_i32
+      when Types::I64
+        read_i64
+      when Types::STRING
+        read_string
+      else
+        raise NotImplementedError
+      end
+    end
+
+    def skip(type)
+      case type
+      when Types::STOP
+        nil
+      when Types::BOOL
+        read_bool
+      when Types::BYTE
+        read_byte
+      when Types::I16
+        read_i16
+      when Types::I32
+        read_i32
+      when Types::I64
+        read_i64
+      when Types::DOUBLE
+        read_double
+      when Types::STRING
+        read_string
+      when Types::STRUCT
+        read_struct_begin
+        while true
+          name, type, id = read_field_begin
+          break if type == Types::STOP
+          skip(type)
+          read_field_end
+        end
+        read_struct_end
+      when Types::MAP
+        ktype, vtype, size = read_map_begin
+        size.times do
+          skip(ktype)
+          skip(vtype)
+        end
+        read_map_end
+      when Types::SET
+        etype, size = read_set_begin
+        size.times do
+          skip(etype)
+        end
+        read_set_end
+      when Types::LIST
+        etype, size = read_list_begin
+        size.times do
+          skip(etype)
+        end
+        read_list_end
+      end
+    end
+  end
+
+  class BaseProtocolFactory
+    def get_protocol(trans)
+      raise NotImplementedError
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,225 @@
+# 
+# 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.
+# 
+
+module Thrift
+  class BinaryProtocol < BaseProtocol
+    VERSION_MASK = 0xffff0000
+    VERSION_1 = 0x80010000
+    TYPE_MASK = 0x000000ff
+    
+    attr_reader :strict_read, :strict_write
+
+    def initialize(trans, strict_read=true, strict_write=true)
+      super(trans)
+      @strict_read = strict_read
+      @strict_write = strict_write
+    end
+
+    def write_message_begin(name, type, seqid)
+      # this is necessary because we added (needed) bounds checking to 
+      # write_i32, and 0x80010000 is too big for that.
+      if strict_write
+        write_i16(VERSION_1 >> 16)
+        write_i16(type)
+        write_string(name)
+        write_i32(seqid)
+      else
+        write_string(name)
+        write_byte(type)
+        write_i32(seqid)
+      end
+    end
+
+    def write_struct_begin(name); nil; end
+
+    def write_field_begin(name, type, id)
+      write_byte(type)
+      write_i16(id)
+    end
+
+    def write_field_stop
+      write_byte(Thrift::Types::STOP)
+    end
+
+    def write_map_begin(ktype, vtype, size)
+      write_byte(ktype)
+      write_byte(vtype)
+      write_i32(size)
+    end
+
+    def write_list_begin(etype, size)
+      write_byte(etype)
+      write_i32(size)
+    end
+
+    def write_set_begin(etype, size)
+      write_byte(etype)
+      write_i32(size)
+    end
+
+    def write_bool(bool)
+      write_byte(bool ? 1 : 0)
+    end
+
+    def write_byte(byte)
+      raise RangeError if byte < -2**31 || byte >= 2**32
+      trans.write([byte].pack('c'))
+    end
+
+    def write_i16(i16)
+      trans.write([i16].pack('n'))
+    end
+
+    def write_i32(i32)
+      raise RangeError if i32 < -2**31 || i32 >= 2**31
+      trans.write([i32].pack('N'))
+    end
+
+    def write_i64(i64)
+      raise RangeError if i64 < -2**63 || i64 >= 2**64
+      hi = i64 >> 32
+      lo = i64 & 0xffffffff
+      trans.write([hi, lo].pack('N2'))
+    end
+
+    def write_double(dub)
+      trans.write([dub].pack('G'))
+    end
+
+    def write_string(str)
+      write_i32(str.length)
+      trans.write(str)
+    end
+
+    def read_message_begin
+      version = read_i32
+      if version < 0
+        if (version & VERSION_MASK != VERSION_1)
+          raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Missing version identifier')
+        end
+        type = version & TYPE_MASK
+        name = read_string
+        seqid = read_i32
+        [name, type, seqid]
+      else
+        if strict_read
+          raise ProtocolException.new(ProtocolException::BAD_VERSION, 'No version identifier, old protocol client?')
+        end
+        name = trans.read_all(version)
+        type = read_byte
+        seqid = read_i32
+        [name, type, seqid]
+      end
+    end
+
+    def read_struct_begin; nil; end
+
+    def read_field_begin
+      type = read_byte
+      if (type == Types::STOP)
+        [nil, type, 0]
+      else
+        id = read_i16
+        [nil, type, id]
+      end
+    end
+
+    def read_map_begin
+      ktype = read_byte
+      vtype = read_byte
+      size = read_i32
+      [ktype, vtype, size]
+    end
+
+    def read_list_begin
+      etype = read_byte
+      size = read_i32
+      [etype, size]
+    end
+
+    def read_set_begin
+      etype = read_byte
+      size = read_i32
+      [etype, size]
+    end
+
+    def read_bool
+      byte = read_byte
+      byte != 0
+    end
+
+    def read_byte
+      dat = trans.read_all(1)
+      val = dat[0].ord
+      if (val > 0x7f)
+        val = 0 - ((val - 1) ^ 0xff)
+      end
+      val
+    end
+
+    def read_i16
+      dat = trans.read_all(2)
+      val, = dat.unpack('n')
+      if (val > 0x7fff)
+        val = 0 - ((val - 1) ^ 0xffff)
+      end
+      val
+    end
+
+    def read_i32
+      dat = trans.read_all(4)
+      val, = dat.unpack('N')
+      if (val > 0x7fffffff)
+        val = 0 - ((val - 1) ^ 0xffffffff)
+      end
+      val
+    end
+
+    def read_i64
+      dat = trans.read_all(8)
+      hi, lo = dat.unpack('N2')
+      if (hi > 0x7fffffff)
+        hi ^= 0xffffffff
+        lo ^= 0xffffffff
+        0 - (hi << 32) - lo - 1
+      else
+        (hi << 32) + lo
+      end
+    end
+
+    def read_double
+      dat = trans.read_all(8)
+      val = dat.unpack('G').first
+      val
+    end
+
+    def read_string
+      sz = read_i32
+      dat = trans.read_all(sz)
+      dat
+    end
+
+  end
+
+  class BinaryProtocolFactory < BaseProtocolFactory
+    def get_protocol(trans)
+      return Thrift::BinaryProtocol.new(trans)
+    end
+  end
+end

Added: incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/protocol/binary_protocol_accelerated.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,35 @@
+# 
+# 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.
+# 
+
+=begin
+The only change required for a transport to support BinaryProtocolAccelerated is to implement 2 methods:
+  * borrow(size), which takes an optional argument and returns atleast _size_ bytes from the transport, 
+                  or the default buffer size if no argument is given
+  * consume!(size), which removes size bytes from the front of the buffer
+
+See MemoryBuffer and BufferedTransport for examples.
+=end
+
+module Thrift
+  class BinaryProtocolAcceleratedFactory < BaseProtocolFactory
+    def get_protocol(trans)
+      BinaryProtocolAccelerated.new(trans)
+    end
+  end
+end

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/protocol/compact_protocol.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/protocol/compact_protocol.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/protocol/compact_protocol.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/protocol/compact_protocol.rb Sat Apr  4 00:58:03 2009
@@ -17,10 +17,8 @@
 # under the License.
 # 
 
-require 'thrift/protocol'
-
 module Thrift
-  class CompactProtocol < Protocol
+  class CompactProtocol < BaseProtocol
 
     PROTOCOL_ID = [0x82].pack('c').unpack('c').first
     VERSION = 1
@@ -416,7 +414,7 @@
     end
   end
 
-  class CompactProtocolFactory < ProtocolFactory
+  class CompactProtocolFactory < BaseProtocolFactory
     def get_protocol(trans)
       CompactProtocol.new(trans)
     end

Added: incubator/thrift/trunk/lib/rb/lib/thrift/serializer/deserializer.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/serializer/deserializer.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/serializer/deserializer.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/serializer/deserializer.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,33 @@
+# 
+# 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.
+# 
+
+module Thrift
+  class Deserializer
+    def initialize(protocol_factory = BinaryProtocolFactory.new)
+      @transport = MemoryBufferTransport.new
+      @protocol = protocol_factory.get_protocol(@transport)
+    end
+
+    def deserialize(base, buffer)
+      @transport.reset_buffer(buffer)
+      base.read(@protocol)
+      base
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/serializer/serializer.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/serializer/serializer.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/serializer/serializer.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/serializer/serializer.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,34 @@
+# 
+# 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.
+# 
+
+module Thrift
+  class Serializer
+    def initialize(protocol_factory = BinaryProtocolFactory.new)
+      @transport = MemoryBufferTransport.new
+      @protocol = protocol_factory.get_protocol(@transport)
+    end
+
+    def serialize(base)
+      @transport.reset_buffer
+      base.write(@protocol)
+      @transport.read(@transport.available)
+    end
+  end
+end
+

Added: incubator/thrift/trunk/lib/rb/lib/thrift/server/base_server.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/server/base_server.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/server/base_server.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/server/base_server.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,31 @@
+# 
+# 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.
+#
+
+module Thrift
+  class BaseServer
+    def initialize(processor, server_transport, transport_factory=nil, protocol_factory=nil)
+      @processor = processor
+      @server_transport = server_transport
+      @transport_factory = transport_factory ? transport_factory : Thrift::BaseTransportFactory.new
+      @protocol_factory = protocol_factory ? protocol_factory : Thrift::BinaryProtocolFactory.new
+    end
+
+    def serve; nil; end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/server/mongrel_http_server.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/server/mongrel_http_server.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/server/mongrel_http_server.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/server/mongrel_http_server.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,58 @@
+# 
+# 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.
+# 
+
+require 'mongrel'
+
+## Sticks a service on a URL, using mongrel to do the HTTP work
+module Thrift
+  class MongrelHTTPServer < BaseServer
+    class Handler < Mongrel::HttpHandler
+      def initialize(processor, protocol_factory)
+        @processor = processor
+        @protocol_factory = protocol_factory
+      end
+
+      def process(request, response)
+        if request.params["REQUEST_METHOD"] == "POST"
+          response.start(200) do |head, out|
+            head["Content-Type"] = "application/x-thrift"
+            transport = IOStreamTransport.new request.body, out
+            protocol = @protocol_factory.get_protocol transport
+            @processor.process protocol, protocol
+          end
+        else
+          response.start(404) { }
+        end
+      end
+    end
+
+    def initialize(processor, opts={})
+      port = opts[:port] || 80
+      ip = opts[:ip] || "0.0.0.0"
+      path = opts[:path] || ""
+      protocol_factory = opts[:protocol_factory] || BinaryProtocolFactory.new
+      @server = Mongrel::HttpServer.new ip, port
+      @server.register "/#{path}", Handler.new(processor, protocol_factory)
+    end
+
+    def serve
+      @server.run.join
+    end
+  end
+end

Added: incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblocking_server.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblocking_server.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblocking_server.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/server/nonblocking_server.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,296 @@
+# 
+# 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.
+# 
+
+require 'logger'
+require 'thread'
+
+module Thrift
+  # this class expects to always use a FramedTransport for reading messages
+  class NonblockingServer < BaseServer
+    def initialize(processor, server_transport, transport_factory=nil, protocol_factory=nil, num=20, logger=nil)
+      super(processor, server_transport, transport_factory, protocol_factory)
+      @num_threads = num
+      if logger.nil?
+        @logger = Logger.new(STDERR)
+        @logger.level = Logger::WARN
+      else
+        @logger = logger
+      end
+      @shutdown_semaphore = Mutex.new
+      @transport_semaphore = Mutex.new
+    end
+
+    def serve
+      @logger.info "Starting #{self}"
+      @server_transport.listen
+      @io_manager = start_io_manager
+
+      begin
+        loop do
+          break if @server_transport.closed?
+          rd, = select([@server_transport], nil, nil, 0.1)
+          next if rd.nil?
+          socket = @server_transport.accept
+          @logger.debug "Accepted socket: #{socket.inspect}"
+          @io_manager.add_connection socket
+        end
+      rescue IOError => e
+      end
+      # we must be shutting down
+      @logger.info "#{self} is shutting down, goodbye"
+    ensure
+      @transport_semaphore.synchronize do
+        @server_transport.close
+      end
+      @io_manager.ensure_closed unless @io_manager.nil?
+    end
+
+    def shutdown(timeout = 0, block = true)
+      @shutdown_semaphore.synchronize do
+        return if @is_shutdown
+        @is_shutdown = true
+      end
+      # nonblocking is intended for calling from within a Handler
+      # but we can't change the order of operations here, so lets thread
+      shutdown_proc = lambda do
+        @io_manager.shutdown(timeout)
+        @transport_semaphore.synchronize do
+          @server_transport.close # this will break the accept loop
+        end
+      end
+      if block
+        shutdown_proc.call
+      else
+        Thread.new &shutdown_proc
+      end
+    end
+
+    private
+
+    def start_io_manager
+      iom = IOManager.new(@processor, @server_transport, @transport_factory, @protocol_factory, @num_threads, @logger)
+      iom.spawn
+      iom
+    end
+
+    class IOManager # :nodoc:
+      DEFAULT_BUFFER = 2**20
+      
+      def initialize(processor, server_transport, transport_factory, protocol_factory, num, logger)
+        @processor = processor
+        @server_transport = server_transport
+        @transport_factory = transport_factory
+        @protocol_factory = protocol_factory
+        @num_threads = num
+        @logger = logger
+        @connections = []
+        @buffers = Hash.new { |h,k| h[k] = '' }
+        @signal_queue = Queue.new
+        @signal_pipes = IO.pipe
+        @signal_pipes[1].sync = true
+        @worker_queue = Queue.new
+        @shutdown_queue = Queue.new
+      end
+
+      def add_connection(socket)
+        signal [:connection, socket]
+      end
+
+      def spawn
+        @iom_thread = Thread.new do
+          @logger.debug "Starting #{self}"
+          run
+        end
+      end
+
+      def shutdown(timeout = 0)
+        @logger.debug "#{self} is shutting down workers"
+        @worker_queue.clear
+        @num_threads.times { @worker_queue.push [:shutdown] }
+        signal [:shutdown, timeout]
+        @shutdown_queue.pop
+        @signal_pipes[0].close
+        @signal_pipes[1].close
+        @logger.debug "#{self} is shutting down, goodbye"
+      end
+
+      def ensure_closed
+        kill_worker_threads if @worker_threads
+        @iom_thread.kill
+      end
+
+      private
+      
+      def run
+        spin_worker_threads
+
+        loop do
+          rd, = select([@signal_pipes[0], *@connections])
+          if rd.delete @signal_pipes[0]
+            break if read_signals == :shutdown
+          end
+          rd.each do |fd|
+            if fd.handle.eof?
+              remove_connection fd
+            else
+              read_connection fd
+            end
+          end
+        end
+        join_worker_threads(@shutdown_timeout)
+      ensure
+        @shutdown_queue.push :shutdown
+      end
+
+      def read_connection(fd)
+        @buffers[fd] << fd.read(DEFAULT_BUFFER)
+        frame = slice_frame!(@buffers[fd])
+        if frame
+          @logger.debug "#{self} is processing a frame"
+          @worker_queue.push [:frame, fd, frame]
+        end
+      end
+
+      def spin_worker_threads
+        @logger.debug "#{self} is spinning up worker threads"
+        @worker_threads = []
+        @num_threads.times do
+          @worker_threads << spin_thread
+        end
+      end
+
+      def spin_thread
+        Worker.new(@processor, @transport_factory, @protocol_factory, @logger, @worker_queue).spawn
+      end
+
+      def signal(msg)
+        @signal_queue << msg
+        @signal_pipes[1].write " "
+      end
+
+      def read_signals
+        # clear the signal pipe
+        # note that since read_nonblock is broken in jruby,
+        # we can only read up to a set number of signals at once
+        sigstr = @signal_pipes[0].readpartial(1024)
+        # now read the signals
+        begin
+          sigstr.length.times do
+            signal, obj = @signal_queue.pop(true)
+            case signal
+            when :connection
+              @connections << obj
+            when :shutdown
+              @shutdown_timeout = obj
+              return :shutdown
+            end
+          end
+        rescue ThreadError
+          # out of signals
+          # note that in a perfect world this would never happen, since we're
+          # only reading the number of signals pushed on the pipe, but given the lack
+          # of locks, in theory we could clear the pipe/queue while a new signal is being
+          # placed on the pipe, at which point our next read_signals would hit this error
+        end
+      end
+
+      def remove_connection(fd)
+        # don't explicitly close it, a thread may still be writing to it
+        @connections.delete fd
+        @buffers.delete fd
+      end
+
+      def join_worker_threads(shutdown_timeout)
+        start = Time.now
+        @worker_threads.each do |t|
+          if shutdown_timeout > 0
+            timeout = (start + shutdown_timeout) - Time.now
+            break if timeout <= 0
+            t.join(timeout)
+          else
+            t.join
+          end
+        end
+        kill_worker_threads
+      end
+
+      def kill_worker_threads
+        @worker_threads.each do |t|
+          t.kill if t.status
+        end
+        @worker_threads.clear
+      end
+
+      def slice_frame!(buf)
+        if buf.length >= 4
+          size = buf.unpack('N').first
+          if buf.length >= size + 4
+            buf.slice!(0, size + 4)
+          else
+            nil
+          end
+        else
+          nil
+        end
+      end
+
+      class Worker # :nodoc:
+        def initialize(processor, transport_factory, protocol_factory, logger, queue)
+          @processor = processor
+          @transport_factory = transport_factory
+          @protocol_factory = protocol_factory
+          @logger = logger
+          @queue = queue
+        end
+
+        def spawn
+          Thread.new do
+            @logger.debug "#{self} is spawning"
+            run
+          end
+        end
+
+        private
+
+        def run
+          loop do
+            cmd, *args = @queue.pop
+            case cmd
+            when :shutdown
+              @logger.debug "#{self} is shutting down, goodbye"
+              break
+            when :frame
+              fd, frame = args
+              begin
+                otrans = @transport_factory.get_transport(fd)
+                oprot = @protocol_factory.get_protocol(otrans)
+                membuf = MemoryBufferTransport.new(frame)
+                itrans = @transport_factory.get_transport(membuf)
+                iprot = @protocol_factory.get_protocol(itrans)
+                @processor.process(iprot, oprot)
+              rescue => e
+                @logger.error "#{Thread.current.inspect} raised error: #{e.inspect}\n#{e.backtrace.join("\n")}"
+              end
+            end
+          end
+        end
+      end
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/server/simple_server.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/server/simple_server.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/server/simple_server.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/server/simple_server.rb Sat Apr  4 00:58:03 2009
@@ -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.
+#
+
+module Thrift
+  class SimpleServer < BaseServer
+    def serve
+      begin
+        @server_transport.listen
+        loop do
+          client = @server_transport.accept
+          trans = @transport_factory.get_transport(client)
+          prot = @protocol_factory.get_protocol(trans)
+          begin
+            loop do
+              @processor.process(prot, prot)
+            end
+          rescue Thrift::TransportException, Thrift::ProtocolException
+          ensure
+            trans.close
+          end
+        end
+      ensure
+        @server_transport.close
+      end
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/server/thread_pool_server.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/server/thread_pool_server.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/server/thread_pool_server.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/server/thread_pool_server.rb Sat Apr  4 00:58:03 2009
@@ -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.
+# 
+
+require 'thread'
+
+module Thrift
+  class ThreadPoolServer < BaseServer
+    def initialize(processor, server_transport, transport_factory=nil, protocol_factory=nil, num=20)
+      super(processor, server_transport, transport_factory, protocol_factory)
+      @thread_q = SizedQueue.new(num)
+      @exception_q = Queue.new
+      @running = false
+    end
+
+    ## exceptions that happen in worker threads will be relayed here and
+    ## must be caught. 'retry' can be used to continue. (threads will
+    ## continue to run while the exception is being handled.)
+    def rescuable_serve
+      Thread.new { serve } unless @running
+      @running = true
+      raise @exception_q.pop
+    end
+
+    ## exceptions that happen in worker threads simply cause that thread
+    ## to die and another to be spawned in its place.
+    def serve
+      @server_transport.listen
+
+      begin
+        loop do
+          @thread_q.push(:token)
+          Thread.new do
+            begin
+              loop do
+                client = @server_transport.accept
+                trans = @transport_factory.get_transport(client)
+                prot = @protocol_factory.get_protocol(trans)
+                begin
+                  loop do
+                    @processor.process(prot, prot)
+                  end
+                rescue Thrift::TransportException, Thrift::ProtocolException => e
+                ensure
+                  trans.close
+                end
+              end
+            rescue => e
+              @exception_q.push(e)
+            ensure
+              @thread_q.pop # thread died!
+            end
+          end
+        end
+      ensure
+        @server_transport.close
+      end
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/server/threaded_server.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/server/threaded_server.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/server/threaded_server.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/server/threaded_server.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,47 @@
+# 
+# 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.
+#
+
+require 'thread'
+
+module Thrift
+  class ThreadedServer < BaseServer
+    def serve
+      begin
+        @server_transport.listen
+        loop do
+          client = @server_transport.accept
+          trans = @transport_factory.get_transport(client)
+          prot = @protocol_factory.get_protocol(trans)
+          Thread.new(prot, trans) do |p, t|
+            begin
+              loop do
+                @processor.process(p, p)
+              end
+            rescue Thrift::TransportException, Thrift::ProtocolException
+            ensure
+              t.close
+            end
+          end
+        end
+      ensure
+        @server_transport.close
+      end
+    end
+  end
+end
\ No newline at end of file

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/struct.rb Sat Apr  4 00:58:03 2009
@@ -17,7 +17,6 @@
 # under the License.
 # 
 
-require 'thrift/types'
 require 'set'
 
 module Thrift

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_server_transport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_server_transport.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_server_transport.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_server_transport.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,37 @@
+# encoding: ascii-8bit
+# 
+# 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.
+# 
+
+module Thrift
+  class BaseServerTransport
+    def listen
+      raise NotImplementedError
+    end
+
+    def accept
+      raise NotImplementedError
+    end
+      
+    def close; nil; end
+
+    def closed?
+      raise NotImplementedError
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_transport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_transport.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_transport.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/base_transport.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,70 @@
+# encoding: ascii-8bit
+# 
+# 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.
+# 
+
+module Thrift
+  class TransportException < Exception
+    UNKNOWN = 0
+    NOT_OPEN = 1
+    ALREADY_OPEN = 2
+    TIMED_OUT = 3
+    END_OF_FILE = 4
+
+    attr_reader :type
+
+    def initialize(type=UNKNOWN, message=nil)
+      super(message)
+      @type = type
+    end
+  end
+
+  class BaseTransport
+    def open?; end
+    
+    def open; end
+
+    def close; end
+
+    def read(sz)
+      raise NotImplementedError
+    end
+
+    def read_all(size)
+      buf = ''
+    
+      while (buf.length < size)
+        chunk = read(size - buf.length)
+        buf << chunk
+      end
+    
+      buf
+    end
+  
+    def write(buf); end
+    alias_method :<<, :write
+
+    def flush; end
+  end
+  
+  class BaseTransportFactory
+    def get_transport(trans)
+      return trans
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/buffered_transport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/buffered_transport.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/buffered_transport.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/buffered_transport.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,77 @@
+# encoding: ascii-8bit
+# 
+# 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.
+#
+
+module Thrift
+  class BufferedTransport < BaseTransport
+    DEFAULT_BUFFER = 4096
+    
+    def initialize(transport)
+      @transport = transport
+      @wbuf = ''
+      @rbuf = ''
+      @index = 0
+    end
+
+    def open?
+      return @transport.open?
+    end
+
+    def open
+      @transport.open
+    end
+
+    def close
+      flush
+      @transport.close
+    end
+
+    def read(sz)
+      @index += sz
+      ret = @rbuf.slice(@index - sz, sz) || ''
+
+      if ret.length == 0
+        @rbuf = @transport.read([sz, DEFAULT_BUFFER].max)
+        @index = sz
+        ret = @rbuf.slice(0, sz) || ''
+      end
+
+      ret
+    end
+
+    def write(buf)
+      @wbuf << buf
+    end
+
+    def flush
+      if @wbuf != ''
+        @transport.write(@wbuf)
+        @wbuf = ''
+      end
+      
+      @transport.flush
+    end
+  end
+
+  class BufferedTransportFactory < BaseTransportFactory
+    def get_transport(transport)
+      return BufferedTransport.new(transport)
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/framed_transport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/framed_transport.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/framed_transport.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/framed_transport.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,90 @@
+# encoding: ascii-8bit
+# 
+# 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.
+#
+
+module Thrift
+  class FramedTransport < BaseTransport
+    def initialize(transport, read=true, write=true)
+      @transport = transport
+      @rbuf      = ''
+      @wbuf      = ''
+      @read      = read
+      @write     = write
+      @index      = 0
+    end
+
+    def open?
+      @transport.open?
+    end
+
+    def open
+      @transport.open
+    end
+
+    def close
+      @transport.close
+    end
+
+    def read(sz)
+      return @transport.read(sz) unless @read
+
+      return '' if sz <= 0
+
+      read_frame if @index >= @rbuf.length
+
+      @index += sz
+      @rbuf.slice(@index - sz, sz) || ''
+    end
+
+    def write(buf,sz=nil)
+      return @transport.write(buf) unless @write
+
+      @wbuf << (sz ? buf[0...sz] : buf)
+    end
+
+    #
+    # Writes the output buffer to the stream in the format of a 4-byte length
+    # followed by the actual data.
+    #
+    def flush
+      return @transport.flush unless @write
+
+      out = [@wbuf.length].pack('N')
+      out << @wbuf
+      @transport.write(out)
+      @transport.flush
+      @wbuf = ''
+    end
+
+    private
+
+    def read_frame
+      sz = @transport.read_all(4).unpack('N').first
+
+      @index = 0
+      @rbuf = @transport.read_all(sz)
+    end
+  end
+
+  class FramedTransportFactory < BaseTransportFactory
+    def get_transport(transport)
+      return FramedTransport.new(transport)
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/http_client_transport.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,45 @@
+# encoding: ascii-8bit
+# 
+# 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.
+# 
+
+require 'net/http'
+require 'net/https'
+require 'uri'
+require 'stringio'
+
+module Thrift
+  class HTTPClientTransport < BaseTransport
+    def initialize(url)
+      @url = URI url
+      @outbuf = ""
+    end
+
+    def open?; true end
+    def read(sz); @inbuf.read sz end
+    def write(buf); @outbuf << buf end
+    def flush
+      http = Net::HTTP.new @url.host, @url.port
+      http.use_ssl = @url.scheme == "https"
+      headers = { 'Content-Type' => 'application/x-thrift' }
+      resp, data = http.post(@url.path, @outbuf, headers)
+      @inbuf = StringIO.new data
+      @outbuf = ""
+    end
+  end
+end

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/io_stream_transport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/io_stream_transport.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/io_stream_transport.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/io_stream_transport.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,39 @@
+# encoding: ascii-8bit
+# 
+# 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.
+#
+
+# Very very simple implementation of wrapping two objects, one with a #read
+# method and one with a #write method, into a transport for thrift.
+#
+# Assumes both objects are open, remain open, don't require flushing, etc.
+#
+module Thrift
+  class IOStreamTransport < BaseTransport
+    def initialize(input, output)
+      @input = input
+      @output = output
+    end
+
+    def open?; not @input.closed? or not @output.closed? end
+    def read(sz); @input.read(sz) end
+    def write(buf); @output.write(buf) end
+    def close; @input.close; @output.close end
+    def to_io; @input end # we're assuming this is used in a IO.select for reading
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,93 @@
+# encoding: ascii-8bit
+# 
+# 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.
+#
+
+module Thrift
+  class MemoryBufferTransport < BaseTransport
+    GARBAGE_BUFFER_SIZE = 4*(2**10) # 4kB
+
+    # If you pass a string to this, you should #dup that string
+    # unless you want it to be modified by #read and #write
+    #--
+    # this behavior is no longer required. If you wish to change it
+    # go ahead, just make sure the specs pass
+    def initialize(buffer = nil)
+      @buf = buffer || ''
+      @index = 0
+    end
+
+    def open?
+      return true
+    end
+
+    def open
+    end
+
+    def close
+    end
+
+    def peek
+      @index < @buf.size
+    end
+
+    # this method does not use the passed object directly but copies it
+    def reset_buffer(new_buf = '')
+      @buf.replace new_buf
+      @index = 0
+    end
+
+    def available
+      @buf.length - @index
+    end
+
+    def read(len)
+      data = @buf.slice(@index, len)
+      @index += len
+      @index = @buf.size if @index > @buf.size
+      if @index >= GARBAGE_BUFFER_SIZE
+        @buf = @buf.slice(@index..-1)
+        @index = 0
+      end
+      data
+    end
+
+    def write(wbuf)
+      @buf << wbuf
+    end
+
+    def flush
+    end
+
+    def inspect_buffer
+      out = []
+      for idx in 0...(@buf.size)
+        # if idx != 0
+        #   out << " "
+        # end
+      
+        if idx == @index
+          out << ">"
+        end
+      
+        out << @buf[idx].to_s(16)
+      end
+      out.join(" ")
+    end
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/server_socket.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/server_socket.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/server_socket.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/server_socket.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,63 @@
+# encoding: ascii-8bit
+# 
+# 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.
+# 
+
+require 'socket'
+
+module Thrift
+  class ServerSocket < BaseServerTransport
+    # call-seq: initialize(host = nil, port)
+    def initialize(host_or_port, port = nil)
+      if port
+        @host = host_or_port
+        @port = port
+      else
+        @host = nil
+        @port = host_or_port
+      end
+      @handle = nil
+    end
+
+    attr_reader :handle
+
+    def listen
+      @handle = TCPServer.new(@host, @port)
+    end
+
+    def accept
+      unless @handle.nil?
+        sock = @handle.accept
+        trans = Socket.new
+        trans.handle = sock
+        trans
+      end
+    end
+
+    def close
+     @handle.close unless @handle.nil? or @handle.closed?
+     @handle = nil
+    end
+
+    def closed?
+      @handle.nil? or @handle.closed?
+    end
+
+    alias to_io handle
+  end
+end
\ No newline at end of file

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/socket.rb Sat Apr  4 00:58:03 2009
@@ -1,3 +1,4 @@
+# encoding: ascii-8bit
 # 
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements. See the NOTICE file
@@ -16,11 +17,11 @@
 # specific language governing permissions and limitations
 # under the License.
 # 
-require 'thrift/transport'
+
 require 'socket'
 
 module Thrift
-  class Socket < Transport
+  class Socket < BaseTransport
     def initialize(host='localhost', port=9090, timeout=nil)
       @host = host
       @port = port
@@ -132,44 +133,4 @@
       @handle
     end
   end
-
-  class ServerSocket < ServerTransport
-    # call-seq: initialize(host = nil, port)
-    def initialize(host_or_port, port = nil)
-      if port
-        @host = host_or_port
-        @port = port
-      else
-        @host = nil
-        @port = host_or_port
-      end
-      @handle = nil
-    end
-
-    attr_reader :handle
-
-    def listen
-      @handle = TCPServer.new(@host, @port)
-    end
-
-    def accept
-      unless @handle.nil?
-        sock = @handle.accept
-        trans = Socket.new
-        trans.handle = sock
-        trans
-      end
-    end
-
-    def close
-     @handle.close unless @handle.nil? or @handle.closed?
-     @handle = nil
-    end
-
-    def closed?
-      @handle.nil? or @handle.closed?
-    end
-
-    alias to_io handle
-  end
-end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_server_socket.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_server_socket.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_server_socket.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_server_socket.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,60 @@
+# encoding: ascii-8bit
+# 
+# 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.
+# 
+
+require 'socket'
+
+module Thrift
+  class UNIXServerSocket < BaseServerTransport
+    def initialize(path)
+      @path = path
+      @handle = nil
+    end
+
+    attr_accessor :handle
+
+    def listen
+      @handle = ::UNIXServer.new(@path)
+    end
+
+    def accept
+      unless @handle.nil?
+        sock = @handle.accept
+        trans = UNIXSocket.new(nil)
+        trans.handle = sock
+        trans
+      end
+    end
+
+    def close
+      if @handle
+        @handle.close unless @handle.closed?
+        @handle = nil
+        # UNIXServer doesn't delete the socket file, so we have to do it ourselves
+        File.delete(@path)
+      end
+    end
+
+    def closed?
+      @handle.nil? or @handle.closed?
+    end
+
+    alias to_io handle
+  end
+end
\ No newline at end of file

Added: incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_socket.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_socket.rb?rev=761849&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_socket.rb (added)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/transport/unix_socket.rb Sat Apr  4 00:58:03 2009
@@ -0,0 +1,40 @@
+# encoding: ascii-8bit
+# 
+# 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.
+# 
+
+require 'socket'
+
+module Thrift
+  class UNIXSocket < Socket
+    def initialize(path, timeout=nil)
+      @path = path
+      @timeout = timeout
+      @desc = @path # for read()'s error
+      @handle = nil
+    end
+
+    def open
+      begin
+        @handle = ::UNIXSocket.new(@path)
+      rescue StandardError
+        raise TransportException.new(TransportException::NOT_OPEN, "Could not open UNIX socket at #{@path}")
+      end
+    end
+  end
+end
\ No newline at end of file

Modified: incubator/thrift/trunk/lib/rb/script/proto_benchmark.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/script/proto_benchmark.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/script/proto_benchmark.rb (original)
+++ incubator/thrift/trunk/lib/rb/script/proto_benchmark.rb Sat Apr  4 00:58:03 2009
@@ -19,7 +19,7 @@
 
 require File.dirname(__FILE__) + "/../spec/spec_helper.rb"
 require "lib/thrift/serializer"
-require "lib/thrift/protocol/binaryprotocolaccelerated"
+require "lib/thrift/protocol/binary_protocol_accelerated"
 
 require "benchmark"
 # require "ruby-prof"
@@ -83,7 +83,7 @@
 
 
   # f = File.new("/tmp/testfile", "w")
-  # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(Thrift::MemoryBuffer.new, f))
+  # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(Thrift::MemoryBufferTransport.new, f))
   # reporter.report("accelerated binary protocol, write (to disk)") do
   #   HOW_MANY.times do
   #     obj.write(proto)
@@ -93,7 +93,7 @@
   # f.close
   #   
   # f = File.new("/tmp/testfile", "r")
-  # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBuffer.new))
+  # proto = Thrift::BinaryProtocolAccelerated.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBufferTransport.new))
   # reporter.report("accelerated binary protocol, read (from disk)") do
   #   HOW_MANY.times do
   #     obj.read(proto)
@@ -103,7 +103,7 @@
   # 
   # f = File.new("/tmp/testfile", "w")
   # reporter.report("compact protocol, write (to disk)") do
-  #   proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(Thrift::MemoryBuffer.new, f))
+  #   proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(Thrift::MemoryBufferTransport.new, f))
   #   HOW_MANY.times do
   #     obj.write(proto)
   #   end
@@ -113,7 +113,7 @@
   # 
   # f = File.new("/tmp/testfile", "r")
   # reporter.report("compact protocol, read (from disk)") do
-  #   proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBuffer.new))
+  #   proto = Thrift::CompactProtocol.new(Thrift::IOStreamTransport.new(f, Thrift::MemoryBufferTransport.new))
   #   HOW_MANY.times do
   #     obj.read(proto)
   #   end

Modified: incubator/thrift/trunk/lib/rb/script/read_struct.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/script/read_struct.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/script/read_struct.rb (original)
+++ incubator/thrift/trunk/lib/rb/script/read_struct.rb Sat Apr  4 00:58:03 2009
@@ -18,7 +18,6 @@
 #
 
 require "spec/spec_helper"
-require "lib/thrift/serializer"
 
 path, factory_class = ARGV
 

Modified: incubator/thrift/trunk/lib/rb/script/write_struct.rb
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/script/write_struct.rb?rev=761849&r1=761848&r2=761849&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/script/write_struct.rb (original)
+++ incubator/thrift/trunk/lib/rb/script/write_struct.rb Sat Apr  4 00:58:03 2009
@@ -18,7 +18,6 @@
 #
 
 require "spec/spec_helper"
-require "lib/thrift/serializer"
 
 path, factory_class = ARGV
 



Mime
View raw message